From: Pierre-Luc Beaudoin Date: Mon, 6 Jul 2009 18:19:43 +0000 (+0100) Subject: Add highlight possibility to base marker X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6930eb4c8c6723374c29128b10a7043d32e15a5f;p=libchamplain Add highlight possibility to base marker --- diff --git a/champlain/champlain-base-marker.c b/champlain/champlain-base-marker.c index 2a6e626..b97d840 100644 --- a/champlain/champlain-base-marker.c +++ b/champlain/champlain-base-marker.c @@ -63,6 +63,7 @@ enum PROP_0, PROP_LONGITUDE, PROP_LATITUDE, + PROP_HIGHLIGHTED, }; //static guint champlain_base_marker_signals[LAST_SIGNAL] = { 0, }; @@ -88,6 +89,9 @@ champlain_base_marker_get_property (GObject *object, case PROP_LATITUDE: g_value_set_double (value, priv->lat); break; + case PROP_HIGHLIGHTED: + g_value_set_boolean (value, priv->highlighted); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -116,6 +120,12 @@ champlain_base_marker_set_property (GObject *object, champlain_base_marker_set_position (base_marker, lat, priv->lon); break; } + case PROP_HIGHLIGHTED: + { + gboolean bvalue = g_value_get_boolean (value); + champlain_base_marker_set_highlighted (base_marker, bvalue); + break; + } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -164,6 +174,17 @@ champlain_base_marker_class_init (ChamplainBaseMarkerClass *champlainBaseMarkerC "The latitude coordonate of the base_marker", -90.0f, 90.0f, 0.0f, CHAMPLAIN_PARAM_READWRITE)); + /** + * ChamplainBaseMarker:highlighted: + * + * The highlighted state of the marker + * + * Since: 0.4 + */ + g_object_class_install_property (object_class, PROP_HIGHLIGHTED, + g_param_spec_boolean ("highlighted", "Highlighted", + "The highlighted stated of the marker", + FALSE, CHAMPLAIN_PARAM_READWRITE)); } static void @@ -171,6 +192,9 @@ champlain_base_marker_init (ChamplainBaseMarker *marker) { ChamplainBaseMarkerPrivate *priv = CHAMPLAIN_BASE_MARKER_GET_PRIVATE (marker); marker->priv = priv; + priv->lat = 0; + priv->lon = 0; + priv->highlighted = FALSE; } @@ -203,7 +227,9 @@ champlain_base_marker_new (void) * Since: 0.4 */ void -champlain_base_marker_set_position (ChamplainBaseMarker *champlainBaseMarker, gdouble latitude, gdouble longitude) +champlain_base_marker_set_position (ChamplainBaseMarker *champlainBaseMarker, + gdouble latitude, + gdouble longitude) { g_return_if_fail (CHAMPLAIN_IS_BASE_MARKER (champlainBaseMarker)); @@ -215,3 +241,44 @@ champlain_base_marker_set_position (ChamplainBaseMarker *champlainBaseMarker, gd g_object_notify (G_OBJECT (champlainBaseMarker), "latitude"); g_object_notify (G_OBJECT (champlainBaseMarker), "longitude"); } + +/** + * champlain_base_marker_set_highlighted: + * @base_marker: a #ChamplainBaseMarker + * @value: the highlighted state + * + * Sets the marker as highlighted or not. This will affect the "Selected" look + * of the marker. + * + * Since: 0.4 + */ +void +champlain_base_marker_set_highlighted (ChamplainBaseMarker *champlainBaseMarker, + gboolean value) +{ + g_return_if_fail (CHAMPLAIN_IS_BASE_MARKER (champlainBaseMarker)); + + ChamplainBaseMarkerPrivate *priv = CHAMPLAIN_BASE_MARKER_GET_PRIVATE (champlainBaseMarker); + + priv->highlighted = value; + + g_object_notify (G_OBJECT (champlainBaseMarker), "highlighted"); +} + +/** + * champlain_base_marker_get_highlighted: + * @base_marker: a #ChamplainBaseMarker + * + * Returns the highlighted or not state of the marker. + * + * Since: 0.4 + */ +gboolean +champlain_base_marker_get_highlighted (ChamplainBaseMarker *champlainBaseMarker) +{ + g_return_val_if_fail (CHAMPLAIN_IS_BASE_MARKER (champlainBaseMarker), FALSE); + + ChamplainBaseMarkerPrivate *priv = CHAMPLAIN_BASE_MARKER_GET_PRIVATE (champlainBaseMarker); + + return priv->highlighted; +} diff --git a/champlain/champlain-base-marker.h b/champlain/champlain-base-marker.h index e303afc..79cf533 100644 --- a/champlain/champlain-base-marker.h +++ b/champlain/champlain-base-marker.h @@ -62,6 +62,9 @@ ClutterActor *champlain_base_marker_new (void); void champlain_base_marker_set_position (ChamplainBaseMarker *marker, gdouble longitude, gdouble latitude); +void champlain_base_marker_set_highlighted (ChamplainBaseMarker *marker, + gboolean value); +gboolean champlain_base_marker_get_highlighted (ChamplainBaseMarker *marker); G_END_DECLS diff --git a/champlain/champlain-marker.c b/champlain/champlain-marker.c index cb16c09..6589d89 100644 --- a/champlain/champlain-marker.c +++ b/champlain/champlain-marker.c @@ -55,6 +55,8 @@ #define DEFAULT_FONT_NAME "Sans 11" +static ClutterColor SELECTED_COLOR = {0x00, 0x00, 0xff, 0xff}; + static ClutterColor DEFAULT_COLOR = {0x33, 0x33, 0x33, 0xff}; static ClutterColor DEFAULT_TEXT_COLOR = {0xee, 0xee, 0xee, 0xff}; @@ -486,22 +488,31 @@ draw_background (ChamplainMarker *marker, gint point) { ChamplainMarkerPrivate *priv = marker->priv; + ChamplainBaseMarkerPrivate *base_priv = CHAMPLAIN_BASE_MARKER (marker)->priv; ClutterActor *bg = NULL; + ClutterColor *color; ClutterColor darker_color; cairo_t *cr; bg = clutter_cairo_new (width, height + point); cr = clutter_cairo_create (CLUTTER_CAIRO (bg)); + /* If selected, add the selection color to the marker's color */ + if (base_priv->highlighted) + color = &SELECTED_COLOR; + else + color = priv->color; + + draw_box (cr, width, height, point, priv->alignment == PANGO_ALIGN_LEFT); - clutter_color_darken (priv->color, &darker_color); + clutter_color_darken (color, &darker_color); cairo_set_source_rgba (cr, - priv->color->red / 255.0, - priv->color->green / 255.0, - priv->color->blue / 255.0, - priv->color->alpha / 255.0); + color->red / 255.0, + color->green / 255.0, + color->blue / 255.0, + color->alpha / 255.0); cairo_fill_preserve (cr); cairo_set_line_width (cr, 1.0); @@ -649,6 +660,14 @@ queue_redraw (ChamplainMarker *marker) marker->priv->redraw_id = g_idle_add (redraw_on_idle, marker); } +static void +notify_highlighted (GObject *gobject, + GParamSpec *pspec, + gpointer user_data) +{ + queue_redraw (CHAMPLAIN_MARKER (gobject)); +} + static void champlain_marker_init (ChamplainMarker *marker) { @@ -670,6 +689,8 @@ champlain_marker_init (ChamplainMarker *marker) priv->ellipsize = PANGO_ELLIPSIZE_NONE; priv->draw_background = TRUE; priv->redraw_id = 0; + + g_signal_connect (marker, "notify::highlighted", G_CALLBACK (notify_highlighted), NULL); } /** diff --git a/champlain/champlain-private.h b/champlain/champlain-private.h index adc4c7a..9c7e4e5 100644 --- a/champlain/champlain-private.h +++ b/champlain/champlain-private.h @@ -35,6 +35,7 @@ struct _ChamplainBaseMarkerPrivate { gdouble lon; gdouble lat; + gboolean highlighted; }; struct _ChamplainPolygonPrivate {