diff options
author | Benjamin Otte <otte@redhat.com> | 2010-10-10 08:31:45 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-10-30 01:49:59 +0800 |
commit | b3a95d0299386bccbdebb967d15f4df02cf15891 (patch) | |
tree | 52b90e4b913bb1c4cd17df3335216bf518a6e01c /libgnomecanvas/gnome-canvas-text.c | |
parent | 08e71ba8ae72f333f017c25168b9ec85ea5954fa (diff) | |
download | gsoc2013-evolution-b3a95d0299386bccbdebb967d15f4df02cf15891.tar.gz gsoc2013-evolution-b3a95d0299386bccbdebb967d15f4df02cf15891.tar.zst gsoc2013-evolution-b3a95d0299386bccbdebb967d15f4df02cf15891.zip |
gnome-canvas: Change GnomeCanvasItem->point vfunc
Previously the function returned the distance to the nearest item. Now
it only returns an item that is hit. This slightly changes semantics
(button events are no longer dispatched to the nearest item, but only to
the item actually clicked on), but makes the code way simpler and
actually does what one would expect.
Diffstat (limited to 'libgnomecanvas/gnome-canvas-text.c')
-rw-r--r-- | libgnomecanvas/gnome-canvas-text.c | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/libgnomecanvas/gnome-canvas-text.c b/libgnomecanvas/gnome-canvas-text.c index f85df6666a..d857eceac0 100644 --- a/libgnomecanvas/gnome-canvas-text.c +++ b/libgnomecanvas/gnome-canvas-text.c @@ -119,12 +119,11 @@ static void gnome_canvas_text_realize (GnomeCanvasItem *item); static void gnome_canvas_text_unrealize (GnomeCanvasItem *item); static void gnome_canvas_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, gint x, gint y, gint width, gint height); -static gdouble gnome_canvas_text_point (GnomeCanvasItem *item, - gdouble x, - gdouble y, - gint cx, - gint cy, - GnomeCanvasItem **actual_item); +static GnomeCanvasItem *gnome_canvas_text_point (GnomeCanvasItem *item, + gdouble x, + gdouble y, + gint cx, + gint cy); static void gnome_canvas_text_bounds (GnomeCanvasItem *item, gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2); @@ -1348,28 +1347,22 @@ gnome_canvas_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, } /* Point handler for the text item */ -static double +static GnomeCanvasItem * gnome_canvas_text_point (GnomeCanvasItem *item, gdouble x, gdouble y, - gint cx, gint cy, GnomeCanvasItem **actual_item) + gint cx, gint cy) { GnomeCanvasText *text; PangoLayoutIter *iter; gint x1, y1, x2, y2; - gint dx, dy; - gdouble dist, best; text = GNOME_CANVAS_TEXT (item); - *actual_item = item; - /* The idea is to build bounding rectangles for each of the lines of * text (clipped by the clipping rectangle, if it is activated) and see * whether the point is inside any of these. If it is, we are done. * Otherwise, calculate the distance to the nearest rectangle. */ - best = 1.0e36; - iter = pango_layout_get_iter (text->layout); do { PangoRectangle log_rect; @@ -1400,34 +1393,16 @@ gnome_canvas_text_point (GnomeCanvasItem *item, gdouble x, gdouble y, /* Calculate distance from point to rectangle */ - if (cx < x1) - dx = x1 - cx; - else if (cx >= x2) - dx = cx - x2 + 1; - else - dx = 0; - - if (cy < y1) - dy = y1 - cy; - else if (cy >= y2) - dy = cy - y2 + 1; - else - dy = 0; - - if ((dx == 0) && (dy == 0)) { + if (cx >= x1 && cx < x2 && cy >= y1 && cy < y2) { pango_layout_iter_free (iter); - return 0.0; + return item; } - dist = sqrt (dx * dx + dy * dy); - if (dist < best) - best = dist; - } while (pango_layout_iter_next_line (iter)); pango_layout_iter_free (iter); - return best / item->canvas->pixels_per_unit; + return NULL; } /* Bounds handler for the text item */ |