From: Pierre-Luc Beaudoin Date: Mon, 25 May 2009 04:22:40 +0000 (-0400) Subject: Implement shape filling and stroking X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27a6a4ce4fc4b58b4fa0aedbc627431a57c42b9e;p=libchamplain Implement shape filling and stroking --- diff --git a/champlain/champlain-line.c b/champlain/champlain-line.c index e432dc3..8612fe9 100644 --- a/champlain/champlain-line.c +++ b/champlain/champlain-line.c @@ -44,7 +44,13 @@ G_DEFINE_TYPE (ChamplainLine, champlain_line, G_TYPE_OBJECT) enum { - PROP_0 + PROP_0, + PROP_CLOSED_PATH, + PROP_LINE_WIDTH, + PROP_LINE_COLOR, + PROP_FILL, + PROP_FILL_COLOR, + PROP_STROKE, }; static void @@ -53,9 +59,25 @@ champlain_line_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - //ChamplainLine *self = CHAMPLAIN_LINE (object); + ChamplainLinePrivate *priv = GET_PRIVATE (object); + switch (property_id) { + case PROP_CLOSED_PATH: + g_value_set_boolean (value, priv->closed_path); + break; + case PROP_FILL: + g_value_set_boolean (value, priv->fill); + break; + case PROP_STROKE: + g_value_set_boolean (value, priv->stroke); + break; + case PROP_FILL_COLOR: + clutter_value_set_color (value, priv->fill_color); + break; + case PROP_LINE_COLOR: + clutter_value_set_color (value, priv->line_color); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -67,9 +89,27 @@ champlain_line_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - //ChamplainLine *self = CHAMPLAIN_LINE (object); + ChamplainLinePrivate *priv = GET_PRIVATE (object); + switch (property_id) { + case PROP_CLOSED_PATH: + priv->closed_path = g_value_get_boolean (value); + break; + case PROP_FILL: + priv->fill = g_value_get_boolean (value); + break; + case PROP_STROKE: + priv->stroke = g_value_get_boolean (value); + break; + case PROP_FILL_COLOR: + clutter_color_free (priv->fill_color); + priv->fill_color = clutter_color_copy (clutter_value_get_color (value)); + break; + case PROP_LINE_COLOR: + clutter_color_free (priv->line_color); + priv->line_color = clutter_color_copy (clutter_value_get_color (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -100,6 +140,48 @@ champlain_line_class_init (ChamplainLineClass *klass) object_class->set_property = champlain_line_set_property; object_class->dispose = champlain_line_dispose; object_class->finalize = champlain_line_finalize; + + /** + * ChamplainLine:close-path: + * + * The shape is a closed path + * + * Since: 0.4 + */ + g_object_class_install_property (object_class, + PROP_CLOSED_PATH, + g_param_spec_boolean ("closed-path", + "Closed Path", + "The Path is Closed", + FALSE, CHAMPLAIN_PARAM_READWRITE)); + + /** + * ChamplainLine:fill: + * + * The shape should be filled + * + * Since: 0.4 + */ + g_object_class_install_property (object_class, + PROP_FILL, + g_param_spec_boolean ("fill", + "Fill", + "The shape is filled", + FALSE, CHAMPLAIN_PARAM_READWRITE)); + + /** + * ChamplainLine:stroke: + * + * The shape should be stroked + * + * Since: 0.4 + */ + g_object_class_install_property (object_class, + PROP_STROKE, + g_param_spec_boolean ("stroke", + "Stroke", + "The shape is stroked", + FALSE, CHAMPLAIN_PARAM_READWRITE)); } static void @@ -108,6 +190,8 @@ champlain_line_init (ChamplainLine *self) self->priv = GET_PRIVATE (self); self->priv->points = NULL; + self->priv->fill = FALSE; + self->priv->stroke = TRUE; } /** diff --git a/champlain/champlain-private.h b/champlain/champlain-private.h index e837afa..a1c1070 100644 --- a/champlain/champlain-private.h +++ b/champlain/champlain-private.h @@ -20,7 +20,7 @@ #define CHAMPLAIN_PRIVATE_H #include - +#include typedef struct _Map Map; @@ -39,6 +39,11 @@ struct _ChamplainBaseMarkerPrivate struct _ChamplainLinePrivate { GList *points; + gboolean closed_path; + ClutterColor *line_color; + gboolean fill; + ClutterColor *fill_color; + gboolean stroke; }; typedef struct diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index 0cad84a..8172be4 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -2200,7 +2200,15 @@ draw_line (ChamplainView *view, cairo_t *cr, ChamplainLine *line) cairo_line_to (cr, x, y); list = list->next; } - cairo_stroke (cr); + + if (line->priv->closed_path) + cairo_close_path (cr); + + if (line->priv->fill) + cairo_fill_preserve (cr); + + if (line->priv->stroke) + cairo_stroke (cr); } static void diff --git a/demos/lines.c b/demos/lines.c index e566c7b..eacca13 100644 --- a/demos/lines.c +++ b/demos/lines.c @@ -116,7 +116,10 @@ main (int argc, line = champlain_line_new (); champlain_line_add_point (line, 44, -75); champlain_line_add_point (line, 45, -74); + champlain_line_add_point (line, 46, -74); champlain_view_add_line (CHAMPLAIN_VIEW (actor), line); + g_object_set (line, "closed-path", TRUE, NULL); + g_object_set (line, "fill", TRUE, NULL); /* Finish initialising the map view */ g_object_set (G_OBJECT (actor), "zoom-level", 12,