[clutter] interactive/image-box: Add a pure Image test, suitable for docs
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter] interactive/image-box: Add a pure Image test, suitable for docs
- Date: Fri, 16 Mar 2012 12:49:51 +0000 (UTC)
commit 1b4bfb04e5dc5f0a173b18d7c54b4d111f298604
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Fri Mar 9 16:26:34 2012 +0000
interactive/image-box: Add a pure Image test, suitable for docs
tests/interactive/Makefile.am | 4 +-
tests/interactive/test-image-box.c | 100 ++++++++++++++++++++++++++++++++++++
2 files changed, 103 insertions(+), 1 deletions(-)
---
diff --git a/tests/interactive/Makefile.am b/tests/interactive/Makefile.am
index f5a5c1d..2c38e30 100644
--- a/tests/interactive/Makefile.am
+++ b/tests/interactive/Makefile.am
@@ -65,7 +65,9 @@ UNIT_TESTS += test-pixmap.c
endif
if PIXBUF_TESTS
-UNIT_TESTS += test-image.c
+UNIT_TESTS += \
+ test-image.c \
+ test-image-box.c
endif
if OS_WIN32
diff --git a/tests/interactive/test-image-box.c b/tests/interactive/test-image-box.c
new file mode 100644
index 0000000..3d29a33
--- /dev/null
+++ b/tests/interactive/test-image-box.c
@@ -0,0 +1,100 @@
+#include <stdlib.h>
+#include <gmodule.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <clutter/clutter.h>
+
+static const struct {
+ ClutterContentGravity gravity;
+ const char *name;
+} gravities[] = {
+ { CLUTTER_CONTENT_GRAVITY_TOP_LEFT, "Top Left" },
+ { CLUTTER_CONTENT_GRAVITY_TOP, "Top" },
+ { CLUTTER_CONTENT_GRAVITY_TOP_RIGHT, "Top Right" },
+
+ { CLUTTER_CONTENT_GRAVITY_LEFT, "Left" },
+ { CLUTTER_CONTENT_GRAVITY_CENTER, "Center" },
+ { CLUTTER_CONTENT_GRAVITY_RIGHT, "Right" },
+
+ { CLUTTER_CONTENT_GRAVITY_BOTTOM_LEFT, "Bottom Left" },
+ { CLUTTER_CONTENT_GRAVITY_BOTTOM, "Bottom" },
+ { CLUTTER_CONTENT_GRAVITY_BOTTOM_RIGHT, "Bottom Right" },
+
+ { CLUTTER_CONTENT_GRAVITY_RESIZE_FILL, "Resize Fill" },
+ { CLUTTER_CONTENT_GRAVITY_RESIZE_ASPECT, "Resize Aspect" },
+};
+
+static int n_gravities = G_N_ELEMENTS (gravities);
+static int cur_gravity = 0;
+
+static void
+on_clicked (ClutterClickAction *action,
+ ClutterActor *actor)
+{
+ clutter_actor_set_content_gravity (actor, gravities[cur_gravity].gravity);
+
+ cur_gravity += 1;
+
+ if (cur_gravity >= n_gravities)
+ cur_gravity = 0;
+}
+
+G_MODULE_EXPORT const char *
+test_image_box_describe (void)
+{
+ return "A test with image content.";
+}
+
+G_MODULE_EXPORT int
+test_image_box_main (int argc, char *argv[])
+{
+ ClutterActor *stage, *box;
+ ClutterContent *image;
+ ClutterAction *action;
+ GdkPixbuf *pixbuf;
+
+ if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
+ return EXIT_FAILURE;
+
+ stage = clutter_stage_new ();
+ clutter_actor_set_name (stage, "Stage");
+ clutter_stage_set_title (CLUTTER_STAGE (stage), "Content");
+ clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
+ g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
+ clutter_actor_show (stage);
+
+ box = clutter_actor_new ();
+ clutter_actor_set_name (box, "Grid");
+ clutter_actor_set_margin_top (box, 12);
+ clutter_actor_set_margin_right (box, 12);
+ clutter_actor_set_margin_bottom (box, 12);
+ clutter_actor_set_margin_left (box, 12);
+ clutter_actor_set_layout_manager (box, clutter_flow_layout_new (CLUTTER_FLOW_HORIZONTAL));
+ clutter_actor_add_constraint (box, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0.0));
+ clutter_actor_add_child (stage, box);
+
+ pixbuf = gdk_pixbuf_new_from_file (TESTS_DATADIR G_DIR_SEPARATOR_S "redhand.png", NULL);
+ image = clutter_image_new ();
+ clutter_image_set_data (CLUTTER_IMAGE (image),
+ 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);
+ g_object_unref (pixbuf);
+
+ clutter_actor_set_content_gravity (box, CLUTTER_CONTENT_GRAVITY_TOP_LEFT);
+ clutter_actor_set_content (box, image);
+ g_object_unref (image);
+
+ action = clutter_click_action_new ();
+ g_signal_connect (action, "clicked", G_CALLBACK (on_clicked), NULL);
+ clutter_actor_set_reactive (box, TRUE);
+ clutter_actor_add_action (box, action);
+
+ clutter_main ();
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]