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 
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 	int[string] connectedSignals;
133 
134 	void delegate(double, double, GestureSwipe)[] onSwipeListeners;
135 	/**
136 	 * This signal is emitted when the recognized gesture is finished, velocity
137 	 * and direction are a product of previously recorded events.
138 	 *
139 	 * Params:
140 	 *     velocityX = velocity in the X axis, in pixels/sec
141 	 *     velocityY = velocity in the Y axis, in pixels/sec
142 	 *
143 	 * Since: 3.14
144 	 */
145 	void addOnSwipe(void delegate(double, double, GestureSwipe) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
146 	{
147 		if ( "swipe" !in connectedSignals )
148 		{
149 			Signals.connectData(
150 				this,
151 				"swipe",
152 				cast(GCallback)&callBackSwipe,
153 				cast(void*)this,
154 				null,
155 				connectFlags);
156 			connectedSignals["swipe"] = 1;
157 		}
158 		onSwipeListeners ~= dlg;
159 	}
160 	extern(C) static void callBackSwipe(GtkGestureSwipe* gestureswipeStruct, double velocityX, double velocityY, GestureSwipe _gestureswipe)
161 	{
162 		foreach ( void delegate(double, double, GestureSwipe) dlg; _gestureswipe.onSwipeListeners )
163 		{
164 			dlg(velocityX, velocityY, _gestureswipe);
165 		}
166 	}
167 }