[goocanvas/new-api: 5/7] added "line-width-is-unscaled" property.
- From: Damon Chaplin <damon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goocanvas/new-api: 5/7] added "line-width-is-unscaled" property.
- Date: Thu, 24 Jun 2010 14:54:42 +0000 (UTC)
commit 80cb9f717cd4309707e8532cb2a262593dfad791
Author: Damon Chaplin <damon gnome org>
Date: Thu Jun 24 15:10:32 2010 +0100
added "line-width-is-unscaled" property.
demo/demo.c | 3 ++-
demo/scalability-demo.c | 15 ++++++++++-----
src/goocanvasitemsimple.c | 45 +++++++++++++++++++++++++++++++++------------
src/goocanvasstyle.c | 17 ++++++++++++++++-
src/goocanvasstyle.h | 1 +
5 files changed, 62 insertions(+), 19 deletions(-)
---
diff --git a/demo/demo.c b/demo/demo.c
index 208c043..7094ea4 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -877,7 +877,8 @@ setup_rectangles (GooCanvasItem *root)
item = goo_canvas_rect_new (root, 20, 90, 70, 60,
"fill-color-rgba", 0x3cb37180,
"stroke-color", "blue",
- "line-width", 2.0,
+ "line-width", 1.0,
+ "line-width-is-unscaled", TRUE,
"tooltip", "Partially transparent rectangle",
NULL);
setup_item_signals (item);
diff --git a/demo/scalability-demo.c b/demo/scalability-demo.c
index 913a996..b507060 100644
--- a/demo/scalability-demo.c
+++ b/demo/scalability-demo.c
@@ -116,8 +116,7 @@ setup_canvas (GtkWidget *canvas)
GooCanvasItem *root, *group, *item;
int group_i, group_j, i, j;
int total_items = 0, id_item_num = 0;;
- GooCanvasStyle *style, *style2;
- PangoFontDescription *font_desc;
+ GooCanvasStyle *style, *style2, *text_style;
cairo_matrix_t item_matrix;
GQuark id_quark = g_quark_from_static_string ("id");
@@ -126,8 +125,6 @@ setup_canvas (GtkWidget *canvas)
g_signal_connect (root, "motion_notify_event",
G_CALLBACK (on_motion_notify), NULL);
- font_desc = pango_font_description_from_string ("Sans 8");
-
style = g_object_new (GOO_TYPE_CANVAS_STYLE,
"fill-color", "mediumseagreen",
NULL);
@@ -136,6 +133,10 @@ setup_canvas (GtkWidget *canvas)
"fill-color", "steelblue",
NULL);
+ text_style = g_object_new (GOO_TYPE_CANVAS_STYLE,
+ "font", "Sans 8",
+ NULL);
+
for (group_i = 0; group_i < N_GROUP_COLS; group_i++)
{
for (group_j = 0; group_j < N_GROUP_ROWS; group_j++)
@@ -194,13 +195,17 @@ setup_canvas (GtkWidget *canvas)
item_x + item_width / 2,
item_y + item_height / 2,
item_width, GTK_ANCHOR_CENTER,
- /*"font-desc", font_desc,*/
/*"height", item_height,*/
/*"alignment", PANGO_ALIGN_CENTER,*/
NULL);
/* FIXME: This is slightly naughty, but much faster. */
GOO_CANVAS_TEXT (item)->height = item_height;
GOO_CANVAS_TEXT (item)->alignment = PANGO_ALIGN_CENTER;
+
+#ifdef SET_STYLE
+ goo_canvas_item_simple_set_style ((GooCanvasItemSimple*) item, text_style);
+#endif
+
#else
item = goo_canvas_rect_new (group, item_x + 20, item_y + 4,
item_width - 40, item_height - 8,
diff --git a/src/goocanvasitemsimple.c b/src/goocanvasitemsimple.c
index a5a43a1..b042d88 100644
--- a/src/goocanvasitemsimple.c
+++ b/src/goocanvasitemsimple.c
@@ -51,6 +51,7 @@ enum {
/* Line style & width properties. */
PROP_LINE_WIDTH,
PROP_LINE_WIDTH_TOLERANCE,
+ PROP_LINE_WIDTH_IS_UNSCALED,
PROP_LINE_CAP,
PROP_LINE_JOIN,
PROP_LINE_JOIN_MITER_LIMIT,
@@ -178,6 +179,9 @@ goo_canvas_item_simple_get_property (GObject *object,
case PROP_LINE_WIDTH_TOLERANCE:
g_value_set_double (value, style ? style->line_width_tolerance : 0);
break;
+ case PROP_LINE_WIDTH_IS_UNSCALED:
+ g_value_set_boolean (value, style ? style->line_width_is_unscaled : FALSE);
+ break;
case PROP_LINE_CAP:
g_value_set_enum (value, style ? style->line_cap : CAIRO_LINE_CAP_BUTT);
break;
@@ -313,6 +317,9 @@ goo_canvas_item_simple_set_property (GObject *object,
style->line_width_tolerance = g_value_get_double (value);
need_update = FALSE;
break;
+ case PROP_LINE_WIDTH_IS_UNSCALED:
+ style->line_width_is_unscaled = g_value_get_boolean (value);
+ break;
case PROP_LINE_CAP:
style->line_cap = g_value_get_enum (value);
recompute_bounds = TRUE;
@@ -1276,7 +1283,7 @@ goo_canvas_item_simple_set_stroke_options (GooCanvasItemSimple *simple,
gboolean add_tolerance)
{
GooCanvasStyle *style = simple->style;
- gdouble line_width;
+ gdouble line_width, scale;
/* If no style is set, just reset the source to black and return TRUE so the
default style will be used. */
@@ -1297,21 +1304,28 @@ goo_canvas_item_simple_set_stroke_options (GooCanvasItemSimple *simple,
if (style->antialias != CAIRO_ANTIALIAS_GRAY)
cairo_set_antialias (cr, style->antialias);
- if (add_tolerance && style->line_width_tolerance > 0)
- {
- if (style->line_width >= 0.0)
- line_width = style->line_width;
- else
- line_width = cairo_get_line_width (cr);
-
- cairo_set_line_width (cr, line_width + style->line_width_tolerance);
- }
+ /* Determine the basic line width. */
+ if (style->line_width >= 0.0)
+ line_width = style->line_width;
else
+ line_width = cairo_get_line_width (cr);
+
+ /* Add on the tolerance, if needed. */
+ if (add_tolerance)
+ 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)
{
- if (style->line_width >= 0.0)
- cairo_set_line_width (cr, style->line_width);
+ scale = MAX (simple->canvas->scale_x, simple->canvas->scale_y);
+ line_width /= scale;
}
+ /* Set the line width. */
+ cairo_set_line_width (cr, line_width);
+
if (style->line_cap != CAIRO_LINE_CAP_BUTT)
cairo_set_line_cap (cr, style->line_cap);
@@ -1461,6 +1475,13 @@ goo_canvas_item_simple_class_init (GooCanvasItemSimpleClass *klass)
0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_LINE_WIDTH_IS_UNSCALED,
+ g_param_spec_boolean ("line-width-is-unscaled",
+ _("Line Width Is Unscaled"),
+ _("If the line width does not grow as the canvas is scaled"),
+ FALSE,
+ G_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class, PROP_LINE_CAP,
g_param_spec_enum ("line-cap",
_("Line Cap"),
diff --git a/src/goocanvasstyle.c b/src/goocanvasstyle.c
index 422a012..a9c7b43 100644
--- a/src/goocanvasstyle.c
+++ b/src/goocanvasstyle.c
@@ -27,6 +27,7 @@ enum {
/* Line style & width properties. */
PROP_LINE_WIDTH,
PROP_LINE_WIDTH_TOLERANCE,
+ PROP_LINE_WIDTH_IS_UNSCALED,
PROP_LINE_CAP,
PROP_LINE_JOIN,
PROP_LINE_JOIN_MITER_LIMIT,
@@ -57,8 +58,9 @@ goo_canvas_style_init (GooCanvasStyle *style)
style->font_desc = NULL;
style->line_width = -1.0;
- style->line_width_tolerance = -1.0;
+ style->line_width_tolerance = 0.0;
style->line_join_miter_limit = 10.0;
+ style->line_width_is_unscaled = FALSE;
style->stroke_pattern_set = FALSE;
style->fill_pattern_set = FALSE;
@@ -137,6 +139,9 @@ goo_canvas_style_get_property (GObject *object,
case PROP_LINE_WIDTH_TOLERANCE:
g_value_set_double (value, style->line_width_tolerance);
break;
+ case PROP_LINE_WIDTH_IS_UNSCALED:
+ g_value_set_boolean (value, style->line_width_is_unscaled);
+ break;
case PROP_LINE_CAP:
g_value_set_enum (value, style->line_cap);
break;
@@ -238,6 +243,9 @@ goo_canvas_style_set_property (GObject *object,
case PROP_LINE_WIDTH_TOLERANCE:
style->line_width_tolerance = g_value_get_double (value);
break;
+ case PROP_LINE_WIDTH_IS_UNSCALED:
+ style->line_width_is_unscaled = g_value_get_boolean (value);
+ break;
case PROP_LINE_CAP:
style->line_cap = g_value_get_enum (value);
break;
@@ -381,6 +389,13 @@ goo_canvas_style_class_init (GooCanvasStyleClass *klass)
0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_LINE_WIDTH_IS_UNSCALED,
+ g_param_spec_boolean ("line-width-is-unscaled",
+ _("Line Width Is Unscaled"),
+ _("If the line width does not grow as the canvas is scaled"),
+ FALSE,
+ G_PARAM_READWRITE));
+
g_object_class_install_property (gobject_class, PROP_LINE_CAP,
g_param_spec_enum ("line-cap",
_("Line Cap"),
diff --git a/src/goocanvasstyle.h b/src/goocanvasstyle.h
index 3b6d79d..d7b6afc 100644
--- a/src/goocanvasstyle.h
+++ b/src/goocanvasstyle.h
@@ -47,6 +47,7 @@ struct _GooCanvasStyle
cairo_line_cap_t line_cap : 4;
cairo_line_join_t line_join : 4;
guint hint_metrics : 2;
+ guint line_width_is_unscaled : 1;
};
struct _GooCanvasStyleClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]