summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Hertzfeld <andy@src.gnome.org>2001-04-05 20:02:09 +0000
committerAndy Hertzfeld <andy@src.gnome.org>2001-04-05 20:02:09 +0000
commitc0fff8a385e50ad0eae0d4e5ae1d7e5c6a2ef2ae (patch)
tree034fbc996615a5c1a2af304c5a9f78dae6aec19c
parent6d5a64fd438530181185530665ed2b7636e72443 (diff)
downloadnautilus-c0fff8a385e50ad0eae0d4e5ae1d7e5c6a2ef2ae.tar.gz
improved the note sizing, by actually measuring the text and adjusting for
* libnautilus-extensions/nautilus-canvas-note-item.c: (nautilus_canvas_note_item_set_note_text), (draw_item_aa_text), (nautilus_canvas_note_item_draw): improved the note sizing, by actually measuring the text and adjusting for the canvas scale factor. * libnautilus-extensions/nautilus-icon-canvas-item.c: (hit_test): made hit-testing prefer emblems when they overlap the icon, since they're visually on top.
-rw-r--r--ChangeLog12
-rw-r--r--libnautilus-extensions/nautilus-canvas-note-item.c41
-rw-r--r--libnautilus-extensions/nautilus-icon-canvas-item.c29
-rw-r--r--libnautilus-private/nautilus-canvas-note-item.c41
-rw-r--r--libnautilus-private/nautilus-icon-canvas-item.c29
5 files changed, 100 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index 5c930b269..79b0572f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2001-04-05 Andy Hertzfeld <andy@eazel.com>
+
+ * libnautilus-extensions/nautilus-canvas-note-item.c:
+ (nautilus_canvas_note_item_set_note_text), (draw_item_aa_text),
+ (nautilus_canvas_note_item_draw):
+ improved the note sizing, by actually measuring the text and
+ adjusting for the canvas scale factor.
+
+ * libnautilus-extensions/nautilus-icon-canvas-item.c: (hit_test):
+ made hit-testing prefer emblems when they overlap the icon, since
+ they're visually on top.
+
2001-04-04 Andy Hertzfeld <andy@eazel.com>
* libnautilus-extensions/nautilus-annotation.c:
diff --git a/libnautilus-extensions/nautilus-canvas-note-item.c b/libnautilus-extensions/nautilus-canvas-note-item.c
index 8c0e6bdd7..1c8246693 100644
--- a/libnautilus-extensions/nautilus-canvas-note-item.c
+++ b/libnautilus-extensions/nautilus-canvas-note-item.c
@@ -69,6 +69,7 @@ enum {
};
#define ANNOTATION_WIDTH 240
+#define DEFAULT_FONT_SIZE 12
#define LINE_BREAK_CHARACTERS " -_,;.?/&"
static void nautilus_canvas_note_item_class_init (NautilusCanvasNoteItemClass *class);
@@ -318,8 +319,11 @@ static void
nautilus_canvas_note_item_set_note_text (NautilusCanvasNoteItem *note_item, const char *new_text)
{
char *display_text;
- int total_width, height, width;
+ int total_width, height, width, font_height;
GnomeCanvasItem *item;
+ NautilusScalableFont *scalable_font;
+ GdkFont *font;
+ NautilusDimensions dimensions;
item = GNOME_CANVAS_ITEM (note_item);
@@ -334,17 +338,30 @@ nautilus_canvas_note_item_set_note_text (NautilusCanvasNoteItem *note_item, cons
/* this will get more sophisticated as we get fancier */
display_text = nautilus_annotation_get_display_text (new_text);
- total_width = 8 * strlen (display_text);
- height = 16 * (1 + (total_width / ANNOTATION_WIDTH));
-
- if (total_width < ANNOTATION_WIDTH) {
- width = total_width;
+ if (item->canvas->aa) {
+ scalable_font = nautilus_scalable_font_get_default_font ();
+ dimensions = nautilus_scalable_font_measure_text (scalable_font,
+ DEFAULT_FONT_SIZE,
+ display_text,
+ strlen (display_text));
+ total_width = dimensions.width + 8;
+ height = dimensions.height * (1 + (total_width / ANNOTATION_WIDTH));
+ gtk_object_unref (GTK_OBJECT (scalable_font));
} else {
- width = ANNOTATION_WIDTH;
+ font = nautilus_font_factory_get_font_from_preferences (DEFAULT_FONT_SIZE);
+ total_width = 8 + gdk_text_measure (font, display_text, strlen (display_text));
+ font_height = gdk_text_height (font, display_text, strlen (display_text));
+ height = font_height * (1 + (total_width / ANNOTATION_WIDTH));
+ gdk_font_unref (font);
}
-
- note_item->x2 = note_item->x1 + width;
- note_item->y2 = note_item->y1 + height + 4; /* room for descenders */
+
+ width = (total_width < ANNOTATION_WIDTH) ? total_width : ANNOTATION_WIDTH;
+
+ /* add some vertical slop for descenders and incorporate scale factor */
+ note_item->x2 = note_item->x1 + (width / item->canvas->pixels_per_unit);
+ note_item->y2 = note_item->y1 + 4.0 + (height / item->canvas->pixels_per_unit);
+
+
update_item_bounding_box (note_item);
g_free (display_text);
@@ -703,7 +720,7 @@ draw_item_aa_text (GnomeCanvasBuf *buf, GnomeCanvasItem *item, const char *note_
smooth_text_layout = nautilus_smooth_text_layout_new (
note_text, strlen(note_text),
- font, 12, TRUE);
+ font, DEFAULT_FONT_SIZE, TRUE);
nautilus_smooth_text_layout_set_line_wrap_width (smooth_text_layout, width - 4);
@@ -798,7 +815,7 @@ nautilus_canvas_note_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, in
/* draw the annotation text */
if (note_item->note_text) {
- font = nautilus_font_factory_get_font_from_preferences (12);
+ font = nautilus_font_factory_get_font_from_preferences (DEFAULT_FONT_SIZE);
display_text = nautilus_annotation_get_display_text (note_item->note_text);
text_info = gnome_icon_layout_text
diff --git a/libnautilus-extensions/nautilus-icon-canvas-item.c b/libnautilus-extensions/nautilus-icon-canvas-item.c
index 66f13046a..faa783016 100644
--- a/libnautilus-extensions/nautilus-icon-canvas-item.c
+++ b/libnautilus-extensions/nautilus-icon-canvas-item.c
@@ -2129,6 +2129,21 @@ hit_test (NautilusIconCanvasItem *icon_item, const ArtIRect *canvas_rect, HitTyp
/* Check for hit in the icon. If we're highlighted for dropping, anywhere in the rect is OK */
get_icon_canvas_rectangle (icon_item, &icon_rect);
+
+ /* Check for hit in the emblem pixbufs first, since they appear on top of the icon. */
+ emblem_layout_reset (&emblem_layout, icon_item, &icon_item->details->canvas_rect);
+ while (emblem_layout_next (&emblem_layout, &emblem_pixbuf, &emblem_rect)) {
+ if (hit_test_pixbuf (emblem_pixbuf, &emblem_rect, canvas_rect)) {
+ if (hit_type != NULL) {
+ *hit_type = EMBLEM_HIT;
+ }
+ if (hit_index != NULL) {
+ *hit_index = emblem_layout.index;
+ }
+ return TRUE;
+ }
+ }
+
if (hit_type != NULL) {
*hit_type = ICON_HIT;
}
@@ -2152,20 +2167,6 @@ hit_test (NautilusIconCanvasItem *icon_item, const ArtIRect *canvas_rect, HitTyp
return TRUE;
}
- /* Check for hit in the emblem pixbufs. */
- emblem_layout_reset (&emblem_layout, icon_item, &icon_item->details->canvas_rect);
- while (emblem_layout_next (&emblem_layout, &emblem_pixbuf, &emblem_rect)) {
- if (hit_test_pixbuf (emblem_pixbuf, &emblem_rect, canvas_rect)) {
- if (hit_type != NULL) {
- *hit_type = EMBLEM_HIT;
- }
- if (hit_index != NULL) {
- *hit_index = emblem_layout.index;
- }
- return TRUE;
- }
- }
-
/* there wasn't a hit, so indicate that */
if (hit_type != NULL) {
*hit_type = NO_HIT;
diff --git a/libnautilus-private/nautilus-canvas-note-item.c b/libnautilus-private/nautilus-canvas-note-item.c
index 8c0e6bdd7..1c8246693 100644
--- a/libnautilus-private/nautilus-canvas-note-item.c
+++ b/libnautilus-private/nautilus-canvas-note-item.c
@@ -69,6 +69,7 @@ enum {
};
#define ANNOTATION_WIDTH 240
+#define DEFAULT_FONT_SIZE 12
#define LINE_BREAK_CHARACTERS " -_,;.?/&"
static void nautilus_canvas_note_item_class_init (NautilusCanvasNoteItemClass *class);
@@ -318,8 +319,11 @@ static void
nautilus_canvas_note_item_set_note_text (NautilusCanvasNoteItem *note_item, const char *new_text)
{
char *display_text;
- int total_width, height, width;
+ int total_width, height, width, font_height;
GnomeCanvasItem *item;
+ NautilusScalableFont *scalable_font;
+ GdkFont *font;
+ NautilusDimensions dimensions;
item = GNOME_CANVAS_ITEM (note_item);
@@ -334,17 +338,30 @@ nautilus_canvas_note_item_set_note_text (NautilusCanvasNoteItem *note_item, cons
/* this will get more sophisticated as we get fancier */
display_text = nautilus_annotation_get_display_text (new_text);
- total_width = 8 * strlen (display_text);
- height = 16 * (1 + (total_width / ANNOTATION_WIDTH));
-
- if (total_width < ANNOTATION_WIDTH) {
- width = total_width;
+ if (item->canvas->aa) {
+ scalable_font = nautilus_scalable_font_get_default_font ();
+ dimensions = nautilus_scalable_font_measure_text (scalable_font,
+ DEFAULT_FONT_SIZE,
+ display_text,
+ strlen (display_text));
+ total_width = dimensions.width + 8;
+ height = dimensions.height * (1 + (total_width / ANNOTATION_WIDTH));
+ gtk_object_unref (GTK_OBJECT (scalable_font));
} else {
- width = ANNOTATION_WIDTH;
+ font = nautilus_font_factory_get_font_from_preferences (DEFAULT_FONT_SIZE);
+ total_width = 8 + gdk_text_measure (font, display_text, strlen (display_text));
+ font_height = gdk_text_height (font, display_text, strlen (display_text));
+ height = font_height * (1 + (total_width / ANNOTATION_WIDTH));
+ gdk_font_unref (font);
}
-
- note_item->x2 = note_item->x1 + width;
- note_item->y2 = note_item->y1 + height + 4; /* room for descenders */
+
+ width = (total_width < ANNOTATION_WIDTH) ? total_width : ANNOTATION_WIDTH;
+
+ /* add some vertical slop for descenders and incorporate scale factor */
+ note_item->x2 = note_item->x1 + (width / item->canvas->pixels_per_unit);
+ note_item->y2 = note_item->y1 + 4.0 + (height / item->canvas->pixels_per_unit);
+
+
update_item_bounding_box (note_item);
g_free (display_text);
@@ -703,7 +720,7 @@ draw_item_aa_text (GnomeCanvasBuf *buf, GnomeCanvasItem *item, const char *note_
smooth_text_layout = nautilus_smooth_text_layout_new (
note_text, strlen(note_text),
- font, 12, TRUE);
+ font, DEFAULT_FONT_SIZE, TRUE);
nautilus_smooth_text_layout_set_line_wrap_width (smooth_text_layout, width - 4);
@@ -798,7 +815,7 @@ nautilus_canvas_note_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, in
/* draw the annotation text */
if (note_item->note_text) {
- font = nautilus_font_factory_get_font_from_preferences (12);
+ font = nautilus_font_factory_get_font_from_preferences (DEFAULT_FONT_SIZE);
display_text = nautilus_annotation_get_display_text (note_item->note_text);
text_info = gnome_icon_layout_text
diff --git a/libnautilus-private/nautilus-icon-canvas-item.c b/libnautilus-private/nautilus-icon-canvas-item.c
index 66f13046a..faa783016 100644
--- a/libnautilus-private/nautilus-icon-canvas-item.c
+++ b/libnautilus-private/nautilus-icon-canvas-item.c
@@ -2129,6 +2129,21 @@ hit_test (NautilusIconCanvasItem *icon_item, const ArtIRect *canvas_rect, HitTyp
/* Check for hit in the icon. If we're highlighted for dropping, anywhere in the rect is OK */
get_icon_canvas_rectangle (icon_item, &icon_rect);
+
+ /* Check for hit in the emblem pixbufs first, since they appear on top of the icon. */
+ emblem_layout_reset (&emblem_layout, icon_item, &icon_item->details->canvas_rect);
+ while (emblem_layout_next (&emblem_layout, &emblem_pixbuf, &emblem_rect)) {
+ if (hit_test_pixbuf (emblem_pixbuf, &emblem_rect, canvas_rect)) {
+ if (hit_type != NULL) {
+ *hit_type = EMBLEM_HIT;
+ }
+ if (hit_index != NULL) {
+ *hit_index = emblem_layout.index;
+ }
+ return TRUE;
+ }
+ }
+
if (hit_type != NULL) {
*hit_type = ICON_HIT;
}
@@ -2152,20 +2167,6 @@ hit_test (NautilusIconCanvasItem *icon_item, const ArtIRect *canvas_rect, HitTyp
return TRUE;
}
- /* Check for hit in the emblem pixbufs. */
- emblem_layout_reset (&emblem_layout, icon_item, &icon_item->details->canvas_rect);
- while (emblem_layout_next (&emblem_layout, &emblem_pixbuf, &emblem_rect)) {
- if (hit_test_pixbuf (emblem_pixbuf, &emblem_rect, canvas_rect)) {
- if (hit_type != NULL) {
- *hit_type = EMBLEM_HIT;
- }
- if (hit_index != NULL) {
- *hit_index = emblem_layout.index;
- }
- return TRUE;
- }
- }
-
/* there wasn't a hit, so indicate that */
if (hit_type != NULL) {
*hit_type = NO_HIT;