[clutter/wip/actor-content: 17/33] Add interactive ClutterImage test
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clutter/wip/actor-content: 17/33] Add interactive ClutterImage test
- Date: Wed, 18 May 2011 11:11:50 +0000 (UTC)
commit ee32c1a60888fc120e9b488a9e7b0b71203aa528
Author: Emmanuele Bassi <ebassi linux intel com>
Date: Tue Dec 7 14:50:23 2010 +0000
Add interactive ClutterImage test
tests/interactive/Makefile.am | 3 +-
tests/interactive/test-image-content.c | 103 ++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+), 1 deletions(-)
---
diff --git a/tests/interactive/Makefile.am b/tests/interactive/Makefile.am
index b03ff78..666eaeb 100644
--- a/tests/interactive/Makefile.am
+++ b/tests/interactive/Makefile.am
@@ -56,7 +56,8 @@ UNIT_TESTS = \
test-table-layout.c \
test-path-constraint.c \
test-snap-constraint.c \
- test-rgba-content.c
+ test-rgba-content.c \
+ test-image-content.c
if X11_TESTS
UNIT_TESTS += test-pixmap.c test-devices.c
diff --git a/tests/interactive/test-image-content.c b/tests/interactive/test-image-content.c
new file mode 100644
index 0000000..8c20746
--- /dev/null
+++ b/tests/interactive/test-image-content.c
@@ -0,0 +1,103 @@
+#include <stdlib.h>
+#include <gmodule.h>
+#include <gio/gio.h>
+#include <clutter/clutter.h>
+
+#define STAGE_WIDTH 400
+#define STAGE_HEIGHT 400
+#define PADDING 10
+#define SPACING 2
+#define RECT_SIZE 64
+
+static void
+load_async_done (GObject *gobject,
+ GAsyncResult *result,
+ gpointer dummy G_GNUC_UNUSED)
+{
+ GError *error = NULL;
+ gboolean res;
+ int width, height;
+
+ res = clutter_image_load_finish (CLUTTER_IMAGE (gobject), result,
+ &width,
+ &height,
+ &error);
+ if (!res)
+ {
+ g_print ("Unable to load 'redhand.png': %s", error->message);
+ g_error_free (error);
+ return;
+ }
+}
+
+G_MODULE_EXPORT int
+test_image_content_main (int argc,
+ char *argv[])
+{
+ ClutterActor *stage, *group;
+ ClutterContent *content;
+ int i, j, n_cols, n_rows;
+ float last_x, last_y;
+ GFile *gfile;
+
+ if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
+ return EXIT_FAILURE;
+
+ stage = clutter_stage_new ();
+ clutter_stage_set_title (CLUTTER_STAGE (stage), "Image Content");
+ clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
+ clutter_actor_set_size (stage, 400, 400);
+ clutter_actor_show (stage);
+
+ g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
+
+ content = clutter_rgba_new (g_random_double_range (0.0, 1.0),
+ g_random_double_range (0.0, 1.0),
+ g_random_double_range (0.0, 1.0),
+ 1.0);
+
+ group = clutter_group_new ();
+ clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
+ clutter_actor_add_constraint (group, clutter_align_constraint_new (stage, CLUTTER_ALIGN_X_AXIS, 0.5));
+ clutter_actor_add_constraint (group, clutter_align_constraint_new (stage, CLUTTER_ALIGN_Y_AXIS, 0.5));
+ clutter_actor_set_content (group, content);
+ g_object_unref (content);
+
+ content = CLUTTER_CONTENT (clutter_image_new ());
+ gfile = g_file_new_for_path (TESTS_DATADIR "/redhand.png");
+ clutter_image_load_async (CLUTTER_IMAGE (content), gfile, NULL,
+ load_async_done,
+ NULL);
+ g_object_unref (gfile);
+
+ n_cols = (STAGE_WIDTH - (2 * PADDING)) / (RECT_SIZE + (2 * SPACING));
+ n_rows = (STAGE_HEIGHT - (2 * PADDING)) / (RECT_SIZE + (2 * SPACING));
+
+ last_y = PADDING + SPACING;
+ for (i = 0; i < n_rows; i++)
+ {
+ last_x = PADDING + SPACING;
+ for (j = 0; j < n_cols; j++)
+ {
+ ClutterActor *rect = g_object_new (CLUTTER_TYPE_ACTOR, NULL);
+
+ clutter_actor_set_position (rect, last_x, last_y);
+ clutter_actor_set_size (rect, RECT_SIZE, RECT_SIZE);
+ clutter_actor_set_content (rect, content);
+
+ clutter_container_add_actor (CLUTTER_CONTAINER (group), rect);
+
+ last_x += RECT_SIZE + SPACING;
+ }
+
+ last_y += RECT_SIZE + SPACING;
+ }
+
+ clutter_actor_set_size (group, last_x + PADDING, last_y + PADDING);
+
+ g_object_unref (content);
+
+ clutter_main ();
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]