]> err.no Git - libchamplain/commitdiff
Add highlight possibility to base marker
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Mon, 6 Jul 2009 18:19:43 +0000 (19:19 +0100)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Tue, 28 Jul 2009 21:23:16 +0000 (17:23 -0400)
champlain/champlain-base-marker.c
champlain/champlain-base-marker.h
champlain/champlain-marker.c
champlain/champlain-private.h

index 2a6e626fbe074a0b5dcc9c622348f488f3f71647..b97d8409fa001148cd4eac27af563fa60136cfe6 100644 (file)
@@ -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;
+}
index e303afc2998f578a7a9811b90eb3a6268ac3159a..79cf5338cf0e4f7b0fa636ca7f930be670402296 100644 (file)
@@ -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
 
index cb16c0947de0c47af4a9165834b0eb124b894408..6589d896d55143623e1e20e29c37dec7761a1f94 100644 (file)
@@ -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);
 }
 
 /**
index adc4c7a39c0dfc495208b5b4af1f4d9bc719b7de..9c7e4e569fd7b0a0d027628cf96398f0ebf1db19 100644 (file)
@@ -35,6 +35,7 @@ struct _ChamplainBaseMarkerPrivate
 {
   gdouble lon;
   gdouble lat;
+  gboolean highlighted;
 };
 
 struct _ChamplainPolygonPrivate {