Blame clutter/clutter-tap-action.c

Packit Service bf98b9
/*
Packit Service bf98b9
 * Clutter.
Packit Service bf98b9
 *
Packit Service bf98b9
 * An OpenGL based 'interactive canvas' library.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Copyright (C) 2010  Intel Corporation.
Packit Service bf98b9
 * Copyright (C) 2011  Robert Bosch Car Multimedia GmbH.
Packit Service bf98b9
 * Copyright (C) 2012  Collabora Ltd.
Packit Service bf98b9
 *
Packit Service bf98b9
 * This library is free software; you can redistribute it and/or
Packit Service bf98b9
 * modify it under the terms of the GNU Lesser General Public
Packit Service bf98b9
 * License as published by the Free Software Foundation; either
Packit Service bf98b9
 * version 2 of the License, or (at your option) any later version.
Packit Service bf98b9
 *
Packit Service bf98b9
 * This library is distributed in the hope that it will be useful,
Packit Service bf98b9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service bf98b9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service bf98b9
 * Lesser General Public License for more details.
Packit Service bf98b9
 *
Packit Service bf98b9
 * You should have received a copy of the GNU Lesser General Public
Packit Service bf98b9
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
Packit Service bf98b9
 *
Packit Service bf98b9
 * Author:
Packit Service bf98b9
 *   Emanuele Aina <emanuele.aina@collabora.com>
Packit Service bf98b9
 *
Packit Service bf98b9
 * Based on ClutterPanAction
Packit Service bf98b9
 * Based on ClutterDragAction, ClutterSwipeAction, and MxKineticScrollView,
Packit Service bf98b9
 * written by:
Packit Service bf98b9
 *   Emmanuele Bassi <ebassi@linux.intel.com>
Packit Service bf98b9
 *   Tomeu Vizoso <tomeu.vizoso@collabora.co.uk>
Packit Service bf98b9
 *   Chris Lord <chris@linux.intel.com>
Packit Service bf98b9
 */
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * SECTION:clutter-tap-action
Packit Service bf98b9
 * @Title: ClutterTapAction
Packit Service bf98b9
 * @Short_Description: Action for tap gestures
Packit Service bf98b9
 *
Packit Service bf98b9
 * #ClutterTapAction is a sub-class of #ClutterGestureAction that implements
Packit Service bf98b9
 * the logic for recognizing mouse clicks and touch tap gestures.
Packit Service bf98b9
 *
Packit Service bf98b9
 * The simplest usage of #ClutterTapAction consists in adding it to
Packit Service bf98b9
 * a #ClutterActor, setting it as reactive and connecting a
Packit Service bf98b9
 * callback for the #ClutterTapAction::tap signal, along the lines of the
Packit Service bf98b9
 * following code:
Packit Service bf98b9
 *
Packit Service bf98b9
 * |[
Packit Service bf98b9
 *   clutter_actor_add_action (actor, clutter_tap_action_new ());
Packit Service bf98b9
 *   clutter_actor_set_reactive (actor, TRUE);
Packit Service bf98b9
 *   g_signal_connect (action, "tap", G_CALLBACK (on_tap_callback), NULL);
Packit Service bf98b9
 * ]|
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.14
Packit Service bf98b9
 */
Packit Service bf98b9
Packit Service bf98b9
#ifdef HAVE_CONFIG_H
Packit Service bf98b9
#include "config.h"
Packit Service bf98b9
#endif
Packit Service bf98b9
Packit Service bf98b9
#include "clutter-tap-action.h"
Packit Service bf98b9
Packit Service bf98b9
#include "clutter-debug.h"
Packit Service bf98b9
#include "clutter-enum-types.h"
Packit Service bf98b9
#include "clutter-gesture-action-private.h"
Packit Service bf98b9
#include "clutter-marshal.h"
Packit Service bf98b9
#include "clutter-private.h"
Packit Service bf98b9
Packit Service bf98b9
enum
Packit Service bf98b9
{
Packit Service bf98b9
  TAP,
Packit Service bf98b9
Packit Service bf98b9
  LAST_SIGNAL
Packit Service bf98b9
};
Packit Service bf98b9
Packit Service bf98b9
static guint tap_signals[LAST_SIGNAL] = { 0, };
Packit Service bf98b9
Packit Service bf98b9
G_DEFINE_TYPE (ClutterTapAction, clutter_tap_action,
Packit Service bf98b9
               CLUTTER_TYPE_GESTURE_ACTION);
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
emit_tap (ClutterTapAction *self,
Packit Service bf98b9
          ClutterActor     *actor)
