[libchamplain] Modify the background pattern interface to use ClutterContent



commit 5df37f9bd3aa2b2e64139be9e903f8f5b211452f
Author: Jiří Techet <techet gmail com>
Date:   Thu Apr 11 18:01:31 2013 +0200

    Modify the background pattern interface to use ClutterContent

 champlain/champlain-view.c |   69 ++++++++++++++++++++++---------------------
 champlain/champlain-view.h |    6 ++--
 demos/launcher-gtk.c       |   35 ++++++++++++----------
 3 files changed, 57 insertions(+), 53 deletions(-)
---
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 4627efd..51340d3 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -101,7 +101,7 @@ enum
   PROP_ZOOM_ON_DOUBLE_CLICK,
   PROP_ANIMATE_ZOOM,
   PROP_STATE,
-  PROP_BACKGROUND_TILE,
+  PROP_BACKGROUND_PATTERN,
 };
 
 #define PADDING 10
@@ -144,7 +144,7 @@ struct _ChamplainViewPrivate
   ClutterActor *zoom_layer; 
   ClutterActor *license_actor; /* Contains the license info */
 
-  ClutterTexture *background_tile_actor; 
+  ClutterContent *background_content; 
 
   ChamplainMapSource *map_source; /* Current map tile source */
   gboolean kinetic_mode;
@@ -449,8 +449,8 @@ champlain_view_get_property (GObject *object,
       g_value_set_enum (value, priv->state);
       break;
 
-    case PROP_BACKGROUND_TILE:
-      g_value_set_object (value, priv->background_tile_actor);
+    case PROP_BACKGROUND_PATTERN:
+      g_value_set_object (value, priv->background_content);
       break;
 
     default:
@@ -518,8 +518,8 @@ champlain_view_set_property (GObject *object,
       champlain_view_set_animate_zoom (view, g_value_get_boolean (value));
       break;
       
-    case PROP_BACKGROUND_TILE:
-      champlain_view_set_background_tile (view, g_value_get_object (value));
+    case PROP_BACKGROUND_PATTERN:
+      champlain_view_set_background_pattern (view, g_value_get_object (value));
       break;
 
     default:
@@ -563,10 +563,10 @@ champlain_view_dispose (GObject *object)
       priv->map_source = NULL;
     }
 
-  if (priv->background_tile_actor)
+  if (priv->background_content)
     {
-      clutter_actor_destroy (CLUTTER_ACTOR (priv->background_tile_actor));
-      priv->background_tile_actor = NULL;
+      g_object_unref (priv->background_content);
+      priv->background_content = NULL;
     }
 
   priv->map_layer = NULL;
@@ -898,16 +898,16 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass)
           G_PARAM_READABLE));
 
   /**
-   * ChamplainView:background-tile:
+   * ChamplainView:background-pattern:
    *
    * The pattern displayed in the background of the map.
    *
    * Since: 0.12.4
    */
   g_object_class_install_property (object_class,
-      PROP_BACKGROUND_TILE,
-      g_param_spec_object ("background-tile",
-          "Background tile",
+      PROP_BACKGROUND_PATTERN,
+      g_param_spec_object ("background-pattern",
+          "Background pattern",
           "The tile's background pattern",
           CLUTTER_TYPE_ACTOR,
           G_PARAM_READWRITE));
@@ -1017,7 +1017,7 @@ champlain_view_init (ChamplainView *view)
   priv->tiles_loading = 0;
   priv->update_viewport_timer = g_timer_new ();
   priv->animating_zoom = FALSE;
-  priv->background_tile_actor = NULL;
+  priv->background_content = NULL;
 
   g_signal_connect (view, "notify::width", G_CALLBACK (view_size_changed_cb), NULL);
   g_signal_connect (view, "notify::height", G_CALLBACK (view_size_changed_cb), NULL);
@@ -1849,10 +1849,11 @@ fill_background_tiles (ChamplainView *view)
   gint children_count;
   gint tiles_count, x_count, y_count, x_first, y_first;
   gdouble x_coord, y_coord;
-  gint i, x, y, size;
+  gint i, x, y;
+  gfloat size;
+
+  clutter_content_get_preferred_size (priv->background_content, &size, &size);
 
-  size = clutter_actor_get_width (CLUTTER_ACTOR (priv->background_tile_actor));
-  
   x_coord = priv->viewport_x + priv->anchor_x;
   y_coord = priv->viewport_y + priv->anchor_y;
 
@@ -1870,11 +1871,10 @@ fill_background_tiles (ChamplainView *view)
       /* add missing background tiles */
       for (i = children_count; i < tiles_count; ++i)
         {
-          ClutterActor *clone = clutter_texture_new ();
-          CoglHandle handle = clutter_texture_get_cogl_texture (priv->background_tile_actor);
-          clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (clone), handle);
-
-          clutter_actor_add_child (priv->background_layer, clone);
+          ClutterActor *actor = clutter_actor_new ();
+          clutter_actor_set_size (actor, size, size);
+          clutter_actor_set_content (actor, priv->background_content);
+          clutter_actor_add_child (priv->background_layer, actor);
         }
     }
   else if (children_count > tiles_count)
