14 /* Press and drag to pan around, or tap to move between zoom levels.
15 * A file must be specified on the command-line, and it must be > 640x480.
17 * This file will be loaded and placed into a shared memory area, which will
18 * be read by hildon-desktop.
19 * An area 640x480 in the top-left corner will be updated with an animation
20 * to show how to modify the area. */
22 #define DO_ANIM 1 /* whether to animate the area defined below */
26 #define ANIM_WIDTH 640
27 #define ANIM_HEIGHT 480
28 #define ANIM_FRAMES 64
30 /* this could come from ftol, but we hardcode it for this example */
31 static key_t shm_key = 0xCAFEBEEF;
33 static gint bpp, width, height;
34 static guchar *shm = 0; /* shared mem area */
35 static int anim_frame = 0;
37 static double scale = 1;
38 static double scale_smooth = 1;
41 static double x_inc = 0;
42 static double y_inc = 0;
43 static double cursor_move = 0;
45 static int last_x, last_y, pressed = 0;
47 static void timeout_cb (void *obj)
49 HildonRemoteTexture *actor = HILDON_REMOTE_TEXTURE (obj);
54 for (y=0;y<ANIM_HEIGHT;y++)
56 guchar *anim = &shm[(width*(y+ANIM_Y) + ANIM_X)*bpp];
57 for (x=0;x<ANIM_WIDTH;x++)
59 *anim = ((x+anim_frame)&(ANIM_FRAMES-1)) * 256 / ANIM_FRAMES;
64 hildon_remote_texture_update_area(actor,
65 ANIM_X, ANIM_Y, ANIM_WIDTH, ANIM_HEIGHT);
71 if (fabs(x_inc)>0.01 || fabs(y_inc)>0.01)
77 hildon_remote_texture_set_offset (actor, x, y);
80 if (fabs(scale - scale_smooth)>0.01)
82 scale_smooth = scale_smooth*0.9 + scale*0.1;
83 hildon_remote_texture_set_scale (actor, scale_smooth, scale_smooth);
89 static void press_cb (GtkWidget *widget,
90 GdkEventButton *event, gpointer data)
98 static void release_cb (GtkWidget *widget,
99 GdkEventButton *event, gpointer obj)
105 if (cursor_move < 40)
108 if (scale>8) scale=0.125;
109 /* scale smooth will actually do the update */
113 static void motion_cb (GtkWidget *widget,
114 GdkEventMotion *event, gpointer data)
116 HildonRemoteTexture *actor = HILDON_REMOTE_TEXTURE(data);
120 x_inc = event->x - last_x;
121 y_inc = event->y - last_y;
122 cursor_move += fabs(x_inc) + fabs(y_inc);
129 hildon_remote_texture_set_offset (actor, x, y);
137 main (int argc, char **argv)
139 gtk_init (&argc, &argv);
147 printf("USAGE: hildon-remote-texture-example image.png\n");
148 printf("NB. Image should be 640x480 in size or greater\n");
152 g_debug("Loading Image %s...", argv[1]);
153 pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
154 width = gdk_pixbuf_get_width (pixbuf);
155 height = gdk_pixbuf_get_height (pixbuf);
156 bpp = gdk_pixbuf_get_n_channels (pixbuf); /* assume 8 bit */
157 gpixels = gdk_pixbuf_get_pixels (pixbuf);
158 g_debug("Creating Shared Memory");
159 size_t shm_size = width*height*bpp;
163 * Create the segment, attach it to our data space, and copy in the
166 if ((shmid = shmget(shm_key, shm_size, IPC_CREAT | 0666)) < 0) {
171 if ((shm = shmat(shmid, NULL, 0)) == (guchar *) -1) {
176 memcpy(shm, gpixels, shm_size);
179 /* Craete the program with the remote texture */
180 HildonProgram *program = hildon_program_get_instance ();
181 HildonWindow *window = HILDON_WINDOW(
182 hildon_window_new());
183 hildon_program_add_window (program, window);
184 gtk_widget_show (GTK_WIDGET(window));
186 HildonRemoteTexture *actor = HILDON_REMOTE_TEXTURE
187 (hildon_remote_texture_new ());
189 g_set_application_name ("Animation");
191 g_signal_connect (G_OBJECT (window),
193 G_CALLBACK (gtk_main_quit), NULL);
194 g_signal_connect (G_OBJECT (window),
195 "button-press-event",
196 G_CALLBACK (press_cb),
198 g_signal_connect (G_OBJECT (window),
199 "button-release-event",
200 G_CALLBACK (release_cb),
202 g_signal_connect (G_OBJECT (window),
203 "motion-notify-event",
204 G_CALLBACK (motion_cb),
206 gtk_widget_add_events (GTK_WIDGET(window),
207 GDK_BUTTON_PRESS_MASK|
208 GDK_BUTTON_MOTION_MASK|
209 GDK_BUTTON_RELEASE_MASK);
212 gtk_widget_show_all (GTK_WIDGET (actor));
215 /* vital: add this remote texture to a proper window */
216 hildon_remote_texture_set_parent(actor, GTK_WINDOW(window));
217 /* Set the actual data we'll be displaying, via the shm key */
218 hildon_remote_texture_set_image(actor, shm_key, width, height, bpp);
219 /* Set the actual position on the screen */
220 hildon_remote_texture_set_position (actor, 0, 56, W, H-56);
221 hildon_remote_texture_set_show (actor, 1);
223 g_timeout_add (25, (GSourceFunc)timeout_cb, actor);
225 printf ("going to gtk_main ()\n");