Debian Codegraph @

tests/interactive/test-rotate-zoom.c

raw
1 /*
2 * Copyright (C) 2013 Intel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU Lesser General Public License,
6 * version 2.1, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT ANY
9 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 * Boston, MA 02111-1307, USA.
17 *
18 */
19 #include <stdlib.h>
20 #include <math.h>
21 #include <cairo.h>
22 #include <glib.h>
23 #include <clutter/clutter.h>
24 #include <gdk-pixbuf/gdk-pixbuf.h>
25
26 #define STAGE_WIDTH 800
27 #define STAGE_HEIGHT 550
28
29 static ClutterActor *
30 create_hand (void)
31 {
32 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (TESTS_DATADIR G_DIR_SEPARATOR_S "redhand.png", NULL);
33 ClutterContent *image = clutter_image_new ();
34 ClutterActor *actor = clutter_actor_new ();
35
36 clutter_image_set_data (CLUTTER_IMAGE (image),
37 gdk_pixbuf_get_pixels (pixbuf),
38 gdk_pixbuf_get_has_alpha (pixbuf)
39 ? COGL_PIXEL_FORMAT_RGBA_8888
40 : COGL_PIXEL_FORMAT_RGB_888,
41 gdk_pixbuf_get_width (pixbuf),
42 gdk_pixbuf_get_height (pixbuf),
43 gdk_pixbuf_get_rowstride (pixbuf),
44 NULL);
45 clutter_actor_set_content (actor, image);
46 clutter_actor_set_size (actor,
47 gdk_pixbuf_get_width (pixbuf),
48 gdk_pixbuf_get_height (pixbuf));
49 clutter_actor_set_reactive (actor, TRUE);
50
51 g_object_unref (pixbuf);
52
53 return actor;
54 }
55
56 G_MODULE_EXPORT int
57 test_rotate_zoom_main (int argc, char *argv[])
58 {
59 ClutterActor *stage, *actor;
60 gfloat width, height;
61
62 /* initialize Clutter */
63 if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
64 return EXIT_FAILURE;
65
66 /* create a resizable stage */
67 stage = clutter_stage_new ();
68 g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
69 clutter_stage_set_title (CLUTTER_STAGE (stage), "Rotate and Zoom actions");
70 clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
71 clutter_actor_set_size (stage, STAGE_WIDTH, STAGE_HEIGHT);
72 clutter_actor_set_reactive (stage, FALSE);
73 clutter_actor_show (stage);
74
75 actor = create_hand ();
76 clutter_actor_add_action (actor, clutter_rotate_action_new ());
77 clutter_actor_add_action (actor, clutter_zoom_action_new ());
78 clutter_actor_add_child (stage, actor);
79
80 clutter_actor_get_size (actor, &width, &height);
81 clutter_actor_set_position (actor,
82 STAGE_WIDTH / 2 - width / 2,
83 STAGE_HEIGHT / 2 - height / 2);
84
85 clutter_main ();
86
87 return EXIT_SUCCESS;
88 }
89
90 G_MODULE_EXPORT const char *
91 test_rotate_zoom_describe (void)
92 {
93 return "Rotates and zooms an actor using touch events";
94 }