diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-annotation.c | 1 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-canvas-note-item.c | 135 | ||||
-rw-r--r-- | libnautilus-extensions/nautilus-icon-canvas-item.c | 42 | ||||
-rw-r--r-- | libnautilus-private/nautilus-annotation.c | 1 | ||||
-rw-r--r-- | libnautilus-private/nautilus-canvas-note-item.c | 135 | ||||
-rw-r--r-- | libnautilus-private/nautilus-icon-canvas-item.c | 42 |
7 files changed, 230 insertions, 144 deletions
@@ -1,5 +1,23 @@ 2001-04-09 Andy Hertzfeld <andy@eazel.com> + implemented arrow pointer for annotations, to make it more + clear what they're annotating. + + * libnautilus-extensions/nautilus-annotation.c: + (nautilus_annotation_send_to_server): + removed debugging message + + * libnautilus-extensions/nautilus-canvas-note-item.c: + (nautilus_canvas_note_item_set_note_text), (draw_item_aa_text), + (nautilus_canvas_note_item_update): + draw the arrow pointer + + * libnautilus-extensions/nautilus-icon-canvas-item.c: + (create_annotation), (get_emblem_rectangle): + position the annotation so the arrow points at the right place. + +2001-04-09 Andy Hertzfeld <andy@eazel.com> + * libnautilus-extensions/Makefile.am: linked with ammonite so we can get the user name * libnautilus-extensions/nautilus-annotation.c: diff --git a/libnautilus-extensions/nautilus-annotation.c b/libnautilus-extensions/nautilus-annotation.c index 756046f2d..07a2d8512 100644 --- a/libnautilus-extensions/nautilus-annotation.c +++ b/libnautilus-extensions/nautilus-annotation.c @@ -1173,7 +1173,6 @@ nautilus_annotation_send_to_server (const char *digest, /* post the annotation request to the server using ghttp */ xmlDocDumpMemory (xml_document, &request_text, &request_size); - g_message ("posted request is %s", request_text); if (!http_post_simple (SERVER_POST_URI, "note", request_text)) { g_message ("post request failed"); } diff --git a/libnautilus-extensions/nautilus-canvas-note-item.c b/libnautilus-extensions/nautilus-canvas-note-item.c index 6e0d0feb9..603f6cc25 100644 --- a/libnautilus-extensions/nautilus-canvas-note-item.c +++ b/libnautilus-extensions/nautilus-canvas-note-item.c @@ -72,6 +72,10 @@ enum { #define DEFAULT_FONT_SIZE 12 #define LINE_BREAK_CHARACTERS " -_,;.?/&" +#define ARROW_HEIGHT 16 +#define MIN_ARROW_HALF_WIDTH 4 +#define MAX_ARROW_HALF_WIDTH 12 + static void nautilus_canvas_note_item_class_init (NautilusCanvasNoteItemClass *class); static void nautilus_canvas_note_item_init (NautilusCanvasNoteItem *note_item); static void nautilus_canvas_note_item_destroy (GtkObject *object); @@ -346,6 +350,7 @@ nautilus_canvas_note_item_set_note_text (NautilusCanvasNoteItem *note_item, cons strlen (display_text)); total_width = dimensions.width + 8; height = dimensions.height * (1 + (total_width / ANNOTATION_WIDTH)); + height += ARROW_HEIGHT; gtk_object_unref (GTK_OBJECT (scalable_font)); } else { font = nautilus_font_factory_get_font_from_preferences (DEFAULT_FONT_SIZE); @@ -725,7 +730,7 @@ draw_item_aa_text (GnomeCanvasBuf *buf, GnomeCanvasItem *item, const char *note_ eel_smooth_text_layout_set_line_wrap_width (smooth_text_layout, width - 4); dest_bounds.x0 = 0; - dest_bounds.y0 = 0; + dest_bounds.y0 = ARROW_HEIGHT; dest_bounds.x1 = width; dest_bounds.y1 = height; @@ -928,12 +933,13 @@ static void nautilus_canvas_note_item_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags) { NautilusCanvasNoteItem *note_item; - ArtVpath vpath[11]; + ArtVpath vpath[9]; ArtVpath *vpath2; ArtSVP *stroke_svp; double x0, y0, x1, y1; - - + double round_off_amount; + double midpoint; + double arrow_half_width; note_item = NAUTILUS_CANVAS_NOTE_ITEM (item); if (note_item_parent_class->update) @@ -941,79 +947,66 @@ nautilus_canvas_note_item_update (GnomeCanvasItem *item, double affine[6], ArtSV if (item->canvas->aa) { x0 = note_item->x1; - y0 = note_item->y1; + y0 = note_item->y1 + ARROW_HEIGHT; x1 = note_item->x2; y1 = note_item->y2; + round_off_amount = item->canvas->pixels_per_unit; + gnome_canvas_item_reset_bounds (item); + midpoint = (x1 + x0) / 2; + arrow_half_width = (x1 - x0) / 16; + arrow_half_width = CLAMP (arrow_half_width, MIN_ARROW_HALF_WIDTH, MAX_ARROW_HALF_WIDTH); + + vpath[0].code = ART_MOVETO; + vpath[0].x = x0 - round_off_amount; + vpath[0].y = y0 - round_off_amount; + + vpath[1].code = ART_LINETO; + vpath[1].x = x0 - round_off_amount; + vpath[1].y = y1 + round_off_amount; + + vpath[2].code = ART_LINETO; + vpath[2].x = x1 + round_off_amount; + vpath[2].y = y1 + round_off_amount; + + vpath[3].code = ART_LINETO; + vpath[3].x = x1 + round_off_amount; + vpath[3].y = y0 - round_off_amount; - if (note_item->fill_set) { - vpath[0].code = ART_MOVETO; - vpath[0].x = x0; - vpath[0].y = y0; - vpath[1].code = ART_LINETO; - vpath[1].x = x0; - vpath[1].y = y1; - vpath[2].code = ART_LINETO; - vpath[2].x = x1; - vpath[2].y = y1; - vpath[3].code = ART_LINETO; - vpath[3].x = x1; - vpath[3].y = y0; - vpath[4].code = ART_LINETO; - vpath[4].x = x0; - vpath[4].y = y0; - vpath[5].code = ART_END; - vpath[5].x = 0; - vpath[5].y = 0; - - vpath2 = art_vpath_affine_transform (vpath, affine); - - gnome_canvas_item_update_svp_clip (item, ¬e_item->fill_svp, art_svp_from_vpath (vpath2), clip_path); - art_free (vpath2); - } else - gnome_canvas_item_update_svp (item, ¬e_item->fill_svp, NULL); - - if (note_item->outline_set) { - /* If the item is filled, the vpath will - * already be built so whats the point in - * rebuilding it? If its not already built - * then lets build it. */ - - if (!note_item->fill_set) { - vpath[0].code = ART_MOVETO; - vpath[0].x = x0; - vpath[0].y = y0; - vpath[1].code = ART_LINETO; - vpath[1].x = x0; - vpath[1].y = y1; - vpath[2].code = ART_LINETO; - vpath[2].x = x1; - vpath[2].y = y1; - vpath[3].code = ART_LINETO; - vpath[3].x = x1; - vpath[3].y = y0; - vpath[4].code = ART_LINETO; - vpath[4].x = x0; - vpath[4].y = y0; - vpath[5].code = ART_END; - vpath[5].x = 0; - vpath[5].y = 0; - } - - vpath2 = art_vpath_affine_transform (vpath, affine); + vpath[4].code = ART_LINETO; + vpath[4].x = midpoint + arrow_half_width + round_off_amount; + vpath[4].y = y0 - round_off_amount; + + vpath[5].code = ART_LINETO; + vpath[5].x = midpoint + round_off_amount; + vpath[5].y = note_item->y1 - round_off_amount; + + vpath[6].code = ART_LINETO; + vpath[6].x = midpoint - arrow_half_width - round_off_amount; + vpath[6].y = y0 - round_off_amount; + + vpath[7].code = ART_LINETO; + vpath[7].x = x0 - round_off_amount; + vpath[7].y = y0 - round_off_amount; + + vpath[8].code = ART_END; + vpath[8].x = 0; + vpath[8].y = 0; + + vpath2 = art_vpath_affine_transform (vpath, affine); + + gnome_canvas_item_update_svp_clip (item, ¬e_item->fill_svp, art_svp_from_vpath (vpath2), clip_path); - stroke_svp = art_svp_vpath_stroke (vpath2, - ART_PATH_STROKE_JOIN_MITER, - ART_PATH_STROKE_CAP_BUTT, - (note_item->width_pixels) ? note_item->width : (note_item->width * item->canvas->pixels_per_unit), - 4, - 0.25); - - gnome_canvas_item_update_svp_clip (item, ¬e_item->outline_svp, stroke_svp, clip_path); - art_free (vpath2); - } else - gnome_canvas_item_update_svp (item, ¬e_item->outline_svp, NULL); + stroke_svp = art_svp_vpath_stroke (vpath2, + ART_PATH_STROKE_JOIN_MITER, + ART_PATH_STROKE_CAP_BUTT, + (note_item->width_pixels) ? note_item->width : (note_item->width * item->canvas->pixels_per_unit), + 4, + 25); + + gnome_canvas_item_update_svp_clip (item, ¬e_item->outline_svp, stroke_svp, clip_path); + art_free (vpath2); eel_gnome_canvas_item_request_redraw (GNOME_CANVAS_ITEM (item)); diff --git a/libnautilus-extensions/nautilus-icon-canvas-item.c b/libnautilus-extensions/nautilus-icon-canvas-item.c index 40cd1f8a3..423f4066a 100644 --- a/libnautilus-extensions/nautilus-icon-canvas-item.c +++ b/libnautilus-extensions/nautilus-icon-canvas-item.c @@ -231,6 +231,10 @@ static void emblem_layout_reset (EmblemLayout static gboolean emblem_layout_next (EmblemLayout *layout, GdkPixbuf **emblem_pixbuf, ArtIRect *emblem_rect); +static void get_emblem_rectangle (NautilusIconCanvasItem *icon_item, + int which_emblem, + ArtIRect *rect); + static void draw_pixbuf (GdkPixbuf *pixbuf, GdkDrawable *drawable, int x, @@ -1872,7 +1876,10 @@ create_annotation (NautilusIconCanvasItem *icon_item, int emblem_index) { uint fill_color, outline_color; double top, left; + double delta_x, delta_y; ArtDRect icon_rect; + ArtIRect emblem_rect; + int annotation_width; char *note_text; GnomeCanvas *canvas; GnomeCanvasItem *item; @@ -1902,6 +1909,19 @@ create_annotation (NautilusIconCanvasItem *icon_item, int emblem_index) NULL); g_free (note_text); + + /* reposition the item now that it's had a chance to be properly sized */ + if (canvas->aa) { + get_emblem_rectangle (icon_item, emblem_index, &emblem_rect); + annotation_width = icon_item->details->annotation->x2 - icon_item->details->annotation->x1; + left = ((emblem_rect.x1 + emblem_rect.x0) / 2) - (annotation_width / 2.0 ); + top = (emblem_rect.y1 + emblem_rect.y0) / 2; + + delta_x = left - icon_item->details->annotation->x1; + delta_y = top - icon_item->details->annotation->y1; + gnome_canvas_item_move (icon_item->details->annotation, delta_x, delta_y); + } + gnome_canvas_item_raise_to_top (icon_item->details->annotation); } @@ -2276,6 +2296,28 @@ nautilus_icon_canvas_item_get_icon_rectangle (NautilusIconCanvasItem *item, rect->y1 = rect->y0 + (pixbuf == NULL ? 0 : nautilus_icon_canvas_item_get_icon_height (item)) / pixels_per_unit; } +static void +get_emblem_rectangle (NautilusIconCanvasItem *icon_item, + int which_emblem, + ArtIRect *rect) +{ + EmblemLayout emblem_layout; + GdkPixbuf *pixbuf; + int emblem_index; + + emblem_layout_reset (&emblem_layout, icon_item, &icon_item->details->canvas_rect); + emblem_index = 0; + + rect->x0 = 0; + rect->y0 = 0; + rect->x1 = 0; + rect->y1 = 0; + + while (emblem_index < which_emblem && emblem_layout_next (&emblem_layout, &pixbuf, rect)) { + emblem_index += 1; + } +} + /* Get the rectangle of the icon only, in canvas coordinates. */ static void get_icon_canvas_rectangle (NautilusIconCanvasItem *item, diff --git a/libnautilus-private/nautilus-annotation.c b/libnautilus-private/nautilus-annotation.c index 756046f2d..07a2d8512 100644 --- a/libnautilus-private/nautilus-annotation.c +++ b/libnautilus-private/nautilus-annotation.c @@ -1173,7 +1173,6 @@ nautilus_annotation_send_to_server (const char *digest, /* post the annotation request to the server using ghttp */ xmlDocDumpMemory (xml_document, &request_text, &request_size); - g_message ("posted request is %s", request_text); if (!http_post_simple (SERVER_POST_URI, "note", request_text)) { g_message ("post request failed"); } diff --git a/libnautilus-private/nautilus-canvas-note-item.c b/libnautilus-private/nautilus-canvas-note-item.c index 6e0d0feb9..603f6cc25 100644 --- a/libnautilus-private/nautilus-canvas-note-item.c +++ b/libnautilus-private/nautilus-canvas-note-item.c @@ -72,6 +72,10 @@ enum { #define DEFAULT_FONT_SIZE 12 #define LINE_BREAK_CHARACTERS " -_,;.?/&" +#define ARROW_HEIGHT 16 +#define MIN_ARROW_HALF_WIDTH 4 +#define MAX_ARROW_HALF_WIDTH 12 + static void nautilus_canvas_note_item_class_init (NautilusCanvasNoteItemClass *class); static void nautilus_canvas_note_item_init (NautilusCanvasNoteItem *note_item); static void nautilus_canvas_note_item_destroy (GtkObject *object); @@ -346,6 +350,7 @@ nautilus_canvas_note_item_set_note_text (NautilusCanvasNoteItem *note_item, cons strlen (display_text)); total_width = dimensions.width + 8; height = dimensions.height * (1 + (total_width / ANNOTATION_WIDTH)); + height += ARROW_HEIGHT; gtk_object_unref (GTK_OBJECT (scalable_font)); } else { font = nautilus_font_factory_get_font_from_preferences (DEFAULT_FONT_SIZE); @@ -725,7 +730,7 @@ draw_item_aa_text (GnomeCanvasBuf *buf, GnomeCanvasItem *item, const char *note_ eel_smooth_text_layout_set_line_wrap_width (smooth_text_layout, width - 4); dest_bounds.x0 = 0; - dest_bounds.y0 = 0; + dest_bounds.y0 = ARROW_HEIGHT; dest_bounds.x1 = width; dest_bounds.y1 = height; @@ -928,12 +933,13 @@ static void nautilus_canvas_note_item_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags) { NautilusCanvasNoteItem *note_item; - ArtVpath vpath[11]; + ArtVpath vpath[9]; ArtVpath *vpath2; ArtSVP *stroke_svp; double x0, y0, x1, y1; - - + double round_off_amount; + double midpoint; + double arrow_half_width; note_item = NAUTILUS_CANVAS_NOTE_ITEM (item); if (note_item_parent_class->update) @@ -941,79 +947,66 @@ nautilus_canvas_note_item_update (GnomeCanvasItem *item, double affine[6], ArtSV if (item->canvas->aa) { x0 = note_item->x1; - y0 = note_item->y1; + y0 = note_item->y1 + ARROW_HEIGHT; x1 = note_item->x2; y1 = note_item->y2; + round_off_amount = item->canvas->pixels_per_unit; + gnome_canvas_item_reset_bounds (item); + midpoint = (x1 + x0) / 2; + arrow_half_width = (x1 - x0) / 16; + arrow_half_width = CLAMP (arrow_half_width, MIN_ARROW_HALF_WIDTH, MAX_ARROW_HALF_WIDTH); + + vpath[0].code = ART_MOVETO; + vpath[0].x = x0 - round_off_amount; + vpath[0].y = y0 - round_off_amount; + + vpath[1].code = ART_LINETO; + vpath[1].x = x0 - round_off_amount; + vpath[1].y = y1 + round_off_amount; + + vpath[2].code = ART_LINETO; + vpath[2].x = x1 + round_off_amount; + vpath[2].y = y1 + round_off_amount; + + vpath[3].code = ART_LINETO; + vpath[3].x = x1 + round_off_amount; + vpath[3].y = y0 - round_off_amount; - if (note_item->fill_set) { - vpath[0].code = ART_MOVETO; - vpath[0].x = x0; - vpath[0].y = y0; - vpath[1].code = ART_LINETO; - vpath[1].x = x0; - vpath[1].y = y1; - vpath[2].code = ART_LINETO; - vpath[2].x = x1; - vpath[2].y = y1; - vpath[3].code = ART_LINETO; - vpath[3].x = x1; - vpath[3].y = y0; - vpath[4].code = ART_LINETO; - vpath[4].x = x0; - vpath[4].y = y0; - vpath[5].code = ART_END; - vpath[5].x = 0; - vpath[5].y = 0; - - vpath2 = art_vpath_affine_transform (vpath, affine); - - gnome_canvas_item_update_svp_clip (item, ¬e_item->fill_svp, art_svp_from_vpath (vpath2), clip_path); - art_free (vpath2); - } else - gnome_canvas_item_update_svp (item, ¬e_item->fill_svp, NULL); - - if (note_item->outline_set) { - /* If the item is filled, the vpath will - * already be built so whats the point in - * rebuilding it? If its not already built - * then lets build it. */ - - if (!note_item->fill_set) { - vpath[0].code = ART_MOVETO; - vpath[0].x = x0; - vpath[0].y = y0; - vpath[1].code = ART_LINETO; - vpath[1].x = x0; - vpath[1].y = y1; - vpath[2].code = ART_LINETO; - vpath[2].x = x1; - vpath[2].y = y1; - vpath[3].code = ART_LINETO; - vpath[3].x = x1; - vpath[3].y = y0; - vpath[4].code = ART_LINETO; - vpath[4].x = x0; - vpath[4].y = y0; - vpath[5].code = ART_END; - vpath[5].x = 0; - vpath[5].y = 0; - } - - vpath2 = art_vpath_affine_transform (vpath, affine); + vpath[4].code = ART_LINETO; + vpath[4].x = midpoint + arrow_half_width + round_off_amount; + vpath[4].y = y0 - round_off_amount; + + vpath[5].code = ART_LINETO; + vpath[5].x = midpoint + round_off_amount; + vpath[5].y = note_item->y1 - round_off_amount; + + vpath[6].code = ART_LINETO; + vpath[6].x = midpoint - arrow_half_width - round_off_amount; + vpath[6].y = y0 - round_off_amount; + + vpath[7].code = ART_LINETO; + vpath[7].x = x0 - round_off_amount; + vpath[7].y = y0 - round_off_amount; + + vpath[8].code = ART_END; + vpath[8].x = 0; + vpath[8].y = 0; + + vpath2 = art_vpath_affine_transform (vpath, affine); + + gnome_canvas_item_update_svp_clip (item, ¬e_item->fill_svp, art_svp_from_vpath (vpath2), clip_path); - stroke_svp = art_svp_vpath_stroke (vpath2, - ART_PATH_STROKE_JOIN_MITER, - ART_PATH_STROKE_CAP_BUTT, - (note_item->width_pixels) ? note_item->width : (note_item->width * item->canvas->pixels_per_unit), - 4, - 0.25); - - gnome_canvas_item_update_svp_clip (item, ¬e_item->outline_svp, stroke_svp, clip_path); - art_free (vpath2); - } else - gnome_canvas_item_update_svp (item, ¬e_item->outline_svp, NULL); + stroke_svp = art_svp_vpath_stroke (vpath2, + ART_PATH_STROKE_JOIN_MITER, + ART_PATH_STROKE_CAP_BUTT, + (note_item->width_pixels) ? note_item->width : (note_item->width * item->canvas->pixels_per_unit), + 4, + 25); + + gnome_canvas_item_update_svp_clip (item, ¬e_item->outline_svp, stroke_svp, clip_path); + art_free (vpath2); eel_gnome_canvas_item_request_redraw (GNOME_CANVAS_ITEM (item)); diff --git a/libnautilus-private/nautilus-icon-canvas-item.c b/libnautilus-private/nautilus-icon-canvas-item.c index 40cd1f8a3..423f4066a 100644 --- a/libnautilus-private/nautilus-icon-canvas-item.c +++ b/libnautilus-private/nautilus-icon-canvas-item.c @@ -231,6 +231,10 @@ static void emblem_layout_reset (EmblemLayout static gboolean emblem_layout_next (EmblemLayout *layout, GdkPixbuf **emblem_pixbuf, ArtIRect *emblem_rect); +static void get_emblem_rectangle (NautilusIconCanvasItem *icon_item, + int which_emblem, + ArtIRect *rect); + static void draw_pixbuf (GdkPixbuf *pixbuf, GdkDrawable *drawable, int x, @@ -1872,7 +1876,10 @@ create_annotation (NautilusIconCanvasItem *icon_item, int emblem_index) { uint fill_color, outline_color; double top, left; + double delta_x, delta_y; ArtDRect icon_rect; + ArtIRect emblem_rect; + int annotation_width; char *note_text; GnomeCanvas *canvas; GnomeCanvasItem *item; @@ -1902,6 +1909,19 @@ create_annotation (NautilusIconCanvasItem *icon_item, int emblem_index) NULL); g_free (note_text); + + /* reposition the item now that it's had a chance to be properly sized */ + if (canvas->aa) { + get_emblem_rectangle (icon_item, emblem_index, &emblem_rect); + annotation_width = icon_item->details->annotation->x2 - icon_item->details->annotation->x1; + left = ((emblem_rect.x1 + emblem_rect.x0) / 2) - (annotation_width / 2.0 ); + top = (emblem_rect.y1 + emblem_rect.y0) / 2; + + delta_x = left - icon_item->details->annotation->x1; + delta_y = top - icon_item->details->annotation->y1; + gnome_canvas_item_move (icon_item->details->annotation, delta_x, delta_y); + } + gnome_canvas_item_raise_to_top (icon_item->details->annotation); } @@ -2276,6 +2296,28 @@ nautilus_icon_canvas_item_get_icon_rectangle (NautilusIconCanvasItem *item, rect->y1 = rect->y0 + (pixbuf == NULL ? 0 : nautilus_icon_canvas_item_get_icon_height (item)) / pixels_per_unit; } +static void +get_emblem_rectangle (NautilusIconCanvasItem *icon_item, + int which_emblem, + ArtIRect *rect) +{ + EmblemLayout emblem_layout; + GdkPixbuf *pixbuf; + int emblem_index; + + emblem_layout_reset (&emblem_layout, icon_item, &icon_item->details->canvas_rect); + emblem_index = 0; + + rect->x0 = 0; + rect->y0 = 0; + rect->x1 = 0; + rect->y1 = 0; + + while (emblem_index < which_emblem && emblem_layout_next (&emblem_layout, &pixbuf, rect)) { + emblem_index += 1; + } +} + /* Get the rectangle of the icon only, in canvas coordinates. */ static void get_icon_canvas_rectangle (NautilusIconCanvasItem *item, |