1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.GestureSwipe; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gtk.Gesture; 31 private import gtk.GestureSingle; 32 private import gtk.Widget; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 public import gtkc.gtktypes; 36 private import std.algorithm; 37 38 39 /** 40 * #GtkGestureSwipe is a #GtkGesture implementation able to recognize 41 * swipes, after a press/move/.../move/release sequence happens, the 42 * #GtkGestureSwipe::swipe signal will be emitted, providing the velocity 43 * and directionality of the sequence at the time it was lifted. 44 * 45 * If the velocity is desired in intermediate points, 46 * gtk_gesture_swipe_get_velocity() can be called on eg. a 47 * #GtkGesture::update handler. 48 * 49 * All velocities are reported in pixels/sec units. 50 */ 51 public class GestureSwipe : GestureSingle 52 { 53 /** the main Gtk struct */ 54 protected GtkGestureSwipe* gtkGestureSwipe; 55 56 /** Get the main Gtk struct */ 57 public GtkGestureSwipe* getGestureSwipeStruct(bool transferOwnership = false) 58 { 59 if (transferOwnership) 60 ownedRef = false; 61 return gtkGestureSwipe; 62 } 63 64 /** the main Gtk struct as a void* */ 65 protected override void* getStruct() 66 { 67 return cast(void*)gtkGestureSwipe; 68 } 69 70 /** 71 * Sets our main struct and passes it to the parent class. 72 */ 73 public this (GtkGestureSwipe* gtkGestureSwipe, bool ownedRef = false) 74 { 75 this.gtkGestureSwipe = gtkGestureSwipe; 76 super(cast(GtkGestureSingle*)gtkGestureSwipe, ownedRef); 77 } 78 79 80 /** */ 81 public static GType getType() 82 { 83 return gtk_gesture_swipe_get_type(); 84 } 85 86 /** 87 * Returns a newly created #GtkGesture that recognizes swipes. 88 * 89 * Params: 90 * widget = a #GtkWidget 91 * 92 * Returns: a newly created #GtkGestureSwipe 93 * 94 * Since: 3.14 95 * 96 * Throws: ConstructionException GTK+ fails to create the object. 97 */ 98 public this(Widget widget) 99 { 100 auto p = gtk_gesture_swipe_new((widget is null) ? null : widget.getWidgetStruct()); 101 102 if(p is null) 103 { 104 throw new ConstructionException("null returned by new"); 105 } 106 107 this(cast(GtkGestureSwipe*) p, true); 108 } 109 110 /** 111 * If the gesture is recognized, this function returns %TRUE and fill in 112 * @velocity_x and @velocity_y with the recorded velocity, as per the 113 * last event(s) processed. 114 * 115 * Params: 116 * velocityX = return value for the velocity in the X axis, in pixels/sec 117 * velocityY = return value for the velocity in the Y axis, in pixels/sec 118 * 119 * Returns: whether velocity could be calculated 120 * 121 * Since: 3.14 122 */ 123 public bool getVelocity(out double velocityX, out double velocityY) 124 { 125 return gtk_gesture_swipe_get_velocity(gtkGestureSwipe, &velocityX, &velocityY) != 0; 126 } 127 128 protected class OnSwipeDelegateWrapper 129 { 130 void delegate(double, double, GestureSwipe) dlg; 131 gulong handlerId; 132 133 this(void delegate(double, double, GestureSwipe) dlg) 134 { 135 this.dlg = dlg; 136 onSwipeListeners ~= this; 137 } 138 139 void remove(OnSwipeDelegateWrapper source) 140 { 141 foreach(index, wrapper; onSwipeListeners) 142 { 143 if (wrapper.handlerId == source.handlerId) 144 { 145 onSwipeListeners[index] = null; 146 onSwipeListeners = std.algorithm.remove(onSwipeListeners, index); 147 break; 148 } 149 } 150 } 151 } 152 OnSwipeDelegateWrapper[] onSwipeListeners; 153 154 /** 155 * This signal is emitted when the recognized gesture is finished, velocity 156 * and direction are a product of previously recorded events. 157 * 158 * Params: 159 * velocityX = velocity in the X axis, in pixels/sec 160 * velocityY = velocity in the Y axis, in pixels/sec 161 * 162 * Since: 3.14 163 */ 164 gulong addOnSwipe(void delegate(double, double, GestureSwipe) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 165 { 166 auto wrapper = new OnSwipeDelegateWrapper(dlg); 167 wrapper.handlerId = Signals.connectData( 168 this, 169 "swipe", 170 cast(GCallback)&callBackSwipe, 171 cast(void*)wrapper, 172 cast(GClosureNotify)&callBackSwipeDestroy, 173 connectFlags); 174 return wrapper.handlerId; 175 } 176 177 extern(C) static void callBackSwipe(GtkGestureSwipe* gestureswipeStruct, double velocityX, double velocityY, OnSwipeDelegateWrapper wrapper) 178 { 179 wrapper.dlg(velocityX, velocityY, wrapper.outer); 180 } 181 182 extern(C) static void callBackSwipeDestroy(OnSwipeDelegateWrapper wrapper, GClosure* closure) 183 { 184 wrapper.remove(wrapper); 185 } 186 }