[gnome-devel-docs] Added initial code for the clutter image viewer in C.
- From: Chris Kühl <chriskuehl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-devel-docs] Added initial code for the clutter image viewer in C.
- Date: Sat, 4 Dec 2010 14:01:44 +0000 (UTC)
commit ce4a5ceb572447c91ad61363fa26e50c4713afdc
Author: Chris Kühl <chrisk openismus com>
Date: Sat Dec 4 15:00:37 2010 +0100
Added initial code for the clutter image viewer in C.
demos/clutter-image-viewer/CREDITS | 16 ++
.../berlin_images/berlin_01.jpg | Bin 0 -> 420284 bytes
.../berlin_images/berlin_02.jpg | Bin 0 -> 805766 bytes
.../berlin_images/berlin_03.jpg | Bin 0 -> 416260 bytes
.../berlin_images/berlin_04.jpg | Bin 0 -> 707196 bytes
.../berlin_images/berlin_05.jpg | Bin 0 -> 524287 bytes
.../berlin_images/berlin_06.jpg | Bin 0 -> 485684 bytes
.../berlin_images/berlin_07.jpg | Bin 0 -> 255185 bytes
.../berlin_images/berlin_08.jpg | Bin 0 -> 311446 bytes
.../berlin_images/berlin_09.jpg | Bin 0 -> 335614 bytes
.../berlin_images/berlin_10.jpg | Bin 0 -> 614353 bytes
.../berlin_images/berlin_11.jpg | Bin 0 -> 755752 bytes
.../berlin_images/berlin_12.jpg | Bin 0 -> 472960 bytes
demos/clutter-image-viewer/clutter-image-viewer.c | 157 ++++++++++++++++++++
14 files changed, 173 insertions(+), 0 deletions(-)
---
diff --git a/demos/clutter-image-viewer/CREDITS b/demos/clutter-image-viewer/CREDITS
new file mode 100644
index 0000000..c381ecc
--- /dev/null
+++ b/demos/clutter-image-viewer/CREDITS
@@ -0,0 +1,16 @@
+This beautiful images images were pulled from Flickr and are licenced under a Creative Commons license.
+
+Here are links to the original photos where you'll also find information pertaining to the photographer and the license.
+
+berlin_01.jpg: http://www.flickr.com/photos/29487767 N02/2904087529/
+berlin_02.jpg: http://www.flickr.com/photos/an_untrained_eye/1185704829/
+berlin_03.jpg: http://www.flickr.com/photos/werkunz/3848863160/
+berlin_04.jpg: http://www.flickr.com/photos/96dpi/4119691598/in/photostream/
+berlin_05.jpg: http://www.flickr.com/photos/seier/2584820865/in/photostream/
+berlin_06.jpg: http://www.flickr.com/photos/johnspooner/3205333317/in/photostream/
+berlin_07.jpg: http://www.flickr.com/photos/42311564 N00/275686244/in/photostream/
+berlin_08.jpg: http://www.flickr.com/photos/extranoise/383181110/in/photostream/
+berlin_09.jpg: http://www.flickr.com/photos/extranoise/155896930/in/photostream/
+berlin_10.jpg: http://www.flickr.com/photos/bcnbits/533496990/in/photostream/
+berlin_11.jpg: http://www.flickr.com/photos/bcnbits/870365081/in/photostream/
+berlin_12.jpg: http://www.flickr.com/photos/werkunz/3892782592/in/photostream/
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_01.jpg b/demos/clutter-image-viewer/berlin_images/berlin_01.jpg
new file mode 100644
index 0000000..5e0d8ee
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_01.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_02.jpg b/demos/clutter-image-viewer/berlin_images/berlin_02.jpg
new file mode 100644
index 0000000..41db896
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_02.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_03.jpg b/demos/clutter-image-viewer/berlin_images/berlin_03.jpg
new file mode 100644
index 0000000..fdf2ac8
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_03.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_04.jpg b/demos/clutter-image-viewer/berlin_images/berlin_04.jpg
new file mode 100644
index 0000000..394200f
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_04.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_05.jpg b/demos/clutter-image-viewer/berlin_images/berlin_05.jpg
new file mode 100644
index 0000000..014c19d
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_05.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_06.jpg b/demos/clutter-image-viewer/berlin_images/berlin_06.jpg
new file mode 100644
index 0000000..92145c5
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_06.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_07.jpg b/demos/clutter-image-viewer/berlin_images/berlin_07.jpg
new file mode 100644
index 0000000..a824100
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_07.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_08.jpg b/demos/clutter-image-viewer/berlin_images/berlin_08.jpg
new file mode 100644
index 0000000..b37d85a
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_08.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_09.jpg b/demos/clutter-image-viewer/berlin_images/berlin_09.jpg
new file mode 100644
index 0000000..c6d9992
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_09.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_10.jpg b/demos/clutter-image-viewer/berlin_images/berlin_10.jpg
new file mode 100644
index 0000000..9c35593
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_10.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_11.jpg b/demos/clutter-image-viewer/berlin_images/berlin_11.jpg
new file mode 100644
index 0000000..b08ebf6
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_11.jpg differ
diff --git a/demos/clutter-image-viewer/berlin_images/berlin_12.jpg b/demos/clutter-image-viewer/berlin_images/berlin_12.jpg
new file mode 100644
index 0000000..90f9a8d
Binary files /dev/null and b/demos/clutter-image-viewer/berlin_images/berlin_12.jpg differ
diff --git a/demos/clutter-image-viewer/clutter-image-viewer.c b/demos/clutter-image-viewer/clutter-image-viewer.c
new file mode 100644
index 0000000..ad70de7
--- /dev/null
+++ b/demos/clutter-image-viewer/clutter-image-viewer.c
@@ -0,0 +1,157 @@
+#include <clutter/clutter.h>
+
+#define STAGE_WIDTH 800
+#define STAGE_HEIGHT 600
+
+#define THUMBNAIL_SIZE 200
+#define ROW_COUNT (STAGE_HEIGHT / THUMBNAIL_SIZE)
+#define COL_COUNT (STAGE_WIDTH / THUMBNAIL_SIZE)
+#define THUMBNAIL_COUNT (ROW_COUNT * COL_COUNT)
+
+#define ANIMATION_DURATION_MS 500
+
+#define FOCUS_DEPTH 100.0
+#define UNFOCUS_DEPTH 0.0
+
+#define IMAGE_DIR_PATH "./berlin_images/"
+
+static GSList *actor_list = NULL;
+static GSList *img_path_list = NULL;
+
+typedef struct Position
+{
+ float x;
+ float y;
+}
+Position;
+
+static Position origin = {0, 0};
+
+static void
+load_image_path_names()
+{
+ /* Insure we can access the directory. */
+ GError *error = NULL;
+ GDir *dir = g_dir_open(IMAGE_DIR_PATH, 0, &error);
+ if(error)
+ {
+ g_warning("g_dir_open() failed with error: %s\n", error->message);
+ g_clear_error(&error);
+ return;
+ }
+
+ const gchar *filename = NULL;
+ filename = g_dir_read_name(dir);
+ while(filename)
+ {
+ gchar *path = g_build_filename(IMAGE_DIR_PATH, filename, NULL);
+
+ img_path_list = g_slist_prepend(img_path_list, path);
+ filename = g_dir_read_name(dir);
+ }
+}
+
+static void
+foreach_set_focus_state(gpointer data, gpointer user_data)
+{
+ ClutterActor *actor = CLUTTER_ACTOR(data);
+ gboolean is_reactive = *((gboolean*)user_data);
+
+ clutter_actor_set_reactive(actor, is_reactive);
+}
+
+static gboolean
+actor_clicked_cb(ClutterActor *actor,
+ ClutterEvent *event,
+ gpointer user_data)
+{
+ /* Flag to keep track of our state. */
+ static gboolean is_focused = FALSE;
+
+ g_slist_foreach(actor_list, foreach_set_focus_state, &is_focused);
+
+ if(!is_focused)
+ {
+ /*Save the current location before animating. */
+ clutter_actor_get_position(actor, &origin.x, &origin.y);
+ clutter_actor_set_reactive(actor, TRUE);
+ clutter_actor_animate(actor, CLUTTER_LINEAR, ANIMATION_DURATION_MS,
+ "x", (STAGE_WIDTH - STAGE_HEIGHT) / 2.0,
+ "y", 0.0,
+ "depth", FOCUS_DEPTH,
+ "width", (float) STAGE_HEIGHT,
+ "height", (float) STAGE_HEIGHT,
+ NULL);
+ }
+ else
+ {
+ clutter_actor_animate(actor, CLUTTER_LINEAR, ANIMATION_DURATION_MS,
+ "x", origin.x,
+ "y", origin.y,
+ "depth", UNFOCUS_DEPTH,
+ "width", (float) THUMBNAIL_SIZE,
+ "height", (float) THUMBNAIL_SIZE,
+ NULL);
+ }
+
+ /* Toggle our flag. */
+ is_focused = !is_focused;
+
+ return TRUE;
+}
+
+/* This functions handles setup and placing the rectangles. */
+static void
+initialize_actor(ClutterActor *actor, guint *row, guint *col)
+{
+ clutter_actor_set_size(actor, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
+ clutter_actor_set_position(actor, (*col) * THUMBNAIL_SIZE, (*row) * THUMBNAIL_SIZE);
+ clutter_actor_set_reactive(actor, TRUE);
+
+ g_signal_connect(actor,
+ "button-press-event",
+ G_CALLBACK(actor_clicked_cb),
+ NULL);
+}
+
+int
+main(int argc, char *argv[])
+{
+ /* Set the color as Red, Green, Blue and Alpha to values between */
+ /* 0 and 255. An alpha value of 255 is opaque and 0 is transparent.*/
+ ClutterColor stage_color = { 16, 16, 16, 255 };
+ ClutterActor *stage = NULL;
+
+ clutter_init (&argc, &argv);
+
+ /* We get the stage... */
+ stage = clutter_stage_get_default();
+ /* ...set the size for the stage... */
+ clutter_actor_set_size(stage, STAGE_WIDTH, STAGE_HEIGHT);
+ /* ...and its color. */
+ clutter_stage_set_color(CLUTTER_STAGE (stage), &stage_color);
+
+ load_image_path_names();
+
+ int row = 0;
+ int col = 0;
+ for(row=0; row < ROW_COUNT; ++row)
+ {
+ for(col=0; col < COL_COUNT; ++col)
+ {
+ GSList *img_path_node = g_slist_nth(img_path_list, (row * COL_COUNT) + col);
+ ClutterActor *actor = clutter_texture_new_from_file((gchar *)(img_path_node->data), NULL);
+ initialize_actor(actor, &row, &col);
+ clutter_container_add_actor(CLUTTER_CONTAINER(stage), actor);
+ actor_list = g_slist_prepend(actor_list, actor);
+ }
+ }
+
+ /* Show the stage. */
+ clutter_actor_show(stage);
+
+ /* Start the clutter main loop. */
+ clutter_main();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]