Blender V5.3
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
21 : native_pixel_(false),
22 window_focus_(true),
23 auto_focus_(true),
24 window_csd_params_({nullptr}),
25 window_csd_layout_({0}),
26 timer_manager_(nullptr),
27 window_manager_(nullptr),
28 event_manager_(nullptr),
29#ifdef WITH_INPUT_NDOF
30 ndof_manager_(nullptr),
31#endif
32 multitouch_gestures_(true),
33 tablet_api_(GHOST_kTabletAutomatic),
34 is_debug_enabled_(false)
35{
36}
37
42
47
48uint *GHOST_System::getClipboardImage(int * /*r_width*/, int * /*r_height*/) const
49{
50 return nullptr;
51}
52
54 int /*width*/,
55 int /*height*/) const
56{
57 return GHOST_kFailure;
58}
59
61{
62 window_csd_params_ = params;
63}
64
69
78
80{
81 icon_generator_ = icon_generator;
82}
83
85 uint64_t interval,
86 GHOST_TimerProcPtr timer_proc,
87 GHOST_TUserDataPtr user_data)
88{
89 uint64_t millis = getMilliSeconds();
90 GHOST_TimerTask *timer = new GHOST_TimerTask(millis + delay, interval, timer_proc, user_data);
91 if (timer) {
92 if (timer_manager_->addTimer(timer) == GHOST_kSuccess) {
93 /* Check to see whether we need to fire the timer right away. */
95 }
96 else {
97 delete timer;
98 timer = nullptr;
99 }
100 }
101 return timer;
102}
103
105{
107 if (timerTask) {
108 success = timer_manager_->removeTimer((GHOST_TimerTask *)timerTask);
109 }
110 return success;
111}
112
114{
115 GHOST_TSuccess success;
116
117 /*
118 * Remove all pending events for the window.
119 */
120 if (window_manager_->getWindowFound(window)) {
122 success = window_manager_->removeWindow(window);
123 if (success) {
124 delete window;
125 }
126 }
127 else {
128 success = GHOST_kFailure;
129 }
130 return success;
131}
132
134{
135 return window_manager_->getWindowFound(window);
136}
137
139{
140 /* TODO: This solution should follow the order of the activated windows (Z-order).
141 * It is imperfect but usable in most cases. Ideally each platform should provide
142 * a custom version of this function that properly considers z-order. */
143
144 std::vector<GHOST_IWindow *> windows = window_manager_->getWindows();
145 std::vector<GHOST_IWindow *>::reverse_iterator iwindow_iter;
146
147 /* Search through the windows in reverse order because in most cases
148 * the window that is on top was created after those that are below it. */
149
150 for (iwindow_iter = windows.rbegin(); iwindow_iter != windows.rend(); ++iwindow_iter) {
151
152 GHOST_IWindow *win = *iwindow_iter;
153
155 continue;
156 }
157
158 GHOST_Rect bounds;
159 win->getClientBounds(bounds);
160 if (bounds.isInside(x, y)) {
161 return win;
162 }
163 }
164
165 return nullptr;
166}
167
169{
170#ifdef WITH_INPUT_NDOF
171 /* NDOF Motion event is sent only once per dispatch, so do it now: */
172 if (ndof_manager_) {
173 ndof_manager_->sendMotionEvent();
174 }
175#endif
176
177 if (event_manager_) {
179 }
180
182}
183
185{
186 GHOST_TSuccess success;
187 if (event_manager_) {
188 success = event_manager_->addConsumer(consumer);
189 }
190 else {
191 success = GHOST_kFailure;
192 }
193 return success;
194}
195
197{
198 GHOST_TSuccess success;
199 if (event_manager_) {
200 success = event_manager_->removeConsumer(consumer);
201 }
202 else {
203 success = GHOST_kFailure;
204 }
205 return success;
206}
207
208GHOST_TSuccess GHOST_System::pushEvent(std::unique_ptr<const GHOST_IEvent> event)
209{
210 GHOST_TSuccess success;
211 if (event_manager_) {
212 success = event_manager_->pushEvent(std::move(event));
213 }
214 else {
215 success = GHOST_kFailure;
216 }
217 return success;
218}
219
221 int32_t &x,
222 int32_t &y) const
223{
224 /* Sub-classes that can implement this directly should do so. */
225 int32_t screen_x, screen_y;
226 GHOST_TSuccess success = getCursorPosition(screen_x, screen_y);
227 if (success == GHOST_kSuccess) {
228 window->screenToClient(screen_x, screen_y, x, y);
229 }
230 return success;
231}
232
234 int32_t x,
235 int32_t y)
236{
237 /* Sub-classes that can implement this directly should do so. */
238 int32_t screen_x, screen_y;
239 window->clientToScreen(x, y, screen_x, screen_y);
240 return setCursorPosition(screen_x, screen_y);
241}
242
244{
245 return uint32_t(24);
246}
247
249{
250 is_down = false;
251
253 /* Get the state of all modifier keys. */
254 GHOST_TSuccess success = getModifierKeys(keys);
255 if (success) {
256 /* Isolate the state of the key requested. */
257 is_down = keys.get(mask);
258 }
259 return success;
260}
261
263{
264 is_down = false;
265
266 GHOST_Buttons buttons;
267 /* Get the state of all mouse buttons. */
268 GHOST_TSuccess success = getButtons(buttons);
269 if (success) {
270 /* Isolate the state of the mouse button requested. */
271 is_down = buttons.get(mask);
272 }
273 return success;
274}
275
277{
279}
280
285
290
292{
293 return GHOST_kFailure;
294}
295
296#ifdef WITH_INPUT_NDOF
297void GHOST_System::setNDOFDeadZone(float deadzone)
298{
299 if (this->ndof_manager_) {
300 this->ndof_manager_->setDeadZone(deadzone);
301 }
302}
303#endif
304
306{
310
311#ifdef WITH_GHOST_DEBUG
312 if (event_manager_) {
313 event_printer_ = new GHOST_EventPrinter();
314 event_manager_->addConsumer(event_printer_);
315 }
316#endif /* WITH_GHOST_DEBUG */
317
319 return GHOST_kSuccess;
320 }
321 return GHOST_kFailure;
322}
323
325{
328
329 delete window_manager_;
330 window_manager_ = nullptr;
331
332 delete timer_manager_;
333 timer_manager_ = nullptr;
334
335 delete event_manager_;
336 event_manager_ = nullptr;
337
338#ifdef WITH_INPUT_NDOF
339 delete ndof_manager_;
340 ndof_manager_ = nullptr;
341#endif
342
343 return GHOST_kSuccess;
344}
345
347{
348 native_pixel_ = true;
349 return true;
350}
351
352void GHOST_System::useWindowFocus(const bool use_focus)
353{
354 window_focus_ = use_focus;
355}
356
357void GHOST_System::setAutoFocus(const bool auto_focus)
358{
359 auto_focus_ = auto_focus;
360}
361
366
void * GHOST_TUserDataPtr
@ GHOST_kWindowStateMinimized
@ GHOST_kDebugDefault
GHOST_TModifierKey
GHOST_TSuccess
@ GHOST_kFailure
@ GHOST_kSuccess
GHOST_TButton
void(*)(GHOST_ITimerTask *task, uint64_t time) GHOST_TimerProcPtr
GHOST_TTabletAPI
@ GHOST_kTabletAutomatic
unsigned long long int uint64_t
GHOST_TSuccess addConsumer(GHOST_IEventConsumer *consumer)
GHOST_TSuccess removeConsumer(GHOST_IEventConsumer *consumer)
GHOST_TSuccess pushEvent(std::unique_ptr< const GHOST_IEvent > event)
void removeWindowEvents(const GHOST_IWindow *window)
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
virtual bool isInside(int32_t x, int32_t y) const
GHOST_TSuccess removeEventConsumer(GHOST_IEventConsumer *consumer) override
GHOST_TSuccess getPixelAtCursor(float r_color[3]) const override
void setWindowCSD(const GHOST_CSD_Params &params) 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
void setIconGenerator(const GHOST_IconGenerator *icon_generator) 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
const GHOST_CSD_Params & getWindowCSD() const
GHOST_WindowManager * window_manager_
uint32_t getCursorPreferredLogicalSize() const override
GHOST_TSuccess init() override
GHOST_TTabletAPI tablet_api_
GHOST_TSuccess getModifierKeyState(GHOST_TModifierKey mask, bool &is_down) const override
const GHOST_CSD_Layout & getWindowCSD_Layout() 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
GHOST_TSuccess pushEvent(std::unique_ptr< const GHOST_IEvent > event)
bool useNativePixel() override
GHOST_CSD_Layout window_csd_layout_
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
const GHOST_IconGenerator * icon_generator_
GHOST_CSD_Params window_csd_params_
bool isDebugEnabled() override
GHOST_TSuccess setCursorPositionClientRelative(GHOST_IWindow *window, int32_t x, int32_t y) override
void setWindowCSD_Layout(const GHOST_CSD_Layout &csd_layout)
void setAutoFocus(const bool auto_focus) override
bool fireTimers(uint64_t time)
GHOST_TSuccess removeTimer(GHOST_TimerTask *timer)
GHOST_TSuccess addTimer(GHOST_TimerTask *timer)
GHOST_TimerTask(uint64_t start, uint64_t interval, GHOST_TimerProcPtr timer_proc, GHOST_TUserDataPtr user_data=nullptr)
GHOST_TSuccess removeWindow(const GHOST_IWindow *window)
const std::vector< GHOST_IWindow * > & getWindows() const
bool getWindowFound(const GHOST_IWindow *window) const
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
bool get(GHOST_TButton mask) const
bool get(GHOST_TModifierKey mask) const