Re: scale operations



I thank i have sent a short code to describe my problem but i'm wrong.
Following a little C code :

This is my plan to do scaling

Stephane

#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 ();
}


2015-05-13 18:35 GMT+02:00 Lionel Landwerlin <llandwerlin gmail com>:
Yes, the Zoom action only reacts to touch points (only way it can detect scaling).
How did plan to do scaling?

On 13/05/15 16:56, Stephane Pion wrote:
Yes, but it seems inoperative. It seems to be relative to Gestures, and it doesn't react to mouse action.
Did i miss something about zoom action ?

2015-05-13 17:55 GMT+02:00 Stephane Pion <stephane pion gmail com>:
Yes, but it seems inoperative. It seems to be relative to Gestures, and it doesn't react to mouse action.
Did i miss something about zoom action ?

2015-05-13 17:43 GMT+02:00 Lionel Landwerlin <llandwerlin gmail com>:
Have you tried the ClutterZoomAction? : https://developer.gnome.org/clutter/stable/ClutterZoomAction.html


On 13/05/15 16:40, Stephane Pion wrote:
Hi All,

I'm working on an application which use clutter (1.20, debian jessie).

I have to display an image and be able to zoom / pan it. I have some troubles to set the pivot point.

As i scale, some shifts appears.

I tried to use clutter_actor_transform_stage_point without any success.

I think it's an obvious problem, but i didn't find the solution
Is somebody know the right way to do that ?

See attached a source which demonstrate my problem

Regards
Stephane


_______________________________________________
clutter-list mailing list
clutter-list gnome org
https://mail.gnome.org/mailman/listinfo/clutter-list


_______________________________________________
clutter-list mailing list
clutter-list gnome org
https://mail.gnome.org/mailman/listinfo/clutter-list





_______________________________________________
clutter-list mailing list
clutter-list gnome org
https://mail.gnome.org/mailman/listinfo/clutter-list


_______________________________________________
clutter-list mailing list
clutter-list gnome org
https://mail.gnome.org/mailman/listinfo/clutter-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]