PROP_FILL,
PROP_FILL_COLOR,
PROP_STROKE,
+ PROP_VISIBLE,
};
static void
case PROP_STROKE_WIDTH:
g_value_set_double (value, priv->stroke_width);
break;
+ case PROP_VISIBLE:
+ g_value_set_boolean (value, priv->visible);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
champlain_polygon_set_stroke_width (CHAMPLAIN_POLYGON (object),
g_value_get_double (value));
break;
+ case PROP_VISIBLE:
+ if (g_value_get_boolean (value) == TRUE)
+ champlain_polygon_show (CHAMPLAIN_POLYGON (object));
+ else
+ champlain_polygon_hide (CHAMPLAIN_POLYGON (object));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
champlain_polygon_dispose (GObject *object)
{
- //ChamplainPolygonPrivate *priv = GET_PRIVATE (object);
+ ChamplainPolygonPrivate *priv = GET_PRIVATE (object);
+
+ if (priv->actor != NULL)
+ {
+ g_object_unref (priv->actor);
+ priv->actor = NULL;
+ }
G_OBJECT_CLASS (champlain_polygon_parent_class)->dispose (object);
}
0, 100.0,
2.0,
CHAMPLAIN_PARAM_READWRITE));
+
+ /**
+ * ChamplainPolygon:visible:
+ *
+ * Wether the polygon is visible
+ *
+ * Since: 0.4
+ */
+ g_object_class_install_property (object_class,
+ PROP_VISIBLE,
+ g_param_spec_boolean ("visible",
+ "Visible",
+ "The polygon's visibility",
+ TRUE,
+ CHAMPLAIN_PARAM_READWRITE));
}
static void
{
self->priv = GET_PRIVATE (self);
+ self->priv->visible = TRUE;
self->priv->points = NULL;
self->priv->fill = FALSE;
self->priv->stroke = TRUE;
self->priv->fill_color = clutter_color_copy (&DEFAULT_FILL_COLOR);
self->priv->stroke_color = clutter_color_copy (&DEFAULT_STROKE_COLOR);
- self->priv->actor = g_object_ref (clutter_cairo_new (800, 600));
- clutter_actor_set_position (self->priv->actor, 0, 0);
}
/**
g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
polygon->priv->stroke = value;
+ g_object_notify (G_OBJECT (polygon), "stroke");
}
/**
g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
polygon->priv->fill = value;
+ g_object_notify (G_OBJECT (polygon), "fill");
}
/**
g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
polygon->priv->stroke_width = value;
+ g_object_notify (G_OBJECT (polygon), "stroke-width");
}
/**
return polygon->priv->stroke_width;
}
+
+/**
+ * champlain_polygon_show:
+ * @polygon: The polygon
+ *
+ * Makes the polygon visible
+ *
+ * Since: 0.4
+ */
+void
+champlain_polygon_show (ChamplainPolygon *polygon)
+{
+ g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
+
+ polygon->priv->visible = TRUE;
+ if (polygon->priv->actor != NULL)
+ clutter_actor_show (polygon->priv->actor);
+ g_object_notify (G_OBJECT (polygon), "visible");
+}
+
+/**
+ * champlain_polygon_hide:
+ * @polygon: The polygon
+ *
+ * Hides the polygon
+ *
+ * Since: 0.4
+ */
+void
+champlain_polygon_hide (ChamplainPolygon *polygon)
+{
+ g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
+
+ polygon->priv->visible = FALSE;
+ if (polygon->priv->actor != NULL)
+ clutter_actor_hide (polygon->priv->actor);
+ g_object_notify (G_OBJECT (polygon), "visible");
+}
PADDING - width, priv->viewport_size.height - PADDING - height);
}
+static void
+draw_polygon (ChamplainView *view, ChamplainPolygon *polygon)
+{
+ cairo_t *cr;
+ ChamplainViewPrivate *priv = view->priv;
+
+ if (polygon->priv->visible == FALSE)
+ return;
+
+ cr = clutter_cairo_create (CLUTTER_CAIRO (polygon->priv->actor));
+
+ /* Clear the drawing area */
+ cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+ cairo_rectangle (cr, 0, 0,
+ view->priv->viewport_size.width,
+ view->priv->viewport_size.height);
+ cairo_fill (cr);
+
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ GList *list = g_list_first (polygon->priv->points);
+ while (list != NULL)
+ {
+ ChamplainPoint *point = (ChamplainPoint*) list->data;
+ gint x, y;
+
+ x = champlain_map_source_get_x (priv->map_source, priv->zoom_level,
+ point->lon);
+ y = champlain_map_source_get_y (priv->map_source, priv->zoom_level,
+ point->lat);
+
+ x -= priv->viewport_size.x + priv->anchor.x;
+ y -= priv->viewport_size.y + priv->anchor.y;
+
+ cairo_line_to (cr, x, y);
+ list = list->next;
+ }
+
+ if (polygon->priv->closed_path)
+ cairo_close_path (cr);
+
+ cairo_set_source_rgba (cr,
+ polygon->priv->fill_color->red / 255.0,
+ polygon->priv->fill_color->green / 255.0,
+ polygon->priv->fill_color->blue / 255.0,
+ polygon->priv->fill_color->alpha / 255.0);
+
+ if (polygon->priv->fill)
+ cairo_fill_preserve (cr);
+
+ cairo_set_source_rgba (cr,
+ polygon->priv->stroke_color->red / 255.0,
+ polygon->priv->stroke_color->green / 255.0,
+ polygon->priv->stroke_color->blue / 255.0,
+ polygon->priv->stroke_color->alpha / 255.0);
+
+ cairo_set_line_width (cr, polygon->priv->stroke_width);
+
+ if (polygon->priv->stroke)
+ cairo_stroke (cr);
+
+ cairo_destroy (cr);
+}
+
+static void
+notify_polygon_visible_cb (ChamplainPolygon *polygon,
+ GParamSpec *arg1,
+ ChamplainView *view)
+{
+ draw_polygon (view, polygon);
+}
+
static void
resize_viewport (ChamplainView *view)
{
gdouble lower, upper;
TidyAdjustment *hadjust, *vadjust;
+ GList *polygons;
ChamplainViewPrivate *priv = view->priv;
}
g_object_set (vadjust, "lower", lower, "upper", upper,
"page-size", 1.0, "step-increment", 1.0, "elastic", TRUE, NULL);
+
+ /* Resize polygon actors */
+ if (priv->viewport_size.width == 0 ||
+ priv->viewport_size.height == 0)
+ return;
+
+ polygons = priv->polygons;
+ while (polygons != NULL)
+ {
+ ChamplainPolygon *polygon;
+
+ polygon = CHAMPLAIN_POLYGON (polygons->data);
+
+ if (polygon->priv->actor != NULL)
+ {
+ g_object_unref (polygon->priv->actor);
+ clutter_container_remove_actor (CLUTTER_CONTAINER (view->priv->polygon_layer),
+ polygon->priv->actor);
+ }
+
+ polygon->priv->actor = g_object_ref (clutter_cairo_new (
+ view->priv->viewport_size.width,
+ view->priv->viewport_size.height));
+ g_object_set (G_OBJECT (polygon->priv->actor), "visible",
+ polygon->priv->visible, NULL);
+ clutter_container_add_actor (CLUTTER_CONTAINER (view->priv->polygon_layer),
+ polygon->priv->actor);
+ clutter_actor_set_position (polygon->priv->actor, 0, 0);
+ draw_polygon (view, polygon);
+ polygons = polygons->next;
+ }
}
static void
return priv->zoom_on_double_click;
}
-static void
-draw_polygon (ChamplainView *view, ChamplainPolygon *polygon)
-{
- cairo_t *cr;
- ChamplainViewPrivate *priv = view->priv;
-
- cr = clutter_cairo_create (CLUTTER_CAIRO (polygon->priv->actor));
-
- /* Clear the drawing area */
- cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
- cairo_rectangle (cr, 0, 0, 800, 600); //XXX
- cairo_fill (cr);
-
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- GList *list = g_list_first (polygon->priv->points);
- while (list != NULL)
- {
- ChamplainPoint *point = (ChamplainPoint*) list->data;
- gint x, y;
-
- x = champlain_map_source_get_x (priv->map_source, priv->zoom_level,
- point->lon);
- y = champlain_map_source_get_y (priv->map_source, priv->zoom_level,
- point->lat);
-
- x -= priv->viewport_size.x + priv->anchor.x;
- y -= priv->viewport_size.y + priv->anchor.y;
-
- cairo_line_to (cr, x, y);
- list = list->next;
- }
-
- if (polygon->priv->closed_path)
- cairo_close_path (cr);
-
- cairo_set_source_rgba (cr,
- polygon->priv->fill_color->red / 255.0,
- polygon->priv->fill_color->green / 255.0,
- polygon->priv->fill_color->blue / 255.0,
- polygon->priv->fill_color->alpha / 255.0);
-
- if (polygon->priv->fill)
- cairo_fill_preserve (cr);
-
- cairo_set_source_rgba (cr,
- polygon->priv->stroke_color->red / 255.0,
- polygon->priv->stroke_color->green / 255.0,
- polygon->priv->stroke_color->blue / 255.0,
- polygon->priv->stroke_color->alpha / 255.0);
-
- cairo_set_line_width (cr, polygon->priv->stroke_width);
-
- if (polygon->priv->stroke)
- cairo_stroke (cr);
-
- cairo_destroy (cr);
-}
-
static void
view_update_polygons (ChamplainView *view)
{
g_return_if_fail (CHAMPLAIN_IS_POLYGON (polygon));
view->priv->polygons = g_list_append (view->priv->polygons, g_object_ref (polygon));
+
+ g_signal_connect (polygon, "notify::visible",
+ G_CALLBACK (notify_polygon_visible_cb), view);
+
+ if (view->priv->viewport_size.width == 0 ||
+ view->priv->viewport_size.height == 0)
+ return;
+
+ polygon->priv->actor = g_object_ref (clutter_cairo_new (
+ view->priv->viewport_size.width,
+ view->priv->viewport_size.height));
+ g_object_set (G_OBJECT (polygon->priv->actor), "visible",
+ polygon->priv->visible, NULL);
+ clutter_actor_set_position (polygon->priv->actor, 0, 0);
clutter_container_add_actor (CLUTTER_CONTAINER (view->priv->polygon_layer),
polygon->priv->actor);
}
#define COL_ID 0
#define COL_NAME 1
+static ChamplainPolygon *polygon;
+
/*
* Terminate the main loop.
*/
ClutterActor *layer)
{
if(gtk_toggle_button_get_active(widget))
- clutter_actor_show_all(layer);
+ {
+ champlain_polygon_show (polygon);
+ clutter_actor_show_all (layer);
+ }
else
- clutter_actor_hide(layer);
+ {
+ champlain_polygon_hide (polygon);
+ clutter_actor_hide (layer);
+ }
}
static void
champlain_view_add_layer(CHAMPLAIN_VIEW (view), layer);
clutter_actor_hide (CLUTTER_ACTOR (layer));
+ polygon = champlain_polygon_new ();
+ /* Cheap approx of Highway 10 */
+ champlain_polygon_append_point (polygon, 45.4095, -73.3197);
+ champlain_polygon_append_point (polygon, 45.4104, -73.2846);
+ champlain_polygon_append_point (polygon, 45.4178, -73.2239);
+ champlain_polygon_append_point (polygon, 45.4176, -73.2181);
+ champlain_polygon_append_point (polygon, 45.4151, -73.2126);
+ champlain_polygon_append_point (polygon, 45.4016, -73.1926);
+ champlain_polygon_append_point (polygon, 45.3994, -73.1877);
+ champlain_polygon_append_point (polygon, 45.4000, -73.1815);
+ champlain_polygon_append_point (polygon, 45.4151, -73.1218);
+ champlain_polygon_set_stroke_width (polygon, 5.0);
+ champlain_view_add_polygon (CHAMPLAIN_VIEW (view), polygon);
+ champlain_polygon_hide (polygon);
+
gtk_widget_set_size_request(widget, 640, 480);
bbox = gtk_hbox_new (FALSE, 10);