2010-05-12 07:00:33 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2010-06-10 11:56:16 -04:00
|
|
|
static gboolean
|
|
|
|
on_enter (ClutterActor *actor,
|
|
|
|
ClutterEvent *event)
|
|
|
|
{
|
2012-05-24 07:08:58 -04:00
|
|
|
ClutterTransition *t;
|
2010-06-10 11:56:16 -04:00
|
|
|
|
2012-05-24 07:08:58 -04:00
|
|
|
t = clutter_actor_get_transition (actor, "curl");
|
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
t = clutter_property_transition_new ("@effects.curl.period");
|
|
|
|
clutter_timeline_set_duration (CLUTTER_TIMELINE (t), 250);
|
|
|
|
clutter_actor_add_transition (actor, "curl", t);
|
|
|
|
g_object_unref (t);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_transition_set_from (t, G_TYPE_DOUBLE, 0.0);
|
|
|
|
clutter_transition_set_to (t, G_TYPE_DOUBLE, 0.25);
|
|
|
|
clutter_timeline_rewind (CLUTTER_TIMELINE (t));
|
|
|
|
clutter_timeline_start (CLUTTER_TIMELINE (t));
|
|
|
|
|
|
|
|
return CLUTTER_EVENT_STOP;
|
2010-06-10 11:56:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
on_leave (ClutterActor *actor,
|
|
|
|
ClutterEvent *event)
|
|
|
|
{
|
2012-05-24 07:08:58 -04:00
|
|
|
ClutterTransition *t;
|
|
|
|
|
|
|
|
t = clutter_actor_get_transition (actor, "curl");
|
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
t = clutter_property_transition_new ("@effects.curl.period");
|
|
|
|
clutter_timeline_set_duration (CLUTTER_TIMELINE (t), 250);
|
|
|
|
clutter_actor_add_transition (actor, "curl", t);
|
|
|
|
g_object_unref (t);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_transition_set_from (t, G_TYPE_DOUBLE, 0.25);
|
|
|
|
clutter_transition_set_to (t, G_TYPE_DOUBLE, 0.0);
|
|
|
|
clutter_timeline_rewind (CLUTTER_TIMELINE (t));
|
|
|
|
clutter_timeline_start (CLUTTER_TIMELINE (t));
|
2010-06-10 11:56:16 -04:00
|
|
|
|
2012-05-24 07:08:58 -04:00
|
|
|
return CLUTTER_EVENT_STOP;
|
2010-06-10 11:56:16 -04:00
|
|
|
}
|
|
|
|
|
2010-05-12 07:00:33 -04:00
|
|
|
static void
|
|
|
|
on_drag_begin (ClutterDragAction *action,
|
|
|
|
ClutterActor *actor,
|
|
|
|
gfloat event_x,
|
|
|
|
gfloat event_y,
|
|
|
|
ClutterModifierType modifiers)
|
|
|
|
{
|
|
|
|
gboolean is_copy = (modifiers & CLUTTER_SHIFT_MASK) ? TRUE : FALSE;
|
|
|
|
ClutterActor *drag_handle = NULL;
|
2012-05-24 07:08:58 -04:00
|
|
|
ClutterTransition *t;
|
2010-05-12 07:00:33 -04:00
|
|
|
|
|
|
|
if (is_copy)
|
|
|
|
{
|
|
|
|
ClutterActor *stage = clutter_actor_get_stage (actor);
|
|
|
|
|
2012-05-24 07:08:58 -04:00
|
|
|
drag_handle = clutter_actor_new ();
|
2010-05-12 07:00:33 -04:00
|
|
|
clutter_actor_set_size (drag_handle, 48, 48);
|
|
|
|
|
2012-05-24 07:08:58 -04:00
|
|
|
clutter_actor_set_background_color (drag_handle, CLUTTER_COLOR_DarkSkyBlue);
|
2010-05-12 07:00:33 -04:00
|
|
|
|
2012-05-24 07:08:58 -04:00
|
|
|
clutter_actor_add_child (stage, drag_handle);
|
2010-05-12 07:00:33 -04:00
|
|
|
clutter_actor_set_position (drag_handle, event_x, event_y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
drag_handle = actor;
|
|
|
|
|
|
|
|
clutter_drag_action_set_drag_handle (action, drag_handle);
|
|
|
|
|
2010-06-03 10:20:17 -04:00
|
|
|
/* fully desaturate the actor */
|
2012-05-24 07:08:58 -04:00
|
|
|
t = clutter_actor_get_transition (actor, "disable");
|
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
t = clutter_property_transition_new ("@effects.disable.factor");
|
|
|
|
clutter_timeline_set_duration (CLUTTER_TIMELINE (t), 250);
|
|
|
|
clutter_actor_add_transition (actor, "disable", t);
|
|
|
|
g_object_unref (t);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_transition_set_from (t, G_TYPE_DOUBLE, 0.0);
|
|
|
|
clutter_transition_set_to (t, G_TYPE_DOUBLE, 1.0);
|
|
|
|
clutter_timeline_rewind (CLUTTER_TIMELINE (t));
|
|
|
|
clutter_timeline_start (CLUTTER_TIMELINE (t));
|
2010-05-12 07:00:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_drag_end (ClutterDragAction *action,
|
|
|
|
ClutterActor *actor,
|
|
|
|
gfloat event_x,
|
|
|
|
gfloat event_y,
|
|
|
|
ClutterModifierType modifiers)
|
|
|
|
{
|
|
|
|
ClutterActor *drag_handle;
|
2012-05-24 07:08:58 -04:00
|
|
|
ClutterTransition *t;
|
2010-05-12 07:00:33 -04:00
|
|
|
|
|
|
|
drag_handle = clutter_drag_action_get_drag_handle (action);
|
|
|
|
if (actor != drag_handle)
|
|
|
|
{
|
|
|
|
gfloat real_x, real_y;
|
|
|
|
ClutterActor *parent;
|
|
|
|
|
|
|
|
/* if we are dragging a copy we can destroy the copy now
|
|
|
|
* and animate the real actor to the drop coordinates,
|
|
|
|
* transformed in the parent's coordinate space
|
|
|
|
*/
|
2012-05-24 07:08:58 -04:00
|
|
|
clutter_actor_save_easing_state (drag_handle);
|
|
|
|
clutter_actor_set_easing_mode (drag_handle, CLUTTER_LINEAR);
|
|
|
|
clutter_actor_set_opacity (drag_handle, 0);
|
|
|
|
clutter_actor_restore_easing_state (drag_handle);
|
|
|
|
g_signal_connect (drag_handle, "transitions-completed",
|
|
|
|
G_CALLBACK (clutter_actor_destroy),
|
|
|
|
NULL);
|
2010-05-12 07:00:33 -04:00
|
|
|
|
|
|
|
parent = clutter_actor_get_parent (actor);
|
|
|
|
clutter_actor_transform_stage_point (parent, event_x, event_y,
|
|
|
|
&real_x,
|
|
|
|
&real_y);
|
|
|
|
|
2012-05-24 07:08:58 -04:00
|
|
|
clutter_actor_save_easing_state (actor);
|
|
|
|
clutter_actor_set_easing_mode (actor, CLUTTER_EASE_OUT_CUBIC);
|
|
|
|
clutter_actor_set_position (actor, real_x, real_y);
|
|
|
|
clutter_actor_restore_easing_state (actor);
|
2010-05-12 07:00:33 -04:00
|
|
|
}
|
2012-05-24 07:08:58 -04:00
|
|
|
|
|
|
|
t = clutter_actor_get_transition (actor, "disable");
|
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
t = clutter_property_transition_new ("@effects.disable.factor");
|
|
|
|
clutter_timeline_set_duration (CLUTTER_TIMELINE (t), 250);
|
|
|
|
clutter_actor_add_transition (actor, "disable", t);
|
|
|
|
g_object_unref (t);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_transition_set_from (t, G_TYPE_DOUBLE, 1.0);
|
|
|
|
clutter_transition_set_to (t, G_TYPE_DOUBLE, 0.0);
|
|
|
|
clutter_timeline_rewind (CLUTTER_TIMELINE (t));
|
|
|
|
clutter_timeline_start (CLUTTER_TIMELINE (t));
|
2010-05-12 07:00:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static ClutterDragAxis
|
|
|
|
get_drag_axis (const gchar *str)
|
|
|
|
{
|
|
|
|
if (str == NULL || *str == '\0')
|
|
|
|
return CLUTTER_DRAG_AXIS_NONE;
|
|
|
|
|
|
|
|
if (*str == 'x' || *str == 'X')
|
|
|
|
return CLUTTER_DRAG_X_AXIS;
|
|
|
|
|
|
|
|
if (*str == 'y' || *str == 'Y')
|
|
|
|
return CLUTTER_DRAG_Y_AXIS;
|
|
|
|
|
|
|
|
g_warn_if_reached ();
|
|
|
|
|
|
|
|
return CLUTTER_DRAG_AXIS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar *drag_axis = NULL;
|
2010-09-03 13:00:40 -04:00
|
|
|
static gint x_drag_threshold = 0;
|
|
|
|
static gint y_drag_threshold = 0;
|
2010-05-12 07:00:33 -04:00
|
|
|
|
|
|
|
static GOptionEntry entries[] = {
|
|
|
|
{
|
2010-09-03 13:00:40 -04:00
|
|
|
"x-threshold", 'x',
|
2010-05-12 07:00:33 -04:00
|
|
|
0,
|
|
|
|
G_OPTION_ARG_INT,
|
2010-09-03 13:00:40 -04:00
|
|
|
&x_drag_threshold,
|
|
|
|
"Set the horizontal drag threshold", "PIXELS"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"y-threshold", 'y',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_INT,
|
|
|
|
&y_drag_threshold,
|
|
|
|
"Set the vertical drag threshold", "PIXELS"
|
2010-05-12 07:00:33 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"axis", 'a',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_STRING,
|
|
|
|
&drag_axis,
|
|
|
|
"Set the drag axis", "AXIS"
|
|
|
|
},
|
|
|
|
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2012-05-01 13:30:10 -04:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
2010-05-12 07:00:33 -04:00
|
|
|
{
|
|
|
|
ClutterActor *stage, *handle;
|
|
|
|
ClutterAction *action;
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
2011-02-22 07:53:15 -05:00
|
|
|
if (clutter_init_with_args (&argc, &argv,
|
|
|
|
"test-drag",
|
|
|
|
entries,
|
|
|
|
NULL,
|
|
|
|
&error) != CLUTTER_INIT_SUCCESS)
|
2010-05-12 07:00:33 -04:00
|
|
|
{
|
2012-05-24 07:08:58 -04:00
|
|
|
g_print ("Unable to run drag-action: %s\n", error->message);
|
2010-05-12 07:00:33 -04:00
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
stage = clutter_stage_new ();
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Drag Test");
|
|
|
|
clutter_actor_set_size (stage, 800, 600);
|
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
|
|
|
|
2012-05-24 07:08:58 -04:00
|
|
|
handle = clutter_actor_new ();
|
|
|
|
clutter_actor_set_background_color (handle, CLUTTER_COLOR_SkyBlue);
|
2010-05-12 07:00:33 -04:00
|
|
|
clutter_actor_set_size (handle, 128, 128);
|
|
|
|
clutter_actor_set_position (handle, (800 - 128) / 2, (600 - 128) / 2);
|
|
|
|
clutter_actor_set_reactive (handle, TRUE);
|
2012-05-24 07:08:58 -04:00
|
|
|
clutter_actor_add_child (stage, handle);
|
2010-06-10 11:56:16 -04:00
|
|
|
g_signal_connect (handle, "enter-event", G_CALLBACK (on_enter), NULL);
|
|
|
|
g_signal_connect (handle, "leave-event", G_CALLBACK (on_leave), NULL);
|
2010-05-12 07:00:33 -04:00
|
|
|
|
|
|
|
action = clutter_drag_action_new ();
|
|
|
|
clutter_drag_action_set_drag_threshold (CLUTTER_DRAG_ACTION (action),
|
2010-09-03 13:00:40 -04:00
|
|
|
x_drag_threshold,
|
|
|
|
y_drag_threshold);
|
2010-05-12 07:00:33 -04:00
|
|
|
clutter_drag_action_set_drag_axis (CLUTTER_DRAG_ACTION (action),
|
|
|
|
get_drag_axis (drag_axis));
|
|
|
|
|
|
|
|
g_signal_connect (action, "drag-begin", G_CALLBACK (on_drag_begin), NULL);
|
|
|
|
g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL);
|
|
|
|
|
|
|
|
clutter_actor_add_action (handle, action);
|
|
|
|
|
2010-06-03 10:20:17 -04:00
|
|
|
clutter_actor_add_effect_with_name (handle, "disable", clutter_desaturate_effect_new (0.0));
|
2010-08-11 08:53:02 -04:00
|
|
|
clutter_actor_add_effect_with_name (handle, "curl", clutter_page_turn_effect_new (0.0, 45.0, 12.0));
|
2010-06-03 10:20:17 -04:00
|
|
|
|
2010-05-12 07:00:33 -04:00
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|