Blender V4.3
GHOST_WindowSDL.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "GHOST_WindowSDL.hh"
10#include "SDL_mouse.h"
11
12#include "GHOST_ContextSDL.hh"
13
14#include <cassert>
15
17 const char *title,
18 int32_t left,
19 int32_t top,
20 uint32_t width,
21 uint32_t height,
24 const bool stereoVisual,
25 const bool exclusive,
26 const GHOST_IWindow * /*parentWindow*/)
27 : GHOST_Window(width, height, state, stereoVisual, exclusive),
28 m_system(system),
29 m_valid_setup(false),
30 m_invalid_window(false),
31 m_sdl_custom_cursor(nullptr)
32{
33
34 /* creating the window _must_ come after setting attributes */
35 m_sdl_win = SDL_CreateWindow(title,
36 left,
37 top,
38 width,
39 height,
40 SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
41
42 /* now set up the rendering context. */
44 m_valid_setup = true;
45 GHOST_PRINT("Created window\n");
46 }
47
48 if (exclusive) {
49 SDL_RaiseWindow(m_sdl_win);
50 }
51
52 setTitle(title);
53}
54
56{
57 if (m_sdl_custom_cursor) {
58 SDL_FreeCursor(m_sdl_custom_cursor);
59 }
60
62
63 SDL_DestroyWindow(m_sdl_win);
64}
65
67{
68 switch (type) {
69#ifdef WITH_OPENGL_BACKEND
70 case GHOST_kDrawingContextTypeOpenGL: {
71 for (int minor = 6; minor >= 3; --minor) {
72 GHOST_Context *context = new GHOST_ContextSDL(
74 m_sdl_win,
75 0, /* Profile bit. */
76 4,
77 minor,
80
81 if (context->initializeDrawingContext()) {
82 return context;
83 }
84 delete context;
85 }
86 return nullptr;
87 }
88#endif
89
90 default:
91 /* Unsupported backend. */
92 return nullptr;
93 }
94}
95
97{
98 if (m_invalid_window == false) {
99 m_system->addDirtyWindow(this);
100 m_invalid_window = true;
101 }
102
103 return GHOST_kSuccess;
104}
105
107{
108 switch (state) {
110 SDL_SetWindowFullscreen(m_sdl_win, SDL_FALSE);
111 SDL_RestoreWindow(m_sdl_win);
112 break;
114 SDL_SetWindowFullscreen(m_sdl_win, SDL_FALSE);
115 SDL_MaximizeWindow(m_sdl_win);
116 break;
118 SDL_MinimizeWindow(m_sdl_win);
119 break;
121 SDL_SetWindowFullscreen(m_sdl_win, SDL_TRUE);
122 break;
123 default:
124 break;
125 }
126
127 return GHOST_kSuccess;
128}
129
131{
132 Uint32 flags = SDL_GetWindowFlags(m_sdl_win);
133
134 if (flags & SDL_WINDOW_FULLSCREEN) {
136 }
137 if (flags & SDL_WINDOW_MAXIMIZED) {
139 }
140 if (flags & SDL_WINDOW_MINIMIZED) {
142 }
144}
145
147{
148 return GHOST_Window::getValid() && m_valid_setup;
149}
150
151void GHOST_WindowSDL::setTitle(const char *title)
152{
153 SDL_SetWindowTitle(m_sdl_win, title);
154}
155
156std::string GHOST_WindowSDL::getTitle() const
157{
158 return SDL_GetWindowTitle(m_sdl_win);
159}
160
165
167{
168 int x, y, w, h;
169 SDL_GetWindowSize(m_sdl_win, &w, &h);
170 SDL_GetWindowPosition(m_sdl_win, &x, &y);
171
172 bounds.m_l = x;
173 bounds.m_r = x + w;
174 bounds.m_t = y;
175 bounds.m_b = y + h;
176}
177
179{
180 int height;
181 SDL_GetWindowSize(m_sdl_win, nullptr, &height);
182 SDL_SetWindowSize(m_sdl_win, width, height);
183 return GHOST_kSuccess;
184}
185
187{
188 int width;
189 SDL_GetWindowSize(m_sdl_win, &width, nullptr);
190 SDL_SetWindowSize(m_sdl_win, width, height);
191 return GHOST_kSuccess;
192}
193
195{
196 SDL_SetWindowSize(m_sdl_win, width, height);
197 return GHOST_kSuccess;
198}
199
201{
202 /* XXXSDL_WEAK_ABS_COORDS */
203 int x_win, y_win;
204 SDL_GetWindowPosition(m_sdl_win, &x_win, &y_win);
205
206 outX = inX - x_win;
207 outY = inY - y_win;
208}
210{
211 /* XXXSDL_WEAK_ABS_COORDS */
212 int x_win, y_win;
213 SDL_GetWindowPosition(m_sdl_win, &x_win, &y_win);
214
215 outX = inX + x_win;
216 outY = inY + y_win;
217}
218
219/* mouse cursor */
221 0xef, 0x01, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
222 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xef, 0x01,
223};
225 0x00, 0x77, 0x00, 0x1c, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08,
226 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x1c, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
227};
228#define sdl_std_cursor_WIDTH_xterm 9
229#define sdl_std_cursor_HEIGHT_xterm 16
230#define sdl_std_cursor_HOT_X_xterm -3
231#define sdl_std_cursor_HOT_Y_xterm -7
232
234 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
235 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0x1f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
236};
238 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0xfc, 0x0f, 0x86, 0x18, 0x83, 0x30, 0x81, 0xe0, 0xc1, 0xe1,
239 0xc1, 0xe1, 0x21, 0xe0, 0x13, 0x30, 0x06, 0x18, 0xfc, 0x0f, 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07,
240};
241#define sdl_std_cursor_WIDTH_watch 16
242#define sdl_std_cursor_HEIGHT_watch 16
243#define sdl_std_cursor_HOT_X_watch -15
244#define sdl_std_cursor_HOT_Y_watch -7
245
247 0xe8, 0x76, 0xfb, 0xdf, 0xfd, 0x3f, 0xfe, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xcf, 0x79, 0xc0, 0x01,
248 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0x80, 0x03,
249};
251 0x88, 0x04, 0x20, 0x0a, 0xc9, 0x32, 0xf2, 0x09, 0x4c, 0x06, 0x43, 0x18, 0x40, 0x00, 0x40, 0x00,
252 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x01, 0x40, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
253};
254#define sdl_std_cursor_WIDTH_umbrella 16
255#define sdl_std_cursor_HEIGHT_umbrella 16
256#define sdl_std_cursor_HOT_X_umbrella -7
257#define sdl_std_cursor_HOT_Y_umbrella -12
258
260 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f,
261 0xdc, 0x1d, 0xcc, 0x19, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
262};
264 0xff, 0x1f, 0xff, 0x1f, 0x00, 0x00, 0x40, 0x00, 0xe0, 0x00, 0x50, 0x01, 0x48, 0x02, 0x44, 0x04,
265 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
266};
267#define sdl_std_cursor_WIDTH_top_side 15
268#define sdl_std_cursor_HEIGHT_top_side 16
269#define sdl_std_cursor_HOT_X_top_side -6
270#define sdl_std_cursor_HOT_Y_top_side -14
271
273 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf0, 0xfc, 0xf7, 0xfc, 0xf7, 0xfc, 0xf7,
274 0xc0, 0xf7, 0xe0, 0xf7, 0x70, 0xf7, 0x38, 0xf7, 0x1c, 0xf7, 0x0c, 0xf7, 0x00, 0xf0, 0x00, 0xf0,
275};
277 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xfc, 0x31, 0x80, 0x31, 0x40, 0x31,
278 0x20, 0x31, 0x10, 0x31, 0x08, 0x31, 0x04, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
279};
280#define sdl_std_cursor_WIDTH_top_right_corner 16
281#define sdl_std_cursor_HEIGHT_top_right_corner 16
282#define sdl_std_cursor_HOT_X_top_right_corner -13
283#define sdl_std_cursor_HOT_Y_top_right_corner -14
284
286 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xef, 0x3f, 0xef, 0x3f, 0xef, 0x3f,
287 0xef, 0x03, 0xef, 0x07, 0xef, 0x0e, 0xef, 0x1c, 0xef, 0x38, 0xef, 0x30, 0x0f, 0x00, 0x0f, 0x00,
288};
290 0xff, 0x3f, 0xff, 0x3f, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xe3, 0x0f, 0x63, 0x00, 0xa3, 0x00,
291 0x23, 0x01, 0x23, 0x02, 0x23, 0x04, 0x23, 0x08, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
292};
293#define sdl_std_cursor_WIDTH_top_left_corner 16
294#define sdl_std_cursor_HEIGHT_top_left_corner 16
295#define sdl_std_cursor_HOT_X_top_left_corner 0
296#define sdl_std_cursor_HOT_Y_top_left_corner -14
297
299 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x7c, 0x00, 0x7c,
300 0x00, 0x7c, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00,
301};
303 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28,
304 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00,
305};
306#define sdl_std_cursor_WIDTH_sb_v_double_arrow 9
307#define sdl_std_cursor_HEIGHT_sb_v_double_arrow 15
308#define sdl_std_cursor_HOT_X_sb_v_double_arrow -3
309#define sdl_std_cursor_HOT_Y_sb_v_double_arrow -8
310
312 0x18,
313 0x0c,
314 0x1c,
315 0x1c,
316 0xfe,
317 0x3f,
318 0xff,
319 0x7f,
320 0xff,
321 0x7f,
322 0xff,
323 0x7f,
324 0xfe,
325 0x3f,
326 0x1c,
327 0x1c,
328 0x18,
329 0x0c,
330};
332 0x00,
333 0x00,
334 0x08,
335 0x08,
336 0x0c,
337 0x18,
338 0xfe,
339 0x3f,
340 0x0f,
341 0x78,
342 0xfe,
343 0x3f,
344 0x0c,
345 0x18,
346 0x08,
347 0x08,
348 0x00,
349 0x00,
350};
351#define sdl_std_cursor_WIDTH_sb_h_double_arrow 15
352#define sdl_std_cursor_HEIGHT_sb_h_double_arrow 9
353#define sdl_std_cursor_HOT_X_sb_h_double_arrow -7
354#define sdl_std_cursor_HOT_Y_sb_h_double_arrow -4
355
357 0x00, 0xf0, 0x00, 0xf0, 0xc0, 0xf0, 0xc0, 0xf1, 0x80, 0xf3, 0x00, 0xf7, 0xff, 0xff, 0xff,
358 0xff, 0xff, 0xff, 0x00, 0xf7, 0x80, 0xf3, 0xc0, 0xf1, 0xc0, 0xf0, 0x00, 0xf0, 0x00, 0xf0,
359};
361 0x00, 0x30, 0x00, 0x30, 0x40, 0x30, 0x80, 0x30, 0x00, 0x31, 0x00, 0x32, 0xff, 0x37, 0x00,
362 0x32, 0x00, 0x31, 0x80, 0x30, 0x40, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
363};
364#define sdl_std_cursor_WIDTH_right_side 16
365#define sdl_std_cursor_HEIGHT_right_side 15
366#define sdl_std_cursor_HOT_X_right_side -13
367#define sdl_std_cursor_HOT_Y_right_side -7
368
370 0x00, 0x03, 0x80, 0x03, 0xc0, 0x03, 0xe0, 0x03, 0xf0, 0x03, 0xf8, 0x03, 0xfc, 0x03, 0xfe, 0x03,
371 0xff, 0x03, 0xff, 0x03, 0xf8, 0x03, 0xbc, 0x03, 0x3c, 0x03, 0x1e, 0x00, 0x1e, 0x00, 0x0c, 0x00,
372};
374 0x00, 0x80, 0x00, 0xc0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf8, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0xff,
375 0x00, 0xf8, 0x00, 0xd8, 0x00, 0x8c, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
376};
377#define sdl_std_cursor_WIDTH_right_ptr 10
378#define sdl_std_cursor_HEIGHT_right_ptr 16
379#define sdl_std_cursor_HOT_X_right_ptr -7
380#define sdl_std_cursor_HOT_Y_right_ptr -14
381
383 0xf8, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xff, 0x07, 0x8f, 0x07, 0x9f, 0x07, 0xde, 0x07, 0xfc, 0x03,
384 0xf8, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xfc, 0x01, 0xf8, 0x00, 0x70, 0x00,
385};
387 0x7c, 0x00, 0xfe, 0x00, 0xc7, 0x01, 0x83, 0x01, 0x87, 0x01, 0xc6, 0x01, 0xe0, 0x00, 0x78, 0x00,
388 0x38, 0x00, 0x28, 0x00, 0x28, 0x00, 0xee, 0x00, 0x6c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00,
389};
390#define sdl_std_cursor_WIDTH_question_arrow 11
391#define sdl_std_cursor_HEIGHT_question_arrow 16
392#define sdl_std_cursor_HOT_X_question_arrow -4
393#define sdl_std_cursor_HOT_Y_question_arrow -8
394
396 0xf0, 0x03, 0xf8, 0x07, 0xfc, 0x0f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfc, 0x0f, 0xf8, 0x07, 0xf1, 0x83,
397 0xf1, 0xe3, 0xf3, 0xf3, 0xef, 0x39, 0x1e, 0x1e, 0xe0, 0x01, 0xfe, 0xc7, 0xff, 0xff, 0x0f, 0x7c,
398};
400 0xe0, 0x01, 0xf0, 0x03, 0xf8, 0x07, 0xcc, 0x0c, 0xcc, 0x0c, 0xf8, 0x07, 0xf0, 0x03, 0xe0, 0x01,
401 0xe1, 0x21, 0xe1, 0x61, 0xc2, 0x10, 0x1c, 0x0e, 0xe0, 0x01, 0xf8, 0x47, 0x0f, 0x7c, 0x01, 0x20,
402};
403#define sdl_std_cursor_WIDTH_pirate 16
404#define sdl_std_cursor_HEIGHT_pirate 16
405#define sdl_std_cursor_HOT_X_pirate -7
406#define sdl_std_cursor_HOT_Y_pirate -4
407
409 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x03, 0x8f, 0x03, 0xcf, 0x01, 0xef, 0x00, 0xff, 0xff, 0xff,
410 0xff, 0xff, 0xff, 0xef, 0x00, 0xcf, 0x01, 0x8f, 0x03, 0x0f, 0x03, 0x0f, 0x00, 0x0f, 0x00,
411};
413 0x03, 0x00, 0x03, 0x00, 0x83, 0x00, 0x43, 0x00, 0x23, 0x00, 0x13, 0x00, 0xfb, 0x3f, 0x13,
414 0x00, 0x23, 0x00, 0x43, 0x00, 0x83, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
415};
416#define sdl_std_cursor_WIDTH_left_side 16
417#define sdl_std_cursor_HEIGHT_left_side 15
418#define sdl_std_cursor_HOT_X_left_side 0
419#define sdl_std_cursor_HOT_Y_left_side -7
420
422 0x03, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x00, 0xff, 0x01,
423 0xff, 0x03, 0xff, 0x03, 0x7f, 0x00, 0xf7, 0x00, 0xf3, 0x00, 0xe0, 0x01, 0xe0, 0x01, 0xc0, 0x00,
424};
426 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x1e, 0x00, 0x3e, 0x00, 0x7e, 0x00, 0xfe, 0x00,
427 0xfe, 0x00, 0x3e, 0x00, 0x36, 0x00, 0x62, 0x00, 0x60, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00,
428};
429#define sdl_std_cursor_WIDTH_left_ptr 10
430#define sdl_std_cursor_HEIGHT_left_ptr 16
431#define sdl_std_cursor_HOT_X_left_ptr -8
432#define sdl_std_cursor_HOT_Y_left_ptr -14
433
435 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xff,
436 0xff, 0xff, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
437};
439 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x7f, 0xff,
440 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00,
441};
442#define sdl_std_cursor_WIDTH_crosshair 16
443#define sdl_std_cursor_HEIGHT_crosshair 16
444#define sdl_std_cursor_HOT_X_crosshair -7
445#define sdl_std_cursor_HOT_Y_crosshair -8
446
448 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xcc, 0x19, 0xdc, 0x1d,
449 0xf8, 0x0f, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f,
450};
452 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x44, 0x04, 0x48, 0x02,
453 0x50, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
454};
455#define sdl_std_cursor_WIDTH_bottom_side 15
456#define sdl_std_cursor_HEIGHT_bottom_side 16
457#define sdl_std_cursor_HOT_X_bottom_side -6
458#define sdl_std_cursor_HOT_Y_bottom_side -1
459
461 0x00, 0xf0, 0x00, 0xf0, 0x0c, 0xf7, 0x1c, 0xf7, 0x38, 0xf7, 0x70, 0xf7, 0xe0, 0xf7, 0xc0, 0xf7,
462 0xfc, 0xf7, 0xfc, 0xf7, 0xfc, 0xf7, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
463};
465 0x00, 0x30, 0x00, 0x30, 0x04, 0x31, 0x08, 0x31, 0x10, 0x31, 0x20, 0x31, 0x40, 0x31, 0x80, 0x31,
466 0xfc, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
467};
468#define sdl_std_cursor_WIDTH_bottom_right_corner 16
469#define sdl_std_cursor_HEIGHT_bottom_right_corner 16
470#define sdl_std_cursor_HOT_X_bottom_right_corner -13
471#define sdl_std_cursor_HOT_Y_bottom_right_corner -1
472
474 0x0f, 0x00, 0x0f, 0x00, 0xef, 0x30, 0xef, 0x38, 0xef, 0x1c, 0xef, 0x0e, 0xef, 0x07, 0xef, 0x03,
475 0xef, 0x3f, 0xef, 0x3f, 0xef, 0x3f, 0x0f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
476};
478 0x03, 0x00, 0x03, 0x00, 0x23, 0x08, 0x23, 0x04, 0x23, 0x02, 0x23, 0x01, 0xa3, 0x00, 0x63, 0x00,
479 0xe3, 0x0f, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
480};
481#define sdl_std_cursor_WIDTH_bottom_left_corner 16
482#define sdl_std_cursor_HEIGHT_bottom_left_corner 16
483#define sdl_std_cursor_HOT_X_bottom_left_corner 0
484#define sdl_std_cursor_HOT_Y_bottom_left_corner -1
485
487 0x00, 0xe0, 0x00, 0xf8, 0x00, 0xfe, 0x80, 0x7f, 0xe0, 0x7f, 0xf8, 0x3f, 0xfc, 0x3f, 0xfc, 0x1f,
488 0xe0, 0x1f, 0xf0, 0x0f, 0xf8, 0x0f, 0x7c, 0x07, 0x3e, 0x07, 0x1f, 0x02, 0x0e, 0x00, 0x04, 0x00,
489};
491 0x00, 0x30, 0x00, 0x3c, 0x00, 0x1f, 0xc0, 0x1f, 0xf0, 0x0f, 0xfc, 0x0f, 0xc0, 0x07, 0xe0, 0x07,
492 0x70, 0x03, 0x38, 0x03, 0x1c, 0x01, 0x0e, 0x01, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
493};
494#define sdl_std_cursor_WIDTH_arrow 16
495#define sdl_std_cursor_HEIGHT_arrow 16
496#define sdl_std_cursor_HOT_X_arrow -13
497#define sdl_std_cursor_HOT_Y_arrow -14
498/* end cursor data */
499
501
502/* utility function mostly a copy of SDL_CreateCursor but allows us to change
503 * color and supports blenders flipped bits */
504static SDL_Cursor *sdl_ghost_CreateCursor(
505 const Uint8 *data, const Uint8 *mask, int w, int h, int hot_x, int hot_y)
506{
507 SDL_Surface *surface;
508 SDL_Cursor *cursor;
509 int x, y;
510 Uint32 *pixel;
511 Uint8 datab = 0, maskb = 0;
512 const Uint32 black = 0xFF000000;
513 const Uint32 white = 0xFFFFFFFF;
514 const Uint32 transparent = 0x00000000;
515
516 /* Make sure the width is a multiple of 8 */
517 w = ((w + 7) & ~7);
518
519 /* Create the surface from a bitmap */
520 surface = SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
521 if (!surface) {
522 return nullptr;
523 }
524 for (y = 0; y < h; ++y) {
525 pixel = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch);
526 for (x = 0; x < w; ++x) {
527 if ((x % 8) == 0) {
528 datab = *data++;
529 maskb = *mask++;
530
531 /* reverse bit order */
532 datab = (datab * 0x0202020202ULL & 0x010884422010ULL) % 1023;
533 maskb = (maskb * 0x0202020202ULL & 0x010884422010ULL) % 1023;
534 }
535 if (maskb & 0x80) {
536 *pixel++ = (datab & 0x80) ? white : black;
537 }
538 else {
539 *pixel++ = (datab & 0x80) ? white : transparent;
540 }
541 datab <<= 1;
542 maskb <<= 1;
543 }
544 }
545
546 cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
547
548 SDL_FreeSurface(surface);
549
550 return cursor;
551}
552
553/* TODO: this is currently never freed but it won't leak either. */
555{
556 if (sdl_std_cursor_array[0] == nullptr) {
557#define DEF_CURSOR(name, ind) \
558 { \
559 sdl_std_cursor_array[int(ind)] = sdl_ghost_CreateCursor( \
560 sdl_std_cursor_##name, \
561 sdl_std_cursor_mask_##name, \
562 sdl_std_cursor_WIDTH_##name, \
563 sdl_std_cursor_HEIGHT_##name, \
564 (sdl_std_cursor_WIDTH_##name + (sdl_std_cursor_HOT_X_##name)) - 1, \
565 (sdl_std_cursor_HEIGHT_##name + (sdl_std_cursor_HOT_Y_##name)) - 1); \
566 assert(sdl_std_cursor_array[int(ind)] != nullptr); \
567 } \
568 (void)0
569
573 DEF_CURSOR(umbrella, GHOST_kStandardCursorInfo); /* TODO: replace this one. */
575 DEF_CURSOR(question_arrow, GHOST_kStandardCursorHelp);
579 DEF_CURSOR(sb_v_double_arrow, GHOST_kStandardCursorUpDown);
580 DEF_CURSOR(sb_h_double_arrow, GHOST_kStandardCursorLeftRight);
590 // DEF_CURSOR(arrow, GHOST_kStandardCursorCustom);
592#undef DEF_CURSOR
593 }
594
595 return sdl_std_cursor_array[int(shape)];
596}
597
602
604{
605 SDL_Cursor *cursor = getStandardCursorShape(shape);
606 if (cursor == nullptr) {
608 }
609
610 SDL_SetCursor(cursor);
611 return GHOST_kSuccess;
612}
613
618
620 uint8_t *mask,
621 int sizex,
622 int sizey,
623 int hotX,
624 int hotY,
625 bool /*canInvertColor*/)
626{
627 if (m_sdl_custom_cursor) {
628 SDL_FreeCursor(m_sdl_custom_cursor);
629 }
630
631 m_sdl_custom_cursor = sdl_ghost_CreateCursor(
632 (const Uint8 *)bitmap, (const Uint8 *)mask, sizex, sizey, hotX, hotY);
633
634 SDL_SetCursor(m_sdl_custom_cursor);
635 return GHOST_kSuccess;
636}
637
639{
640 SDL_ShowCursor(visible);
641 return GHOST_kSuccess;
642}
643
645{
646 int displayIndex = SDL_GetWindowDisplayIndex(m_sdl_win);
647 if (displayIndex < 0) {
648 return 96;
649 }
650
651 float ddpi;
652 if (SDL_GetDisplayDPI(displayIndex, &ddpi, nullptr, nullptr) != 0) {
653 return 96;
654 }
655
656 return int(ddpi);
657}
unsigned char uchar
#define GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY
#define GHOST_OPENGL_SDL_CONTEXT_FLAGS
#define GHOST_PRINT(x)
GHOST_TWindowState
@ GHOST_kWindowStateMinimized
@ GHOST_kWindowStateMaximized
@ GHOST_kWindowStateNormal
@ GHOST_kWindowStateFullScreen
GHOST_TStandardCursor
@ GHOST_kStandardCursorBottomLeftCorner
@ GHOST_kStandardCursorHelp
@ GHOST_kStandardCursorCopy
@ GHOST_kStandardCursorWait
@ GHOST_kStandardCursorTopSide
@ GHOST_kStandardCursorCrosshair
@ GHOST_kStandardCursorLeftRight
@ GHOST_kStandardCursorPencil
@ GHOST_kStandardCursorUpDown
@ GHOST_kStandardCursorBottomSide
@ GHOST_kStandardCursorInfo
@ GHOST_kStandardCursorTopLeftCorner
@ GHOST_kStandardCursorBottomRightCorner
@ GHOST_kStandardCursorDefault
@ GHOST_kStandardCursorRightSide
@ GHOST_kStandardCursorRightArrow
@ GHOST_kStandardCursorTopRightCorner
@ GHOST_kStandardCursorDestroy
@ GHOST_kStandardCursorLeftSide
@ GHOST_kStandardCursorText
@ GHOST_kStandardCursorLeftArrow
#define GHOST_kStandardCursorNumCursors
GHOST_TDrawingContextType
GHOST_TSuccess
Definition GHOST_Types.h:87
@ GHOST_kFailure
Definition GHOST_Types.h:87
@ GHOST_kSuccess
Definition GHOST_Types.h:87
GHOST_TGrabCursorMode
static uchar sdl_std_cursor_mask_right_ptr[]
static uchar sdl_std_cursor_xterm[]
static SDL_Cursor * sdl_ghost_CreateCursor(const Uint8 *data, const Uint8 *mask, int w, int h, int hot_x, int hot_y)
static uchar sdl_std_cursor_bottom_side[]
static uchar sdl_std_cursor_left_side[]
static uchar sdl_std_cursor_mask_left_side[]
static uchar sdl_std_cursor_arrow[]
static uchar sdl_std_cursor_top_side[]
static uchar sdl_std_cursor_question_arrow[]
static uchar sdl_std_cursor_right_side[]
static uchar sdl_std_cursor_mask_crosshair[]
static uchar sdl_std_cursor_mask_top_right_corner[]
static uchar sdl_std_cursor_mask_bottom_side[]
static uchar sdl_std_cursor_mask_watch[]
static uchar sdl_std_cursor_mask_right_side[]
static SDL_Cursor * sdl_std_cursor_array[int(GHOST_kStandardCursorNumCursors)]
static uchar sdl_std_cursor_top_right_corner[]
static uchar sdl_std_cursor_mask_top_left_corner[]
static SDL_Cursor * getStandardCursorShape(GHOST_TStandardCursor shape)
static uchar sdl_std_cursor_mask_top_side[]
static uchar sdl_std_cursor_mask_left_ptr[]
static uchar sdl_std_cursor_mask_arrow[]
static uchar sdl_std_cursor_mask_bottom_left_corner[]
static uchar sdl_std_cursor_top_left_corner[]
static uchar sdl_std_cursor_umbrella[]
static uchar sdl_std_cursor_sb_v_double_arrow[]
static uchar sdl_std_cursor_left_ptr[]
static uchar sdl_std_cursor_mask_pirate[]
static uchar sdl_std_cursor_bottom_right_corner[]
static uchar sdl_std_cursor_watch[]
static uchar sdl_std_cursor_mask_umbrella[]
static uchar sdl_std_cursor_crosshair[]
static uchar sdl_std_cursor_sb_h_double_arrow[]
static uchar sdl_std_cursor_mask_sb_v_double_arrow[]
static uchar sdl_std_cursor_bottom_left_corner[]
static uchar sdl_std_cursor_mask_xterm[]
static uchar sdl_std_cursor_mask_question_arrow[]
static uchar sdl_std_cursor_mask_bottom_right_corner[]
static uchar sdl_std_cursor_mask_sb_h_double_arrow[]
#define DEF_CURSOR(name, ind)
static uchar sdl_std_cursor_pirate[]
static uchar sdl_std_cursor_right_ptr[]
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
Definition btDbvt.cpp:299
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
void addDirtyWindow(GHOST_WindowSDL *bad_wind)
GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode) override
std::string getTitle() const override
GHOST_TWindowState getState() const override
void clientToScreen(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
GHOST_TSuccess invalidate() override
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape) override
GHOST_TSuccess setClientHeight(uint32_t height) override
GHOST_Context * newDrawingContext(GHOST_TDrawingContextType type) override
GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor) override
void getClientBounds(GHOST_Rect &bounds) const override
GHOST_TSuccess setWindowCursorVisibility(bool visible) override
GHOST_TSuccess setClientWidth(uint32_t width) override
GHOST_WindowSDL(GHOST_SystemSDL *system, const char *title, int32_t left, int32_t top, uint32_t width, uint32_t height, GHOST_TWindowState state, GHOST_TDrawingContextType type=GHOST_kDrawingContextTypeNone, const bool stereoVisual=false, const bool exclusive=false, const GHOST_IWindow *parentWindow=nullptr)
GHOST_TSuccess setState(GHOST_TWindowState state) override
GHOST_TSuccess setClientSize(uint32_t width, uint32_t height) override
void getWindowBounds(GHOST_Rect &bounds) const override
uint16_t getDPIHint() override
bool getValid() const override
void setTitle(const char *title) override
GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor shape) override
void screenToClient(int32_t inX, int32_t inY, int32_t &outX, int32_t &outY) const override
bool m_wantStereoVisual
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) override
GHOST_TSuccess releaseNativeHandles()
virtual bool getValid() const override
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
static ulong state[N]
unsigned short uint16_t
Definition stdint.h:79
unsigned int uint32_t
Definition stdint.h:80
signed int int32_t
Definition stdint.h:77
unsigned char uint8_t
Definition stdint.h:78