[libchamplain] Use selection color based on GTK colors again and use it for all markers



commit 50d403a341a7564aa9ab9b86636b5b196f98750c
Author: JiÅ?í Techet <techet gmail com>
Date:   Wed Feb 16 01:15:20 2011 +0100

    Use selection color based on GTK colors again and use it for all markers

 champlain-gtk/gtk-champlain-embed.c |   26 +++++++++++-
 champlain/champlain-label.c         |   78 +---------------------------------
 champlain/champlain-label.h         |    5 --
 champlain/champlain-marker.c        |   74 +++++++++++++++++++++++++++++++++
 champlain/champlain-marker.h        |    7 +++
 champlain/champlain-point.c         |   40 +-----------------
 champlain/champlain-point.h         |    2 -
 7 files changed, 111 insertions(+), 121 deletions(-)
---
diff --git a/champlain-gtk/gtk-champlain-embed.c b/champlain-gtk/gtk-champlain-embed.c
index f8f38bc..4462508 100644
--- a/champlain-gtk/gtk-champlain-embed.c
+++ b/champlain-gtk/gtk-champlain-embed.c
@@ -250,13 +250,37 @@ gtk_champlain_embed_init (GtkChamplainEmbed *embed)
 
 
 static void
+gdk_to_clutter_color (GdkColor *gtk_color,
+                      ClutterColor *color)
+{
+  color->red   = CLAMP (((gtk_color->red   / 65535.0) * 255), 0, 255);
+  color->green = CLAMP (((gtk_color->green / 65535.0) * 255), 0, 255);
+  color->blue  = CLAMP (((gtk_color->blue  / 65535.0) * 255), 0, 255);
+  color->alpha = 255;
+}
+
+
+static void
 view_realize_cb (GtkWidget *widget,
     GtkChamplainEmbed *view)
 {
+  ClutterColor color = { 0, 0, 0, };
   GtkChamplainEmbedPrivate *priv = view->priv;
-
+  GtkStyle *style;
+ 
   /* Setup mouse cursor to a hand */
   gdk_window_set_cursor (gtk_widget_get_window (priv->clutter_embed), priv->cursor_hand_open);
+
+  /* Set selection color */
+  style = gtk_widget_get_style (widget);
+
+  gdk_to_clutter_color (&style->text[GTK_STATE_SELECTED], &color);
+  champlain_marker_set_selection_text_color (&color);
+
+  gdk_to_clutter_color (&style->bg[GTK_STATE_SELECTED], &color);
+  champlain_marker_set_selection_color (&color);
+
+  /* To be added later: bg[active] (for selected markers, but focus is on another widget) */
 }
 
 
diff --git a/champlain/champlain-label.c b/champlain/champlain-label.c
index 317fb98..e737227 100644
--- a/champlain/champlain-label.c
+++ b/champlain/champlain-label.c
@@ -51,9 +51,6 @@
 
 #define DEFAULT_FONT_NAME "Sans 11"
 
-static ClutterColor SELECTED_COLOR = { 0x00, 0x33, 0xcc, 0xff };
-static ClutterColor SELECTED_TEXT_COLOR = { 0xff, 0xff, 0xff, 0xff };
-
 static ClutterColor DEFAULT_COLOR = { 0x33, 0x33, 0x33, 0xff };
 static ClutterColor DEFAULT_TEXT_COLOR = { 0xee, 0xee, 0xee, 0xff };
 
