[goocanvas/new-api] 2010-07-07 Damon Chaplin <damon gnome org>
- From: Damon Chaplin <damon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goocanvas/new-api] 2010-07-07 Damon Chaplin <damon gnome org>
- Date: Wed, 7 Jul 2010 21:27:58 +0000 (UTC)
commit 9d6bdf2d44017965131fc8a807cd3c4a9a8a3c21
Author: Damon Chaplin <damon gnome org>
Date: Wed Jul 7 22:14:39 2010 +0100
2010-07-07 Damon Chaplin <damon gnome org>
* Finished support for unscaled line widths, which was quite tricky as
goo_canvas_item_simple_set_stroke_options() needs to change behavior
based on where it is called - from update, paint or get_items_at().
Added a GooCanvasOperation type to use for this.
Also added a scale argument to the simple_paint() function and
set_stroke_options as we need that for unscaled lines too.
* src/goocanvasitem.h: moved GooCanvasAnimateType and GooCanvasBounds
to goocanvasutils.h to tidy it up a bit.
* src/goocanvas.c (goo_canvas_set_scale_internal): canvas->scale is
now set to MAX (scale_x, scale_y) rather than MIN, since we use it
for unscaled line widths and MAX works better (it is better to
paint unscaled lines too thin rather than too fat).
ChangeLog | 17 +++++++++++++
demo/demo-item.c | 3 +-
demo/demo-large-line.c | 6 +++-
demo/demo-large-rect.c | 5 ++-
src/goocanvas.c | 2 +-
src/goocanvasgrid.c | 23 ++++++++++-------
src/goocanvasimage.c | 3 +-
src/goocanvasitem.h | 41 +------------------------------
src/goocanvasitemsimple.c | 59 +++++++++++++++++++++-----------------------
src/goocanvasitemsimple.h | 14 ++++++----
src/goocanvaspath.c | 3 +-
src/goocanvaspolyline.c | 38 +++++++++++++----------------
src/goocanvastable.c | 2 +-
src/goocanvastext.c | 3 +-
src/goocanvasutils.h | 48 ++++++++++++++++++++++++++++++++++++
src/goocanvaswidget.c | 3 +-
16 files changed, 151 insertions(+), 119 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dd77926..77a6563 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2010-07-07 Damon Chaplin <damon gnome org>
+
+ * Finished support for unscaled line widths, which was quite tricky as
+ goo_canvas_item_simple_set_stroke_options() needs to change behavior
+ based on where it is called - from update, paint or get_items_at().
+ Added a GooCanvasOperation type to use for this.
+ Also added a scale argument to the simple_paint() function and
+ set_stroke_options as we need that for unscaled lines too.
+
+ * src/goocanvasitem.h: moved GooCanvasAnimateType and GooCanvasBounds
+ to goocanvasutils.h to tidy it up a bit.
+
+ * src/goocanvas.c (goo_canvas_set_scale_internal): canvas->scale is
+ now set to MAX (scale_x, scale_y) rather than MIN, since we use it
+ for unscaled line widths and MAX works better (it is better to
+ paint unscaled lines too thin rather than too fat).
+
2010-07-01 Damon Chaplin <damon gnome org>
* src/goocanvasitemsimple.c (goo_canvas_item_simple_get_items_at):
diff --git a/demo/demo-item.c b/demo/demo-item.c
index 027911d..6872983 100644
--- a/demo/demo-item.c
+++ b/demo/demo-item.c
@@ -89,7 +89,8 @@ goo_demo_item_update (GooCanvasItemSimple *simple,
static void
goo_demo_item_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooDemoItem *demo_item = (GooDemoItem*) simple;
diff --git a/demo/demo-large-line.c b/demo/demo-large-line.c
index c5b83b3..fa091a2 100644
--- a/demo/demo-large-line.c
+++ b/demo/demo-large-line.c
@@ -205,12 +205,14 @@ paint_large_line (GooDemoLargeLine *line,
static void
goo_demo_large_line_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooDemoLargeLine *item = (GooDemoLargeLine*) simple;
gdouble line_width;
- goo_canvas_item_simple_set_stroke_options (simple, cr, FALSE);
+ goo_canvas_item_simple_set_stroke_options (simple, cr,
+ GOO_CANVAS_OPERATION_PAINT, scale);
line_width = goo_canvas_item_simple_get_line_width (simple);
paint_large_line (item, cr, bounds, line_width,
item->x1, item->y1, item->x2, item->y2);
diff --git a/demo/demo-large-rect.c b/demo/demo-large-rect.c
index 8caea3a..d897e73 100644
--- a/demo/demo-large-rect.c
+++ b/demo/demo-large-rect.c
@@ -152,7 +152,8 @@ create_large_rect_path (GooDemoLargeRect *rect,
static void
goo_demo_large_rect_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooDemoLargeRect *item = (GooDemoLargeRect*) simple;
gdouble line_width;
@@ -160,7 +161,7 @@ goo_demo_large_rect_paint (GooCanvasItemSimple *simple,
line_width = goo_canvas_item_simple_get_line_width (simple);
create_large_rect_path (item, cr, bounds, line_width,
item->x, item->y, item->width, item->height);
- goo_canvas_item_simple_paint_path (simple, cr);
+ goo_canvas_item_simple_paint_path (simple, cr, scale);
}
diff --git a/src/goocanvas.c b/src/goocanvas.c
index 6c6b20a..2649d0d 100644
--- a/src/goocanvas.c
+++ b/src/goocanvas.c
@@ -1997,7 +1997,7 @@ goo_canvas_set_scale_internal (GooCanvas *canvas,
canvas->scale_x = scale_x;
canvas->scale_y = scale_y;
- canvas->scale = MIN (scale_x, scale_y);
+ canvas->scale = MAX (scale_x, scale_y);
reconfigure_canvas (canvas, FALSE);
/* Convert from the center point to the new desired top-left posision. */
diff --git a/src/goocanvasgrid.c b/src/goocanvasgrid.c
index 9a02695..7f12a54 100644
--- a/src/goocanvasgrid.c
+++ b/src/goocanvasgrid.c
@@ -440,7 +440,8 @@ calculate_start_position (gdouble start_pos,
static void
paint_vertical_lines (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooCanvasGrid *grid = (GooCanvasGrid*) simple;
double x, max_x, max_y, max_bounds_x, line_width;
@@ -452,7 +453,7 @@ paint_vertical_lines (GooCanvasItemSimple *simple,
max_x = grid->x + grid->width;
max_y = grid->y + grid->height;
- has_stroke = goo_canvas_item_simple_set_stroke_options (simple, cr, FALSE);
+ has_stroke = goo_canvas_item_simple_set_stroke_options (simple, cr, GOO_CANVAS_OPERATION_PAINT, scale);
line_width = goo_canvas_item_simple_get_line_width (simple);
/* If the grid's vertical grid line pattern/color has been set, use that.
@@ -500,7 +501,8 @@ paint_vertical_lines (GooCanvasItemSimple *simple,
static void
paint_horizontal_lines (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooCanvasGrid *grid = (GooCanvasGrid*) simple;
double y, max_x, max_y, max_bounds_y, line_width;
@@ -512,7 +514,7 @@ paint_horizontal_lines (GooCanvasItemSimple *simple,
max_x = grid->x + grid->width;
max_y = grid->y + grid->height;
- has_stroke = goo_canvas_item_simple_set_stroke_options (simple, cr, FALSE);
+ has_stroke = goo_canvas_item_simple_set_stroke_options (simple, cr, GOO_CANVAS_OPERATION_PAINT, scale);
line_width = goo_canvas_item_simple_get_line_width (simple);
/* If the grid's horizontal grid line pattern/color has been set, use that.
@@ -560,7 +562,8 @@ paint_horizontal_lines (GooCanvasItemSimple *simple,
static void
goo_canvas_grid_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooCanvasGrid *grid = (GooCanvasGrid*) simple;
GooCanvasBounds redraw_bounds = *bounds;
@@ -588,13 +591,13 @@ goo_canvas_grid_paint (GooCanvasItemSimple *simple,
/* Paint the grid lines, in the required order. */
if (grid->vert_grid_lines_on_top)
{
- paint_horizontal_lines (simple, cr, &redraw_bounds);
- paint_vertical_lines (simple, cr, &redraw_bounds);
+ paint_horizontal_lines (simple, cr, &redraw_bounds, scale);
+ paint_vertical_lines (simple, cr, &redraw_bounds, scale);
}
else
{
- paint_vertical_lines (simple, cr, &redraw_bounds);
- paint_horizontal_lines (simple, cr, &redraw_bounds);
+ paint_vertical_lines (simple, cr, &redraw_bounds, scale);
+ paint_horizontal_lines (simple, cr, &redraw_bounds, scale);
}
cairo_restore (cr);
@@ -605,7 +608,7 @@ goo_canvas_grid_paint (GooCanvasItemSimple *simple,
if (grid->border_pattern)
cairo_set_source (cr, grid->border_pattern);
else
- goo_canvas_item_simple_set_stroke_options (simple, cr, FALSE);
+ goo_canvas_item_simple_set_stroke_options (simple, cr, GOO_CANVAS_OPERATION_PAINT, scale);
cairo_set_line_width (cr, grid->border_width);
half_border_width = grid->border_width / 2.0;
diff --git a/src/goocanvasimage.c b/src/goocanvasimage.c
index 8ef7a33..1b679a1 100644
--- a/src/goocanvasimage.c
+++ b/src/goocanvasimage.c
@@ -252,7 +252,8 @@ goo_canvas_image_update (GooCanvasItemSimple *simple,
static void
goo_canvas_image_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooCanvasImage *image = (GooCanvasImage*) simple;
cairo_matrix_t matrix = { 1, 0, 0, 1, 0, 0 };
diff --git a/src/goocanvasitem.h b/src/goocanvasitem.h
index 220c1e5..d49ac08 100644
--- a/src/goocanvasitem.h
+++ b/src/goocanvasitem.h
@@ -8,50 +8,11 @@
#define __GOO_CANVAS_ITEM_H__
#include <gtk/gtk.h>
+#include <goocanvasutils.h>
G_BEGIN_DECLS
-/**
- * GooCanvasAnimateType
- * @GOO_CANVAS_ANIMATE_FREEZE: the item remains in the final position.
- * @GOO_CANVAS_ANIMATE_RESET: the item is moved back to the initial position.
- * @GOO_CANVAS_ANIMATE_RESTART: the animation is restarted from the initial
- * position.
- * @GOO_CANVAS_ANIMATE_BOUNCE: the animation bounces back and forth between the
- * start and end positions.
- *
- * #GooCanvasAnimateType is used to specify what happens when the end of an
- * animation is reached.
- */
-typedef enum
-{
- GOO_CANVAS_ANIMATE_FREEZE,
- GOO_CANVAS_ANIMATE_RESET,
- GOO_CANVAS_ANIMATE_RESTART,
- GOO_CANVAS_ANIMATE_BOUNCE
-} GooCanvasAnimateType;
-
-
-/**
- * GooCanvasBounds
- * @x1: the left edge.
- * @y1: the top edge.
- * @x2: the right edge.
- * @y2: the bottom edge.
- *
- * #GooCanvasBounds represents the bounding box of an item in the canvas.
- */
-typedef struct _GooCanvasBounds GooCanvasBounds;
-struct _GooCanvasBounds
-{
- gdouble x1, y1, x2, y2;
-};
-
-GType goo_canvas_bounds_get_type (void) G_GNUC_CONST;
-#define GOO_TYPE_CANVAS_BOUNDS (goo_canvas_bounds_get_type ())
-
-
#define GOO_TYPE_CANVAS_ITEM (goo_canvas_item_get_type ())
#define GOO_CANVAS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_ITEM, GooCanvasItem))
#define GOO_CANVAS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_ITEM, GooCanvasItemClass))
diff --git a/src/goocanvasitemsimple.c b/src/goocanvasitemsimple.c
index 4279ee0..4f7c477 100644
--- a/src/goocanvasitemsimple.c
+++ b/src/goocanvasitemsimple.c
@@ -727,7 +727,8 @@ goo_canvas_item_simple_default_is_item_at (GooCanvasItemSimple *simple,
/* Use the virtual method subclasses define to create the path. */
class->simple_create_path (simple, cr);
- if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events, TRUE))
+ if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events,
+ simple->canvas->scale))
return TRUE;
return FALSE;
@@ -857,7 +858,7 @@ goo_canvas_item_simple_default_update (GooCanvasItemSimple *simple,
cairo_identity_matrix (cr);
class->simple_create_path (simple, cr);
- goo_canvas_item_simple_get_path_bounds (simple, cr, &simple->bounds, TRUE);
+ goo_canvas_item_simple_get_path_bounds (simple, cr, &simple->bounds);
}
@@ -1213,7 +1214,7 @@ goo_canvas_item_simple_paint (GooCanvasItem *item,
cairo_clip (cr);
}
- class->simple_paint (simple, cr, bounds);
+ class->simple_paint (simple, cr, bounds, scale);
cairo_restore (cr);
@@ -1238,12 +1239,13 @@ goo_canvas_item_simple_paint (GooCanvasItem *item,
static void
goo_canvas_item_simple_default_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (simple);
class->simple_create_path (simple, cr);
- goo_canvas_item_simple_paint_path (simple, cr);
+ goo_canvas_item_simple_paint_path (simple, cr, scale);
}
@@ -1285,12 +1287,15 @@ goo_canvas_item_simple_query_tooltip (GooCanvasItem *item,
**/
void
goo_canvas_item_simple_paint_path (GooCanvasItemSimple *simple,
- cairo_t *cr)
+ cairo_t *cr,
+ gdouble scale)
{
if (goo_canvas_item_simple_set_fill_options (simple, cr))
cairo_fill_preserve (cr);
- if (goo_canvas_item_simple_set_stroke_options (simple, cr, FALSE))
+ if (goo_canvas_item_simple_set_stroke_options (simple, cr,
+ GOO_CANVAS_OPERATION_PAINT,
+ scale))
cairo_stroke (cr);
cairo_new_path (cr);
@@ -1306,8 +1311,6 @@ goo_canvas_item_simple_paint_path (GooCanvasItemSimple *simple,
* @item: a #GooCanvasItemSimple.
* @cr: a cairo context.
* @bounds: the #GooCanvasBounds struct to store the resulting bounding box.
- * @add_tolerance: if the line width tolerance setting should be added to the
- * line width when calculating the bounds.
*
* This function is intended to be used by subclasses of #GooCanvasItemSimple,
* typically in their update() or get_requested_area() methods.
@@ -1323,8 +1326,7 @@ goo_canvas_item_simple_paint_path (GooCanvasItemSimple *simple,
void
goo_canvas_item_simple_get_path_bounds (GooCanvasItemSimple *simple,
cairo_t *cr,
- GooCanvasBounds *bounds,
- gboolean add_tolerance)
+ GooCanvasBounds *bounds)
{
GooCanvasBounds fill_bounds, stroke_bounds;
@@ -1334,7 +1336,8 @@ goo_canvas_item_simple_get_path_bounds (GooCanvasItemSimple *simple,
&fill_bounds.x2, &fill_bounds.y2);
/* Check the stroke. */
- goo_canvas_item_simple_set_stroke_options (simple, cr, add_tolerance);
+ goo_canvas_item_simple_set_stroke_options (simple, cr,
+ GOO_CANVAS_OPERATION_UPDATE, 1.0);
cairo_stroke_extents (cr, &stroke_bounds.x1, &stroke_bounds.y1,
&stroke_bounds.x2, &stroke_bounds.y2);
@@ -1501,8 +1504,6 @@ goo_canvas_item_simple_user_bounds_to_parent (GooCanvasItemSimple *simple,
* @y: the y coordinate of the point.
* @cr: a cairo context.
* @pointer_events: specifies which parts of the path to check.
- * @add_tolerance: if the line width tolerance setting should be added to
- * the line width for the check.
*
* This function is intended to be used by subclasses of #GooCanvasItemSimple.
*
@@ -1517,7 +1518,7 @@ goo_canvas_item_simple_check_in_path (GooCanvasItemSimple *simple,
gdouble y,
cairo_t *cr,
GooCanvasPointerEvents pointer_events,
- gboolean add_tolerance)
+ gdouble scale)
{
gboolean do_fill, do_stroke;
@@ -1535,7 +1536,7 @@ goo_canvas_item_simple_check_in_path (GooCanvasItemSimple *simple,
/* Check the stroke, if required. */
if (pointer_events & GOO_CANVAS_EVENTS_STROKE_MASK)
{
- do_stroke = goo_canvas_item_simple_set_stroke_options (simple, cr, add_tolerance);
+ do_stroke = goo_canvas_item_simple_set_stroke_options (simple, cr, GOO_CANVAS_OPERATION_GET_ITEMS_AT, scale);
if (!(pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK) || do_stroke)
{
if (cairo_in_stroke (cr, x, y))
@@ -1585,10 +1586,11 @@ goo_canvas_item_simple_set_style (GooCanvasItemSimple *simple,
gboolean
goo_canvas_item_simple_set_stroke_options (GooCanvasItemSimple *simple,
cairo_t *cr,
- gboolean add_tolerance)
+ GooCanvasOperation op,
+ gdouble scale)
{
GooCanvasStyle *style = simple->style;
- gdouble line_width, scale;
+ gdouble line_width;
/* If no style is set, just reset the source to black and return TRUE so the
default style will be used. */
@@ -1615,22 +1617,17 @@ goo_canvas_item_simple_set_stroke_options (GooCanvasItemSimple *simple,
else
line_width = cairo_get_line_width (cr);
- /* Add on the tolerance, if needed. */
- if (add_tolerance)
+ /* Add on the tolerance, when calculating bounds and hit-testing. */
+ if (op == GOO_CANVAS_OPERATION_UPDATE
+ || op == GOO_CANVAS_OPERATION_GET_ITEMS_AT)
line_width += style->line_width_tolerance;
/* If the line width is supposed to be unscaled, try to reverse the effects
- of the canvas scale. We use the maximum canvas scale, since being too
- thin is better than being too fat. */
- if (style->line_width_is_unscaled && simple->canvas)
- {
- scale = MAX (simple->canvas->scale_x, simple->canvas->scale_y);
-
- /* We only want to shrink the lines as the canvas is scaled up.
- We don't want to affect the line width when the scales are < 1. */
- if (scale > 1.0)
- line_width /= scale;
- }
+ of the canvas scale. But only when painting and hit-testing. */
+ if ((op == GOO_CANVAS_OPERATION_PAINT
+ || op == GOO_CANVAS_OPERATION_GET_ITEMS_AT)
+ && style->line_width_is_unscaled && scale > 1.0)
+ line_width /= scale;
/* Set the line width. */
cairo_set_line_width (cr, line_width);
diff --git a/src/goocanvasitemsimple.h b/src/goocanvasitemsimple.h
index 700b5a9..9e2174f 100644
--- a/src/goocanvasitemsimple.h
+++ b/src/goocanvasitemsimple.h
@@ -117,7 +117,8 @@ struct _GooCanvasItemSimpleClass
cairo_t *cr);
void (* simple_paint) (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds);
+ const GooCanvasBounds *bounds,
+ gdouble scale);
gboolean (* simple_is_item_at) (GooCanvasItemSimple *simple,
gdouble x,
gdouble y,
@@ -141,8 +142,7 @@ void goo_canvas_item_simple_set_style (GooCanvasItemSimple *simple,
void goo_canvas_item_simple_get_path_bounds (GooCanvasItemSimple *item,
cairo_t *cr,
- GooCanvasBounds *bounds,
- gboolean add_tolerance);
+ GooCanvasBounds *bounds);
void goo_canvas_item_simple_user_bounds_to_device (GooCanvasItemSimple *item,
cairo_t *cr,
GooCanvasBounds *bounds);
@@ -154,9 +154,10 @@ gboolean goo_canvas_item_simple_check_in_path (GooCanvasItemSimple *item,
gdouble y,
cairo_t *cr,
GooCanvasPointerEvents pointer_events,
- gboolean add_tolerance);
+ gdouble scale);
void goo_canvas_item_simple_paint_path (GooCanvasItemSimple *item,
- cairo_t *cr);
+ cairo_t *cr,
+ gdouble scale);
void goo_canvas_item_simple_changed (GooCanvasItemSimple *item,
gboolean recompute_bounds);
@@ -164,7 +165,8 @@ gdouble goo_canvas_item_simple_get_line_width (GooCanvasItemSimple *item);
gboolean goo_canvas_item_simple_set_stroke_options (GooCanvasItemSimple *simple,
cairo_t *cr,
- gboolean add_tolerance);
+ GooCanvasOperation op,
+ gdouble scale);
gboolean goo_canvas_item_simple_set_fill_options (GooCanvasItemSimple *simple,
cairo_t *cr);
diff --git a/src/goocanvaspath.c b/src/goocanvaspath.c
index 71c8fb5..713f4e8 100644
--- a/src/goocanvaspath.c
+++ b/src/goocanvaspath.c
@@ -456,7 +456,8 @@ goo_canvas_path_is_item_at (GooCanvasItemSimple *simple,
pointer_events = simple->pointer_events;
goo_canvas_path_create_path (simple, cr);
- if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events, TRUE))
+ if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events,
+ simple->canvas->scale))
return TRUE;
return FALSE;
diff --git a/src/goocanvaspolyline.c b/src/goocanvaspolyline.c
index bb3b93e..3367dc6 100644
--- a/src/goocanvaspolyline.c
+++ b/src/goocanvaspolyline.c
@@ -348,26 +348,20 @@ reconfigure_arrow (GooCanvasPolyline *polyline,
/* Recalculates the arrow polygons for the line */
static void
-goo_canvas_polyline_reconfigure_arrows (GooCanvasPolyline *polyline)
+goo_canvas_polyline_reconfigure_arrows (GooCanvasPolyline *polyline,
+ gdouble scale)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) polyline;
GooCanvasStyle *style = simple->style;
- double line_width, scale;
+ double line_width;
if (polyline->num_points < 2
|| (!polyline->start_arrow && !polyline->end_arrow))
return;
line_width = goo_canvas_item_simple_get_line_width (simple);
- if (style && style->line_width_is_unscaled && simple->canvas)
- {
- scale = MAX (simple->canvas->scale_x, simple->canvas->scale_y);
-
- /* We only want to shrink the lines as the canvas is scaled up.
- We don't want to affect the line width when the scales are < 1. */
- if (scale > 1.0)
- line_width /= scale;
- }
+ if (style && style->line_width_is_unscaled && scale > 1.0)
+ line_width /= scale;
ensure_arrow_data (polyline);
@@ -780,9 +774,10 @@ goo_canvas_polyline_is_item_at (GooCanvasItemSimple *simple,
pointer_events &= ~GOO_CANVAS_EVENTS_FILL_MASK;
if (style && style->line_width_is_unscaled)
- goo_canvas_polyline_reconfigure_arrows (polyline);
+ goo_canvas_polyline_reconfigure_arrows (polyline, simple->canvas->scale);
goo_canvas_polyline_create_path (polyline, cr);
- if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events, TRUE))
+ if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events,
+ simple->canvas->scale))
return TRUE;
/* Check the arrows, if the polyline has them. */
@@ -791,7 +786,7 @@ goo_canvas_polyline_is_item_at (GooCanvasItemSimple *simple,
&& (pointer_events & GOO_CANVAS_EVENTS_STROKE_MASK))
{
/* We use the stroke pattern to match the style of the line. */
- do_stroke = goo_canvas_item_simple_set_stroke_options (simple, cr, TRUE);
+ do_stroke = goo_canvas_item_simple_set_stroke_options (simple, cr, GOO_CANVAS_OPERATION_GET_ITEMS_AT, simple->canvas->scale);
if (!(pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK) || do_stroke)
{
if (polyline->start_arrow)
@@ -834,14 +829,14 @@ goo_canvas_polyline_compute_bounds (GooCanvasPolyline *polyline,
cairo_identity_matrix (cr);
goo_canvas_polyline_create_path (polyline, cr);
- goo_canvas_item_simple_get_path_bounds (simple, cr, bounds, TRUE);
+ goo_canvas_item_simple_get_path_bounds (simple, cr, bounds);
/* Add on the arrows, if required. */
if ((polyline->start_arrow || polyline->end_arrow)
&& polyline->num_points >= 2)
{
/* We use the stroke pattern to match the style of the line. */
- goo_canvas_item_simple_set_stroke_options (simple, cr, TRUE);
+ goo_canvas_item_simple_set_stroke_options (simple, cr, GOO_CANVAS_OPERATION_UPDATE, 1.0);
if (polyline->start_arrow)
{
@@ -876,7 +871,7 @@ goo_canvas_polyline_update (GooCanvasItemSimple *simple,
{
GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
- goo_canvas_polyline_reconfigure_arrows (polyline);
+ goo_canvas_polyline_reconfigure_arrows (polyline, 1.0);
/* Compute the new bounds. */
goo_canvas_polyline_compute_bounds (polyline, cr, &simple->bounds);
@@ -886,7 +881,8 @@ goo_canvas_polyline_update (GooCanvasItemSimple *simple,
static void
goo_canvas_polyline_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
GooCanvasStyle *style = simple->style;
@@ -895,16 +891,16 @@ goo_canvas_polyline_paint (GooCanvasItemSimple *simple,
return;
if (style && style->line_width_is_unscaled)
- goo_canvas_polyline_reconfigure_arrows (polyline);
+ goo_canvas_polyline_reconfigure_arrows (polyline, scale);
goo_canvas_polyline_create_path (polyline, cr);
- goo_canvas_item_simple_paint_path (simple, cr);
+ goo_canvas_item_simple_paint_path (simple, cr, scale);
/* Paint the arrows, if required. */
if ((polyline->start_arrow || polyline->end_arrow)
&& polyline->num_points >= 2)
{
/* We use the stroke pattern to match the style of the line. */
- goo_canvas_item_simple_set_stroke_options (simple, cr, FALSE);
+ goo_canvas_item_simple_set_stroke_options (simple, cr, GOO_CANVAS_OPERATION_PAINT, scale);
if (polyline->start_arrow)
{
diff --git a/src/goocanvastable.c b/src/goocanvastable.c
index 4e01578..9531fd2 100644
--- a/src/goocanvastable.c
+++ b/src/goocanvastable.c
@@ -2185,7 +2185,7 @@ goo_canvas_table_paint (GooCanvasItem *item,
/* We use the style for the stroke color, but the line cap style and line
width are overridden here. */
- goo_canvas_item_simple_set_stroke_options (simple, cr, FALSE);
+ goo_canvas_item_simple_set_stroke_options (simple, cr, GOO_CANVAS_OPERATION_PAINT, scale);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
diff --git a/src/goocanvastext.c b/src/goocanvastext.c
index e12398c..ac3a1c6 100644
--- a/src/goocanvastext.c
+++ b/src/goocanvastext.c
@@ -572,7 +572,8 @@ goo_canvas_text_is_item_at (GooCanvasItemSimple *simple,
static void
goo_canvas_text_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
GooCanvasText *text = (GooCanvasText*) simple;
PangoLayout *layout;
diff --git a/src/goocanvasutils.h b/src/goocanvasutils.h
index 7f158d4..64b5bb9 100644
--- a/src/goocanvasutils.h
+++ b/src/goocanvasutils.h
@@ -12,10 +12,58 @@
G_BEGIN_DECLS
+/**
+ * GooCanvasBounds
+ * @x1: the left edge.
+ * @y1: the top edge.
+ * @x2: the right edge.
+ * @y2: the bottom edge.
+ *
+ * #GooCanvasBounds represents the bounding box of an item in the canvas.
+ */
+typedef struct _GooCanvasBounds GooCanvasBounds;
+struct _GooCanvasBounds
+{
+ gdouble x1, y1, x2, y2;
+};
+
+GType goo_canvas_bounds_get_type (void) G_GNUC_CONST;
+#define GOO_TYPE_CANVAS_BOUNDS (goo_canvas_bounds_get_type ())
+
+
/*
* Enum types.
*/
+typedef enum
+{
+ GOO_CANVAS_OPERATION_UPDATE,
+ GOO_CANVAS_OPERATION_PAINT,
+ GOO_CANVAS_OPERATION_GET_ITEMS_AT
+} GooCanvasOperation;
+
+
+/**
+ * GooCanvasAnimateType
+ * @GOO_CANVAS_ANIMATE_FREEZE: the item remains in the final position.
+ * @GOO_CANVAS_ANIMATE_RESET: the item is moved back to the initial position.
+ * @GOO_CANVAS_ANIMATE_RESTART: the animation is restarted from the initial
+ * position.
+ * @GOO_CANVAS_ANIMATE_BOUNCE: the animation bounces back and forth between the
+ * start and end positions.
+ *
+ * #GooCanvasAnimateType is used to specify what happens when the end of an
+ * animation is reached.
+ */
+typedef enum
+{
+ GOO_CANVAS_ANIMATE_FREEZE,
+ GOO_CANVAS_ANIMATE_RESET,
+ GOO_CANVAS_ANIMATE_RESTART,
+ GOO_CANVAS_ANIMATE_BOUNCE
+} GooCanvasAnimateType;
+
+
/**
* GooCanvasPointerEvents
* @GOO_CANVAS_EVENTS_VISIBLE_MASK: a mask indicating that the item only
diff --git a/src/goocanvaswidget.c b/src/goocanvaswidget.c
index 1e9c296..88089de 100644
--- a/src/goocanvaswidget.c
+++ b/src/goocanvaswidget.c
@@ -475,7 +475,8 @@ goo_canvas_widget_allocate_area (GooCanvasItem *item,
static void
goo_canvas_widget_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
- const GooCanvasBounds *bounds)
+ const GooCanvasBounds *bounds,
+ gdouble scale)
{
/* Do nothing for now. Maybe render for printing in future. */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]