summaryrefslogtreecommitdiff
path: root/clutter/clutter-tap-action.c
blob: 4d30eb129ed88c3ab763ab04890dbec55136888b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * Clutter.
 *
 * An OpenGL based 'interactive canvas' library.
 *
 * Copyright (C) 2010  Intel Corporation.
 * Copyright (C) 2011  Robert Bosch Car Multimedia GmbH.
 * Copyright (C) 2012  Collabora Ltd.
 *
 * 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:
 *   Emanuele Aina <emanuele.aina@collabora.com>
 *
 * Based on ClutterPanAction
 * Based on ClutterDragAction, ClutterSwipeAction, and MxKineticScrollView,
 * written by:
 *   Emmanuele Bassi <ebassi@linux.intel.com>
 *   Tomeu Vizoso <tomeu.vizoso@collabora.co.uk>
 *   Chris Lord <chris@linux.intel.com>
 */

/**
 * SECTION:clutter-tap-action
 * @Title: ClutterTapAction
 * @Short_Description: Action for tap gestures
 *
 * #ClutterTapAction is a sub-class of #ClutterGestureAction that implements
 * the logic for recognizing mouse clicks and touch tap gestures.
 *
 * The simplest usage of #ClutterTapAction consists in adding it to
 * a #ClutterActor, setting it as reactive and connecting a
 * callback for the #ClutterTapAction::tap signal, along the lines of the
 * following code:
 *
 * |[
 *   clutter_actor_add_action (actor, clutter_tap_action_new ());
 *   clutter_actor_set_reactive (actor, TRUE);
 *   g_signal_connect (action, "tap", G_CALLBACK (on_tap_callback), NULL);
 * ]|
 *
 * Since: 1.14
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "clutter-tap-action.h"

#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-gesture-action-private.h"
#include "clutter-marshal.h"
#include "clutter-private.h"

enum
{
  TAP,

  LAST_SIGNAL
};

static guint tap_signals[LAST_SIGNAL] = { 0, };

G_DEFINE_TYPE (ClutterTapAction, clutter_tap_action,
               CLUTTER_TYPE_GESTURE_ACTION);

static void
emit_tap (ClutterTapAction *self,
          ClutterActor     *actor)
{
  g_signal_emit (self, tap_signals[TAP], 0, actor);
}

static void
gesture_end (ClutterGestureAction *gesture,
             ClutterActor         *actor)
{
  emit_tap (CLUTTER_TAP_ACTION (gesture), actor);
}

static void
clutter_tap_action_constructed (GObject *object)
{
  clutter_gesture_action_set_threshold_trigger_edge (CLUTTER_GESTURE_ACTION (object),
                                                     CLUTTER_GESTURE_TRIGGER_EDGE_BEFORE);
}

static void
clutter_tap_action_class_init (ClutterTapActionClass *klass)
{
  ClutterGestureActionClass *gesture_class =
      CLUTTER_GESTURE_ACTION_CLASS (klass);
  GObjectClass *object_class =
      G_OBJECT_CLASS (klass);

  object_class->constructed = clutter_tap_action_constructed;

  gesture_class->gesture_end = gesture_end;

  /**
   * ClutterTapAction::tap:
   * @action: the #ClutterTapAction that emitted the signal
   * @actor: the #ClutterActor attached to the @action
   *
   * The ::tap signal is emitted when the tap gesture is complete.
   *
   * Since: 1.14
   */
  tap_signals[TAP] =
    g_signal_new (I_("tap"),
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (ClutterTapActionClass, tap),
                  NULL, NULL,
                  _clutter_marshal_VOID__OBJECT,
                  G_TYPE_NONE, 1,
                  CLUTTER_TYPE_ACTOR);
}

static void
clutter_tap_action_init (ClutterTapAction *self)
{
}

/**
 * clutter_tap_action_new:
 *
 * Creates a new #ClutterTapAction instance
 *
 * Return value: the newly created #ClutterTapAction
 *
 * Since: 1.14
 */
ClutterAction *
clutter_tap_action_new (void)
{
  return g_object_new (CLUTTER_TYPE_TAP_ACTION, NULL);
}