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 public import gtkc.gdktypes; 34 private import gtkc.gtk; 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() 58 { 59 return gtkGestureSwipe; 60 } 61 62 /** the main Gtk struct as a void* */ 63 protected override void* getStruct() 64 { 65 return cast(void*)gtkGestureSwipe; 66 } 67 68 protected override void setStruct(GObject* obj) 69 { 70 gtkGestureSwipe = cast(GtkGestureSwipe*)obj; 71 super.setStruct(obj); 72 } 73 74 /** 75 * Sets our main struct and passes it to the parent class. 76 */ 77 public this (GtkGestureSwipe* gtkGestureSwipe, bool ownedRef = false) 78 { 79 this.gtkGestureSwipe = gtkGestureSwipe; 80 super(cast(GtkGestureSingle*)gtkGestureSwipe, ownedRef); 81 } 82 83 84 /** */ 85 public static GType getType() 86 { 87 return gtk_gesture_swipe_get_type(); 88 } 89 90 /** 91 * Returns a newly created #GtkGesture that recognizes swipes. 92 * 93 * Params: 94 * widget = a #GtkWidget 95 * 96 * Return: a newly created #GtkGestureSwipe 97 * 98 * Since: 3.14 99 * 100 * Throws: ConstructionException GTK+ fails to create the object. 101 */ 102 public this(Widget widget) 103 { 104 auto p = gtk_gesture_swipe_new((widget is null) ? null : widget.getWidgetStruct()); 105 106 if(p is null) 107 { 108 throw new ConstructionException("null returned by new"); 109 } 110 111 this(cast(GtkGestureSwipe*) p, true); 112 } 113 114 /** 115 * If the gesture is recognized, this function returns %TRUE and fill in 116 * @velocity_x and @velocity_y with the recorded velocity, as per the 117 * last event(s) processed. 118 * 119 * Params: 120 * velocityX = return value for the velocity in the X axis, in pixels/sec 121 * velocityY = return value for the velocity in the Y axis, in pixels/sec 122 * 123 * Return: whether velocity could be calculated 124 * 125 * Since: 3.14 126 */ 127 public bool getVelocity(out double velocityX, out double velocityY) 128 { 129 return gtk_gesture_swipe_get_velocity(gtkGestureSwipe, &velocityX, &velocityY) != 0; 130 } 131 132 protected class OnSwipeDelegateWrapper 133 { 134 void delegate(double, double, GestureSwipe) dlg; 135 gulong handlerId; 136 ConnectFlags flags; 137 this(void delegate(double, double, GestureSwipe) dlg, gulong handlerId, ConnectFlags flags) 138 { 139 this.dlg = dlg; 140 this.handlerId = handlerId; 141 this.flags = flags; 142 } 143 } 144 protected OnSwipeDelegateWrapper[] onSwipeListeners; 145 146 /** 147 * This signal is emitted when the recognized gesture is finished, velocity 148 * and direction are a product of previously recorded events. 149 * 150 * Params: 151 * velocityX = velocity in the X axis, in pixels/sec 152 * velocityY = velocity in the Y axis, in pixels/sec 153 * 154 * Since: 3.14 155 */ 156 gulong addOnSwipe(void delegate(double, double, GestureSwipe) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 157 { 158 onSwipeListeners ~= new OnSwipeDelegateWrapper(dlg, 0, connectFlags); 159 onSwipeListeners[onSwipeListeners.length - 1].handlerId = Signals.connectData( 160 this, 161 "swipe", 162 cast(GCallback)&callBackSwipe, 163 cast(void*)onSwipeListeners[onSwipeListeners.length - 1], 164 cast(GClosureNotify)&callBackSwipeDestroy, 165 connectFlags); 166 return onSwipeListeners[onSwipeListeners.length - 1].handlerId; 167 } 168 169 extern(C) static void callBackSwipe(GtkGestureSwipe* gestureswipeStruct, double velocityX, double velocityY,OnSwipeDelegateWrapper wrapper) 170 { 171 wrapper.dlg(velocityX, velocityY, wrapper.outer); 172 } 173 174 extern(C) static void callBackSwipeDestroy(OnSwipeDelegateWrapper wrapper, GClosure* closure) 175 { 176 wrapper.outer.internalRemoveOnSwipe(wrapper); 177 } 178 179 protected void internalRemoveOnSwipe(OnSwipeDelegateWrapper source) 180 { 181 foreach(index, wrapper; onSwipeListeners) 182 { 183 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 184 { 185 onSwipeListeners[index] = null; 186 onSwipeListeners = std.algorithm.remove(onSwipeListeners, index); 187 break; 188 } 189 } 190 } 191 192 }