Packit Service bf98b9
{
Packit Service bf98b9
  g_signal_emit (self, tap_signals[TAP], 0, actor);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
gesture_end (ClutterGestureAction *gesture,
Packit Service bf98b9
             ClutterActor         *actor)
Packit Service bf98b9
{
Packit Service bf98b9
  emit_tap (CLUTTER_TAP_ACTION (gesture), actor);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
clutter_tap_action_constructed (GObject *object)
Packit Service bf98b9
{
Packit Service bf98b9
  clutter_gesture_action_set_threshold_trigger_edge (CLUTTER_GESTURE_ACTION (object),
Packit Service bf98b9
                                                     CLUTTER_GESTURE_TRIGGER_EDGE_BEFORE);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
clutter_tap_action_class_init (ClutterTapActionClass *klass)
Packit Service bf98b9
{
Packit Service bf98b9
  ClutterGestureActionClass *gesture_class =
Packit Service bf98b9
      CLUTTER_GESTURE_ACTION_CLASS (klass);
Packit Service bf98b9
  GObjectClass *object_class =
Packit Service bf98b9
      G_OBJECT_CLASS (klass);
Packit Service bf98b9
Packit Service bf98b9
  object_class->constructed = clutter_tap_action_constructed;
Packit Service bf98b9
Packit Service bf98b9
  gesture_class->gesture_end = gesture_end;
Packit Service bf98b9
Packit Service bf98b9
  /**
Packit Service bf98b9
   * ClutterTapAction::tap:
Packit Service bf98b9
   * @action: the #ClutterTapAction that emitted the signal
Packit Service bf98b9
   * @actor: the #ClutterActor attached to the @action
Packit Service bf98b9
   *
Packit Service bf98b9
   * The ::tap signal is emitted when the tap gesture is complete.
Packit Service bf98b9
   *
Packit Service bf98b9
   * Since: 1.14
Packit Service bf98b9
   */
Packit Service bf98b9
  tap_signals[TAP] =
Packit Service bf98b9
    g_signal_new (I_("tap"),
Packit Service bf98b9
                  G_TYPE_FROM_CLASS (klass),
Packit Service bf98b9
                  G_SIGNAL_RUN_LAST,
Packit Service bf98b9
                  G_STRUCT_OFFSET (ClutterTapActionClass, tap),
Packit Service bf98b9
                  NULL, NULL,
Packit Service bf98b9
                  _clutter_marshal_VOID__OBJECT,
Packit Service bf98b9
                  G_TYPE_NONE, 1,
Packit Service bf98b9
                  CLUTTER_TYPE_ACTOR);
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
static void
Packit Service bf98b9
clutter_tap_action_init (ClutterTapAction *self)
Packit Service bf98b9
{
Packit Service bf98b9
}
Packit Service bf98b9
Packit Service bf98b9
/**
Packit Service bf98b9
 * clutter_tap_action_new:
Packit Service bf98b9
 *
Packit Service bf98b9
 * Creates a new #ClutterTapAction instance
Packit Service bf98b9
 *
Packit Service bf98b9
 * Return value: the newly created #ClutterTapAction
Packit Service bf98b9
 *
Packit Service bf98b9
 * Since: 1.14
Packit Service bf98b9
 */
Packit Service bf98b9
ClutterAction *
Packit Service bf98b9
clutter_tap_action_new (void)
Packit Service bf98b9
{
Packit Service bf98b9
  return g_object_new (CLUTTER_TYPE_TAP_ACTION, NULL);
Packit Service bf98b9
}