mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 18:11:05 -05:00
clutter: Remove drag and drop actions
We aren't using those actions in the shell or anywhere in Mutter, our DnD support is implemented on the shell side. https://gitlab.gnome.org/GNOME/mutter/merge_requests/789
This commit is contained in:
parent
6aead84d7a
commit
eb6e1f694a
@ -50,8 +50,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterConstraint, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterContainer, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterDeformEffect, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterDesaturateEffect, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterDragAction, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterDropAction, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterEffect, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterFixedLayout, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterFlowLayout, g_object_unref)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,152 +0,0 @@
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Copyright (C) 2010 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author:
|
||||
* Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __CLUTTER_DRAG_ACTION_H__
|
||||
#define __CLUTTER_DRAG_ACTION_H__
|
||||
|
||||
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <clutter/clutter.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <clutter/clutter-action.h>
|
||||
#include <clutter/clutter-event.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_DRAG_ACTION (clutter_drag_action_get_type ())
|
||||
#define CLUTTER_DRAG_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_DRAG_ACTION, ClutterDragAction))
|
||||
#define CLUTTER_IS_DRAG_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_DRAG_ACTION))
|
||||
#define CLUTTER_DRAG_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_DRAG_ACTION, ClutterDragActionClass))
|
||||
#define CLUTTER_IS_DRAG_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_DRAG_ACTION))
|
||||
#define CLUTTER_DRAG_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_DRAG_ACTION, ClutterDragActionClass))
|
||||
|
||||
typedef struct _ClutterDragAction ClutterDragAction;
|
||||
typedef struct _ClutterDragActionPrivate ClutterDragActionPrivate;
|
||||
typedef struct _ClutterDragActionClass ClutterDragActionClass;
|
||||
|
||||
/**
|
||||
* ClutterDragAction:
|
||||
*
|
||||
* The #ClutterDragAction structure contains only
|
||||
* private data and should be accessed using the provided API
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
struct _ClutterDragAction
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterAction parent_instance;
|
||||
|
||||
ClutterDragActionPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* ClutterDragActionClass:
|
||||
* @drag_begin: class handler of the #ClutterDragAction::drag-begin signal
|
||||
* @drag_motion: class handler of the #ClutterDragAction::drag-motion signal
|
||||
* @drag_end: class handler of the #ClutterDragAction::drag-end signal
|
||||
* @drag_progress: class handler of the #ClutterDragAction::drag-progress signal
|
||||
*
|
||||
* The #ClutterDragActionClass structure contains
|
||||
* only private data
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
struct _ClutterDragActionClass
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterActionClass parent_class;
|
||||
|
||||
/*< public >*/
|
||||
void (* drag_begin) (ClutterDragAction *action,
|
||||
ClutterActor *actor,
|
||||
gfloat event_x,
|
||||
gfloat event_y,
|
||||
ClutterModifierType modifiers);
|
||||
void (* drag_motion) (ClutterDragAction *action,
|
||||
ClutterActor *actor,
|
||||
gfloat delta_x,
|
||||
gfloat delta_y);
|
||||
void (* drag_end) (ClutterDragAction *action,
|
||||
ClutterActor *actor,
|
||||
gfloat event_x,
|
||||
gfloat event_y,
|
||||
ClutterModifierType modifiers);
|
||||
gboolean (* drag_progress) (ClutterDragAction *action,
|
||||
ClutterActor *actor,
|
||||
gfloat delta_x,
|
||||
gfloat delta_y);
|
||||
|
||||
/*< private >*/
|
||||
void (* _clutter_drag_action1) (void);
|
||||
void (* _clutter_drag_action2) (void);
|
||||
void (* _clutter_drag_action3) (void);
|
||||
void (* _clutter_drag_action4) (void);
|
||||
};
|
||||
|
||||
CLUTTER_EXPORT
|
||||
GType clutter_drag_action_get_type (void) G_GNUC_CONST;
|
||||
|
||||
CLUTTER_EXPORT
|
||||
ClutterAction * clutter_drag_action_new (void);
|
||||
|
||||
CLUTTER_EXPORT
|
||||
void clutter_drag_action_set_drag_threshold (ClutterDragAction *action,
|
||||
gint x_threshold,
|
||||
gint y_threshold);
|
||||
CLUTTER_EXPORT
|
||||
void clutter_drag_action_get_drag_threshold (ClutterDragAction *action,
|
||||
guint *x_threshold,
|
||||
guint *y_threshold);
|
||||
CLUTTER_EXPORT
|
||||
void clutter_drag_action_set_drag_handle (ClutterDragAction *action,
|
||||
ClutterActor *handle);
|
||||
CLUTTER_EXPORT
|
||||
ClutterActor * clutter_drag_action_get_drag_handle (ClutterDragAction *action);
|
||||
CLUTTER_EXPORT
|
||||
void clutter_drag_action_set_drag_axis (ClutterDragAction *action,
|
||||
ClutterDragAxis axis);
|
||||
CLUTTER_EXPORT
|
||||
ClutterDragAxis clutter_drag_action_get_drag_axis (ClutterDragAction *action);
|
||||
|
||||
CLUTTER_EXPORT
|
||||
void clutter_drag_action_get_press_coords (ClutterDragAction *action,
|
||||
gfloat *press_x,
|
||||
gfloat *press_y);
|
||||
CLUTTER_EXPORT
|
||||
void clutter_drag_action_get_motion_coords (ClutterDragAction *action,
|
||||
gfloat *motion_x,
|
||||
gfloat *motion_y);
|
||||
|
||||
CLUTTER_EXPORT
|
||||
gboolean clutter_drag_action_get_drag_area (ClutterDragAction *action,
|
||||
graphene_rect_t *drag_area);
|
||||
|
||||
CLUTTER_EXPORT
|
||||
void clutter_drag_action_set_drag_area (ClutterDragAction *action,
|
||||
const graphene_rect_t *drag_area);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_DRAG_ACTION_H__ */
|
@ -1,527 +0,0 @@
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Copyright © 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author:
|
||||
* Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:clutter-drop-action
|
||||
* @Title: ClutterDropAction
|
||||
* @short_description: An action for drop targets
|
||||
*
|
||||
* #ClutterDropAction is a #ClutterAction that allows a #ClutterActor
|
||||
* implementation to control what happens when an actor dragged using
|
||||
* a #ClutterDragAction crosses the target area or when a dragged actor
|
||||
* is released (or "dropped") on the target area.
|
||||
*
|
||||
* A trivial use of #ClutterDropAction consists in connecting to the
|
||||
* #ClutterDropAction::drop signal and handling the drop from there,
|
||||
* for instance:
|
||||
*
|
||||
* |[<!-- language="C" -->
|
||||
* ClutterAction *action = clutter_drop_action ();
|
||||
*
|
||||
* g_signal_connect (action, "drop", G_CALLBACK (on_drop), NULL);
|
||||
* clutter_actor_add_action (an_actor, action);
|
||||
* ]|
|
||||
*
|
||||
* The #ClutterDropAction::can-drop can be used to control whether the
|
||||
* #ClutterDropAction::drop signal is going to be emitted; returning %FALSE
|
||||
* from a handler connected to the #ClutterDropAction::can-drop signal will
|
||||
* cause the #ClutterDropAction::drop signal to be skipped when the input
|
||||
* device button is released.
|
||||
*
|
||||
* It's important to note that #ClutterDropAction will only work with
|
||||
* actors dragged using #ClutterDragAction.
|
||||
*
|
||||
* See [drop-action.c](https://git.gnome.org/browse/clutter/tree/examples/drop-action.c?h=clutter-1.18)
|
||||
* for an example of how to use #ClutterDropAction.
|
||||
*
|
||||
* #ClutterDropAction is available since Clutter 1.8
|
||||
*/
|
||||
|
||||
#include "clutter-build-config.h"
|
||||
|
||||
#include "clutter-drop-action.h"
|
||||
|
||||
#include "clutter-actor-meta-private.h"
|
||||
#include "clutter-actor-private.h"
|
||||
#include "clutter-drag-action.h"
|
||||
#include "clutter-main.h"
|
||||
#include "clutter-marshal.h"
|
||||
#include "clutter-stage-private.h"
|
||||
|
||||
struct _ClutterDropActionPrivate
|
||||
{
|
||||
ClutterActor *actor;
|
||||
ClutterActor *stage;
|
||||
|
||||
gulong mapped_id;
|
||||
};
|
||||
|
||||
typedef struct _DropTarget {
|
||||
ClutterActor *stage;
|
||||
|
||||
gulong capture_id;
|
||||
|
||||
GHashTable *actions;
|
||||
|
||||
ClutterDropAction *last_action;
|
||||
} DropTarget;
|
||||
|
||||
enum
|
||||
{
|
||||
CAN_DROP,
|
||||
OVER_IN,
|
||||
OVER_OUT,
|
||||
DROP,
|
||||
DROP_CANCEL,
|
||||
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint drop_signals[LAST_SIGNAL] = { 0, };
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (ClutterDropAction, clutter_drop_action, CLUTTER_TYPE_ACTION)
|
||||
|
||||
static void
|
||||
drop_target_free (gpointer _data)
|
||||
{
|
||||
DropTarget *data = _data;
|
||||
|
||||
g_clear_signal_handler (&data->capture_id, data->stage);
|
||||
g_hash_table_destroy (data->actions);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_stage_capture (ClutterStage *stage,
|
||||
ClutterEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
DropTarget *data = user_data;
|
||||
gfloat event_x, event_y;
|
||||
ClutterActor *actor, *drag_actor;
|
||||
ClutterDropAction *drop_action;
|
||||
ClutterInputDevice *device;
|
||||
gboolean was_reactive;
|
||||
|
||||
switch (clutter_event_type (event))
|
||||
{
|
||||
case CLUTTER_MOTION:
|
||||
case CLUTTER_BUTTON_RELEASE:
|
||||
if (clutter_event_type (event) == CLUTTER_MOTION &&
|
||||
!(clutter_event_get_state (event) & CLUTTER_BUTTON1_MASK))
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
|
||||
if (clutter_event_type (event) == CLUTTER_BUTTON_RELEASE &&
|
||||
clutter_event_get_button (event) != CLUTTER_BUTTON_PRIMARY)
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
|
||||
device = clutter_event_get_device (event);
|
||||
drag_actor = _clutter_stage_get_pointer_drag_actor (stage, device);
|
||||
if (drag_actor == NULL)
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
break;
|
||||
|
||||
case CLUTTER_TOUCH_UPDATE:
|
||||
case CLUTTER_TOUCH_END:
|
||||
drag_actor = _clutter_stage_get_touch_drag_actor (stage,
|
||||
clutter_event_get_event_sequence (event));
|
||||
if (drag_actor == NULL)
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
break;
|
||||
|
||||
default:
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
clutter_event_get_coords (event, &event_x, &event_y);
|
||||
|
||||
/* get the actor under the cursor, excluding the dragged actor; we
|
||||
* use reactivity because it won't cause any scene invalidation
|
||||
*/
|
||||
was_reactive = clutter_actor_get_reactive (drag_actor);
|
||||
clutter_actor_set_reactive (drag_actor, FALSE);
|
||||
|
||||
actor = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_REACTIVE,
|
||||
event_x,
|
||||
event_y);
|
||||
if (actor == NULL || actor == CLUTTER_ACTOR (stage))
|
||||
{
|
||||
if (data->last_action != NULL)
|
||||
{
|
||||
ClutterActorMeta *meta = CLUTTER_ACTOR_META (data->last_action);
|
||||
|
||||
g_signal_emit (data->last_action, drop_signals[OVER_OUT], 0,
|
||||
clutter_actor_meta_get_actor (meta));
|
||||
|
||||
data->last_action = NULL;
|
||||
}
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
drop_action = g_hash_table_lookup (data->actions, actor);
|
||||
|
||||
if (drop_action == NULL)
|
||||
{
|
||||
if (data->last_action != NULL)
|
||||
{
|
||||
ClutterActorMeta *meta = CLUTTER_ACTOR_META (data->last_action);
|
||||
|
||||
g_signal_emit (data->last_action, drop_signals[OVER_OUT], 0,
|
||||
clutter_actor_meta_get_actor (meta));
|
||||
|
||||
data->last_action = NULL;
|
||||
}
|
||||
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (data->last_action != drop_action)
|
||||
{
|
||||
ClutterActorMeta *meta;
|
||||
|
||||
if (data->last_action != NULL)
|
||||
{
|
||||
meta = CLUTTER_ACTOR_META (data->last_action);
|
||||
|
||||
g_signal_emit (data->last_action, drop_signals[OVER_OUT], 0,
|
||||
clutter_actor_meta_get_actor (meta));
|
||||
}
|
||||
|
||||
meta = CLUTTER_ACTOR_META (drop_action);
|
||||
|
||||
g_signal_emit (drop_action, drop_signals[OVER_IN], 0,
|
||||
clutter_actor_meta_get_actor (meta));
|
||||
}
|
||||
|
||||
data->last_action = drop_action;
|
||||
}
|
||||
|
||||
out:
|
||||
if (clutter_event_type (event) == CLUTTER_BUTTON_RELEASE ||
|
||||
clutter_event_type (event) == CLUTTER_TOUCH_END)
|
||||
{
|
||||
if (data->last_action != NULL)
|
||||
{
|
||||
ClutterActorMeta *meta = CLUTTER_ACTOR_META (data->last_action);
|
||||
gboolean can_drop = FALSE;
|
||||
|
||||
g_signal_emit (data->last_action, drop_signals[CAN_DROP], 0,
|
||||
clutter_actor_meta_get_actor (meta),
|
||||
event_x, event_y,
|
||||
&can_drop);
|
||||
|
||||
if (can_drop)
|
||||
{
|
||||
g_signal_emit (data->last_action, drop_signals[DROP], 0,
|
||||
clutter_actor_meta_get_actor (meta),
|
||||
event_x, event_y);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_signal_emit (data->last_action, drop_signals[DROP_CANCEL], 0,
|
||||
clutter_actor_meta_get_actor (meta),
|
||||
event_x, event_y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data->last_action = NULL;
|
||||
}
|
||||
|
||||
if (drag_actor != NULL)
|
||||
clutter_actor_set_reactive (drag_actor, was_reactive);
|
||||
|
||||
return CLUTTER_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
static void
|
||||
drop_action_register (ClutterDropAction *self)
|
||||
{
|
||||
ClutterDropActionPrivate *priv = self->priv;
|
||||
DropTarget *data;
|
||||
|
||||
g_assert (priv->stage != NULL);
|
||||
|
||||
data = g_object_get_data (G_OBJECT (priv->stage), "__clutter_drop_targets");
|
||||
if (data == NULL)
|
||||
{
|
||||
data = g_new0 (DropTarget, 1);
|
||||
|
||||
data->stage = priv->stage;
|
||||
data->actions = g_hash_table_new (NULL, NULL);
|
||||
data->capture_id = g_signal_connect (priv->stage, "captured-event",
|
||||
G_CALLBACK (on_stage_capture),
|
||||
data);
|
||||
g_object_set_data_full (G_OBJECT (priv->stage), "__clutter_drop_targets",
|
||||
data,
|
||||
drop_target_free);
|
||||
}
|
||||
|
||||
g_hash_table_replace (data->actions, priv->actor, self);
|
||||
}
|
||||
|
||||
static void
|
||||
drop_action_unregister (ClutterDropAction *self)
|
||||
{
|
||||
ClutterDropActionPrivate *priv = self->priv;
|
||||
DropTarget *data = NULL;
|
||||
|
||||
if (priv->stage != NULL)
|
||||
data = g_object_get_data (G_OBJECT (priv->stage), "__clutter_drop_targets");
|
||||
|
||||
if (data == NULL)
|
||||
return;
|
||||
|
||||
g_hash_table_remove (data->actions, priv->actor);
|
||||
if (g_hash_table_size (data->actions) == 0)
|
||||
g_object_set_data (G_OBJECT (data->stage), "__clutter_drop_targets", NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
on_actor_mapped (ClutterActor *actor,
|
||||
GParamSpec *pspec,
|
||||
ClutterDropAction *self)
|
||||
{
|
||||
if (clutter_actor_is_mapped (actor))
|
||||
{
|
||||
if (self->priv->stage == NULL)
|
||||
self->priv->stage = clutter_actor_get_stage (actor);
|
||||
|
||||
drop_action_register (self);
|
||||
}
|
||||
else
|
||||
drop_action_unregister (self);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_drop_action_set_actor (ClutterActorMeta *meta,
|
||||
ClutterActor *actor)
|
||||
{
|
||||
ClutterDropActionPrivate *priv = CLUTTER_DROP_ACTION (meta)->priv;
|
||||
|
||||
if (priv->actor != NULL)
|
||||
{
|
||||
drop_action_unregister (CLUTTER_DROP_ACTION (meta));
|
||||
|
||||
g_clear_signal_handler (&priv->mapped_id, priv->actor);
|
||||
|
||||
priv->stage = NULL;
|
||||
priv->actor = NULL;
|
||||
}
|
||||
|
||||
priv->actor = actor;
|
||||
|
||||
if (priv->actor != NULL)
|
||||
{
|
||||
priv->stage = clutter_actor_get_stage (actor);
|
||||
priv->mapped_id = g_signal_connect (actor, "notify::mapped",
|
||||
G_CALLBACK (on_actor_mapped),
|
||||
meta);
|
||||
|
||||
if (priv->stage != NULL)
|
||||
drop_action_register (CLUTTER_DROP_ACTION (meta));
|
||||
}
|
||||
|
||||
CLUTTER_ACTOR_META_CLASS (clutter_drop_action_parent_class)->set_actor (meta, actor);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
signal_accumulator (GSignalInvocationHint *ihint,
|
||||
GValue *return_accu,
|
||||
const GValue *handler_return,
|
||||
gpointer user_data)
|
||||
{
|
||||
gboolean continue_emission;
|
||||
|
||||
continue_emission = g_value_get_boolean (handler_return);
|
||||
g_value_set_boolean (return_accu, continue_emission);
|
||||
|
||||
return continue_emission;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
clutter_drop_action_real_can_drop (ClutterDropAction *action,
|
||||
ClutterActor *actor,
|
||||
gfloat event_x,
|
||||
gfloat event_y)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_drop_action_class_init (ClutterDropActionClass *klass)
|
||||
{
|
||||
ClutterActorMetaClass *meta_class = CLUTTER_ACTOR_META_CLASS (klass);
|
||||
|
||||
meta_class->set_actor = clutter_drop_action_set_actor;
|
||||
|
||||
klass->can_drop = clutter_drop_action_real_can_drop;
|
||||
|
||||
/**
|
||||
* ClutterDropAction::can-drop:
|
||||
* @action: the #ClutterDropAction that emitted the signal
|
||||
* @actor: the #ClutterActor attached to the @action
|
||||
* @event_x: the X coordinate (in stage space) of the drop event
|
||||
* @event_y: the Y coordinate (in stage space) of the drop event
|
||||
*
|
||||
* The ::can-drop signal is emitted when the dragged actor is dropped
|
||||
* on @actor. The return value of the ::can-drop signal will determine
|
||||
* whether or not the #ClutterDropAction::drop signal is going to be
|
||||
* emitted on @action.
|
||||
*
|
||||
* The default implementation of #ClutterDropAction returns %TRUE for
|
||||
* this signal.
|
||||
*
|
||||
* Return value: %TRUE if the drop is accepted, and %FALSE otherwise
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
drop_signals[CAN_DROP] =
|
||||
g_signal_new (I_("can-drop"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterDropActionClass, can_drop),
|
||||
signal_accumulator, NULL,
|
||||
_clutter_marshal_BOOLEAN__OBJECT_FLOAT_FLOAT,
|
||||
G_TYPE_BOOLEAN, 3,
|
||||
CLUTTER_TYPE_ACTOR,
|
||||
G_TYPE_FLOAT,
|
||||
G_TYPE_FLOAT);
|
||||
|
||||
/**
|
||||
* ClutterDropAction::over-in:
|
||||
* @action: the #ClutterDropAction that emitted the signal
|
||||
* @actor: the #ClutterActor attached to the @action
|
||||
*
|
||||
* The ::over-in signal is emitted when the dragged actor crosses
|
||||
* into @actor.
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
drop_signals[OVER_IN] =
|
||||
g_signal_new (I_("over-in"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterDropActionClass, over_in),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
CLUTTER_TYPE_ACTOR);
|
||||
|
||||
/**
|
||||
* ClutterDropAction::over-out:
|
||||
* @action: the #ClutterDropAction that emitted the signal
|
||||
* @actor: the #ClutterActor attached to the @action
|
||||
*
|
||||
* The ::over-out signal is emitted when the dragged actor crosses
|
||||
* outside @actor.
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
drop_signals[OVER_OUT] =
|
||||
g_signal_new (I_("over-out"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterDropActionClass, over_out),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
CLUTTER_TYPE_ACTOR);
|
||||
|
||||
/**
|
||||
* ClutterDropAction::drop:
|
||||
* @action: the #ClutterDropAction that emitted the signal
|
||||
* @actor: the #ClutterActor attached to the @action
|
||||
* @event_x: the X coordinate (in stage space) of the drop event
|
||||
* @event_y: the Y coordinate (in stage space) of the drop event
|
||||
*
|
||||
* The ::drop signal is emitted when the dragged actor is dropped
|
||||
* on @actor. This signal is only emitted if at least an handler of
|
||||
* #ClutterDropAction::can-drop returns %TRUE.
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
drop_signals[DROP] =
|
||||
g_signal_new (I_("drop"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterDropActionClass, drop),
|
||||
NULL, NULL,
|
||||
_clutter_marshal_VOID__OBJECT_FLOAT_FLOAT,
|
||||
G_TYPE_NONE, 3,
|
||||
CLUTTER_TYPE_ACTOR,
|
||||
G_TYPE_FLOAT,
|
||||
G_TYPE_FLOAT);
|
||||
|
||||
|
||||
/**
|
||||
* ClutterDropAction::drop-cancel:
|
||||
* @action: the #ClutterDropAction that emitted the signal
|
||||
* @actor: the #ClutterActor attached to the @action
|
||||
* @event_x: the X coordinate (in stage space) of the drop event
|
||||
* @event_y: the Y coordinate (in stage space) of the drop event
|
||||
*
|
||||
* The ::drop-cancel signal is emitted when the drop is refused
|
||||
* by an emission of the #ClutterDropAction::can-drop signal.
|
||||
*
|
||||
* After the ::drop-cancel signal is fired the active drag is
|
||||
* terminated.
|
||||
*
|
||||
* Since: 1.12
|
||||
*/
|
||||
drop_signals[DROP_CANCEL] =
|
||||
g_signal_new (I_("drop-cancel"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (ClutterDropActionClass, drop),
|
||||
NULL, NULL,
|
||||
_clutter_marshal_VOID__OBJECT_FLOAT_FLOAT,
|
||||
G_TYPE_NONE, 3,
|
||||
CLUTTER_TYPE_ACTOR,
|
||||
G_TYPE_FLOAT,
|
||||
G_TYPE_FLOAT);
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_drop_action_init (ClutterDropAction *self)
|
||||
{
|
||||
self->priv = clutter_drop_action_get_instance_private (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_drop_action_new:
|
||||
*
|
||||
* Creates a new #ClutterDropAction.
|
||||
*
|
||||
* Use clutter_actor_add_action() to add the action to a #ClutterActor.
|
||||
*
|
||||
* Return value: the newly created #ClutterDropAction
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
ClutterAction *
|
||||
clutter_drop_action_new (void)
|
||||
{
|
||||
return g_object_new (CLUTTER_TYPE_DROP_ACTION, NULL);
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Copyright © 2011 Intel Corporation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Author:
|
||||
* Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
*/
|
||||
|
||||
#ifndef __CLUTTER_DROP_ACTION_H__
|
||||
#define __CLUTTER_DROP_ACTION_H__
|
||||
|
||||
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <clutter/clutter.h> can be directly included."
|
||||
#endif
|
||||
|
||||
#include <clutter/clutter-action.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_DROP_ACTION (clutter_drop_action_get_type ())
|
||||
#define CLUTTER_DROP_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_DROP_ACTION, ClutterDropAction))
|
||||
#define CLUTTER_IS_DROP_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_DROP_ACTION))
|
||||
#define CLUTTER_DROP_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_DROP_ACTION, ClutterDropActionClass))
|
||||
#define CLUTTER_IS_DROP_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_DROP_ACTION))
|
||||
#define CLUTTER_DROP_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_DROP_ACTION, ClutterDropActionClass))
|
||||
|
||||
typedef struct _ClutterDropAction ClutterDropAction;
|
||||
typedef struct _ClutterDropActionPrivate ClutterDropActionPrivate;
|
||||
typedef struct _ClutterDropActionClass ClutterDropActionClass;
|
||||
|
||||
/**
|
||||
* ClutterDropAction:
|
||||
*
|
||||
* The #ClutterDropAction structure contains only
|
||||
* private data and should be accessed using the provided API.
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
struct _ClutterDropAction
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterAction parent_instance;
|
||||
|
||||
ClutterDropActionPrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* ClutterDropActionClass:
|
||||
* @can_drop: class handler for the #ClutterDropAction::can-drop signal
|
||||
* @over_in: class handler for the #ClutterDropAction::over-in signal
|
||||
* @over_out: class handler for the #ClutterDropAction::over-out signal
|
||||
* @drop: class handler for the #ClutterDropAction::drop signal
|
||||
*
|
||||
* The #ClutterDropActionClass structure contains
|
||||
* only private data.
|
||||
*
|
||||
* Since: 1.8
|
||||
*/
|
||||
struct _ClutterDropActionClass
|
||||
{
|
||||
/*< private >*/
|
||||
ClutterActionClass parent_class;
|
||||
|
||||
/*< public >*/
|
||||
gboolean (* can_drop) (ClutterDropAction *action,
|
||||
ClutterActor *actor,
|
||||
gfloat event_x,
|
||||
gfloat event_y);
|
||||
|
||||
void (* over_in) (ClutterDropAction *action,
|
||||
ClutterActor *actor);
|
||||
void (* over_out) (ClutterDropAction *action,
|
||||
ClutterActor *actor);
|
||||
|
||||
void (* drop) (ClutterDropAction *action,
|
||||
ClutterActor *actor,
|
||||
gfloat event_x,
|
||||
gfloat event_y);
|
||||
|
||||
/*< private >*/
|
||||
void (*_clutter_drop_action1) (void);
|
||||
void (*_clutter_drop_action2) (void);
|
||||
void (*_clutter_drop_action3) (void);
|
||||
void (*_clutter_drop_action4) (void);
|
||||
void (*_clutter_drop_action5) (void);
|
||||
void (*_clutter_drop_action6) (void);
|
||||
void (*_clutter_drop_action7) (void);
|
||||
void (*_clutter_drop_action8) (void);
|
||||
};
|
||||
|
||||
CLUTTER_EXPORT
|
||||
GType clutter_drop_action_get_type (void) G_GNUC_CONST;
|
||||
|
||||
CLUTTER_EXPORT
|
||||
ClutterAction * clutter_drop_action_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_DROP_ACTION_H__ */
|
@ -56,8 +56,6 @@
|
||||
#include "clutter-content.h"
|
||||
#include "clutter-deform-effect.h"
|
||||
#include "clutter-desaturate-effect.h"
|
||||
#include "clutter-drag-action.h"
|
||||
#include "clutter-drop-action.h"
|
||||
#include "clutter-effect.h"
|
||||
#include "clutter-enums.h"
|
||||
#include "clutter-enum-types.h"
|
||||
|
@ -30,8 +30,6 @@ clutter_headers = [
|
||||
'clutter-deform-effect.h',
|
||||
'clutter-deprecated.h',
|
||||
'clutter-desaturate-effect.h',
|
||||
'clutter-drag-action.h',
|
||||
'clutter-drop-action.h',
|
||||
'clutter-effect.h',
|
||||
'clutter-enums.h',
|
||||
'clutter-event.h',
|
||||
@ -118,8 +116,6 @@ clutter_sources = [
|
||||
'clutter-content.c',
|
||||
'clutter-deform-effect.c',
|
||||
'clutter-desaturate-effect.c',
|
||||
'clutter-drag-action.c',
|
||||
'clutter-drop-action.c',
|
||||
'clutter-effect.c',
|
||||
'clutter-event.c',
|
||||
'clutter-feature.c',
|
||||
|
@ -37,7 +37,6 @@ clutter_tests_interactive_test_sources = [
|
||||
'test-cairo-clock.c',
|
||||
'test-cairo-flowers.c',
|
||||
'test-stage-sizing.c',
|
||||
'test-scrolling.c',
|
||||
'test-swipe-action.c',
|
||||
'test-cogl-point-sprites.c',
|
||||
'test-path-constraint.c',
|
||||
|
@ -1,137 +0,0 @@
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <gmodule.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define RECT_WIDTH 400
|
||||
#define RECT_HEIGHT 300
|
||||
#define N_RECTS 7
|
||||
|
||||
static const gchar *rect_color[N_RECTS] = {
|
||||
"#edd400",
|
||||
"#f57900",
|
||||
"#c17d11",
|
||||
"#73d216",
|
||||
"#3465a4",
|
||||
"#75507b",
|
||||
"#cc0000"
|
||||
};
|
||||
|
||||
static ClutterActor *rectangle[N_RECTS];
|
||||
static ClutterActor *viewport = NULL;
|
||||
|
||||
int
|
||||
test_scrolling_main (int argc, char *argv[]);
|
||||
|
||||
static void
|
||||
on_drag_end (ClutterDragAction *action,
|
||||
ClutterActor *actor,
|
||||
gfloat event_x,
|
||||
gfloat event_y,
|
||||
ClutterModifierType modifiers)
|
||||
{
|
||||
gfloat viewport_x = clutter_actor_get_x (viewport);
|
||||
gfloat offset_x;
|
||||
gint child_visible;
|
||||
|
||||
/* check if we're at the viewport edges */
|
||||
if (viewport_x > 0)
|
||||
{
|
||||
clutter_actor_save_easing_state (viewport);
|
||||
clutter_actor_set_easing_mode (viewport, CLUTTER_EASE_OUT_BOUNCE);
|
||||
clutter_actor_set_x (viewport, 0);
|
||||
clutter_actor_restore_easing_state (viewport);
|
||||
return;
|
||||
}
|
||||
|
||||
if (viewport_x < (-1.0f * (RECT_WIDTH * (N_RECTS - 1))))
|
||||
{
|
||||
clutter_actor_save_easing_state (viewport);
|
||||
clutter_actor_set_easing_mode (viewport, CLUTTER_EASE_OUT_BOUNCE);
|
||||
clutter_actor_set_x (viewport, -1.0f * (RECT_WIDTH * (N_RECTS - 1)));
|
||||
clutter_actor_restore_easing_state (viewport);
|
||||
return;
|
||||
}
|
||||
|
||||
/* animate the viewport to fully show the child once we pass
|
||||
* a certain threshold with the dragging action
|
||||
*/
|
||||
offset_x = fabsf (viewport_x) / RECT_WIDTH + 0.5f;
|
||||
if (offset_x > (RECT_WIDTH * 0.33))
|
||||
child_visible = (int) offset_x + 1;
|
||||
else
|
||||
child_visible = (int) offset_x;
|
||||
|
||||
/* sanity check on the children number */
|
||||
child_visible = CLAMP (child_visible, 0, N_RECTS);
|
||||
|
||||
clutter_actor_save_easing_state (viewport);
|
||||
clutter_actor_set_x (viewport, -1.0f * RECT_WIDTH * child_visible);
|
||||
clutter_actor_restore_easing_state (viewport);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT int
|
||||
test_scrolling_main (int argc, char *argv[])
|
||||
{
|
||||
ClutterActor *stage;
|
||||
ClutterActor *scroll;
|
||||
ClutterAction *action;
|
||||
gint i;
|
||||
|
||||
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
||||
return 1;
|
||||
|
||||
stage = clutter_stage_new ();
|
||||
clutter_stage_set_title (CLUTTER_STAGE (stage), "Scrolling");
|
||||
clutter_actor_set_size (stage, 800, 600);
|
||||
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
||||
|
||||
/* scroll: the group that contains the scrolling viewport; we set its
|
||||
* size to be the same as one rectangle, position it in the middle of
|
||||
* the stage and set it to clip its contents to the allocated size
|
||||
*/
|
||||
scroll = clutter_actor_new ();
|
||||
clutter_actor_add_child (stage, scroll);
|
||||
clutter_actor_set_size (scroll, RECT_WIDTH, RECT_HEIGHT);
|
||||
clutter_actor_add_constraint (scroll, clutter_align_constraint_new (stage, CLUTTER_ALIGN_BOTH, 0.5));
|
||||
clutter_actor_set_clip_to_allocation (scroll, TRUE);
|
||||
|
||||
/* viewport: the actual container for the children; we scroll it using
|
||||
* the Drag action constrained to the horizontal axis, and every time
|
||||
* the dragging ends we check whether we're dragging past the end of
|
||||
* the viewport
|
||||
*/
|
||||
viewport = clutter_actor_new ();
|
||||
clutter_actor_set_layout_manager (viewport, clutter_box_layout_new ());
|
||||
clutter_actor_add_child (scroll, viewport);
|
||||
|
||||
/* add dragging capabilities to the viewport; the heavy lifting is
|
||||
* all done by the DragAction itself, plus the ::drag-end signal
|
||||
* handler in our code
|
||||
*/
|
||||
action = clutter_drag_action_new ();
|
||||
clutter_actor_add_action (viewport, action);
|
||||
clutter_drag_action_set_drag_axis (CLUTTER_DRAG_ACTION (action),
|
||||
CLUTTER_DRAG_X_AXIS);
|
||||
g_signal_connect (action, "drag-end", G_CALLBACK (on_drag_end), NULL);
|
||||
clutter_actor_set_reactive (viewport, TRUE);
|
||||
|
||||
/* children of the viewport */
|
||||
for (i = 0; i < N_RECTS; i++)
|
||||
{
|
||||
ClutterColor color;
|
||||
|
||||
clutter_color_from_string (&color, rect_color[i]);
|
||||
|
||||
rectangle[i] = clutter_actor_new ();
|
||||
clutter_actor_set_background_color (rectangle[i], &color);
|
||||
clutter_actor_add_child (viewport, rectangle[i]);
|
||||
clutter_actor_set_size (rectangle[i], RECT_WIDTH, RECT_HEIGHT);
|
||||
}
|
||||
|
||||
clutter_actor_show (stage);
|
||||
|
||||
clutter_main ();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user