AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
ScriptGuiEventListener.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#ifndef AGXPYTHON_SCRIPTGUIEVENTLISTENER_H
18#define AGXPYTHON_SCRIPTGUIEVENTLISTENER_H
19
20
21#include <agx/config/AGX_USE_PYTHON.h>
22#include <agx/config.h>
23
24#if 0
25#if AGX_USE_PYTHON()
26
27#include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
28#include <Python.h>
29#include <agx/PopDisableWarnings.h> // End of disabled warnings.
30
31namespace agxSDK
32{
33 class Simulation;
34}
35
36#include <agxPython/export.h>
37#include <agx/Referenced.h>
38#include <agx/ref_ptr.h>
40
41namespace agxPython
42{
43
44 class ScriptContext;
45
46 class AGXPYTHON_EXPORT GuiEvent
47 {
48
49 public:
50
51 friend class ScriptGuiEventListener;
52
53 enum GuiEventType
54 {
55 UPDATE = 0x1,
56 MOUSE = 0x2,
57 KEYBOARD = 0x4,
58 };
59
60 bool isUpdate() const { return (m_type == UPDATE); }
61
62 bool isKeyboard() const { return (m_type == KEYBOARD); }
63
64 bool isMouse() const { return (m_type == MOUSE); }
65
66 bool isMouseDragged() const { return (isMouse() && (m_mouseState & agxSDK::GuiEventListener::MouseState::MOUSE_DOWN) == agxSDK::GuiEventListener::MouseState::MOUSE_DOWN); }
67
68 bool isMouseMoved() const { return (!isMouseDragged() && (m_mouseState & agxSDK::GuiEventListener::MouseState::NO_MOUSE_STATE) == agxSDK::GuiEventListener::MouseState::NO_MOUSE_STATE); }
69
70 float x() const { return m_x; }
71
72 float y() const { return m_y; }
73
74 int mouseButton() const { return m_mouseButtonMask; }
75
76 int mouseState() const { return m_mouseState; }
77
78 int key() const { return m_key; }
79
80 unsigned int modKey() const { return m_modKeyMask; }
81
82 bool keyIsDown() const { return m_keyDown; }
83
84 protected:
85
86 GuiEvent(float x, float y) : m_type(UPDATE), m_x(x), m_y(y) {}
87 GuiEvent(int key, int modKeyMask, bool keyDown, float x, float y) : m_type(KEYBOARD), m_x(x), m_y(y), m_key(key), m_modKeyMask(modKeyMask), m_keyDown(keyDown) {}
88 GuiEvent(agxSDK::GuiEventListener::MouseButtonMask button, agxSDK::GuiEventListener::MouseState state, float x, float y) : m_type(MOUSE), m_x(x), m_y(y), m_mouseButtonMask(button), m_mouseState(state) {}
89
90 PyObject *makeDict();
91
92 private:
93
94 GuiEventType m_type;
95
96 float m_x;
97 float m_y;
98
99 int m_mouseButtonMask;
100 int m_mouseState;
101
102 int m_key;
103 unsigned int m_modKeyMask;
104 bool m_keyDown;
105 };
106
107 class AGXPYTHON_EXPORT ScriptGuiEventListener : public agxSDK::GuiEventListener
108 {
109
110 public:
111
112 friend class ScriptContext_listeners;
113
114#ifndef SWIG
115 virtual bool mouseDragged(MouseButtonMask /*buttonMask*/, float /*x*/, float /*y*/) override;
116
117 virtual bool mouseMoved(float /*x*/, float /*y*/) override;
118
119 virtual bool mouse(MouseButtonMask /*button*/, MouseState /*state*/, float /*x*/, float /*y*/) override;
120
121 virtual bool keyboard(int /*key*/, unsigned int /*modKeyMask*/, float /*x*/, float /*y*/, bool /*keydown*/) override;
122
123 virtual void update(float /*x*/, float /*y*/) override;
124#endif
125
126 void onEvent(PyObject *callback);
127
128 protected:
129
130 ScriptGuiEventListener(ScriptContext *scriptContext);
131
132 virtual ~ScriptGuiEventListener();
133
134 void callbackSet(PyObject *pyCallback);
135
136 private:
137
138 ScriptGuiEventListener();
139
140 ScriptContext *m_scriptContext;
141
142 PyObject *m_pyCallback;
143
144 };
145
146}
147
148
149#endif
150
151#endif
152
153#endif
#define AGXPYTHON_EXPORT
Derive from this class to implement a listener for simulation GuiEvents.
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition Constraint.h:31