Blender V5.0
GHOST_System.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "GHOST_System.hh"
10
11#include "GHOST_EventManager.hh"
12#include "GHOST_TimerManager.hh"
13#include "GHOST_TimerTask.hh"
15
16#ifdef WITH_INPUT_NDOF
17# include "GHOST_NDOFManager.hh"
18#endif
19
35
40
45
46uint *GHOST_System::getClipboardImage(int * /*r_width*/, int * /*r_height*/) const
47{
48 return nullptr;
49}
50
52 int /*width*/,
53 int /*height*/) const
54{
55 return GHOST_kFailure;
56}
57
59 uint64_t interval,
60 GHOST_TimerProcPtr timer_proc,
61 GHOST_TUserDataPtr user_data)
62{
63 uint64_t millis = getMilliSeconds();
64 GHOST_TimerTask *timer = new GHOST_TimerTask(millis + delay, interval, timer_proc, user_data);
65 if (timer) {
66 if (timer_manager_->addTimer(timer) == GHOST_kSuccess) {
67 /* Check to see whether we need to fire the timer right away. */
68 timer_manager_->fireTimers(millis);
69 }
70 else {
71 delete timer;
72 timer = nullptr;
73 }
74 }
75 return timer;
76}
77
79{
81 if (timerTask) {
82 success = timer_manager_->removeTimer((GHOST_TimerTask *)timerTask);
83 }
84 return success;
85}
86
88{
89 GHOST_TSuccess success;
90
91 /*
92 * Remove all pending events for the window.
93 */
94 if (window_manager_->getWindowFound(window)) {
95 event_manager_->removeWindowEvents(window);
96 success = window_manager_->removeWindow(window);
97 if (success) {
98 delete window;
99 }
100 }
101 else {
102 success = GHOST_kFailure;
103 }
104 return success;
105}
106
108{
109 return window_manager_->getWindowFound(window);
110}
111
113{
114 /* TODO: This solution should follow the order of the activated windows (Z-order).
115 * It is imperfect but usable in most cases. Ideally each platform should provide
116 * a custom version of this function that properly considers z-order. */
117
118 std::vector<GHOST_IWindow *> windows = window_manager_->getWindows();
119 std::vector<GHOST_IWindow *>::reverse_iterator iwindow_iter;
120
121 /* Search through the windows in reverse order because in most cases
122 * the window that is on top was created after those that are below it. */
123
124 for (iwindow_iter = windows.rbegin(); iwindow_iter != windows.rend(); ++iwindow_iter) {
125
126 GHOST_IWindow *win = *iwindow_iter;
127
129 continue;
130 }
131
134 if (bounds.isInside(x, y)) {
135 return win;
136 }
137 }
138
139 return nullptr;
140}
141
143{
144#ifdef WITH_INPUT_NDOF
145 /* NDOF Motion event is sent only once per dispatch, so do it now: */
146 if (ndof_manager_) {
147 ndof_manager_->sendMotionEvent();
148 }
149#endif
150
151 if (event_manager_) {
152 event_manager_->dispatchEvents();
153 }
154
155 timer_manager_->fireTimers(getMilliSeconds());
156}
157
159{
160 GHOST_TSuccess success;
161 if (event_manager_) {
162 success = event_manager_->addConsumer(consumer);
163 }
164 else {
165 success = GHOST_kFailure;
166 }
167 return success;
168}
169
171{
172 GHOST_TSuccess success;
173 if (event_manager_) {
174 success = event_manager_->removeConsumer(consumer);
175 }
176 else {
177 success = GHOST_kFailure;
178 }
179 return success;
180}
181
183{
184 GHOST_TSuccess success;
185 if (event_manager_) {
186 success = event_manager_->pushEvent(event);
187 }
188 else {
189 success = GHOST_kFailure;
190 }
191 return success;
192}
193
195 int32_t &x,
196 int32_t &y) const
197{
198 /* Sub-classes that can implement this directly should do so. */
199 int32_t screen_x, screen_y;
200 GHOST_TSuccess success = getCursorPosition(screen_x, screen_y);
201 if (success == GHOST_kSuccess) {
202 window->screenToClient(screen_x, screen_y, x, y);
203 }
204 return success;
205}
206
208 int32_t x,
209 int32_t y)
210{
211 /* Sub-classes that can implement this directly should do so. */
212 int32_t screen_x, screen_y;
213 window->clientToScreen(x, y, screen_x, screen_y);
214 return setCursorPosition(screen_x, screen_y);
215}
216
218{
219 return uint32_t(24);
220}
221
223{
225 /* Get the state of all modifier keys. */
226 GHOST_TSuccess success = getModifierKeys(keys);
227 if (success) {
228 /* Isolate the state of the key requested. */
229 is_down = keys.get(mask);
230 }
231 return success;
232}
233
235{
236 GHOST_Buttons buttons;
237 /* Get the state of all mouse buttons. */
238 GHOST_TSuccess success = getButtons(buttons);
239 if (success) {
240 /* Isolate the state of the mouse button requested. */
241 is_down = buttons.get(mask);
242 }
243 return success;
244}
245
247{
249}
250
255
260
262{
263 return GHOST_kFailure;
264}
265
266#ifdef WITH_INPUT_NDOF
267void GHOST_System::setNDOFDeadZone(float deadzone)
268{
269 if (this->ndof_manager_) {
270 this->ndof_manager_->setDeadZone(deadzone);
271 }
272}
273#endif
274
276{
280
281#ifdef WITH_GHOST_DEBUG
282 if (event_manager_) {
283 event_printer_ = new GHOST_EventPrinter();
284 event_manager_->addConsumer(event_printer_);
285 }
286#endif /* WITH_GHOST_DEBUG */
287
289 return GHOST_kSuccess;
290 }
291 return GHOST_kFailure;
292}
293
295{
298
299 delete window_manager_;
300 window_manager_ = nullptr;
301
302 delete timer_manager_;
303 timer_manager_ = nullptr;
304
305 delete event_manager_;
306 event_manager_ = nullptr;
307
308#ifdef WITH_INPUT_NDOF
309 delete ndof_manager_;
310 ndof_manager_ = nullptr;
311#endif
312
313 return GHOST_kSuccess;
314}
315
317{
318 native_pixel_ = true;
319 return true;
320}
321
322void GHOST_System::useWindowFocus(const bool use_focus)
323{
324 window_focus_ = use_focus;
325}
326
327void GHOST_System::setAutoFocus(const bool auto_focus)
328{
329 auto_focus_ = auto_focus;
330}
331
336
unsigned int uint
@ GHOST_kWindowStateMinimized
void * GHOST_TUserDataPtr
Definition GHOST_Types.h:55
@ GHOST_kDebugDefault
void(* GHOST_TimerProcPtr)(struct GHOST_TimerTaskHandle__ *task, uint64_t time)
GHOST_TModifierKey
GHOST_TSuccess
Definition GHOST_Types.h:57
@ GHOST_kFailure
Definition GHOST_Types.h:57
@ GHOST_kSuccess
Definition GHOST_Types.h:57
GHOST_TButton
GHOST_TTabletAPI
@ GHOST_kTabletAutomatic
return true
unsigned long long int uint64_t
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition btDbvt.cpp:299
virtual GHOST_TSuccess getCursorPosition(int32_t &x, int32_t &y) const =0
virtual uint64_t getMilliSeconds() const =0
virtual GHOST_TSuccess setCursorPosition(int32_t x, int32_t y)=0
virtual void getClientBounds(GHOST_Rect &bounds) const =0
virtual void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const =0
virtual void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const =0
virtual GHOST_TWindowState getState() const =0
GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer *consumer) override
GHOST_TSuccess getPixelAtCursor(float r_color[3]) const override
GHOST_TSuccess removeTimer(GHOST_ITimerTask *timerTask) override
virtual GHOST_TSuccess getButtons(GHOST_Buttons &buttons) const =0
GHOST_TSuccess getButtonState(GHOST_TButton mask, bool &is_down) const override
void setMultitouchGestures(const bool use) override
uint * getClipboardImage(int *r_width, int *r_height) const override
GHOST_TTabletAPI getTabletAPI()
~GHOST_System() override
GHOST_TSuccess getCursorPositionClientRelative(const GHOST_IWindow *window, int32_t &x, int32_t &y) const override
GHOST_TimerManager * timer_manager_
GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer *consumer) override
GHOST_ITimerTask * installTimer(uint64_t delay, uint64_t interval, GHOST_TimerProcPtr timer_proc, GHOST_TUserDataPtr user_data=nullptr) override
GHOST_WindowManager * window_manager_
uint32_t getCursorPreferredLogicalSize() const override
GHOST_TSuccess pushEvent(const GHOST_IEvent *event)
GHOST_TSuccess init() override
GHOST_TTabletAPI tablet_api_
GHOST_TSuccess getModifierKeyState(GHOST_TModifierKey mask, bool &is_down) const override
GHOST_TSuccess disposeWindow(GHOST_IWindow *window) override
void initDebug(GHOST_Debug debug) override
bool validWindow(GHOST_IWindow *window) override
void useWindowFocus(const bool use_focus) override
GHOST_TSuccess hasClipboardImage() const override
void setTabletAPI(GHOST_TTabletAPI api) override
bool useNativePixel() override
bool multitouch_gestures_
GHOST_IWindow * getWindowUnderCursor(int32_t x, int32_t y) override
virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys &keys) const =0
GHOST_TSuccess exit() override
GHOST_TSuccess putClipboardImage(uint *rgba, int width, int height) const override
GHOST_EventManager * event_manager_
void dispatchEvents() override
bool isDebugEnabled() override
GHOST_TSuccess setCursorPositionClientRelative(GHOST_IWindow *window, int32_t x, int32_t y) override
void setAutoFocus(const bool auto_focus) override
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
bool get(GHOST_TButton mask) const
bool get(GHOST_TModifierKey mask) const
wmTimer * timer