AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
agxSDK/GuiEventListener.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
20#include <agx/TimeStamp.h>
21#include <agxSDK/agxSDK.h>
23#include <agx/Vec3.h>
24#include <agxCollide/Geometry.h>
26
27
28namespace agxSDK
29{
30
44
45
52 {
53 public:
54 friend class EventManager;
55
57 NO_MOUSE_STATE = 0,
58 MOUSE_DOWN = 1,
59 MOUSE_UP = 2,
60 DOUBLECLICK = 4
61 };
62
64 NO_MOUSE_BUTTON = GuiEventAdapter::NO_MOUSE_BUTTON,
65 LEFT_MOUSE_BUTTON = GuiEventAdapter::LEFT_MOUSE_BUTTON,
66 MIDDLE_MOUSE_BUTTON = GuiEventAdapter::MIDDLE_MOUSE_BUTTON,
67 RIGHT_MOUSE_BUTTON = GuiEventAdapter::RIGHT_MOUSE_BUTTON
68 };
69
70
71 enum KeySymbol {
72 KEY_Space = 0x20,
73
74 KEY_BackSpace = 0xFF08, /* back space, back char */
75 KEY_Tab = 0xFF09,
76 KEY_Linefeed = 0xFF0A, /* Linefeed, LF */
77 KEY_Clear = 0xFF0B,
78 KEY_Return = 0xFF0D, /* Return, enter */
79 KEY_Pause = 0xFF13, /* Pause, hold */
80 KEY_Scroll_Lock = 0xFF14,
81 KEY_Sys_Req = 0xFF15,
82 KEY_Escape = 0xFF1B,
83 KEY_Delete = 0xFFFF, /* Delete, rubout */
84
85
86 /* Cursor control & motion */
87
88 KEY_Home = 0xFF50,
89 KEY_Left = 0xFF51, /* Move left, left arrow */
90 KEY_Up = 0xFF52, /* Move up, up arrow */
91 KEY_Right = 0xFF53, /* Move right, right arrow */
92 KEY_Down = 0xFF54, /* Move down, down arrow */
93 KEY_Prior = 0xFF55, /* Prior, previous */
94 KEY_Page_Up = 0xFF55,
95 KEY_Next = 0xFF56, /* Next */
96 KEY_Page_Down = 0xFF56,
97 KEY_End = 0xFF57, /* EOL */
98 KEY_Begin = 0xFF58, /* BOL */
99
100
101 /* Misc Functions */
102
103 KEY_Select = 0xFF60, /* Select, mark */
104 KEY_Print = 0xFF61,
105 KEY_Execute = 0xFF62, /* Execute, run, do */
106 KEY_Insert = 0xFF63, /* Insert, insert here */
107 KEY_Undo = 0xFF65, /* Undo, oops */
108 KEY_Redo = 0xFF66, /* redo, again */
109 KEY_Menu = 0xFF67, /* On Windows, this is VK_APPS, the component-menu key */
110 KEY_Find = 0xFF68, /* Find, search */
111 KEY_Cancel = 0xFF69, /* Cancel, stop, abort, exit */
112 KEY_Help = 0xFF6A, /* Help */
113 KEY_Break = 0xFF6B,
114 KEY_Mode_switch = 0xFF7E, /* Character set switch */
115 KEY_Script_switch = 0xFF7E, /* Alias for mode_switch */
116 KEY_Num_Lock = 0xFF7F,
117
118 /* Keypad Functions, keypad numbers cleverly chosen to map to ascii */
119
120 KEY_KP_Space = 0xFF80, /* space */
121 KEY_KP_Tab = 0xFF89,
122 KEY_KP_Enter = 0xFF8D, /* enter */
123 KEY_KP_F1 = 0xFF91, /* PF1, KP_A, ... */
124 KEY_KP_F2 = 0xFF92,
125 KEY_KP_F3 = 0xFF93,
126 KEY_KP_F4 = 0xFF94,
127 KEY_KP_Home = 0xFF95,
128 KEY_KP_Left = 0xFF96,
129 KEY_KP_Up = 0xFF97,
130 KEY_KP_Right = 0xFF98,
131 KEY_KP_Down = 0xFF99,
132 KEY_KP_Prior = 0xFF9A,
133 KEY_KP_Page_Up = 0xFF9A,
134 KEY_KP_Next = 0xFF9B,
135 KEY_KP_Page_Down = 0xFF9B,
136 KEY_KP_End = 0xFF9C,
137 KEY_KP_Begin = 0xFF9D,
138 KEY_KP_Insert = 0xFF9E,
139 KEY_KP_Delete = 0xFF9F,
140 KEY_KP_Equal = 0xFFBD, /* equals */
141 KEY_KP_Multiply = 0xFFAA,
142 KEY_KP_Add = 0xFFAB,
143 KEY_KP_Separator = 0xFFAC, /* separator, often comma */
144 KEY_KP_Subtract = 0xFFAD,
145 KEY_KP_Decimal = 0xFFAE,
146 KEY_KP_Divide = 0xFFAF,
147
148 KEY_KP_0 = 0xFFB0,
149 KEY_KP_1 = 0xFFB1,
150 KEY_KP_2 = 0xFFB2,
151 KEY_KP_3 = 0xFFB3,
152 KEY_KP_4 = 0xFFB4,
153 KEY_KP_5 = 0xFFB5,
154 KEY_KP_6 = 0xFFB6,
155 KEY_KP_7 = 0xFFB7,
156 KEY_KP_8 = 0xFFB8,
157 KEY_KP_9 = 0xFFB9,
158
159 /*
160 * Auxiliary Functions; note the duplicate definitions for left and right
161 * function keys; Sun keyboards and a few other manufactures have such
162 * function key groups on the left and/or right sides of the keyboard.
163 * We've not found a keyboard with more than 35 function keys total.
164 */
165
166 KEY_F1 = 0xFFBE,
167 KEY_F2 = 0xFFBF,
168 KEY_F3 = 0xFFC0,
169 KEY_F4 = 0xFFC1,
170 KEY_F5 = 0xFFC2,
171 KEY_F6 = 0xFFC3,
172 KEY_F7 = 0xFFC4,
173 KEY_F8 = 0xFFC5,
174 KEY_F9 = 0xFFC6,
175 KEY_F10 = 0xFFC7,
176 KEY_F11 = 0xFFC8,
177 KEY_F12 = 0xFFC9,
178 KEY_F13 = 0xFFCA,
179 KEY_F14 = 0xFFCB,
180 KEY_F15 = 0xFFCC,
181 KEY_F16 = 0xFFCD,
182 KEY_F17 = 0xFFCE,
183 KEY_F18 = 0xFFCF,
184 KEY_F19 = 0xFFD0,
185 KEY_F20 = 0xFFD1,
186 KEY_F21 = 0xFFD2,
187 KEY_F22 = 0xFFD3,
188 KEY_F23 = 0xFFD4,
189 KEY_F24 = 0xFFD5,
190 KEY_F25 = 0xFFD6,
191 KEY_F26 = 0xFFD7,
192 KEY_F27 = 0xFFD8,
193 KEY_F28 = 0xFFD9,
194 KEY_F29 = 0xFFDA,
195 KEY_F30 = 0xFFDB,
196 KEY_F31 = 0xFFDC,
197 KEY_F32 = 0xFFDD,
198 KEY_F33 = 0xFFDE,
199 KEY_F34 = 0xFFDF,
200 KEY_F35 = 0xFFE0,
201
202 /* Modifiers */
203
204 KEY_Shift_L = 0xFFE1, /* Left shift */
205 KEY_Shift_R = 0xFFE2, /* Right shift */
206 KEY_Control_L = 0xFFE3, /* Left control */
207 KEY_Control_R = 0xFFE4, /* Right control */
208 KEY_Caps_Lock = 0xFFE5, /* Caps lock */
209 KEY_Shift_Lock = 0xFFE6, /* Shift lock */
210
211 KEY_Meta_L = 0xFFE7, /* Left meta */
212 KEY_Meta_R = 0xFFE8, /* Right meta */
213 KEY_Alt_L = 0xFFE9, /* Left alt */
214 KEY_Alt_R = 0xFFEA, /* Right alt */
215 KEY_Super_L = 0xFFEB, /* Left super */
216 KEY_Super_R = 0xFFEC, /* Right super */
217 KEY_Hyper_L = 0xFFED, /* Left hyper */
218 KEY_Hyper_R = 0xFFEE /* Right hyper */
219 };
220
222 MODKEY_LEFT_SHIFT = 0x0001,
223 MODKEY_RIGHT_SHIFT = 0x0002,
224 MODKEY_LEFT_CTRL = 0x0004,
225 MODKEY_RIGHT_CTRL = 0x0008,
226 MODKEY_LEFT_ALT = 0x0010,
227 MODKEY_RIGHT_ALT = 0x0020,
228 MODKEY_LEFT_META = 0x0040,
229 MODKEY_RIGHT_META = 0x0080,
230 MODKEY_LEFT_SUPER = 0x0100,
231 MODKEY_RIGHT_SUPER = 0x0200,
232 MODKEY_LEFT_HYPER = 0x0400,
233 MODKEY_RIGHT_HYPER = 0x0800,
234 MODKEY_NUM_LOCK = 0x1000,
235 MODKEY_CAPS_LOCK = 0x2000,
236 MODKEY_CTRL = (MODKEY_LEFT_CTRL | MODKEY_RIGHT_CTRL),
237 MODKEY_SHIFT = (MODKEY_LEFT_SHIFT | MODKEY_RIGHT_SHIFT),
238 MODKEY_ALT = (MODKEY_LEFT_ALT | MODKEY_RIGHT_ALT),
239 MODKEY_META = (MODKEY_LEFT_META | MODKEY_RIGHT_META),
240 MODKEY_SUPER = (MODKEY_LEFT_SUPER | MODKEY_RIGHT_SUPER),
241 MODKEY_HYPER = (MODKEY_LEFT_HYPER | MODKEY_RIGHT_HYPER)
242 };
243
246 Y_INCREASING_DOWNWARDS
247 };
248
257
258
261 NONE = 0,
262
263 MOUSE_BUTTON = 1,
264 MOUSE_MOTION = 2,
265 MOUSE_PASSIVE_MOTION = 4,
266 KEYBOARD = 8,
267 UPDATE = 16,
268 DEFAULT = MOUSE_BUTTON | KEYBOARD | UPDATE,
269 ALL = MOUSE_BUTTON | MOUSE_MOTION | MOUSE_PASSIVE_MOTION | KEYBOARD | UPDATE
270
271 };
272
274 GuiEventListener( ActivationMask mask = DEFAULT );
275
277 virtual void setMask(int f);
278
279 // ================ Override these two methods to catch events
280
287 virtual bool mouseDragged( MouseButtonMask buttonMask, float x, float y );
288
293 virtual bool mouseMoved( float x, float y );
294
300 virtual bool mouse( MouseButtonMask button, MouseState state, float x, float y );
301
309 virtual bool keyboard( int key, unsigned int modKeyMask, float x, float y, bool keydown );
310
315 virtual void update( float x, float y );
316
323 agxSDK::PickResult intersect(const agx::Vec3& start, const agx::Vec3& end, bool onlyDynamics);
324
325 virtual void setInverseTransform(const agx::AffineMatrix4x4& inverseTransform);
326
327
328 protected:
329
330 size_t findIntersectGeometryIndex(const agxCollide::LocalGeometryContactVector& geometryContacts, bool onlyDynamic);
331
332 bool _mouseDragged( MouseButtonMask buttonMask, float x, float y );
333
334
335 bool _mouseMoved( float x, float y );
336
337 bool _mouse( MouseButtonMask buttonMask, MouseState state, float x, float y );
338
339 bool _keyboard( int key, unsigned int modKeyMask, float x, float y, bool keydown );
340
341 void _update( float x, float y );
342
343 virtual ~GuiEventListener() {}
344
347
348 };
349
351
352
354 setMask( mask );
355 }
356
358 inline void GuiEventListener::setMask(int f) {
360 }
361
362 inline bool GuiEventListener::mouseDragged( MouseButtonMask /*buttonMask*/, float /*x*/, float /*y*/ ) {
363 return false;
364 }
365
366 inline bool GuiEventListener::mouseMoved( float /*x*/, float /*y*/ ) {
367 return false;
368 }
369
370 inline bool GuiEventListener::mouse( MouseButtonMask /*button*/, MouseState /*state*/, float /*x*/, float /*y*/ ) {
371 return false;
372 }
373
374 inline bool GuiEventListener::keyboard( int /*key*/, unsigned int /*modKeyMask*/, float /*x*/, float /*y*/, bool /*keydown*/ ) {
375 return false;
376 }
377
378 inline void GuiEventListener::update( float /*x*/, float /*y*/ ) {
379 return;
380 }
381
382 inline bool GuiEventListener::_mouseDragged( MouseButtonMask buttonMask, float x, float y ) {
383 if (getMask() & MOUSE_MOTION)
384 return mouseDragged( buttonMask, x, y );
385 return false;
386 }
387
388
389 inline bool GuiEventListener::_mouseMoved( float x, float y ) {
391 return mouseMoved( x, y );
392 return false;
393 }
394
395 inline bool GuiEventListener::_mouse( MouseButtonMask buttonMask, MouseState state, float x, float y ) {
396 if (getMask() & MOUSE_BUTTON) return mouse( buttonMask, state, x, y);
397 return false;
398 }
399
400 inline bool GuiEventListener::_keyboard( int key, unsigned int modKeyMask, float x, float y, bool keydown ) {
401 if (getMask() & KEYBOARD)
402 return keyboard( key, modKeyMask, x, y, keydown );
403 return false;
404 }
405
406 inline void GuiEventListener::_update( float x, float y ) {
407 if (getMask() & UPDATE)
408 return update( x, y );
409 return;
410 }
411
412}
#define AGXPHYSICS_EXPORT
An EventListener can be associated to a Simulation and triggered upon various events.
virtual void setMask(int f)
Specifies a bit mask which determines which event types that will activate this listener.
Derive from this class to implement a listener for simulation GuiEvents.
bool _mouse(MouseButtonMask buttonMask, MouseState state, float x, float y)
virtual bool mouseDragged(MouseButtonMask buttonMask, float x, float y)
Called when one or more mouse buttons are pressed and moved.
size_t findIntersectGeometryIndex(const agxCollide::LocalGeometryContactVector &geometryContacts, bool onlyDynamic)
agx::AffineMatrix4x4 m_directTransform
GuiEventListener(ActivationMask mask=DEFAULT)
Constructor, sets the default activation mask to the events defined by mask.
virtual void setMask(int f)
Specifies a bitmask which determines which event types that will activate this listener.
ActivationMask
Defines the event states for which a listener will be activated, a mask can be bitwise OR:ed from the...
bool _mouseMoved(float x, float y)
virtual bool mouseMoved(float x, float y)
virtual bool mouse(MouseButtonMask button, MouseState state, float x, float y)
bool _keyboard(int key, unsigned int modKeyMask, float x, float y, bool keydown)
virtual void setInverseTransform(const agx::AffineMatrix4x4 &inverseTransform)
virtual void update(float x, float y)
Called once per simulation frame.
agxSDK::PickResult intersect(const agx::Vec3 &start, const agx::Vec3 &end, bool onlyDynamics)
Shoot a ray from start to end into the space and calculate the closest geometry.
virtual bool keyboard(int key, unsigned int modKeyMask, float x, float y, bool keydown)
agx::AffineMatrix4x4 m_inverseTransform
bool _mouseDragged(MouseButtonMask buttonMask, float x, float y)
Pointer to a entity instance of type Physics.Particle.
Smart pointer for handling referenced counted objects.
Definition ref_ptr.h:30
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31
agx::ref_ptr< GuiEventListener > GuiEventListenerRef
double Real
Definition Real.h:42
agx::observer_ptr< agxCollide::Geometry > geometry
agx::Physics::ParticlePtr particle