Blender V5.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
8
9#include "GHOST_WindowSDL.hh"
10
11#ifdef WITH_OPENGL_BACKEND
12# include "GHOST_ContextSDL.hh"
13#endif
14#ifdef WITH_VULKAN_BACKEND
15# include "GHOST_ContextVK.hh"
16#endif
17
18#include <cassert>
19
21 const char *title,
22 int32_t left,
23 int32_t top,
24 uint32_t width,
25 uint32_t height,
28 const GHOST_ContextParams &context_params,
29 const GHOST_GPUDevice &preferred_device,
30 const bool exclusive,
31 const GHOST_IWindow * /*parent_window*/)
32 : GHOST_Window(width, height, state, context_params, exclusive),
33 system_(system),
34 valid_setup_(false),
35 invalid_window_(false),
36 sdl_custom_cursor_(nullptr),
37 preferred_device_(preferred_device)
38{
39 SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE;
40 switch (type) {
41#ifdef WITH_OPENGL_BACKEND
42 case GHOST_kDrawingContextTypeOpenGL:
43 window_flags |= SDL_WINDOW_OPENGL;
44 break;
45#endif
46#ifdef WITH_VULKAN_BACKEND
47 case GHOST_kDrawingContextTypeVulkan:
48 window_flags |= SDL_WINDOW_VULKAN;
49 break;
50#endif
51 default:
52 break;
53 }
54
55 /* creating the window _must_ come after setting attributes */
56 sdl_win_ = SDL_CreateWindow(title, width, height, window_flags);
57 if (sdl_win_) {
58 SDL_SetWindowPosition(sdl_win_, left, top);
59 }
60
61 /* now set up the rendering context. */
63 valid_setup_ = true;
64 GHOST_PRINT("Created window\n");
65 }
66
67 if (exclusive) {
68 SDL_RaiseWindow(sdl_win_);
69 }
70
71 setTitle(title);
72}
73
75{
76 if (sdl_custom_cursor_) {
77 SDL_DestroyCursor(sdl_custom_cursor_);
78 }
79
81
82 SDL_DestroyWindow(sdl_win_);
83}
84
86{
87
88 switch (type) {
89#ifdef WITH_OPENGL_BACKEND
90 case GHOST_kDrawingContextTypeOpenGL: {
91 for (int minor = 6; minor >= 3; --minor) {
92 GHOST_Context *context = new GHOST_ContextSDL(
94 sdl_win_,
95 0, /* Profile bit. */
96 4,
97 minor,
100
101 if (context->initializeDrawingContext()) {
102 return context;
103 }
104 delete context;
105 }
106 return nullptr;
107 }
108#endif
109
110#ifdef WITH_VULKAN_BACKEND
111 case GHOST_kDrawingContextTypeVulkan: {
112 GHOST_Context *context = new GHOST_ContextVK(
113 want_context_params_, sdl_win_, 1, 1, preferred_device_, &hdr_info_);
114 if (context->initializeDrawingContext()) {
115 return context;
116 }
117 delete context;
118 return nullptr;
119 }
120#endif
121
122 default:
123 /* Unsupported backend. */
124 return nullptr;
125 }
126}
127
129{
130 if (invalid_window_ == false) {
131 system_->addDirtyWindow(this);
132 invalid_window_ = true;
133 }
134
135 return GHOST_kSuccess;
136}
137
139{
140 switch (state) {
142 SDL_SetWindowFullscreen(sdl_win_, false);
143 SDL_RestoreWindow(sdl_win_);
144 break;
146 SDL_SetWindowFullscreen(sdl_win_, false);
147 SDL_MaximizeWindow(sdl_win_);
148 break;
150 SDL_MinimizeWindow(sdl_win_);
151 break;
153 SDL_SetWindowFullscreen(sdl_win_, true);
154 break;
155 default:
156 break;
157 }
158
159 return GHOST_kSuccess;
160}
161
163{
164 SDL_WindowFlags flags = SDL_GetWindowFlags(sdl_win_);
165
166 if (flags & SDL_WINDOW_FULLSCREEN) {
168 }
169 if (flags & SDL_WINDOW_MAXIMIZED) {
171 }
172 if (flags & SDL_WINDOW_MINIMIZED) {
174 }
176}
177
179{
180 return GHOST_Window::getValid() && valid_setup_;
181}
182
183void GHOST_WindowSDL::setTitle(const char *title)
184{
185 SDL_SetWindowTitle(sdl_win_, title);
186}
187
188std::string GHOST_WindowSDL::getTitle() const
189{
190 return SDL_GetWindowTitle(sdl_win_);
191}
192
194{
195 getClientBounds(bounds);
196}
197
199{
200 int x, y, w, h;
201 SDL_GetWindowSize(sdl_win_, &w, &h);
202 SDL_GetWindowPosition(sdl_win_, &x, &y);
203
204 bounds.l_ = x;
205 bounds.r_ = x + w;
206 bounds.t_ = y;
207 bounds.b_ = y + h;
208}
209
211{
212 int height;
213 SDL_GetWindowSize(sdl_win_, nullptr, &height);
214 SDL_SetWindowSize(sdl_win_, width, height);
215 return GHOST_kSuccess;
216}
217
219{
220 int width;
221 SDL_GetWindowSize(sdl_win_, &width, nullptr);
222 SDL_SetWindowSize(sdl_win_, width, height);
223 return GHOST_kSuccess;
224}
225
226GHOST_TSuccess GHOST_WindowSDL::setClientSize(uint32_t width, uint32_t height)
227{
228 SDL_SetWindowSize(sdl_win_, width, height);
229 return GHOST_kSuccess;
230}
231
233{
234 /* XXXSDL_WEAK_ABS_COORDS */
235 int x_win, y_win;
236 SDL_GetWindowPosition(sdl_win_, &x_win, &y_win);
237
238 outX = inX - x_win;
239 outY = inY - y_win;
240}
242{
243 /* XXXSDL_WEAK_ABS_COORDS */
244 int x_win, y_win;
245 SDL_GetWindowPosition(sdl_win_, &x_win, &y_win);
246
247 outX = inX + x_win;
248 outY = inY + y_win;
249}
250
251/* mouse cursor */
253 0xef, 0x01, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
254 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xef, 0x01,
255};
257 0x00, 0x77, 0x00, 0x1c, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08,
258 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x1c, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
259};
260#define sdl_std_cursor_WIDTH_xterm 9
261#define sdl_std_cursor_HEIGHT_xterm 16
262#define sdl_std_cursor_HOT_X_xterm -3
263#define sdl_std_cursor_HOT_Y_xterm -7
264
266 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
267 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0x1f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
268};
270 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0xfc, 0x0f, 0x86, 0x18, 0x83, 0x30, 0x81, 0xe0, 0xc1, 0xe1,
271 0xc1, 0xe1, 0x21, 0xe0, 0x13, 0x30, 0x06, 0x18, 0xfc, 0x0f, 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07,
272};
273#define sdl_std_cursor_WIDTH_watch 16
274#define sdl_std_cursor_HEIGHT_watch 16
275#define sdl_std_cursor_HOT_X_watch -15
276#define sdl_std_cursor_HOT_Y_watch -7
277
279 0xe8, 0x76, 0xfb, 0xdf, 0xfd, 0x3f, 0xfe, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xcf, 0x79, 0xc0, 0x01,
280 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0x80, 0x03,
281};
283 0x88, 0x04, 0x20, 0x0a, 0xc9, 0x32, 0xf2, 0x09, 0x4c, 0x06, 0x43, 0x18, 0x40, 0x00, 0x40, 0x00,
284 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x01, 0x40, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
285};
286#define sdl_std_cursor_WIDTH_umbrella 16
287#define sdl_std_cursor_HEIGHT_umbrella 16
288#define sdl_std_cursor_HOT_X_umbrella -7
289#define sdl_std_cursor_HOT_Y_umbrella -12
290
292 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f,
293 0xdc, 0x1d, 0xcc, 0x19, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
294};
296 0xff, 0x1f, 0xff, 0x1f, 0x00, 0x00, 0x40, 0x00, 0xe0, 0x00, 0x50, 0x01, 0x48, 0x02, 0x44, 0x04,
297 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
298};
299#define sdl_std_cursor_WIDTH_top_side 15
300#define sdl_std_cursor_HEIGHT_top_side 16
301#define sdl_std_cursor_HOT_X_top_side -6
302#define sdl_std_cursor_HOT_Y_top_side -14
303
305 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf0, 0xfc, 0xf7, 0xfc, 0xf7, 0xfc, 0xf7,
306 0xc0, 0xf7, 0xe0, 0xf7, 0x70, 0xf7, 0x38, 0xf7, 0x1c, 0xf7, 0x0c, 0xf7, 0x00, 0xf0, 0x00, 0xf0,
307};
309 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xfc, 0x31, 0x80, 0x31, 0x40, 0x31,
310 0x20, 0x31, 0x10, 0x31, 0x08, 0x31, 0x04, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
311};
312#define sdl_std_cursor_WIDTH_top_right_corner 16
313#define sdl_std_cursor_HEIGHT_top_right_corner 16
314#define sdl_std_cursor_HOT_X_top_right_corner -13
315#define sdl_std_cursor_HOT_Y_top_right_corner -14
316
318 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xef, 0x3f, 0xef, 0x3f, 0xef, 0x3f,
319 0xef, 0x03, 0xef, 0x07, 0xef, 0x0e, 0xef, 0x1c, 0xef, 0x38, 0xef, 0x30, 0x0f, 0x00, 0x0f, 0x00,
320};
322 0xff, 0x3f, 0xff, 0x3f, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xe3, 0x0f, 0x63, 0x00, 0xa3, 0x00,
323 0x23, 0x01, 0x23, 0x02, 0x23, 0x04, 0x23, 0x08, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
324};
325#define sdl_std_cursor_WIDTH_top_left_corner 16
326#define sdl_std_cursor_HEIGHT_top_left_corner 16
327#define sdl_std_cursor_HOT_X_top_left_corner 0
328#define sdl_std_cursor_HOT_Y_top_left_corner -14
329
331 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x7c, 0x00, 0x7c,
332 0x00, 0x7c, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00,
333};
335 0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28,
336 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00,
337};
338#define sdl_std_cursor_WIDTH_sb_v_double_arrow 9
339#define sdl_std_cursor_HEIGHT_sb_v_double_arrow 15
340#define sdl_std_cursor_HOT_X_sb_v_double_arrow -3
341#define sdl_std_cursor_HOT_Y_sb_v_double_arrow -8
342
344 0x18,
345 0x0c,
346 0x1c,
347 0x1c,
348 0xfe,
349 0x3f,
350 0xff,
351 0x7f,
352 0xff,
353 0x7f,
354 0xff,
355 0x7f,
356 0xfe,
357 0x3f,
358 0x1c,
359 0x1c,
360 0x18,
361 0x0c,
362};
364 0x00,
365 0x00,
366 0x08,
367 0x08,
368 0x0c,
369 0x18,
370 0xfe,
371 0x3f,
372 0x0f,
373 0x78,
374 0xfe,
375 0x3f,
376 0x0c,
377 0x18,
378 0x08,
379 0x08,
380 0x00,
381 0x00,
382};
383#define sdl_std_cursor_WIDTH_sb_h_double_arrow 15
384#define sdl_std_cursor_HEIGHT_sb_h_double_arrow 9
385#define sdl_std_cursor_HOT_X_sb_h_double_arrow -7
386#define sdl_std_cursor_HOT_Y_sb_h_double_arrow -4
387
389 0x00, 0xf0, 0x00, 0xf0, 0xc0, 0xf0, 0xc0, 0xf1, 0x80, 0xf3, 0x00, 0xf7, 0xff, 0xff, 0xff,
390 0xff, 0xff, 0xff, 0x00, 0xf7, 0x80, 0xf3, 0xc0, 0xf1, 0xc0, 0xf0, 0x00, 0xf0, 0x00, 0xf0,
391};
393 0x00, 0x30, 0x00, 0x30, 0x40, 0x30, 0x80, 0x30, 0x00, 0x31, 0x00, 0x32, 0xff, 0x37, 0x00,
394 0x32, 0x00, 0x31, 0x80, 0x30, 0x40, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
395};
396#define sdl_std_cursor_WIDTH_right_side 16
397#define sdl_std_cursor_HEIGHT_right_side 15
398#define sdl_std_cursor_HOT_X_right_side -13
399#define sdl_std_cursor_HOT_Y_right_side -7
400
402 0x00, 0x03, 0x80, 0x03, 0xc0, 0x03, 0xe0, 0x03, 0xf0, 0x03, 0xf8, 0x03, 0xfc, 0x03, 0xfe, 0x03,
403 0xff, 0x03, 0xff, 0x03, 0xf8, 0x03, 0xbc, 0x03, 0x3c, 0x03, 0x1e, 0x00, 0x1e, 0x00, 0x0c, 0x00,
404};
406 0x00, 0x80, 0x00, 0xc0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf8, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0xff,
407 0x00, 0xf8, 0x00, 0xd8, 0x00, 0x8c, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
408};
409#define sdl_std_cursor_WIDTH_right_ptr 10
410#define sdl_std_cursor_HEIGHT_right_ptr 16
411#define sdl_std_cursor_HOT_X_right_ptr -7
412#define sdl_std_cursor_HOT_Y_right_ptr -14
413
415 0xf8, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xff, 0x07, 0x8f, 0x07, 0x9f, 0x07, 0xde, 0x07, 0xfc, 0x03,
416 0xf8, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xfc, 0x01, 0xf8, 0x00, 0x70, 0x00,
417};
419 0x7c, 0x00, 0xfe, 0x00, 0xc7, 0x01, 0x83, 0x01, 0x87, 0x01, 0xc6, 0x01, 0xe0, 0x00, 0x78, 0x00,
420 0x38, 0x00, 0x28, 0x00, 0x28, 0x00, 0xee, 0x00, 0x6c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00,
421};
422#define sdl_std_cursor_WIDTH_question_arrow 11
423#define sdl_std_cursor_HEIGHT_question_arrow 16
424#define sdl_std_cursor_HOT_X_question_arrow -4
425#define sdl_std_cursor_HOT_Y_question_arrow -8
426
428 0xf0, 0x03, 0xf8, 0x07, 0xfc, 0x0f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfc, 0x0f, 0xf8, 0x07, 0xf1, 0x83,
429 0xf1, 0xe3, 0xf3, 0xf3, 0xef, 0x39, 0x1e, 0x1e, 0xe0, 0x01, 0xfe, 0xc7, 0xff, 0xff, 0x0f, 0x7c,
430};
432 0xe0, 0x01, 0xf0, 0x03, 0xf8, 0x07, 0xcc, 0x0c, 0xcc, 0x0c, 0xf8, 0x07, 0xf0, 0x03, 0xe0, 0x01,
433 0xe1, 0x21, 0xe1, 0x61, 0xc2, 0x10, 0x1c, 0x0e, 0xe0, 0x01, 0xf8, 0x47, 0x0f, 0x7c, 0x01, 0x20,
434};
435#define sdl_std_cursor_WIDTH_pirate 16
436#define sdl_std_cursor_HEIGHT_pirate 16
437#define sdl_std_cursor_HOT_X_pirate -7
438#define sdl_std_cursor_HOT_Y_pirate -4
439
441 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x03, 0x8f, 0x03, 0xcf, 0x01, 0xef, 0x00, 0xff, 0xff, 0xff,
442 0xff, 0xff, 0xff, 0xef, 0x00, 0xcf, 0x01, 0x8f, 0x03, 0x0f, 0x03, 0x0f, 0x00, 0x0f, 0x00,
443};
445 0x03, 0x00, 0x03, 0x00, 0x83, 0x00, 0x43, 0x00, 0x23, 0x00, 0x13, 0x00, 0xfb, 0x3f, 0x13,
446 0x00, 0x23, 0x00, 0x43, 0x00, 0x83, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
447};
448#define sdl_std_cursor_WIDTH_left_side 16
449#define sdl_std_cursor_HEIGHT_left_side 15
450#define sdl_std_cursor_HOT_X_left_side 0
451#define sdl_std_cursor_HOT_Y_left_side -7
452
454 0x03, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x00, 0xff, 0x01,
455 0xff, 0x03, 0xff, 0x03, 0x7f, 0x00, 0xf7, 0x00, 0xf3, 0x00, 0xe0, 0x01, 0xe0, 0x01, 0xc0, 0x00,
456};
458 0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x1e, 0x00, 0x3e, 0x00, 0x7e, 0x00, 0xfe, 0x00,
459 0xfe, 0x00, 0x3e, 0x00, 0x36, 0x00, 0x62, 0x00, 0x60, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00,
460};
461#define sdl_std_cursor_WIDTH_left_ptr 10
462#define sdl_std_cursor_HEIGHT_left_ptr 16
463#define sdl_std_cursor_HOT_X_left_ptr -8
464#define sdl_std_cursor_HOT_Y_left_ptr -14
465
467 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xff,
468 0xff, 0xff, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
469};
471 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x7f, 0xff,
472 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00,
473};
474#define sdl_std_cursor_WIDTH_crosshair 16
475#define sdl_std_cursor_HEIGHT_crosshair 16
476#define sdl_std_cursor_HOT_X_crosshair -7
477#define sdl_std_cursor_HOT_Y_crosshair -8
478
480 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xcc, 0x19, 0xdc, 0x1d,
481 0xf8, 0x0f, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f,
482};
484 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x44, 0x04, 0x48, 0x02,
485 0x50, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
486};
487#define sdl_std_cursor_WIDTH_bottom_side 15
488#define sdl_std_cursor_HEIGHT_bottom_side 16
489#define sdl_std_cursor_HOT_X_bottom_side -6
490#define sdl_std_cursor_HOT_Y_bottom_side -1
491
493 0x00, 0xf0, 0x00, 0xf0, 0x0c, 0xf7, 0x1c, 0xf7, 0x38, 0xf7, 0x70, 0xf7, 0xe0, 0xf7, 0xc0, 0xf7,
494 0xfc, 0xf7, 0xfc, 0xf7, 0xfc, 0xf7, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
495};
497 0x00, 0x30, 0x00, 0x30, 0x04, 0x31, 0x08, 0x31, 0x10, 0x31, 0x20, 0x31, 0x40, 0x31, 0x80, 0x31,
498 0xfc, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
499};
500#define sdl_std_cursor_WIDTH_bottom_right_corner 16
501#define sdl_std_cursor_HEIGHT_bottom_right_corner 16
502#define sdl_std_cursor_HOT_X_bottom_right_corner -13
503#define sdl_std_cursor_HOT_Y_bottom_right_corner -1
504
506 0x0f, 0x00, 0x0f, 0x00, 0xef, 0x30, 0xef, 0x38, 0xef, 0x1c, 0xef, 0x0e, 0xef, 0x07, 0xef, 0x03,
507 0xef, 0x3f, 0xef, 0x3f, 0xef, 0x3f, 0x0f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
508};
510 0x03, 0x00, 0x03, 0x00, 0x23, 0x08, 0x23, 0x04, 0x23, 0x02, 0x23, 0x01, 0xa3, 0x00, 0x63, 0x00,
511 0xe3, 0x0f, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
512};
513#define sdl_std_cursor_WIDTH_bottom_left_corner 16
514#define sdl_std_cursor_HEIGHT_bottom_left_corner 16
515#define sdl_std_cursor_HOT_X_bottom_left_corner 0
516#define sdl_std_cursor_HOT_Y_bottom_left_corner -1
517
519 0x00, 0xe0, 0x00, 0xf8, 0x00, 0xfe, 0x80, 0x7f, 0xe0, 0x7f, 0xf8, 0x3f, 0xfc, 0x3f, 0xfc, 0x1f,
520 0xe0, 0x1f, 0xf0, 0x0f, 0xf8, 0x0f, 0x7c, 0x07, 0x3e, 0x07, 0x1f, 0x02, 0x0e, 0x00, 0x04, 0x00,
521};
523 0x00, 0x30, 0x00, 0x3c, 0x00, 0x1f, 0xc0, 0x1f, 0xf0, 0x0f, 0xfc, 0x0f, 0xc0, 0x07, 0xe0, 0x07,
524 0x70, 0x03, 0x38, 0x03, 0x1c, 0x01, 0x0e, 0x01, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
525};
526#define sdl_std_cursor_WIDTH_arrow 16
527#define sdl_std_cursor_HEIGHT_arrow 16
528#define sdl_std_cursor_HOT_X_arrow -13
529#define sdl_std_cursor_HOT_Y_arrow -14
530/* end cursor data */
531
532static SDL_Cursor *sdl_std_cursor_array[int(GHOST_kStandardCursorNumCursors)] = {nullptr};
533
534/* utility function mostly a copy of SDL_CreateCursor but allows us to change
535 * color and supports blenders flipped bits */
536static SDL_Cursor *sdl_ghost_CreateCursor(
537 const uint8_t *data, const uint8_t *mask, int w, int h, int hot_x, int hot_y)
538{
539 SDL_Surface *surface;
540 SDL_Cursor *cursor;
541 int x, y;
542 Uint32 *pixel;
543 Uint8 datab = 0, maskb = 0;
544 const Uint32 black = 0xFF000000;
545 const Uint32 white = 0xFFFFFFFF;
546 const Uint32 transparent = 0x00000000;
547
548 /* Make sure the width is a multiple of 8 */
549 w = ((w + 7) & ~7);
550
551 /* Create the surface from a bitmap */
552 surface = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_ARGB8888);
553 if (!surface) {
554 return nullptr;
555 }
556 for (y = 0; y < h; ++y) {
557 pixel = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch);
558 for (x = 0; x < w; ++x) {
559 if ((x % 8) == 0) {
560 datab = *data++;
561 maskb = *mask++;
562
563 /* reverse bit order */
564 datab = (datab * 0x0202020202ULL & 0x010884422010ULL) % 1023;
565 maskb = (maskb * 0x0202020202ULL & 0x010884422010ULL) % 1023;
566 }
567 if (maskb & 0x80) {
568 *pixel++ = (datab & 0x80) ? white : black;
569 }
570 else {
571 *pixel++ = (datab & 0x80) ? white : transparent;
572 }
573 datab <<= 1;
574 maskb <<= 1;
575 }
576 }
577
578 cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
579
580 SDL_DestroySurface(surface);
581
582 return cursor;
583}
584
585/* TODO: this is currently never freed but it won't leak either. */
587{
588 if (sdl_std_cursor_array[0] == nullptr) {
589#define DEF_CURSOR(name, ind) \
590 { \
591 sdl_std_cursor_array[int(ind)] = sdl_ghost_CreateCursor( \
592 sdl_std_cursor_##name, \
593 sdl_std_cursor_mask_##name, \
594 sdl_std_cursor_WIDTH_##name, \
595 sdl_std_cursor_HEIGHT_##name, \
596 (sdl_std_cursor_WIDTH_##name + (sdl_std_cursor_HOT_X_##name)) - 1, \
597 (sdl_std_cursor_HEIGHT_##name + (sdl_std_cursor_HOT_Y_##name)) - 1); \
598 assert(sdl_std_cursor_array[int(ind)] != nullptr); \
599 } \
600 (void)0
601
605 DEF_CURSOR(umbrella, GHOST_kStandardCursorInfo); /* TODO: replace this one. */
607 DEF_CURSOR(question_arrow, GHOST_kStandardCursorHelp);
611 DEF_CURSOR(sb_v_double_arrow, GHOST_kStandardCursorUpDown);
612 DEF_CURSOR(sb_h_double_arrow, GHOST_kStandardCursorLeftRight);
622 // DEF_CURSOR(arrow, GHOST_kStandardCursorCustom);
624#undef DEF_CURSOR
625 }
626
627 return sdl_std_cursor_array[int(shape)];
628}
629
634
636{
637 SDL_Cursor *cursor = getStandardCursorShape(shape);
638 if (cursor == nullptr) {
640 }
641
642 SDL_SetCursor(cursor);
643 return GHOST_kSuccess;
644}
645
650
652 const uint8_t *mask,
653 const int size[2],
654 const int hot_spot[2],
655 bool /*can_invert_color*/)
656{
657 if (sdl_custom_cursor_) {
658 SDL_DestroyCursor(sdl_custom_cursor_);
659 }
660
661 sdl_custom_cursor_ = sdl_ghost_CreateCursor(
662 bitmap, mask, size[0], size[1], hot_spot[0], hot_spot[1]);
663
664 SDL_SetCursor(sdl_custom_cursor_);
665 return GHOST_kSuccess;
666}
667
669{
670 if (visible) {
671 SDL_ShowCursor();
672 }
673 else {
674 SDL_HideCursor();
675 }
676 return GHOST_kSuccess;
677}
678
680{
681 SDL_DisplayID display_id = SDL_GetDisplayForWindow(sdl_win_);
682 if (display_id == 0) {
683 return 96;
684 }
685
686 float scale = SDL_GetDisplayContentScale(display_id);
687 if (scale <= 0.0f) {
688 return 96;
689 }
690
691 return uint16_t(96.0f * scale);
692}
#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
@ GHOST_kFailure
@ GHOST_kSuccess
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[]
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
GHOST_ContextSDL(const GHOST_ContextParams &context_params, SDL_Window *window, int contextProfileMask, int contextMajorVersion, int contextMinorVersion, int contextFlags, int contextResetNotificationStrategy)
GHOST_ContextVK(const GHOST_ContextParams &context_params, GHOST_TVulkanPlatformType platform, Window window, Display *display, wl_surface *wayland_surface, wl_display *wayland_display, const GHOST_ContextVK_WindowInfo *wayland_window_info, int contextMajorVersion, int contextMinorVersion, const GHOST_GPUDevice &preferred_device, const GHOST_WindowHDRInfo *hdr_info_=nullptr)
int32_t t_
int32_t r_
int32_t b_
int32_t l_
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 GHOST_GPUDevice &preferred_device, const bool exclusive=false, const GHOST_IWindow *parent_window=nullptr)
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
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)
GHOST_WindowHDRInfo hdr_info_
unsigned int uchar
float3x3 scale(float3x3 mat, float2 scale)
const int state
ccl_device_inline float2 mask(const MaskType mask, const float2 a)