@@ -131,75 +128,6 @@ static void allocate (ClutterActor *self,
 static void map (ClutterActor *self);
 static void unmap (ClutterActor *self);
 
-/**
- * champlain_label_set_selection_color:
- * @color: a #ClutterColor
- *
- * Changes the selection color, this is to ensure a better integration with
- * the desktop, this is automatically done by GtkChamplainEmbed.
- *
- * Since: 0.10
- */
-void
-champlain_label_set_selection_color (ClutterColor *color)
-{
-  SELECTED_COLOR.red = color->red;
-  SELECTED_COLOR.green = color->green;
-  SELECTED_COLOR.blue = color->blue;
-  SELECTED_COLOR.alpha = color->alpha;
-}
-
-
-/**
- * champlain_label_get_selection_color:
- *
- * Gets the selection color.
- *
- * Returns: the selection color. Should not be freed.
- *
- * Since: 0.10
- */
-const ClutterColor *
-champlain_label_get_selection_color ()
-{
-  return &SELECTED_COLOR;
-}
-
-
-/**
- * champlain_label_set_selection_text_color:
- * @color: a #ClutterColor
- *
- * Changes the selection text color, this is to ensure a better integration with
- * the desktop, this is automatically done by GtkChamplainEmbed.
- *
- * Since: 0.10
- */
-void
-champlain_label_set_selection_text_color (ClutterColor *color)
-{
-  SELECTED_TEXT_COLOR.red = color->red;
-  SELECTED_TEXT_COLOR.green = color->green;
-  SELECTED_TEXT_COLOR.blue = color->blue;
-  SELECTED_TEXT_COLOR.alpha = color->alpha;
-}
-
-
-/**
- * champlain_label_get_selection_text_color:
- *
- * Gets the selection text color.
- *
- * Returns: the selection text color. Should not be freed.
- *
- * Since: 0.10
- */
-const ClutterColor *
-champlain_label_get_selection_text_color ()
-{
-  return &SELECTED_TEXT_COLOR;
-}
-
 
 static void
 champlain_label_get_property (GObject *object,
@@ -667,7 +595,7 @@ draw_background (ChamplainLabel *label,
   ChamplainLabelPrivate *priv = label->priv;
   ChamplainMarker *marker = CHAMPLAIN_MARKER (label);
   ClutterActor *bg = NULL;
-  ClutterColor *color;
+  const ClutterColor *color;
   ClutterColor darker_color;
   cairo_t *cr;
 
@@ -676,7 +604,7 @@ draw_background (ChamplainLabel *label,
 
   /* If selected, add the selection color to the marker's color */
   if (champlain_marker_get_selected (marker))
-    color = &SELECTED_COLOR;
+    color = champlain_marker_get_selection_color ();
   else
     color = priv->color;
 
@@ -767,7 +695,7 @@ draw_label (ChamplainLabel *label)
         total_height = height;
 
       clutter_text_set_color (CLUTTER_TEXT (priv->text_actor),
-          (champlain_marker_get_selected (marker) ? &SELECTED_TEXT_COLOR : priv->text_color));
+          (champlain_marker_get_selected (marker) ? champlain_marker_get_selection_text_color () : priv->text_color));
       if (clutter_actor_get_parent (priv->text_actor) == NULL)
         clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), priv->text_actor);
     }
diff --git a/champlain/champlain-label.h b/champlain/champlain-label.h
index 0c03759..5b2afeb 100644
--- a/champlain/champlain-label.h
+++ b/champlain/champlain-label.h
@@ -121,11 +121,6 @@ PangoEllipsizeMode champlain_label_get_ellipsize (ChamplainLabel *label);
 gboolean champlain_label_get_single_line_mode (ChamplainLabel *label);
 gboolean champlain_label_get_draw_background (ChamplainLabel *label);
 
-void champlain_label_set_selection_color (ClutterColor *color);
-const ClutterColor *champlain_label_get_selection_color (void);
-
-void champlain_label_set_selection_text_color (ClutterColor *color);
-const ClutterColor *champlain_label_get_selection_text_color (void);
 
 G_END_DECLS
 
diff --git a/champlain/champlain-marker.c b/champlain/champlain-marker.c
index 39b17ac..f354f20 100644
--- a/champlain/champlain-marker.c
+++ b/champlain/champlain-marker.c
@@ -49,6 +49,9 @@
 #include <cairo.h>
 #include <math.h>
 
+static ClutterColor SELECTED_COLOR = { 0x00, 0x33, 0xcc, 0xff };
+static ClutterColor SELECTED_TEXT_COLOR = { 0xff, 0xff, 0xff, 0xff };
+
 enum
 {
   /* normal signals */
@@ -100,6 +103,77 @@ struct _ChamplainMarkerPrivate
   gfloat click_y;
 };
 