@@ -1956,7 +1956,7 @@ view_load_visible_tiles (ChamplainView *view)
   tile_map = g_slice_alloc0 (sizeof (gboolean) * x_count * y_count);
 
   /* fill background tiles */
-  if (priv->background_tile_actor != NULL)
+  if (priv->background_content != NULL)
     {
       fill_background_tiles (view);
     }
@@ -2421,7 +2421,7 @@ champlain_view_ensure_layers_visible (ChamplainView *view,
 
 
 /**
- * champlain_view_set_background_tile:
+ * champlain_view_set_background_pattern:
  * @view: a #ChamplainView
  * @background: The background texture
  *
@@ -2430,8 +2430,8 @@ champlain_view_ensure_layers_visible (ChamplainView *view,
  * Since: 0.12.4
  */
 void 
-champlain_view_set_background_tile (ChamplainView *view,
-    ClutterTexture *background)
+champlain_view_set_background_pattern (ChamplainView *view,
+    ClutterContent *background)
 {
   DEBUG_LOG ()
 
@@ -2439,15 +2439,16 @@ champlain_view_set_background_tile (ChamplainView *view,
 
   ChamplainViewPrivate *priv = view->priv;
   
-  if (priv->background_tile_actor)
-    clutter_actor_destroy (CLUTTER_ACTOR (priv->background_tile_actor));
-
-  priv->background_tile_actor = g_object_ref_sink (background);
+  if (priv->background_content)
+    g_object_unref (priv->background_content);
+    
+  priv->background_content = g_object_ref_sink (background);
+  clutter_actor_destroy_all_children (priv->background_layer);
 }
 
 
 /**
- * champlain_view_get_background_tile:
+ * champlain_view_get_background_pattern:
  * @view: a #ChamplainView
  *
  * Gets the current background texture displayed behind the map.
@@ -2456,8 +2457,8 @@ champlain_view_set_background_tile (ChamplainView *view,
  * 
  * Since: 0.12.4
  */
-ClutterTexture *
-champlain_view_get_background_tile (ChamplainView *view)
+ClutterContent *
+champlain_view_get_background_pattern (ChamplainView *view)
 {
   DEBUG_LOG ()
 
@@ -2465,7 +2466,7 @@ champlain_view_get_background_tile (ChamplainView *view)
 
   ChamplainViewPrivate *priv = view->priv;
 
-  return priv->background_tile_actor;
+  return priv->background_content;
 }
 
 
diff --git a/champlain/champlain-view.h b/champlain/champlain-view.h
index da490f4..244e24b 100644
--- a/champlain/champlain-view.h
+++ b/champlain/champlain-view.h
@@ -117,8 +117,8 @@ void champlain_view_set_zoom_on_double_click (ChamplainView *view,
     gboolean value);
 void champlain_view_set_animate_zoom (ChamplainView *view,
     gboolean value);
-void champlain_view_set_background_tile (ChamplainView *view,
-    ClutterTexture *background);
+void champlain_view_set_background_pattern (ChamplainView *view,
+    ClutterContent *background);
 
 void champlain_view_add_layer (ChamplainView *view,
     ChamplainLayer *layer);
@@ -136,7 +136,7 @@ gboolean champlain_view_get_keep_center_on_resize (ChamplainView *view);
 gboolean champlain_view_get_zoom_on_double_click (ChamplainView *view);
 gboolean champlain_view_get_animate_zoom (ChamplainView *view);
 ChamplainState champlain_view_get_state (ChamplainView *view);
-ClutterTexture *champlain_view_get_background_tile (ChamplainView *view);
+ClutterContent *champlain_view_get_background_pattern (ChamplainView *view);
 
 void champlain_view_reload_tiles (ChamplainView *view);
 
diff --git a/demos/launcher-gtk.c b/demos/launcher-gtk.c
index 828ab0b..e71ada8 100644
--- a/demos/launcher-gtk.c
+++ b/demos/launcher-gtk.c
@@ -27,7 +27,7 @@
 #define N_COLS 2
 #define COL_ID 0
 #define COL_NAME 1
-#define TILE_SQUARE_SIZE 8
+#define TILE_SQUARE_SIZE 32
 
 static ChamplainPathLayer *path_layer;
 static ChamplainPathLayer *path;
@@ -213,28 +213,26 @@ append_point (ChamplainPathLayer *layer, gdouble lon, gdouble lat)
 }
 
 
-static ClutterTexture *
-fill_background_tile (gint size)
+static gboolean
+draw_background_tile (ClutterCanvas *canvas,
+    cairo_t *cr,
+    int width,
+    int height)
 {
-  ClutterActor *actor = NULL;
-  cairo_t *cr;
   cairo_pattern_t *pat;
-  gint no_of_squares = size / TILE_SQUARE_SIZE;
+  gint no_of_squares = width / TILE_SQUARE_SIZE;
   gint row, column;
 
-  actor = clutter_cairo_texture_new (size, size);
-
   /* Create the background tile */
-  cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (actor));
-  pat = cairo_pattern_create_linear (size / 2.0, 0.0, size, size / 2.0);
+  pat = cairo_pattern_create_linear (width / 2.0, 0.0, width, width / 2.0);
   cairo_pattern_add_color_stop_rgb (pat, 0, 0.662, 0.662, 0.662);
   cairo_set_source (cr, pat);
-  cairo_rectangle (cr, 0, 0, size, size);
+  cairo_rectangle (cr, 0, 0, width, width);
   cairo_fill (cr);
   cairo_pattern_destroy (pat);
 
   /* Filling the tile */
-  cairo_set_source_rgb (cr, 0.411, 0.411, 0.411);
+  cairo_set_source_rgb (cr, 0.811, 0.811, 0.811);
   cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
 
   for (row = 0; row < no_of_squares; ++row)
@@ -253,9 +251,8 @@ fill_background_tile (gint size)
       cairo_fill (cr);
     }
   cairo_stroke (cr);
-  cairo_destroy (cr);
-
-  return CLUTTER_TEXTURE(actor);
+  
+  return TRUE;
 }
 
 
@@ -321,7 +318,13 @@ main (int argc,
   champlain_view_add_layer (view, CHAMPLAIN_LAYER (path));
   champlain_view_add_layer (view, CHAMPLAIN_LAYER (layer));
   
-  champlain_view_set_background_tile (view, fill_background_tile (256));
+  ClutterContent *canvas;
+  canvas = clutter_canvas_new ();
+  clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 256, 256);
+  g_signal_connect (canvas, "draw", G_CALLBACK (draw_background_tile), NULL);
+  clutter_content_invalidate (canvas);
+
+  champlain_view_set_background_pattern (view, canvas);
 
   path_layer = champlain_path_layer_new ();
   /* Cheap approx of Highway 10 */


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