summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
authorJiří Techet <techet@gmail.com>2013-04-13 00:42:17 +0200
committerJiří Techet <techet@gmail.com>2013-04-13 00:42:17 +0200
commit4bf9388ae1697901913f8deb8eed18f14b3d41b1 (patch)
treec65fdcbf6c6e19023b99d2ed24a854012439bd33 /demos
parent332c00d46ad6b51661bf249d8a704604498234b1 (diff)
downloadlibchamplain-4bf9388ae1697901913f8deb8eed18f14b3d41b1.tar.gz
Update demos to use Clutter 1.12 API
Diffstat (limited to 'demos')
-rw-r--r--demos/Makefile.am8
-rw-r--r--demos/animated-marker.c132
-rw-r--r--demos/launcher-gtk.c5
-rw-r--r--demos/launcher-vala.vala21
-rw-r--r--demos/local-rendering.c10
-rwxr-xr-xdemos/minimal.py2
-rwxr-xr-xdemos/polygons.py19
-rw-r--r--demos/url-marker.c59
8 files changed, 136 insertions, 120 deletions
diff --git a/demos/Makefile.am b/demos/Makefile.am
index 0126324..6433420 100644
--- a/demos/Makefile.am
+++ b/demos/Makefile.am
@@ -20,7 +20,7 @@ polygons_SOURCES = polygons.c
polygons_LDADD = $(DEPS_LIBS) ../champlain/libchamplain-@CHAMPLAIN_API_VERSION@.la
url_marker_SOURCES = url-marker.c
-url_marker_CPPFLAGS = $(DEPS_CFLAGS) $(SOUP_CFLAGS)
+url_marker_CPPFLAGS = $(DEPS_CFLAGS) $(SOUP_CFLAGS) $(WARN_CFLAGS)
url_marker_LDADD = $(SOUP_LIBS) $(DEPS_LIBS) ../champlain/libchamplain-@CHAMPLAIN_API_VERSION@.la
create_destroy_test_SOURCES = create-destroy-test.c
@@ -29,14 +29,14 @@ create_destroy_test_LDADD = $(DEPS_LIBS) ../champlain/libchamplain-@CHAMPLAIN_AP
if ENABLE_GTK
noinst_PROGRAMS += minimal-gtk
minimal_gtk_SOURCES = minimal-gtk.c
-minimal_gtk_CPPFLAGS = $(GTK_CFLAGS)
+minimal_gtk_CPPFLAGS = $(GTK_CFLAGS) $(WARN_CFLAGS)
minimal_gtk_LDADD = $(GTK_LIBS) $(DEPS_LIBS) \
../champlain-gtk/libchamplain-gtk-@CHAMPLAIN_API_VERSION@.la \
../champlain/libchamplain-@CHAMPLAIN_API_VERSION@.la
noinst_PROGRAMS += launcher-gtk
launcher_gtk_SOURCES = launcher-gtk.c markers.c
-launcher_gtk_CPPFLAGS = $(GTK_CFLAGS)
+launcher_gtk_CPPFLAGS = $(GTK_CFLAGS) $(WARN_CFLAGS)
launcher_gtk_LDADD = $(GTK_LIBS) $(DEPS_LIBS) \
../champlain-gtk/libchamplain-gtk-@CHAMPLAIN_API_VERSION@.la \
../champlain/libchamplain-@CHAMPLAIN_API_VERSION@.la
@@ -44,7 +44,7 @@ launcher_gtk_LDADD = $(GTK_LIBS) $(DEPS_LIBS) \
if ENABLE_MEMPHIS
noinst_PROGRAMS += local-rendering
local_rendering_SOURCES = local-rendering.c
-local_rendering_CPPFLAGS = $(GTK_CFLAGS) $(MEMPHIS_CFLAGS)
+local_rendering_CPPFLAGS = $(GTK_CFLAGS) $(MEMPHIS_CFLAGS) $(WARN_CFLAGS)
local_rendering_LDADD = $(GTK_LIBS) $(MEMPHIS_LIBS) $(DEPS_LIBS) \
../champlain-gtk/libchamplain-gtk-@CHAMPLAIN_API_VERSION@.la \
../champlain/libchamplain-@CHAMPLAIN_API_VERSION@.la
diff --git a/demos/animated-marker.c b/demos/animated-marker.c
index 8736298..4c2e334 100644
--- a/demos/animated-marker.c
+++ b/demos/animated-marker.c
@@ -21,24 +21,13 @@
#define MARKER_SIZE 10
-/* The marker is drawn with cairo. It is composed of 1 static filled circle
- * and 1 stroked circle animated as an echo.
- */
-static ClutterActor *
-create_marker ()
-{
- ClutterActor *marker;
- ClutterActor *bg;
- ClutterTimeline *timeline;
- cairo_t *cr;
-
- /* Create the marker */
- marker = champlain_custom_marker_new ();
-
- /* Static filled circle ----------------------------------------------- */
- bg = clutter_cairo_texture_new (MARKER_SIZE, MARKER_SIZE);
- cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (bg));
+static gboolean
+draw_center (ClutterCanvas *canvas,
+ cairo_t *cr,
+ int width,
+ int height)
+{
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint(cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
@@ -51,19 +40,18 @@ create_marker ()
/* Fill the circle */
cairo_set_source_rgba (cr, 0.1, 0.1, 0.9, 1.0);
cairo_fill (cr);
+
+ return TRUE;
+}
- cairo_destroy (cr);
-
- /* Add the circle to the marker */
- clutter_actor_add_child (marker, bg);
- clutter_actor_set_anchor_point_from_gravity (bg, CLUTTER_GRAVITY_CENTER);
- clutter_actor_set_position (bg, 0, 0);
-
- /* Echo circle -------------------------------------------------------- */
- bg = clutter_cairo_texture_new (2 * MARKER_SIZE, 2 * MARKER_SIZE);
- cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (bg));
- /* Draw the circle */
+static gboolean
+draw_circle (ClutterCanvas *canvas,
+ cairo_t *cr,
+ int width,
+ int height)
+{
+ /* Draw the circle */
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_arc (cr, MARKER_SIZE, MARKER_SIZE, 0.9 * MARKER_SIZE, 0, 2 * M_PI);
cairo_close_path (cr);
@@ -73,28 +61,78 @@ create_marker ()
cairo_set_source_rgba (cr, 0.1, 0.1, 0.7, 1.0);
cairo_stroke (cr);
- cairo_destroy (cr);
+ return TRUE;
+}
+
+
+/* The marker is drawn with cairo. It is composed of 1 static filled circle
+ * and 1 stroked circle animated as an echo.
+ */
+static ClutterActor *
+create_marker ()
+{
+ ClutterActor *marker;
+ ClutterActor *bg;
+ ClutterContent *canvas;
+ ClutterTransition *transition;
+
+ /* Create the marker */
+ marker = champlain_custom_marker_new ();
+
+ /* Static filled circle ----------------------------------------------- */
+ canvas = clutter_canvas_new ();
+ clutter_canvas_set_size (CLUTTER_CANVAS (canvas), MARKER_SIZE, MARKER_SIZE);
+ g_signal_connect (canvas, "draw", G_CALLBACK (draw_center), NULL);
+
+ bg = clutter_actor_new ();
+ clutter_actor_set_size (bg, MARKER_SIZE, MARKER_SIZE);
+ clutter_actor_set_content (bg, canvas);
+ clutter_content_invalidate (canvas);
+ g_object_unref (canvas);
+
+ /* Add the circle to the marker */
+ clutter_actor_add_child (marker, bg);
+ clutter_actor_set_position (bg, -0.5 * MARKER_SIZE, -0.5 * MARKER_SIZE);
+
+ /* Echo circle -------------------------------------------------------- */
+ canvas = clutter_canvas_new ();
+ clutter_canvas_set_size (CLUTTER_CANVAS (canvas), 2 * MARKER_SIZE, 2 * MARKER_SIZE);
+ g_signal_connect (canvas, "draw", G_CALLBACK (draw_circle), NULL);
+
+ bg = clutter_actor_new ();
+ clutter_actor_set_size (bg, 2 * MARKER_SIZE, 2 * MARKER_SIZE);
+ clutter_actor_set_content (bg, canvas);
+ clutter_content_invalidate (canvas);
+ g_object_unref (canvas);
/* Add the circle to the marker */
clutter_actor_add_child (marker, bg);
- clutter_actor_lower_bottom (bg); /* Ensure it is under the previous circle */
- clutter_actor_set_position (bg, 0, 0);
- clutter_actor_set_anchor_point_from_gravity (bg, CLUTTER_GRAVITY_CENTER);
-
- /* Animate the echo circle */
- timeline = clutter_timeline_new (1000);
- clutter_timeline_set_loop (timeline, TRUE);
- clutter_actor_set_opacity (CLUTTER_ACTOR (bg), 255);
- clutter_actor_set_scale (CLUTTER_ACTOR (bg), 0.5, 0.5);
- clutter_actor_animate_with_timeline (CLUTTER_ACTOR (bg),
- CLUTTER_EASE_OUT_SINE,
- timeline,
- "opacity", 0,
- "scale-x", 2.0,
- "scale-y", 2.0,
- NULL);
-
- clutter_timeline_start (timeline);
+ clutter_actor_set_pivot_point (bg, 0.5, 0.5);
+ clutter_actor_set_position (bg, -MARKER_SIZE, -MARKER_SIZE);
+
+ transition = clutter_property_transition_new ("opacity");
+ clutter_actor_set_easing_mode (bg, CLUTTER_EASE_OUT_SINE);
+ clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 1000);
+ clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), -1);
+ clutter_transition_set_from (transition, G_TYPE_UINT, 255);
+ clutter_transition_set_to (transition, G_TYPE_UINT, 0);
+ clutter_actor_add_transition (bg, "animate-opacity", transition);
+
+ transition = clutter_property_transition_new ("scale-x");
+ clutter_actor_set_easing_mode (bg, CLUTTER_EASE_OUT_SINE);
+ clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 1000);
+ clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), -1);
+ clutter_transition_set_from (transition, G_TYPE_FLOAT, 0.5);
+ clutter_transition_set_to (transition, G_TYPE_FLOAT, 2.0);
+ clutter_actor_add_transition (bg, "animate-scale-x", transition);
+
+ transition = clutter_property_transition_new ("scale-y");
+ clutter_actor_set_easing_mode (bg, CLUTTER_EASE_OUT_SINE);
+ clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 1000);
+ clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), -1);
+ clutter_transition_set_from (transition, G_TYPE_FLOAT, 0.5);
+ clutter_transition_set_to (transition, G_TYPE_FLOAT, 2.0);
+ clutter_actor_add_transition (bg, "animate-scale-y", transition);
return marker;
}
diff --git a/demos/launcher-gtk.c b/demos/launcher-gtk.c
index e71ada8..d1d2125 100644
--- a/demos/launcher-gtk.c
+++ b/demos/launcher-gtk.c
@@ -63,7 +63,7 @@ toggle_layer (GtkToggleButton *widget,
}
-gboolean
+static gboolean
mouse_click_cb (ClutterActor *actor, ClutterButtonEvent *event, ChamplainView *view)
{
gdouble lat, lon;
@@ -165,7 +165,6 @@ build_combo_box (GtkComboBox *box)
{
ChamplainMapSourceFactory *factory;
GSList *sources, *iter;
- gint i = 0;
GtkTreeStore *store;
GtkTreeIter parent;
GtkCellRenderer *cell;
@@ -266,8 +265,6 @@ main (int argc,
ChamplainMarkerLayer *layer;
ClutterActor *scale;
ChamplainLicense *license_actor;
- gint size;
- ChamplainMapSource *map_source;
if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return 1;
diff --git a/demos/launcher-vala.vala b/demos/launcher-vala.vala
index 822a2b5..ed772f4 100644
--- a/demos/launcher-vala.vala
+++ b/demos/launcher-vala.vala
@@ -30,21 +30,21 @@ public class Launcher : GLib.Object
{
float width, total_width = 0;
- stage = Clutter.Stage.get_default ();
+ stage = new Clutter.Stage ();
stage.title = "Champlain Vala Example";
stage.set_size (800, 600);
/* Create the map view */
view = new Champlain.View ();
view.set_size (800, 600);
- stage.add_actor (view);
+ stage.add_child (view);
/* Create the buttons */
- var buttons = new Clutter.Group ();
+ var buttons = new Clutter.Actor ();
buttons.set_position (PADDING, PADDING);
var button = make_button ("Zoom in");
- buttons.add_actor (button);
+ buttons.add_child (button);
button.reactive = true;
button.get_size (out width, null);
total_width += width + PADDING;
@@ -54,7 +54,7 @@ public class Launcher : GLib.Object
});
button = make_button ("Zoom out");
- buttons.add_actor (button);
+ buttons.add_child (button);
button.reactive = true;
button.set_position (total_width, 0);
button.get_size (out width, null);
@@ -64,7 +64,7 @@ public class Launcher : GLib.Object
return true;
});
- stage.add_actor (buttons);
+ stage.add_child (buttons);
/* Create the markers and marker layer */
var layer = new DemoLayer ();
@@ -106,14 +106,15 @@ public class Launcher : GLib.Object
Clutter.Color black = { 0x00, 0x00, 0x00, 0xff };
float width, height;
- var button = new Clutter.Group ();
+ var button = new Clutter.Actor ();
- var button_bg = new Clutter.Rectangle.with_color (white);
- button.add_actor (button_bg);
+ var button_bg = new Clutter.Actor ();
+ button_bg.set_background_color (white);
+ button.add_child (button_bg);
button_bg.opacity = 0xcc;
var button_text = new Clutter.Text.full ("Sans 10", text, black);
- button.add_actor (button_text);
+ button.add_child (button_text);
button_text.get_size (out width, out height);
button_bg.set_size (width + PADDING * 2, height + PADDING * 2);
diff --git a/demos/local-rendering.c b/demos/local-rendering.c
index 51b2ee4..3fc706b 100644
--- a/demos/local-rendering.c
+++ b/demos/local-rendering.c
@@ -22,6 +22,7 @@
#include <champlain/champlain-memphis-renderer.h>
#include <champlain-gtk/champlain-gtk.h>
#include <clutter-gtk/clutter-gtk.h>
+#include <memphis/memphis.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
@@ -181,7 +182,7 @@ static void
rule_window_close_cb (GtkWidget *widget, gpointer data)
{
gtk_widget_destroy (rule_edit_window);
- memphis_rule_free (current_rule);
+ memphis_rule_free (MEMPHIS_RULE (current_rule));
current_rule = NULL;
rule_edit_window = NULL;
}
@@ -238,7 +239,7 @@ rule_apply_cb (GtkWidget *widget, ChamplainMemphisRenderer *renderer)
}
-GtkWidget *
+static GtkWidget *
gtk_memphis_prop_new (gint type, ChamplainMemphisRuleAttr *attr)
{
GtkWidget *hbox, *cb, *sb1, *sb2, *sb3;
@@ -411,7 +412,7 @@ request_osm_data_cb (GtkWidget *widget, ChamplainView *view)
}
-void
+static void
bg_color_set_cb (GtkColorButton *widget, ChamplainView *view)
{
GdkRGBA gdk_color;
@@ -610,7 +611,6 @@ build_source_combo_box (GtkComboBox *box)
{
ChamplainMapSourceFactory *factory;
GSList *sources, *iter;
- gint i = 0;
GtkTreeStore *store;
GtkTreeIter parent;
GtkCellRenderer *cell;
@@ -698,7 +698,7 @@ build_rules_combo_box (GtkComboBox *box)
}
-void
+static void
list_item_selected_cb (GtkTreeView *tree_view,
GtkTreePath *path,
GtkTreeViewColumn *column,
diff --git a/demos/minimal.py b/demos/minimal.py
index 6be224e..3d7a4c1 100755
--- a/demos/minimal.py
+++ b/demos/minimal.py
@@ -6,10 +6,8 @@
# export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:/usr/local/lib/girepository-1.0/
from gi.repository import GtkClutter
-GtkClutter.init([])
from gi.repository import GObject, Gtk, GtkChamplain
-GObject.threads_init()
GtkClutter.init([])
window = Gtk.Window(type=Gtk.WindowType.TOPLEVEL)
diff --git a/demos/polygons.py b/demos/polygons.py
index a99a863..a888309 100755
--- a/demos/polygons.py
+++ b/demos/polygons.py
@@ -31,14 +31,15 @@ def make_button(text):
black = Clutter.Color.new(0x00, 0x00, 0x00, 0xff)
white = Clutter.Color.new(0xff, 0xff, 0xff, 0xff)
- button = Clutter.Group()
+ button = Clutter.Actor()
- button_bg = Clutter.Rectangle.new_with_color(white)
+ button_bg = Clutter.Actor()
+ button_bg.set_background_color(white)
button_bg.set_opacity(0xcc)
- button.add_actor(button_bg)
+ button.add_child(button_bg)
button_text = Clutter.Text.new_full("Sans 10", text, black)
- button.add_actor(button_text)
+ button.add_child(button_text)
(width, height) = button_text.get_size()
button_bg.set_size(width + PADDING * 2, height + PADDING * 2)
@@ -67,14 +68,14 @@ if __name__ == '__main__':
# Create the map view
view = Champlain.View()
view.set_size(800, 600)
- stage.add_actor(view)
+ stage.add_child(view)
# Create the buttons
- buttons = Clutter.Group()
+ buttons = Clutter.Actor()
buttons.set_position(PADDING, PADDING)
button = make_button('Zoom in')
- buttons.add_actor(button)
+ buttons.add_child(button)
button.set_reactive(True)
(width, height) = button.get_size()
total_width += width + PADDING;
@@ -82,13 +83,13 @@ if __name__ == '__main__':
button.connect('button-release-event', zoom_in, view)
button = make_button('Zoom out')
- buttons.add_actor(button)
+ buttons.add_child(button)
button.set_reactive(True)
button.set_position(total_width, 0)
(width, height) = button.get_size()
button.connect('button-release-event', zoom_out, view)
- stage.add_actor(buttons)
+ stage.add_child(buttons)
# Draw a line
layer = Champlain.PathLayer()
diff --git a/demos/url-marker.c b/demos/url-marker.c
index c9133be..73a13dd 100644
--- a/demos/url-marker.c
+++ b/demos/url-marker.c
@@ -88,49 +88,30 @@ cleanup:
}
-/**
- * Transforms a GdkPixbuf into a ClutterTexture.
- * If there's an error building the ClutterActor (the texture) the function
- * will return NULL and set error accordingly.
- *
- * If you are using ClutterGtk, you can also use gtk_clutter_texture_set_from_pixbuf
- * instead of cluter_texture_set_from_rgb_data.
- *
- * The ClutterActor has to be freed with clutter_actor_destroy.
- */
static ClutterActor *
texture_new_from_pixbuf (GdkPixbuf *pixbuf, GError **error)
{
ClutterActor *texture = NULL;
- const guchar *data;
- gboolean has_alpha, success;
- int width, height, rowstride;
- ClutterTextureFlags flags = 0;
-
- *error = NULL;
-
- data = gdk_pixbuf_get_pixels (pixbuf);
- width = gdk_pixbuf_get_width (pixbuf);
- height = gdk_pixbuf_get_height (pixbuf);
- has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
- rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-
- texture = clutter_texture_new ();
- success = clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE (texture),
- data,
- has_alpha,
- width,
- height,
- rowstride,
- (has_alpha ? 4 : 3),
- flags,
- error);
-
- if (!success)
- {
- clutter_actor_destroy (CLUTTER_ACTOR (texture));
- texture = NULL;
- }
+ gfloat width, height;
+ ClutterContent *content;
+
+ content = clutter_image_new ();
+ clutter_image_set_data (CLUTTER_IMAGE (content),
+ gdk_pixbuf_get_pixels (pixbuf),
+ gdk_pixbuf_get_has_alpha (pixbuf)
+ ? COGL_PIXEL_FORMAT_RGBA_8888
+ : COGL_PIXEL_FORMAT_RGB_888,
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ gdk_pixbuf_get_rowstride (pixbuf),
+ NULL);
+
+ texture = clutter_actor_new ();
+ clutter_content_get_preferred_size (content, &width, &height);
+ clutter_actor_set_size (texture, width, height);
+ clutter_actor_set_content (texture, content);
+ clutter_content_invalidate (content);
+ g_object_unref (content);
return texture;
}