]> err.no Git - libchamplain/commitdiff
Add default label markers
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 6 Sep 2008 15:37:56 +0000 (11:37 -0400)
committerPierre-Luc Beaudoin <pierre-luc@squidy.info>
Sat, 6 Sep 2008 15:37:56 +0000 (11:37 -0400)
champlain/champlainmarker.c
champlain/champlainmarker.h
champlain/launcher.c
configure.ac

index bef0329b3874cc23281f67984ba98ca2563409b3..7fe3b508489aa62d4f966ea05bb6d766384f02e8 100644 (file)
@@ -32,6 +32,7 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk-clutter-embed.h>
+#include <cairo.h>
 #include <math.h>
 
 enum
@@ -221,3 +222,88 @@ champlain_marker_set_anchor (ChamplainMarker *champlainMarker, gint x, gint y)
   clutter_actor_set_position(CLUTTER_ACTOR(champlainMarker), -x, -y);
 }
 
+/**
+ * champlain_marker_new_with_label:
+ * @label: the text of the label
+ * @font: the font to use to draw the text, for example "Courrier Bold 11", can be NULL
+ * @text_color: a #ClutterColor, the color of the text, can be NULL
+ * @marker_color: a #ClutterColor, the color of the marker, can be NULL
+ *
+ * Returns a new #ChamplainWidget with a drawn marker containing the given text. 
+ *
+ * Since: 0.2
+ */
+ClutterActor * 
+champlain_marker_new_with_label (const gchar *label, 
+                                 const gchar *font, 
+                                 ClutterColor *text_color, 
+                                 ClutterColor *marker_color)
+{
+  ChamplainMarker *champlainMarker = CHAMPLAIN_MARKER(champlain_marker_new ());
+  ChamplainMarkerPrivate *priv = CHAMPLAIN_MARKER_GET_PRIVATE (champlainMarker);
+  ClutterColor default_text_color = { 0x22, 022, 0x22, 0xFF },
+               default_marker_color = { 0x2A, 0xB1, 0x26, 0xEE },
+               darker_color;
+  ClutterActor *actor, *bg;
+  cairo_t *cr;
+  guint text_width, text_height, point;
+  const gint padding = 5;
+
+  if (!font)
+    font = "Sans 11";
+  if (!text_color)
+    text_color = &default_text_color;
+  if (!marker_color)
+    marker_color = &default_marker_color;
+
+  actor = clutter_label_new_with_text(font, label);
+  clutter_actor_set_position(actor, padding, padding / 2.0);
+  text_width = clutter_actor_get_width(actor) + 2 * padding;
+  text_height = clutter_actor_get_height(actor)+ padding;
+  clutter_label_set_color(CLUTTER_LABEL(actor), text_color);
+  clutter_container_add_actor(CLUTTER_CONTAINER(champlainMarker), actor);
+
+  point = (text_height + 2 * padding) / 4.0;
+
+  bg = clutter_cairo_new (text_width, text_height + point);
+  cr = clutter_cairo_create (bg);
+
+  cairo_set_source_rgb (cr, 0, 0, 0);
+  cairo_move_to (cr, 0, 0);
+  cairo_line_to (cr, text_width, 0);
+  cairo_line_to (cr, text_width, text_height);
+  cairo_line_to (cr, point, text_height);
+  cairo_line_to (cr, 0, text_height + point);
+  cairo_close_path (cr);
+
+  cairo_set_source_rgba (cr, 
+                        marker_color->red / 255.0,
+                        marker_color->green / 255.0,
+                        marker_color->blue / 255.0,
+                        marker_color->alpha / 255.0);
+  cairo_fill (cr);
+
+  cairo_set_line_width (cr, 1.0);
+  clutter_color_darken(marker_color, &darker_color);
+  cairo_move_to (cr, 0, 0);
+  cairo_line_to (cr, text_width, 0);
+  cairo_line_to (cr, text_width, text_height);
+  cairo_line_to (cr, point, text_height);
+  cairo_line_to (cr, 0, text_height + point);
+  cairo_close_path (cr);
+  cairo_set_source_rgba (cr, 
+                        darker_color.red / 255.0,
+                        darker_color.green / 255.0,
+                        darker_color.blue / 255.0,
+                        darker_color.alpha / 255.0);
+  cairo_stroke (cr);
+
+  cairo_destroy(cr);
+  clutter_container_add_actor(CLUTTER_CONTAINER(champlainMarker), bg);
+  clutter_actor_raise(actor, bg);
+
+  champlain_marker_set_anchor(CHAMPLAIN_MARKER(champlainMarker), 0, text_height + point);
+
+  return champlainMarker;
+}
+
index 38ddc08870ad23efa27c100df8a56fdbb20a9b09..899ae4328cb034dcc60b2be8746a11e56b44a7c3 100644 (file)
@@ -54,4 +54,8 @@ CHAMPLAIN_API void champlain_marker_set_position (ChamplainMarker *marker, gdoub
 
 CHAMPLAIN_API void champlain_marker_set_anchor (ChamplainMarker *marker, gint x, gint y);
 
+CHAMPLAIN_API ClutterActor *champlain_marker_new_with_label (const gchar *label, 
+                                 const gchar *font, 
+                                 ClutterColor *text_color, 
+                                 ClutterColor *marker_color);
 #endif
index 6c23fb2f65ca80f5dcb2e2529edb53004cbe5865..46df999155dfcee68f0d66990f4a418596a037b0 100644 (file)
  * Terminate the main loop.
  */
 static void
-on_destroy (GtkWidget * widget, gpointer data)
+on_destroy (GtkWidget *widget, gpointer data)
 {
   gtk_main_quit ();
 }
 
-
-static ClutterActor*
-create_marker (gchar* title, gdouble lon, gdouble lat)
-{
-  ClutterActor* marker, *actor;
-  
-  marker = champlain_marker_new();
-  champlain_marker_set_position(CHAMPLAIN_MARKER(marker), lon, lat);
-  champlain_marker_set_anchor(CHAMPLAIN_MARKER(marker), 0, 32);
-  
-  actor = clutter_texture_new_from_file("marker.svg", NULL);
-  clutter_container_add_actor(CLUTTER_CONTAINER(marker), actor);
-  
-  actor = clutter_label_new_with_text("Arial 14", title);
-  clutter_actor_set_position(actor, 30, 0);
-  clutter_container_add_actor(CLUTTER_CONTAINER(marker), actor);
-  
-  return marker;
-}
-
 static ClutterActor*
 create_marker_layer ()
 {
-  ClutterActor* layer, * marker;
+  ClutterActor *layer, *marker;
   
   layer = clutter_group_new();
   
-  marker = create_marker("MontrĂ©al", -73.563788, 45.528178);
+  ClutterColor orange = { 0xf3, 0x94, 0x07, 0xbb };
+  ClutterColor white = { 0xff, 0xff, 0xff, 0xff };
+  marker = champlain_marker_new_with_label("MontrĂ©al", "Airmole 14", NULL, NULL);
+  champlain_marker_set_position(CHAMPLAIN_MARKER(marker), -73.563788, 45.528178);
   clutter_container_add(CLUTTER_CONTAINER(layer), marker, NULL);
-  marker = create_marker("New York", -73.98, 40.77);
+  
+  marker = champlain_marker_new_with_label("New York", "Sans 25", &white, NULL);
+  champlain_marker_set_position(CHAMPLAIN_MARKER(marker), -73.98, 40.77);
   clutter_container_add(CLUTTER_CONTAINER(layer), marker, NULL);
-  marker = create_marker("Miami", -80.28, 25.82);
+  
+  marker = champlain_marker_new_with_label("Saint-Tite-des-Caps", "Serif 12", NULL, &orange);
+  champlain_marker_set_position(CHAMPLAIN_MARKER(marker), -70.764141, 47.130885);
   clutter_container_add(CLUTTER_CONTAINER(layer), marker, NULL);
   
   clutter_actor_hide(layer);
@@ -75,7 +62,7 @@ create_marker_layer ()
 }
 
 static void
-toggle_layer (GtkToggleButton * widget, ClutterActor* layer)
+toggle_layer (GtkToggleButton *widget, ClutterActor *layer)
 {
   if(gtk_toggle_button_get_active(widget))
     clutter_actor_show_all(layer);
@@ -84,7 +71,7 @@ toggle_layer (GtkToggleButton * widget, ClutterActor* layer)
 }
 
 static void
-map_source_changed (GtkWidget * widget, ChamplainView* view)
+map_source_changed (GtkWidget *widget, ChamplainView *view)
 {
   gchar* selection = gtk_combo_box_get_active_text(GTK_COMBO_BOX(widget));
   if (g_strcmp0(selection, OSM_MAP) == 0)
@@ -102,14 +89,14 @@ map_source_changed (GtkWidget * widget, ChamplainView* view)
 }
 
 static void 
-zoom_changed (GtkSpinButton *spinbutton, ChamplainViewview)
+zoom_changed (GtkSpinButton *spinbutton, ChamplainView *view)
 {
   gint zoom = gtk_spin_button_get_value_as_int(spinbutton);
   g_object_set(G_OBJECT(view), "zoom-level", zoom, NULL);
 }
 
 static void 
-map_zoom_changed (ChamplainViewview, GParamSpec *gobject, GtkSpinButton *spinbutton)
+map_zoom_changed (ChamplainView *view, GParamSpec *gobject, GtkSpinButton *spinbutton)
 {
   gint zoom;
   g_object_get(G_OBJECT(view), "zoom-level", &zoom, NULL);
@@ -117,13 +104,13 @@ map_zoom_changed (ChamplainView* view, GParamSpec *gobject, GtkSpinButton *spinb
 }
 
 static void
-zoom_in (GtkWidget * widget, ChamplainView* view)
+zoom_in (GtkWidget *widget, ChamplainView *view)
 {
   champlain_view_zoom_in(view);
 }
 
 static void
-zoom_out (GtkWidget * widget, ChamplainView* view)
+zoom_out (GtkWidget *widget, ChamplainView *view)
 {
   champlain_view_zoom_out(view);
 }
index 7a0ffbd168237bf7d459a00b0d2da40b344490f4..d2529d33811e6cd8c2e2cf92bbaa28b42ddbdca9 100644 (file)
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.61)
-AC_INIT(champlain, 0.1, pierre-luc@squidy.info)
+AC_INIT(champlain, 0.2, pierre-luc@squidy.info)
 AC_CONFIG_SRCDIR([champlain/champlainview.h])
 AC_CONFIG_HEADER([config.h])
 AC_CONFIG_MACRO_DIR(m4)
@@ -30,6 +30,8 @@ PKG_CHECK_MODULES(DEPS,
       gtk+-2.0 >= 2.2,
       clutter-0.8 >= 0.8,
       clutter-gtk-0.8 >= 0.8,
+      clutter-cairo-0.8 >= 0.8,
+      cairo >= 1.6,
       libsoup-2.4 >= 2.4.1,
       gio-2.0 >= 2.16
   ]