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