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 
37 
38 /**
39  * #GtkGestureSwipe is a #GtkGesture implementation able to recognize
40  * swipes, after a press/move/.../move/release sequence happens, the
41  * #GtkGestureSwipe::swipe signal will be emitted, providing the velocity
42  * and directionality of the sequence at the time it was lifted.
43  * 
44  * If the velocity is desired in intermediate points,
45  * gtk_gesture_swipe_get_velocity() can be called on eg. a
46  * #GtkGesture::update handler.
47  * 
48  * All velocities are reported in pixels/sec units.
49  */
50 public class GestureSwipe : GestureSingle
51 {
52 	/** the main Gtk struct */
53 	protected GtkGestureSwipe* gtkGestureSwipe;
54 
55 	/** Get the main Gtk struct */
56 	public GtkGestureSwipe* getGestureSwipeStruct()
57 	{
58 		return gtkGestureSwipe;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected override void* getStruct()
63 	{
64 		return cast(void*)gtkGestureSwipe;
65 	}
66 
67 	protected override void setStruct(GObject* obj)
68 	{
69 		gtkGestureSwipe = cast(GtkGestureSwipe*)obj;
70 		super.setStruct(obj);
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GtkGestureSwipe* gtkGestureSwipe, bool ownedRef = false)
77 	{
78 		this.gtkGestureSwipe = gtkGestureSwipe;
79 		super(cast(GtkGestureSingle*)gtkGestureSwipe, ownedRef);
80 	}
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return gtk_gesture_swipe_get_type();
87 	}
88 
89 	/**
90 	 * Returns a newly created #GtkGesture that recognizes swipes.
91 	 *
92 	 * Params:
93 	 *     widget = a #GtkWidget
94 	 *
95 	 * Return: a newly created #GtkGestureSwipe
96 	 *
97 	 * Since: 3.14
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this(Widget widget)
102 	{
103 		auto p = gtk_gesture_swipe_new((widget is null) ? null : widget.getWidgetStruct());
104 		
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 		
110 		this(cast(GtkGestureSwipe*) p, true);
111 	}
112 
113 	/**
114 	 * If the gesture is recognized, this function returns %TRUE and fill in
115 	 * @velocity_x and @velocity_y with the recorded velocity, as per the
116 	 * last event(s) processed.
117 	 *
118 	 * Params:
119 	 *     velocityX = return value for the velocity in the X axis, in pixels/sec
120 	 *     velocityY = return value for the velocity in the Y axis, in pixels/sec
121 	 *
122 	 * Return: whether velocity could be calculated
123 	 *
124 	 * Since: 3.14
125 	 */
126 	public bool getVelocity(out double velocityX, out double velocityY)
127 	{
128 		return gtk_gesture_swipe_get_velocity(gtkGestureSwipe, &velocityX, &velocityY) != 0;
129 	}
130 
131 	int[string] connectedSignals;
132 
133 	void delegate(double, double, GestureSwipe)[] onSwipeListeners;
134 	/**
135 	 * This signal is emitted when the recognized gesture is finished, velocity
136 	 * and direction are a product of previously recorded events.
137 	 *
138 	 * Params:
139 	 *     velocityX = velocity in the X axis, in pixels/sec
140 	 *     velocityY = velocity in the Y axis, in pixels/sec
141 	 *
142 	 * Since: 3.14
143 	 */
144 	void addOnSwipe(void delegate(double, double, GestureSwipe) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
145 	{
146 		if ( "swipe" !in connectedSignals )
147 		{
148 			Signals.connectData(
149 				this,
150 				"swipe",
151 				cast(GCallback)&callBackSwipe,
152 				cast(void*)this,
153 				null,
154 				connectFlags);
155 			connectedSignals["swipe"] = 1;
156 		}
157 		onSwipeListeners ~= dlg;
158 	}
159 	extern(C) static void callBackSwipe(GtkGestureSwipe* gestureswipeStruct, double velocityX, double velocityY, GestureSwipe _gestureswipe)
160 	{
161 		foreach ( void delegate(double, double, GestureSwipe) dlg; _gestureswipe.onSwipeListeners )
162 		{
163 			dlg(velocityX, velocityY, _gestureswipe);
164 		}
165 	}
166 }