+
+/**
+ * champlain_marker_set_selection_color:
+ * @color: a #ClutterColor
+ *
+ * Changes the selection color, this is to ensure a better integration with
+ * the desktop, this is automatically done by GtkChamplainEmbed.
+ *
+ * Since: 0.10
+ */
+void
+champlain_marker_set_selection_color (ClutterColor *color)
+{
+  SELECTED_COLOR.red = color->red;
+  SELECTED_COLOR.green = color->green;
+  SELECTED_COLOR.blue = color->blue;
+  SELECTED_COLOR.alpha = color->alpha;
+}
+
+
+/**
+ * champlain_marker_get_selection_color:
+ *
+ * Gets the selection color.
+ *
+ * Returns: the selection color. Should not be freed.
+ *
+ * Since: 0.10
+ */
+const ClutterColor *
+champlain_marker_get_selection_color ()
+{
+  return &SELECTED_COLOR;
+}
+
+
+/**
+ * champlain_marker_set_selection_text_color:
+ * @color: a #ClutterColor
+ *
+ * Changes the selection text color, this is to ensure a better integration with
+ * the desktop, this is automatically done by GtkChamplainEmbed.
+ *
+ * Since: 0.10
+ */
+void
+champlain_marker_set_selection_text_color (ClutterColor *color)
+{
+  SELECTED_TEXT_COLOR.red = color->red;
+  SELECTED_TEXT_COLOR.green = color->green;
+  SELECTED_TEXT_COLOR.blue = color->blue;
+  SELECTED_TEXT_COLOR.alpha = color->alpha;
+}
+
+
+/**
+ * champlain_marker_get_selection_text_color:
+ *
+ * Gets the selection text color.
+ *
+ * Returns: the selection text color. Should not be freed.
+ *
+ * Since: 0.10
+ */
+const ClutterColor *
+champlain_marker_get_selection_text_color ()
+{
+  return &SELECTED_TEXT_COLOR;
+}
+
+
 static void
 champlain_marker_get_property (GObject *object,
     guint prop_id,
diff --git a/champlain/champlain-marker.h b/champlain/champlain-marker.h
index e9567e3..1565ee0 100644
--- a/champlain/champlain-marker.h
+++ b/champlain/champlain-marker.h
@@ -89,6 +89,13 @@ void champlain_marker_animate_out (ChamplainMarker *marker);
 void champlain_marker_animate_out_with_delay (ChamplainMarker *marker,
     guint delay);
 
+
+void champlain_marker_set_selection_color (ClutterColor *color);
+const ClutterColor *champlain_marker_get_selection_color (void);
+
+void champlain_marker_set_selection_text_color (ClutterColor *color);
+const ClutterColor *champlain_marker_get_selection_text_color (void);
+
 G_END_DECLS
 
 #endif
diff --git a/champlain/champlain-point.c b/champlain/champlain-point.c
index 992ebda..15b7e92 100644
--- a/champlain/champlain-point.c
+++ b/champlain/champlain-point.c
@@ -42,8 +42,6 @@
 
 #define DEFAULT_FONT_NAME "Sans 11"
 
-static ClutterColor SELECTED_COLOR = { 0x00, 0x33, 0xcc, 0xff };
-
 static ClutterColor DEFAULT_COLOR = { 0x33, 0x33, 0x33, 0xff };
 
 enum
@@ -95,40 +93,6 @@ static void unmap (ClutterActor *self);
 static void draw_point (ChamplainPoint *point);
 
 
-/**
- * champlain_point_set_selection_color:
- * @color: The selection color.
- *
- * Set the selection color.
- *
- * Since: 0.10
- */
-void
-champlain_point_set_selection_color (ClutterColor *color)
-{
-  SELECTED_COLOR.red = color->red;
-  SELECTED_COLOR.green = color->green;
-  SELECTED_COLOR.blue = color->blue;
-  SELECTED_COLOR.alpha = color->alpha;
-}
-
-
-/**
- * champlain_point_get_selection_color:
- *
- * Gets the selection color.
- *
- * Returns: the color.
- *
- * Since: 0.10
- */
-const ClutterColor *
-champlain_point_get_selection_color ()
-{
-  return &SELECTED_COLOR;
-}
-
-
 static void
 champlain_point_get_property (GObject *object,
     guint prop_id,
@@ -246,7 +210,7 @@ draw_point (ChamplainPoint *point)
   cairo_t *cr;
   gdouble size = priv->size;
   gdouble radius = size / 2.0;
-  ClutterColor *color;
+  const ClutterColor *color;
   
   clutter_group_remove_all (CLUTTER_GROUP (priv->content_group));
   cairo_texture = clutter_cairo_texture_new (size, size);
@@ -256,7 +220,7 @@ draw_point (ChamplainPoint *point)
   cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (cairo_texture));
 
   if (champlain_marker_get_selected (CHAMPLAIN_MARKER (point)))
-    color = &SELECTED_COLOR;
+    color = champlain_marker_get_selection_color ();
   else
     color = priv->color;  
   
diff --git a/champlain/champlain-point.h b/champlain/champlain-point.h
index 3828c1b..86ac7b6 100644
--- a/champlain/champlain-point.h
+++ b/champlain/champlain-point.h
@@ -79,8 +79,6 @@ void champlain_point_set_size (ChamplainPoint *point,
     gdouble size);
 gdouble champlain_point_get_size (ChamplainPoint *point);
 
-void champlain_point_set_selection_color (ClutterColor *color);
-const ClutterColor *champlain_point_get_selection_color (void);
 
 G_END_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]