Blender V5.0
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
8
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,
20 uint32_t width,
21 uint32_t height,
24 const GHOST_ContextParams &context_params,
25 const bool exclusive,
26 const GHOST_IWindow * /*parent_window*/)
27 : GHOST_Window(width, height, state, context_params, exclusive),
28 system_(system),
29 valid_setup_(false),
30 invalid_window_(false),
31 sdl_custom_cursor_(nullptr)
32{
33
34 /* creating the window _must_ come after setting attributes */
35 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 valid_setup_ = true;
45 GHOST_PRINT("Created window\n");
46 }
47
48 if (exclusive) {
49 SDL_RaiseWindow(sdl_win_);
50 }
51
52 setTitle(title);
53}
54
56{
57 if (sdl_custom_cursor_) {
58 SDL_FreeCursor(sdl_custom_cursor_);
59 }
60
62
63 SDL_DestroyWindow(sdl_win_);
64}
65
67{
68
69 switch (type) {
70#ifdef WITH_OPENGL_BACKEND
71 case GHOST_kDrawingContextTypeOpenGL: {
72 for (int minor = 6; minor >= 3; --minor) {
73 GHOST_Context *context = new GHOST_ContextSDL(
75 sdl_win_,
76 0, /* Profile bit. */
77 4,
78 minor,
81
82 if (context->initializeDrawingContext()) {
83 return context;
84 }
85 delete context;
86 }
87 return nullptr;
88 }
89#endif
90
91 default:
92 /* Unsupported backend. */
93 return nullptr;
94 }
95}
96
98{
99 if (invalid_window_ == false) {
100 system_->addDirtyWindow(this);
101 invalid_window_ = true;
102 }
103
104 return GHOST_kSuccess;
105}
106
108{
109 switch (state) {
111 SDL_SetWindowFullscreen(sdl_win_, SDL_FALSE);
112 SDL_RestoreWindow(sdl_win_);
113 break;
115 SDL_SetWindowFullscreen(sdl_win_, SDL_FALSE);
116 SDL_MaximizeWindow(sdl_win_);
117 break;
119 SDL_MinimizeWindow(sdl_win_);
120 break;
122 SDL_SetWindowFullscreen(sdl_win_, SDL_TRUE);
123 break;
124 default:
125 break;
126 }
127
128 return GHOST_kSuccess;
129}
130
132{
133 Uint32 flags = SDL_GetWindowFlags(sdl_win_);
134
135 if (flags & SDL_WINDOW_FULLSCREEN) {
137 }
138 if (flags & SDL_WINDOW_MAXIMIZED) {
140 }
141 if (flags & SDL_WINDOW_MINIMIZED) {
143 }
145}
146
148{
149 return GHOST_Window::getValid() && valid_setup_;
150}
151
152void GHOST_WindowSDL::setTitle(const char *title)
153{
154 SDL_SetWindowTitle(sdl_win_, title);
155}
156
157std::string GHOST_WindowSDL::getTitle() const
158{
159 return SDL_GetWindowTitle(sdl_win_);
160}
161
166
168{
169 int x, y, w, h;
170 SDL_GetWindowSize(sdl_win_, &w, &h);
171 SDL_GetWindowPosition(sdl_win_, &x, &y);
172
173 bounds.l_ = x;
174 bounds.r_ = x + w;
175 bounds.t_ = y;
176 bounds.b_ = y + h;
177}
178
180{
181 int height;
182 SDL_GetWindowSize(sdl_win_, nullptr, &height);
183 SDL_SetWindowSize(sdl_win_, width, height);
184 return GHOST_kSuccess;
185}
186
188{
189 int width;
190 SDL_GetWindowSize(sdl_win_, &width, nullptr);
191 SDL_SetWindowSize(sdl_win_, width, height);
192 return GHOST_kSuccess;
193}
194
195GHOST_TSuccess GHOST_WindowSDL::setClientSize(uint32_t width, uint32_t height)
196{
197 SDL_SetWindowSize(sdl_win_, width, height);
198 return GHOST_kSuccess;
199}
200
202{
203 /* XXXSDL_WEAK_ABS_COORDS */
204 int x_win, y_win;
205 SDL_GetWindowPosition(sdl_win_, &x_win, &y_win);
206
207 outX = inX - x_win;
208 outY = inY - y_win;
209}
211{
212 /* XXXSDL_WEAK_ABS_COORDS */
213 int x_win, y_win;
214 SDL_GetWindowPosition(sdl_win_, &x_win, &y_win);
215
216 outX = inX + x_win;
217 outY = inY + y_win;
218}
219
220/* mouse cursor */
222 0xef, 0x01, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
223 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xef, 0x01,
224};
226 0x00, 0x77, 0x00, 0x1c, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08,
227 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x1c, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
228};
229#define sdl_std_cursor_WIDTH_xterm 9
230#define sdl_std_cursor_HEIGHT_xterm 16
231#define sdl_std_cursor_HOT_X_xterm -3
232#define sdl_std_cursor_HOT_Y_xterm -7
233
235 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
236 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0x1f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
237};
239 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0xfc, 0x0f, 0x86, 0x18, 0x83, 0x30, 0x81, 0xe0, 0xc1, 0xe1,
240 0xc1, 0xe1, 0x21, 0xe0, 0x13, 0x30, 0x06, 0x18, 0xfc, 0x0f, 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07,
241};
242#define sdl_std_cursor_WIDTH_watch 16
243#define sdl_std_cursor_HEIGHT_watch 16
244#define sdl_std_cursor_HOT_X_watch -15
245#define sdl_std_cursor_HOT_Y_watch -7
246
248 0xe8, 0x76, 0xfb, 0xdf, 0xfd, 0x3f, 0xfe, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xcf, 0x79, 0xc0, 0x01,
249 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0x80, 0x03,
250};
252 0x88, 0x04, 0x20, 0x0a, 0xc9, 0x32, 0xf2, 0x09, 0x4c, 0x06, 0x43, 0x18, 0x40, 0x00, 0x40, 0x00,
253 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x01, 0x40, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
254};
255#define sdl_std_cursor_WIDTH_umbrella 16
256#define sdl_std_cursor_HEIGHT_umbrella 16
257#define sdl_std_cursor_HOT_X_umbrella -7
258#define sdl_std_cursor_HOT_Y_umbrella -12
259
261 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f,
262 0xdc, 0x1d, 0xcc, 0x19, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
263};
265 0xff, 0x1f, 0xff, 0x1f, 0x00, 0x00, 0x40, 0x00, 0xe0, 0x00, 0x50, 0x01, 0x48, 0x02, 0x44, 0x04,
266 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
267};
268#define sdl_std_cursor_WIDTH_top_side 15
269#define sdl_std_cursor_HEIGHT_top_side 16
270#define sdl_std_cursor_HOT_X_top_side -6
271#define sdl_std_cursor_HOT_Y_top_side -14
272
274 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf0, 0xfc, 0xf7, 0xfc, 0xf7, 0xfc, 0xf7,
275 0xc0, 0xf7, 0xe0, 0xf7, 0x70, 0xf7, 0x38, 0xf7, 0x1c, 0xf7, 0x0c, 0xf7, 0x00, 0xf0, 0x00, 0xf0,
276};
278 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xfc, 0x31, 0x80, 0x31, 0x40, 0x31,
279 0x20, 0x31, 0x10, 0x31, 0x08, 0x31, 0x04, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
280};
281#define sdl_std_cursor_WIDTH_top_right_corner 16
282#define sdl_std_cursor_HEIGHT_top_right_corner 16
283#define sdl_std_cursor_HOT_X_top_right_corner -13
284#define sdl_std_cursor_HOT_Y_top_right_corner -14
285
287 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xef, 0x3f, 0xef, 0x3f, 0xef, 0x3f,
288 0xef, 0x03, 0xef, 0x07, 0xef, 0x0e, 0xef, 0x1c, 0xef, 0x38, 0xef, 0x30, 0x0f, 0x00, 0x0f, 0x00,
289};
291 0xff, 0x3f, 0xff, 0x3f, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xe3, 0x0f, 0x63, 0x00, 0xa3, 0x00,
292 0x23, 0x01, 0x23, 0x02, 0x23, 0x04, 0x23, 0x08, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
293};
294#define sdl_std_cursor_WIDTH_top_left_corner 16
295#define sdl_std_cursor_HEIGHT_top_left_corner 16
296#define sdl_std_cursor_HOT_X_top_left_corner 0
297#define sdl_std_cursor_HOT_Y_top_left_corner -14
298
300 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x7c, 0x00, 0x7c,
301 0x00, 0x7c, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00,
302};
304 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28,
305 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00,
306};
307#define sdl_std_cursor_WIDTH_sb_v_double_arrow 9
308#define sdl_std_cursor_HEIGHT_sb_v_double_arrow 15
309#define sdl_std_cursor_HOT_X_sb_v_double_arrow -3
310#define sdl_std_cursor_HOT_Y_sb_v_double_arrow -8
311
313 0x18,
314 0x0c,
315 0x1c,
316 0x1c,
317 0xfe,
318 0x3f,
319 0xff,
320 0x7f,
321 0xff,
322 0x7f,
323 0xff,
324 0x7f,
325 0xfe,
326 0x3f,
327 0x1c,
328 0x1c,
329 0x18,
330 0x0c,
331};
333 0x00,
334 0x00,
335 0x08,
336 0x08,
337 0x0c,
338 0x18,
339 0xfe,
340 0x3f,
341 0x0f,
342 0x78,
343 0xfe,
344 0x3f,
345 0x0c,
346 0x18,
347 0x08,
348 0x08,
349 0x00,
350 0x00,
351};
352#define sdl_std_cursor_WIDTH_sb_h_double_arrow 15
353#define sdl_std_cursor_HEIGHT_sb_h_double_arrow 9
354#define sdl_std_cursor_HOT_X_sb_h_double_arrow -7
355#define sdl_std_cursor_HOT_Y_sb_h_double_arrow -4
356
358 0x00, 0xf0, 0x00, 0xf0, 0xc0, 0xf0, 0xc0, 0xf1, 0x80, 0xf3, 0x00, 0xf7, 0xff, 0xff, 0xff,
359 0xff, 0xff, 0xff, 0x00, 0xf7, 0x80, 0xf3, 0xc0, 0xf1, 0xc0, 0xf0, 0x00, 0xf0, 0x00, 0xf0,
360};
362 0x00, 0x30, 0x00, 0x30, 0x40, 0x30, 0x80, 0x30, 0x00, 0x31, 0x00, 0x32, 0xff, 0x37, 0x00,
363 0x32, 0x00, 0x31, 0x80, 0x30, 0x40, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
364};
365#define sdl_std_cursor_WIDTH_right_side 16
366#define sdl_std_cursor_HEIGHT_right_side 15
367#define sdl_std_cursor_HOT_X_right_side -13
368#define sdl_std_cursor_HOT_Y_right_side -7
369
371 0x00, 0x03, 0x80, 0x03, 0xc0, 0x03, 0xe0, 0x03, 0xf0, 0x03, 0xf8, 0x03, 0xfc, 0x03, 0xfe, 0x03,
372 0xff, 0x03, 0xff, 0x03, 0xf8, 0x03, 0xbc, 0x03, 0x3c, 0x03, 0x1e, 0x00, 0x1e, 0x00, 0x0c, 0x00,
373};
375 0x00, 0x80, 0x00, 0xc0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf8, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0xff,
376 0x00, 0xf8, 0x00, 0xd8, 0x00, 0x8c, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
377};
378#define sdl_std_cursor_WIDTH_right_ptr 10
379#define sdl_std_cursor_HEIGHT_right_ptr 16
380#define sdl_std_cursor_HOT_X_right_ptr -7
381#define sdl_std_cursor_HOT_Y_right_ptr -14
382
384 0xf8, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xff, 0x07, 0x8f, 0x07, 0x9f, 0x07, 0xde, 0x07, 0xfc, 0x03,
385 0xf8, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xfc, 0x01, 0xf8, 0x00, 0x70, 0x00,
386};
388 0x7c, 0x00, 0xfe, 0x00, 0xc7, 0x01, 0x83, 0x01, 0x87, 0x01, 0xc6, 0x01, 0xe0, 0x00, 0x78, 0x00,
389 0x38, 0x00, 0x28, 0x00, 0x28, 0x00, 0xee, 0x00, 0x6c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00,
390};
391#define sdl_std_cursor_WIDTH_question_arrow 11
392#define sdl_std_cursor_HEIGHT_question_arrow 16
393#define sdl_std_cursor_HOT_X_question_arrow -4
394#define sdl_std_cursor_HOT_Y_question_arrow -8
395
397 0xf0, 0x03, 0xf8, 0x07, 0xfc, 0x0f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfc, 0x0f, 0xf8, 0x07, 0xf1, 0x83,
398 0xf1, 0xe3, 0xf3, 0xf3, 0xef, 0x39, 0x1e, 0x1e, 0xe0, 0x01, 0xfe, 0xc7, 0xff, 0xff, 0x0f, 0x7c,
399};
401 0xe0, 0x01, 0xf0, 0x03, 0xf8, 0x07, 0xcc, 0x0c, 0xcc, 0x0c, 0xf8, 0x07, 0xf0, 0x03, 0xe0, 0x01,
402 0xe1, 0x21, 0xe1, 0x61, 0xc2, 0x10, 0x1c, 0x0e, 0xe0, 0x01, 0xf8, 0x47, 0x0f, 0x7c, 0x01, 0x20,
403};
404#define sdl_std_cursor_WIDTH_pirate 16
405#define sdl_std_cursor_HEIGHT_pirate 16
406#define sdl_std_cursor_HOT_X_pirate -7
407#define sdl_std_cursor_HOT_Y_pirate -4
408
410 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x03, 0x8f, 0x03, 0xcf, 0x01, 0xef, 0x00, 0xff, 0xff, 0xff,
411 0xff, 0xff, 0xff, 0xef, 0x00, 0xcf, 0x01, 0x8f, 0x03, 0x0f, 0x03, 0x0f, 0x00, 0x0f, 0x00,
412};
414 0x03, 0x00, 0x03, 0x00, 0x83, 0x00, 0x43, 0x00, 0x23, 0x00, 0x13, 0x00, 0xfb, 0x3f, 0x13,
415 0x00, 0x23, 0x00, 0x43, 0x00, 0x83, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
416};
417#define sdl_std_cursor_WIDTH_left_side 16
418#define sdl_std_cursor_HEIGHT_left_side 15
419#define sdl_std_cursor_HOT_X_left_side 0
420#define sdl_std_cursor_HOT_Y_left_side -7
421
423 0x03, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x00, 0xff, 0x01,
424 0xff, 0x03, 0xff, 0x03, 0x7f, 0x00, 0xf7, 0x00, 0xf3, 0x00, 0xe0, 0x01, 0xe0, 0x01, 0xc0, 0x00,
425};
427 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x1e, 0x00, 0x3e, 0x00, 0x7e, 0x00, 0xfe, 0x00,
428 0xfe, 0x00, 0x3e, 0x00, 0x36, 0x00, 0x62, 0x00, 0x60, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00,
429};
430#define sdl_std_cursor_WIDTH_left_ptr 10
431#define sdl_std_cursor_HEIGHT_left_ptr 16
432#define sdl_std_cursor_HOT_X_left_ptr -8
433#define sdl_std_cursor_HOT_Y_left_ptr -14
434
436 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xff,
437 0xff, 0xff, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
438};
440 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x7f, 0xff,
441 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00,
442};
443#define sdl_std_cursor_WIDTH_crosshair 16
444#define sdl_std_cursor_HEIGHT_crosshair 16
445#define sdl_std_cursor_HOT_X_crosshair -7
446#define sdl_std_cursor_HOT_Y_crosshair -8
447
449 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xcc, 0x19, 0xdc, 0x1d,
450 0xf8, 0x0f, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f,
451};
453 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x44, 0x04, 0x48, 0x02,
454 0x50, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
455};
456#define sdl_std_cursor_WIDTH_bottom_side 15
457#define sdl_std_cursor_HEIGHT_bottom_side 16
458#define sdl_std_cursor_HOT_X_bottom_side -6
459#define sdl_std_cursor_HOT_Y_bottom_side -1
460
462 0x00, 0xf0, 0x00, 0xf0, 0x0c, 0xf7, 0x1c, 0xf7, 0x38, 0xf7, 0x70, 0xf7, 0xe0, 0xf7, 0xc0, 0xf7,
463 0xfc, 0xf7, 0xfc, 0xf7, 0xfc, 0xf7, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
464};
466 0x00, 0x30, 0x00, 0x30, 0x04, 0x31, 0x08, 0x31, 0x10, 0x31, 0x20, 0x31, 0x40, 0x31, 0x80, 0x31,
467 0xfc, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
468};
469#define sdl_std_cursor_WIDTH_bottom_right_corner 16
470#define sdl_std_cursor_HEIGHT_bottom_right_corner 16
471#define sdl_std_cursor_HOT_X_bottom_right_corner -13
472#define sdl_std_cursor_HOT_Y_bottom_right_corner -1
473
475 0x0f, 0x00, 0x0f, 0x00, 0xef, 0x30, 0xef, 0x38, 0xef, 0x1c, 0xef, 0x0e, 0xef, 0x07, 0xef, 0x03,
476 0xef, 0x3f, 0xef, 0x3f, 0xef, 0x3f, 0x0f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
477};
479 0x03, 0x00, 0x03, 0x00, 0x23, 0x08, 0x23, 0x04, 0x23, 0x02, 0x23, 0x01, 0xa3, 0x00, 0x63, 0x00,
480 0xe3, 0x0f, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
481};
482#define sdl_std_cursor_WIDTH_bottom_left_corner 16
483#define sdl_std_cursor_HEIGHT_bottom_left_corner 16
484#define sdl_std_cursor_HOT_X_bottom_left_corner 0
485#define sdl_std_cursor_HOT_Y_bottom_left_corner -1
486
488 0x00, 0xe0, 0x00, 0xf8, 0x00, 0xfe, 0x80, 0x7f, 0xe0, 0x7f, 0xf8, 0x3f, 0xfc, 0x3f, 0xfc, 0x1f,
489 0xe0, 0x1f, 0xf0, 0x0f, 0xf8, 0x0f, 0x7c, 0x07, 0x3e, 0x07, 0x1f, 0x02, 0x0e, 0x00, 0x04, 0x00,
490};
492 0x00, 0x30, 0x00, 0x3c, 0x00, 0x1f, 0xc0, 0x1f, 0xf0, 0x0f, 0xfc, 0x0f, 0xc0, 0x07, 0xe0, 0x07,
493 0x70, 0x03, 0x38, 0x03, 0x1c, 0x01, 0x0e, 0x01, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
494};
495#define sdl_std_cursor_WIDTH_arrow 16
496#define sdl_std_cursor_HEIGHT_arrow 16
497#define sdl_std_cursor_HOT_X_arrow -13
498#define sdl_std_cursor_HOT_Y_arrow -14
499/* end cursor data */
500
501static SDL_Cursor *sdl_std_cursor_array[int(GHOST_kStandardCursorNumCursors)] = {nullptr};
502
503/* utility function mostly a copy of SDL_CreateCursor but allows us to change
504 * color and supports blenders flipped bits */
505static SDL_Cursor *sdl_ghost_CreateCursor(
506 const uint8_t *data, const uint8_t *mask, int w, int h, int hot_x, int hot_y)
507{
508 SDL_Surface *surface;
509 SDL_Cursor *cursor;
510 int x, y;
511 Uint32 *pixel;
512 Uint8 datab = 0, maskb = 0;
513 const Uint32 black = 0xFF000000;
514 const Uint32 white = 0xFFFFFFFF;
515 const Uint32 transparent = 0x00000000;
516
517 /* Make sure the width is a multiple of 8 */
518 w = ((w + 7) & ~7);
519
520 /* Create the surface from a bitmap */
521 surface = SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
522 if (!surface) {
523 return nullptr;
524 }
525 for (y = 0; y < h; ++y) {
526 pixel = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch);
527 for (x = 0; x < w; ++x) {
528 if ((x % 8) == 0) {
529 datab = *data++;
530 maskb = *mask++;
531
532 /* reverse bit order */
533 datab = (datab * 0x0202020202ULL & 0x010884422010ULL) % 1023;
534 maskb = (maskb * 0x0202020202ULL & 0x010884422010ULL) % 1023;
535 }
536 if (maskb & 0x80) {
537 *pixel++ = (datab & 0x80) ? white : black;
538 }
539 else {
540 *pixel++ = (datab & 0x80) ? white : transparent;
541 }
542 datab <<= 1;
543 maskb <<= 1;
544 }
545 }
546
547 cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
548
549 SDL_FreeSurface(surface);
550
551 return cursor;
552}
553
554/* TODO: this is currently never freed but it won't leak either. */
556{
557 if (sdl_std_cursor_array[0] == nullptr) {
558#define DEF_CURSOR(name, ind) \
559 { \
560 sdl_std_cursor_array[int(ind)] = sdl_ghost_CreateCursor( \
561 sdl_std_cursor_##name, \
562 sdl_std_cursor_mask_##name, \
563 sdl_std_cursor_WIDTH_##name, \
564 sdl_std_cursor_HEIGHT_##name, \
565 (sdl_std_cursor_WIDTH_##name + (sdl_std_cursor_HOT_X_##name)) - 1, \
566 (sdl_std_cursor_HEIGHT_##name + (sdl_std_cursor_HOT_Y_##name)) - 1); \
567 assert(sdl_std_cursor_array[int(ind)] != nullptr); \
568 } \
569 (void)0
570
574 DEF_CURSOR(umbrella, GHOST_kStandardCursorInfo); /* TODO: replace this one. */
576 DEF_CURSOR(question_arrow, GHOST_kStandardCursorHelp);
580 DEF_CURSOR(sb_v_double_arrow, GHOST_kStandardCursorUpDown);
581 DEF_CURSOR(sb_h_double_arrow, GHOST_kStandardCursorLeftRight);
591 // DEF_CURSOR(arrow, GHOST_kStandardCursorCustom);
593#undef DEF_CURSOR
594 }
595
596 return sdl_std_cursor_array[int(shape)];
597}
598
603
605{
606 SDL_Cursor *cursor = getStandardCursorShape(shape);
607 if (cursor == nullptr) {
609 }
610
611 SDL_SetCursor(cursor);
612 return GHOST_kSuccess;
613}
614
619
621 const uint8_t *mask,
622 const int size[2],
623 const int hot_spot[2],
624 bool /*can_invert_color*/)
625{
626 if (sdl_custom_cursor_) {
627 SDL_FreeCursor(sdl_custom_cursor_);
628 }
629
630 sdl_custom_cursor_ = sdl_ghost_CreateCursor(
631 bitmap, mask, size[0], size[1], hot_spot[0], hot_spot[1]);
632
633 SDL_SetCursor(sdl_custom_cursor_);
634 return GHOST_kSuccess;
635}
636
638{
639 SDL_ShowCursor(visible);
640 return GHOST_kSuccess;
641}
642
644{
645 int displayIndex = SDL_GetWindowDisplayIndex(sdl_win_);
646 if (displayIndex < 0) {
647 return 96;
648 }
649
650 float ddpi;
651 if (SDL_GetDisplayDPI(displayIndex, &ddpi, nullptr, nullptr) != 0) {
652 return 96;
653 }
654
655 return int(ddpi);
656}
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:57
@ GHOST_kFailure
Definition GHOST_Types.h:57
@ GHOST_kSuccess
Definition GHOST_Types.h:57
GHOST_TGrabCursorMode
static uchar sdl_std_cursor_mask_right_ptr[]
static uchar sdl_std_cursor_xterm[]
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 SDL_Cursor * sdl_ghost_CreateCursor(const uint8_t *data, const uint8_t *mask, int w, int h, int hot_x, int hot_y)
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[]
BMesh const char void * data
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
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
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_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, const GHOST_ContextParams &context_params, const bool exclusive=false, const GHOST_IWindow *parent_window=nullptr)
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape) override
GHOST_TSuccess setClientHeight(uint32_t height) override
GHOST_Context * newDrawingContext(GHOST_TDrawingContextType type) override
void getClientBounds(GHOST_Rect &bounds) const override
GHOST_TSuccess setWindowCursorVisibility(bool visible) override
GHOST_TSuccess setClientWidth(uint32_t width) override
GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap, const uint8_t *mask, const int size[2], const int hot_spot[2], bool can_invert_color) override
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
GHOST_ContextParams want_context_params_
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type) override
GHOST_TSuccess releaseNativeHandles()
bool getValid() const override
GHOST_Window(uint32_t width, uint32_t height, GHOST_TWindowState state, const GHOST_ContextParams &context_params, const bool exclusive=false)
uint top
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
static ulong state[N]
static int left