#include <stdlib.h>
#include <clutter/clutter.h>
#include <gdk/gdk.h>
gboolean on_event_cb (ClutterActor *actor, ClutterEvent *event, gpointer user_data)
{
switch (event->type)
{
case CLUTTER_SCROLL:
{
ClutterScrollDirection scroll_direction=clutter_event_get_scroll_direction (event);
if (scroll_direction == CLUTTER_SCROLL_SMOOTH)
{
gdouble delta, x_scale, y_scale;
gfloat x_event,y_event,width,height;
gfloat x_pivot,y_pivot;
clutter_event_get_scroll_delta (event,NULL,&delta);
clutter_actor_get_scale (actor,&x_scale,&y_scale);
x_scale = x_scale * (1 - delta*.01);
y_scale = y_scale * (1 - delta*.01);
// set the focal point and rescale
clutter_event_get_coords (event,&x_event,&y_event);
clutter_actor_get_size (actor,&width,&height);
clutter_actor_transform_stage_point (actor,x_event,y_event,&x_pivot,&y_pivot);
x_pivot=x_pivot/width;
y_pivot=y_pivot/height;
clutter_actor_set_pivot_point (actor,x_pivot,y_pivot);
clutter_actor_set_scale (actor,x_scale,y_scale);
}
}
break;
default:
break;
}
return FALSE;
}
void set_image (ClutterActor *image_actor,const char *path)
{
GdkPixbuf *image=gdk_pixbuf_new_from_file (path, NULL);
ClutterContent *image_content=clutter_image_new ();
clutter_image_set_data (CLUTTER_IMAGE (image_content),
gdk_pixbuf_get_pixels (image),
gdk_pixbuf_get_has_alpha (image)
? COGL_PIXEL_FORMAT_RGBA_8888
: COGL_PIXEL_FORMAT_RGB_888,
gdk_pixbuf_get_width (image),
gdk_pixbuf_get_height (image),
gdk_pixbuf_get_rowstride (image),
NULL);
g_object_unref (image);
clutter_actor_set_content (image_actor,image_content);
g_object_unref (image_content);
}
int main(int argc,char **argv)
{
ClutterActor *stage;
ClutterActor *image_actor;
ClutterContent *image_content;
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return EXIT_FAILURE;
stage = clutter_stage_new ();
clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);
image_actor = clutter_actor_new ();
clutter_actor_set_reactive (image_actor,TRUE);
clutter_actor_add_constraint (image_actor,clutter_bind_constraint_new (stage,CLUTTER_BIND_SIZE,0));
// drag image
clutter_actor_add_action (image_actor, clutter_drag_action_new ());
// zoom event
g_signal_connect(image_actor, "captured-event", G_CALLBACK (on_event_cb), NULL );
clutter_actor_add_child (stage, image_actor);
image_content = clutter_image_new ();
clutter_actor_set_content (image_actor, image_content);
g_object_unref (image_content);
set_image (image_actor,"put your image here.jpg");
clutter_actor_show (stage);
clutter_main ();
}