Blender  V2.93
GHOST_WindowSDL.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "GHOST_WindowSDL.h"
22 #include "SDL_mouse.h"
23 #include "glew-mx.h"
24 
25 #include "GHOST_ContextSDL.h"
26 
27 #include <assert.h>
28 
30  const char *title,
37  const bool stereoVisual,
38  const bool exclusive,
39  const GHOST_IWindow *parentWindow)
40  : GHOST_Window(width, height, state, stereoVisual, exclusive),
41  m_system(system),
42  m_valid_setup(false),
43  m_invalid_window(false),
44  m_sdl_custom_cursor(NULL)
45 {
46 
47  /* creating the window _must_ come after setting attributes */
48  m_sdl_win = SDL_CreateWindow(title,
49  left,
50  top,
51  width,
52  height,
53  SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
54 
55  /* now set up the rendering context. */
57  m_valid_setup = true;
58  GHOST_PRINT("Created window\n");
59  }
60 
61  if (exclusive) {
62  SDL_RaiseWindow(m_sdl_win);
63  }
64 
65  setTitle(title);
66 }
67 
69 {
70  if (m_sdl_custom_cursor) {
71  SDL_FreeCursor(m_sdl_custom_cursor);
72  }
73 
75 
76  SDL_DestroyWindow(m_sdl_win);
77 }
78 
80 {
83  m_sdl_win,
84  0, // profile bit
85  3,
86  3,
89 
90  if (context->initializeDrawingContext())
91  return context;
92  else
93  delete context;
94  }
95 
96  return NULL;
97 }
98 
100 {
101  if (m_invalid_window == false) {
102  m_system->addDirtyWindow(this);
103  m_invalid_window = true;
104  }
105 
106  return GHOST_kSuccess;
107 }
108 
110 {
111  switch (state) {
113  SDL_SetWindowFullscreen(m_sdl_win, SDL_FALSE);
114  SDL_RestoreWindow(m_sdl_win);
115  break;
117  SDL_SetWindowFullscreen(m_sdl_win, SDL_FALSE);
118  SDL_MaximizeWindow(m_sdl_win);
119  break;
121  SDL_MinimizeWindow(m_sdl_win);
122  break;
124  SDL_SetWindowFullscreen(m_sdl_win, SDL_TRUE);
125  break;
126  default:
127  break;
128  }
129 
130  return GHOST_kSuccess;
131 }
132 
134 {
135  Uint32 flags = SDL_GetWindowFlags(m_sdl_win);
136 
137  if (flags & SDL_WINDOW_FULLSCREEN)
139  else if (flags & SDL_WINDOW_MAXIMIZED)
141  else if (flags & SDL_WINDOW_MINIMIZED)
144 }
145 
147 {
148  return GHOST_Window::getValid() && m_valid_setup;
149 }
150 
151 void GHOST_WindowSDL::setTitle(const char *title)
152 {
153  SDL_SetWindowTitle(m_sdl_win, title);
154 }
155 
156 std::string GHOST_WindowSDL::getTitle() const
157 {
158  return SDL_GetWindowTitle(m_sdl_win);
159 }
160 
162 {
164 }
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, NULL, &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, NULL);
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  GHOST_TInt32 inY,
202  GHOST_TInt32 &outX,
203  GHOST_TInt32 &outY) const
204 {
205  /* XXXSDL_WEAK_ABS_COORDS */
206  int x_win, y_win;
207  SDL_GetWindowPosition(m_sdl_win, &x_win, &y_win);
208 
209  outX = inX - x_win;
210  outY = inY - y_win;
211 }
213  GHOST_TInt32 inY,
214  GHOST_TInt32 &outX,
215  GHOST_TInt32 &outY) const
216 {
217  /* XXXSDL_WEAK_ABS_COORDS */
218  int x_win, y_win;
219  SDL_GetWindowPosition(m_sdl_win, &x_win, &y_win);
220 
221  outX = inX + x_win;
222  outY = inY + y_win;
223 }
224 
225 /* mouse cursor */
226 static unsigned char sdl_std_cursor_mask_xterm[] = {
227  0xef, 0x01, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00,
228  0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xef, 0x01,
229 };
230 static unsigned char sdl_std_cursor_xterm[] = {
231  0x00, 0x77, 0x00, 0x1c, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08,
232  0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x08, 0x00, 0x1c, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
233 };
234 #define sdl_std_cursor_WIDTH_xterm 9
235 #define sdl_std_cursor_HEIGHT_xterm 16
236 #define sdl_std_cursor_HOT_X_xterm -3
237 #define sdl_std_cursor_HOT_Y_xterm -7
238 
239 static unsigned char sdl_std_cursor_mask_watch[] = {
240  0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfe, 0x1f, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
241  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfe, 0x1f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
242 };
243 static unsigned char sdl_std_cursor_watch[] = {
244  0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0xfc, 0x0f, 0x86, 0x18, 0x83, 0x30, 0x81, 0xe0, 0xc1, 0xe1,
245  0xc1, 0xe1, 0x21, 0xe0, 0x13, 0x30, 0x06, 0x18, 0xfc, 0x0f, 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07,
246 };
247 #define sdl_std_cursor_WIDTH_watch 16
248 #define sdl_std_cursor_HEIGHT_watch 16
249 #define sdl_std_cursor_HOT_X_watch -15
250 #define sdl_std_cursor_HOT_Y_watch -7
251 
252 static unsigned char sdl_std_cursor_mask_umbrella[] = {
253  0xe8, 0x76, 0xfb, 0xdf, 0xfd, 0x3f, 0xfe, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xcf, 0x79, 0xc0, 0x01,
254  0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0x80, 0x03,
255 };
256 static unsigned char sdl_std_cursor_umbrella[] = {
257  0x88, 0x04, 0x20, 0x0a, 0xc9, 0x32, 0xf2, 0x09, 0x4c, 0x06, 0x43, 0x18, 0x40, 0x00, 0x40, 0x00,
258  0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x01, 0x40, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
259 };
260 #define sdl_std_cursor_WIDTH_umbrella 16
261 #define sdl_std_cursor_HEIGHT_umbrella 16
262 #define sdl_std_cursor_HOT_X_umbrella -7
263 #define sdl_std_cursor_HOT_Y_umbrella -12
264 
265 static unsigned char sdl_std_cursor_mask_top_side[] = {
266  0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xc0, 0x01, 0xe0, 0x03, 0xf0, 0x07, 0xf8, 0x0f,
267  0xdc, 0x1d, 0xcc, 0x19, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
268 };
269 static unsigned char sdl_std_cursor_top_side[] = {
270  0xff, 0x1f, 0xff, 0x1f, 0x00, 0x00, 0x40, 0x00, 0xe0, 0x00, 0x50, 0x01, 0x48, 0x02, 0x44, 0x04,
271  0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
272 };
273 #define sdl_std_cursor_WIDTH_top_side 15
274 #define sdl_std_cursor_HEIGHT_top_side 16
275 #define sdl_std_cursor_HOT_X_top_side -6
276 #define sdl_std_cursor_HOT_Y_top_side -14
277 
278 static unsigned char sdl_std_cursor_mask_top_right_corner[] = {
279  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf0, 0xfc, 0xf7, 0xfc, 0xf7, 0xfc, 0xf7,
280  0xc0, 0xf7, 0xe0, 0xf7, 0x70, 0xf7, 0x38, 0xf7, 0x1c, 0xf7, 0x0c, 0xf7, 0x00, 0xf0, 0x00, 0xf0,
281 };
282 static unsigned char sdl_std_cursor_top_right_corner[] = {
283  0xff, 0x3f, 0xff, 0x3f, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xfc, 0x31, 0x80, 0x31, 0x40, 0x31,
284  0x20, 0x31, 0x10, 0x31, 0x08, 0x31, 0x04, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
285 };
286 #define sdl_std_cursor_WIDTH_top_right_corner 16
287 #define sdl_std_cursor_HEIGHT_top_right_corner 16
288 #define sdl_std_cursor_HOT_X_top_right_corner -13
289 #define sdl_std_cursor_HOT_Y_top_right_corner -14
290 
291 static unsigned char sdl_std_cursor_mask_top_left_corner[] = {
292  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xef, 0x3f, 0xef, 0x3f, 0xef, 0x3f,
293  0xef, 0x03, 0xef, 0x07, 0xef, 0x0e, 0xef, 0x1c, 0xef, 0x38, 0xef, 0x30, 0x0f, 0x00, 0x0f, 0x00,
294 };
295 static unsigned char sdl_std_cursor_top_left_corner[] = {
296  0xff, 0x3f, 0xff, 0x3f, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xe3, 0x0f, 0x63, 0x00, 0xa3, 0x00,
297  0x23, 0x01, 0x23, 0x02, 0x23, 0x04, 0x23, 0x08, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
298 };
299 #define sdl_std_cursor_WIDTH_top_left_corner 16
300 #define sdl_std_cursor_HEIGHT_top_left_corner 16
301 #define sdl_std_cursor_HOT_X_top_left_corner 0
302 #define sdl_std_cursor_HOT_Y_top_left_corner -14
303 
304 static unsigned char sdl_std_cursor_mask_sb_v_double_arrow[] = {
305  0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0xff, 0x01, 0xff, 0x01, 0x7c, 0x00, 0x7c, 0x00, 0x7c,
306  0x00, 0x7c, 0x00, 0x7c, 0x00, 0xff, 0x01, 0xff, 0x01, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00,
307 };
308 static unsigned char sdl_std_cursor_sb_v_double_arrow[] = {
309  0x10, 0x00, 0x38, 0x00, 0x7c, 0x00, 0xfe, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0x28,
310  0x00, 0x28, 0x00, 0x28, 0x00, 0x28, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00,
311 };
312 #define sdl_std_cursor_WIDTH_sb_v_double_arrow 9
313 #define sdl_std_cursor_HEIGHT_sb_v_double_arrow 15
314 #define sdl_std_cursor_HOT_X_sb_v_double_arrow -3
315 #define sdl_std_cursor_HOT_Y_sb_v_double_arrow -8
316 
317 static unsigned char sdl_std_cursor_mask_sb_h_double_arrow[] = {
318  0x18,
319  0x0c,
320  0x1c,
321  0x1c,
322  0xfe,
323  0x3f,
324  0xff,
325  0x7f,
326  0xff,
327  0x7f,
328  0xff,
329  0x7f,
330  0xfe,
331  0x3f,
332  0x1c,
333  0x1c,
334  0x18,
335  0x0c,
336 };
337 static unsigned char sdl_std_cursor_sb_h_double_arrow[] = {
338  0x00,
339  0x00,
340  0x08,
341  0x08,
342  0x0c,
343  0x18,
344  0xfe,
345  0x3f,
346  0x0f,
347  0x78,
348  0xfe,
349  0x3f,
350  0x0c,
351  0x18,
352  0x08,
353  0x08,
354  0x00,
355  0x00,
356 };
357 #define sdl_std_cursor_WIDTH_sb_h_double_arrow 15
358 #define sdl_std_cursor_HEIGHT_sb_h_double_arrow 9
359 #define sdl_std_cursor_HOT_X_sb_h_double_arrow -7
360 #define sdl_std_cursor_HOT_Y_sb_h_double_arrow -4
361 
362 static unsigned char sdl_std_cursor_mask_right_side[] = {
363  0x00, 0xf0, 0x00, 0xf0, 0xc0, 0xf0, 0xc0, 0xf1, 0x80, 0xf3, 0x00, 0xf7, 0xff, 0xff, 0xff,
364  0xff, 0xff, 0xff, 0x00, 0xf7, 0x80, 0xf3, 0xc0, 0xf1, 0xc0, 0xf0, 0x00, 0xf0, 0x00, 0xf0,
365 };
366 static unsigned char sdl_std_cursor_right_side[] = {
367  0x00, 0x30, 0x00, 0x30, 0x40, 0x30, 0x80, 0x30, 0x00, 0x31, 0x00, 0x32, 0xff, 0x37, 0x00,
368  0x32, 0x00, 0x31, 0x80, 0x30, 0x40, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
369 };
370 #define sdl_std_cursor_WIDTH_right_side 16
371 #define sdl_std_cursor_HEIGHT_right_side 15
372 #define sdl_std_cursor_HOT_X_right_side -13
373 #define sdl_std_cursor_HOT_Y_right_side -7
374 
375 static unsigned char sdl_std_cursor_mask_right_ptr[] = {
376  0x00, 0x03, 0x80, 0x03, 0xc0, 0x03, 0xe0, 0x03, 0xf0, 0x03, 0xf8, 0x03, 0xfc, 0x03, 0xfe, 0x03,
377  0xff, 0x03, 0xff, 0x03, 0xf8, 0x03, 0xbc, 0x03, 0x3c, 0x03, 0x1e, 0x00, 0x1e, 0x00, 0x0c, 0x00,
378 };
379 static unsigned char sdl_std_cursor_right_ptr[] = {
380  0x00, 0x80, 0x00, 0xc0, 0x00, 0xe0, 0x00, 0xf0, 0x00, 0xf8, 0x00, 0xfc, 0x00, 0xfe, 0x00, 0xff,
381  0x00, 0xf8, 0x00, 0xd8, 0x00, 0x8c, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
382 };
383 #define sdl_std_cursor_WIDTH_right_ptr 10
384 #define sdl_std_cursor_HEIGHT_right_ptr 16
385 #define sdl_std_cursor_HOT_X_right_ptr -7
386 #define sdl_std_cursor_HOT_Y_right_ptr -14
387 
388 static unsigned char sdl_std_cursor_mask_question_arrow[] = {
389  0xf8, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xff, 0x07, 0x8f, 0x07, 0x9f, 0x07, 0xde, 0x07, 0xfc, 0x03,
390  0xf8, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0xfc, 0x01, 0xfe, 0x03, 0xfc, 0x01, 0xf8, 0x00, 0x70, 0x00,
391 };
392 static unsigned char sdl_std_cursor_question_arrow[] = {
393  0x7c, 0x00, 0xfe, 0x00, 0xc7, 0x01, 0x83, 0x01, 0x87, 0x01, 0xc6, 0x01, 0xe0, 0x00, 0x78, 0x00,
394  0x38, 0x00, 0x28, 0x00, 0x28, 0x00, 0xee, 0x00, 0x6c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00,
395 };
396 #define sdl_std_cursor_WIDTH_question_arrow 11
397 #define sdl_std_cursor_HEIGHT_question_arrow 16
398 #define sdl_std_cursor_HOT_X_question_arrow -4
399 #define sdl_std_cursor_HOT_Y_question_arrow -8
400 
401 static unsigned char sdl_std_cursor_mask_pirate[] = {
402  0xf0, 0x03, 0xf8, 0x07, 0xfc, 0x0f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfc, 0x0f, 0xf8, 0x07, 0xf1, 0x83,
403  0xf1, 0xe3, 0xf3, 0xf3, 0xef, 0x39, 0x1e, 0x1e, 0xe0, 0x01, 0xfe, 0xc7, 0xff, 0xff, 0x0f, 0x7c,
404 };
405 static unsigned char sdl_std_cursor_pirate[] = {
406  0xe0, 0x01, 0xf0, 0x03, 0xf8, 0x07, 0xcc, 0x0c, 0xcc, 0x0c, 0xf8, 0x07, 0xf0, 0x03, 0xe0, 0x01,
407  0xe1, 0x21, 0xe1, 0x61, 0xc2, 0x10, 0x1c, 0x0e, 0xe0, 0x01, 0xf8, 0x47, 0x0f, 0x7c, 0x01, 0x20,
408 };
409 #define sdl_std_cursor_WIDTH_pirate 16
410 #define sdl_std_cursor_HEIGHT_pirate 16
411 #define sdl_std_cursor_HOT_X_pirate -7
412 #define sdl_std_cursor_HOT_Y_pirate -4
413 
414 static unsigned char sdl_std_cursor_mask_left_side[] = {
415  0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x03, 0x8f, 0x03, 0xcf, 0x01, 0xef, 0x00, 0xff, 0xff, 0xff,
416  0xff, 0xff, 0xff, 0xef, 0x00, 0xcf, 0x01, 0x8f, 0x03, 0x0f, 0x03, 0x0f, 0x00, 0x0f, 0x00,
417 };
418 static unsigned char sdl_std_cursor_left_side[] = {
419  0x03, 0x00, 0x03, 0x00, 0x83, 0x00, 0x43, 0x00, 0x23, 0x00, 0x13, 0x00, 0xfb, 0x3f, 0x13,
420  0x00, 0x23, 0x00, 0x43, 0x00, 0x83, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
421 };
422 #define sdl_std_cursor_WIDTH_left_side 16
423 #define sdl_std_cursor_HEIGHT_left_side 15
424 #define sdl_std_cursor_HOT_X_left_side 0
425 #define sdl_std_cursor_HOT_Y_left_side -7
426 
427 static unsigned char sdl_std_cursor_mask_left_ptr[] = {
428  0x03, 0x00, 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3f, 0x00, 0x7f, 0x00, 0xff, 0x00, 0xff, 0x01,
429  0xff, 0x03, 0xff, 0x03, 0x7f, 0x00, 0xf7, 0x00, 0xf3, 0x00, 0xe0, 0x01, 0xe0, 0x01, 0xc0, 0x00,
430 };
431 static unsigned char sdl_std_cursor_left_ptr[] = {
432  0x00, 0x00, 0x02, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x1e, 0x00, 0x3e, 0x00, 0x7e, 0x00, 0xfe, 0x00,
433  0xfe, 0x00, 0x3e, 0x00, 0x36, 0x00, 0x62, 0x00, 0x60, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x00, 0x00,
434 };
435 #define sdl_std_cursor_WIDTH_left_ptr 10
436 #define sdl_std_cursor_HEIGHT_left_ptr 16
437 #define sdl_std_cursor_HOT_X_left_ptr -8
438 #define sdl_std_cursor_HOT_Y_left_ptr -14
439 
440 static unsigned char sdl_std_cursor_mask_crosshair[] = {
441  0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xff,
442  0xff, 0xff, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01,
443 };
444 static unsigned char sdl_std_cursor_crosshair[] = {
445  0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x7f, 0xff,
446  0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00,
447 };
448 #define sdl_std_cursor_WIDTH_crosshair 16
449 #define sdl_std_cursor_HEIGHT_crosshair 16
450 #define sdl_std_cursor_HOT_X_crosshair -7
451 #define sdl_std_cursor_HOT_Y_crosshair -8
452 
453 static unsigned char sdl_std_cursor_mask_bottom_side[] = {
454  0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xcc, 0x19, 0xdc, 0x1d,
455  0xf8, 0x0f, 0xf0, 0x07, 0xe0, 0x03, 0xc0, 0x01, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f,
456 };
457 static unsigned char sdl_std_cursor_bottom_side[] = {
458  0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x44, 0x04, 0x48, 0x02,
459  0x50, 0x01, 0xe0, 0x00, 0x40, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00,
460 };
461 #define sdl_std_cursor_WIDTH_bottom_side 15
462 #define sdl_std_cursor_HEIGHT_bottom_side 16
463 #define sdl_std_cursor_HOT_X_bottom_side -6
464 #define sdl_std_cursor_HOT_Y_bottom_side -1
465 
466 static unsigned char sdl_std_cursor_mask_bottom_right_corner[] = {
467  0x00, 0xf0, 0x00, 0xf0, 0x0c, 0xf7, 0x1c, 0xf7, 0x38, 0xf7, 0x70, 0xf7, 0xe0, 0xf7, 0xc0, 0xf7,
468  0xfc, 0xf7, 0xfc, 0xf7, 0xfc, 0xf7, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
469 };
470 static unsigned char sdl_std_cursor_bottom_right_corner[] = {
471  0x00, 0x30, 0x00, 0x30, 0x04, 0x31, 0x08, 0x31, 0x10, 0x31, 0x20, 0x31, 0x40, 0x31, 0x80, 0x31,
472  0xfc, 0x31, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
473 };
474 #define sdl_std_cursor_WIDTH_bottom_right_corner 16
475 #define sdl_std_cursor_HEIGHT_bottom_right_corner 16
476 #define sdl_std_cursor_HOT_X_bottom_right_corner -13
477 #define sdl_std_cursor_HOT_Y_bottom_right_corner -1
478 
479 static unsigned char sdl_std_cursor_mask_bottom_left_corner[] = {
480  0x0f, 0x00, 0x0f, 0x00, 0xef, 0x30, 0xef, 0x38, 0xef, 0x1c, 0xef, 0x0e, 0xef, 0x07, 0xef, 0x03,
481  0xef, 0x3f, 0xef, 0x3f, 0xef, 0x3f, 0x0f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
482 };
483 static unsigned char sdl_std_cursor_bottom_left_corner[] = {
484  0x03, 0x00, 0x03, 0x00, 0x23, 0x08, 0x23, 0x04, 0x23, 0x02, 0x23, 0x01, 0xa3, 0x00, 0x63, 0x00,
485  0xe3, 0x0f, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xff, 0x3f, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00,
486 };
487 #define sdl_std_cursor_WIDTH_bottom_left_corner 16
488 #define sdl_std_cursor_HEIGHT_bottom_left_corner 16
489 #define sdl_std_cursor_HOT_X_bottom_left_corner 0
490 #define sdl_std_cursor_HOT_Y_bottom_left_corner -1
491 
492 static unsigned char sdl_std_cursor_mask_arrow[] = {
493  0x00, 0xe0, 0x00, 0xf8, 0x00, 0xfe, 0x80, 0x7f, 0xe0, 0x7f, 0xf8, 0x3f, 0xfc, 0x3f, 0xfc, 0x1f,
494  0xe0, 0x1f, 0xf0, 0x0f, 0xf8, 0x0f, 0x7c, 0x07, 0x3e, 0x07, 0x1f, 0x02, 0x0e, 0x00, 0x04, 0x00,
495 };
496 static unsigned char sdl_std_cursor_arrow[] = {
497  0x00, 0x30, 0x00, 0x3c, 0x00, 0x1f, 0xc0, 0x1f, 0xf0, 0x0f, 0xfc, 0x0f, 0xc0, 0x07, 0xe0, 0x07,
498  0x70, 0x03, 0x38, 0x03, 0x1c, 0x01, 0x0e, 0x01, 0x07, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
499 };
500 #define sdl_std_cursor_WIDTH_arrow 16
501 #define sdl_std_cursor_HEIGHT_arrow 16
502 #define sdl_std_cursor_HOT_X_arrow -13
503 #define sdl_std_cursor_HOT_Y_arrow -14
504 /* end cursor data */
505 
507 
508 /* utility function mostly a copy of SDL_CreateCursor but allows us to change
509  * color and supports blenders flipped bits */
510 static SDL_Cursor *sdl_ghost_CreateCursor(
511  const Uint8 *data, const Uint8 *mask, int w, int h, int hot_x, int hot_y)
512 {
513  SDL_Surface *surface;
514  SDL_Cursor *cursor;
515  int x, y;
516  Uint32 *pixel;
517  Uint8 datab = 0, maskb = 0;
518  const Uint32 black = 0xFF000000;
519  const Uint32 white = 0xFFFFFFFF;
520  const Uint32 transparent = 0x00000000;
521 
522  /* Make sure the width is a multiple of 8 */
523  w = ((w + 7) & ~7);
524 
525  /* Create the surface from a bitmap */
526  surface = SDL_CreateRGBSurface(0, w, h, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
527  if (!surface) {
528  return NULL;
529  }
530  for (y = 0; y < h; ++y) {
531  pixel = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch);
532  for (x = 0; x < w; ++x) {
533  if ((x % 8) == 0) {
534  datab = *data++;
535  maskb = *mask++;
536 
537  /* reverse bit order */
538  datab = (datab * 0x0202020202ULL & 0x010884422010ULL) % 1023;
539  maskb = (maskb * 0x0202020202ULL & 0x010884422010ULL) % 1023;
540  }
541  if (maskb & 0x80) {
542  *pixel++ = (datab & 0x80) ? white : black;
543  }
544  else {
545  *pixel++ = (datab & 0x80) ? white : transparent;
546  }
547  datab <<= 1;
548  maskb <<= 1;
549  }
550  }
551 
552  cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
553 
554  SDL_FreeSurface(surface);
555 
556  return cursor;
557 }
558 
559 /* TODO, this is currently never freed but it wont leak either. */
561 {
562  if (sdl_std_cursor_array[0] == NULL) {
563 #define DEF_CURSOR(name, ind) \
564  { \
565  sdl_std_cursor_array[(int)ind] = sdl_ghost_CreateCursor( \
566  sdl_std_cursor_##name, \
567  sdl_std_cursor_mask_##name, \
568  sdl_std_cursor_WIDTH_##name, \
569  sdl_std_cursor_HEIGHT_##name, \
570  (sdl_std_cursor_WIDTH_##name + (sdl_std_cursor_HOT_X_##name)) - 1, \
571  (sdl_std_cursor_HEIGHT_##name + (sdl_std_cursor_HOT_Y_##name)) - 1); \
572  assert(sdl_std_cursor_array[(int)ind] != NULL); \
573  } \
574  (void)0
575 
579  DEF_CURSOR(umbrella, GHOST_kStandardCursorInfo); // TODO, replace this one.
581  DEF_CURSOR(question_arrow, GHOST_kStandardCursorHelp);
585  DEF_CURSOR(sb_v_double_arrow, GHOST_kStandardCursorUpDown);
586  DEF_CURSOR(sb_h_double_arrow, GHOST_kStandardCursorLeftRight);
596  // DEF_CURSOR(arrow, GHOST_kStandardCursorCustom);
598 #undef DEF_CURSOR
599  }
600 
601  return sdl_std_cursor_array[(int)shape];
602 }
603 
605 {
606  return GHOST_kSuccess;
607 }
608 
610 {
611  SDL_Cursor *cursor = getStandardCursorShape(shape);
612  if (cursor == NULL) {
614  }
615 
616  SDL_SetCursor(cursor);
617  return GHOST_kSuccess;
618 }
619 
621 {
623 }
624 
626  GHOST_TUns8 *mask,
627  int sizex,
628  int sizey,
629  int hotX,
630  int hotY,
631  bool canInvertColor)
632 {
633  if (m_sdl_custom_cursor) {
634  SDL_FreeCursor(m_sdl_custom_cursor);
635  }
636 
637  m_sdl_custom_cursor = sdl_ghost_CreateCursor(
638  (const Uint8 *)bitmap, (const Uint8 *)mask, sizex, sizex, hotX, hotY);
639 
640  SDL_SetCursor(m_sdl_custom_cursor);
641  return GHOST_kSuccess;
642 }
643 
645 {
646  SDL_ShowCursor(visible);
647  return GHOST_kSuccess;
648 }
649 
651 {
652  int displayIndex = SDL_GetWindowDisplayIndex(m_sdl_win);
653  if (displayIndex < 0) {
654  return 96;
655  }
656 
657  float ddpi;
658  if (SDL_GetDisplayDPI(displayIndex, &ddpi, NULL, NULL) != 0) {
659  return 96;
660  }
661 
662  return (int)ddpi;
663 }
#define GHOST_OPENGL_SDL_RESET_NOTIFICATION_STRATEGY
#define GHOST_OPENGL_SDL_CONTEXT_FLAGS
#define GHOST_PRINT(x)
Definition: GHOST_Debug.h:51
GHOST_TWindowState
Definition: GHOST_Types.h:144
@ GHOST_kWindowStateMinimized
Definition: GHOST_Types.h:147
@ GHOST_kWindowStateMaximized
Definition: GHOST_Types.h:146
@ GHOST_kWindowStateNormal
Definition: GHOST_Types.h:145
@ GHOST_kWindowStateFullScreen
Definition: GHOST_Types.h:148
GHOST_TStandardCursor
Definition: GHOST_Types.h:222
@ GHOST_kStandardCursorBottomLeftCorner
Definition: GHOST_Types.h:260
@ GHOST_kStandardCursorHelp
Definition: GHOST_Types.h:229
@ GHOST_kStandardCursorCopy
Definition: GHOST_Types.h:261
@ GHOST_kStandardCursorWait
Definition: GHOST_Types.h:230
@ GHOST_kStandardCursorTopSide
Definition: GHOST_Types.h:253
@ GHOST_kStandardCursorCrosshair
Definition: GHOST_Types.h:232
@ GHOST_kStandardCursorLeftRight
Definition: GHOST_Types.h:252
@ GHOST_kStandardCursorPencil
Definition: GHOST_Types.h:236
@ GHOST_kStandardCursorUpDown
Definition: GHOST_Types.h:251
@ GHOST_kStandardCursorBottomSide
Definition: GHOST_Types.h:254
@ GHOST_kStandardCursorInfo
Definition: GHOST_Types.h:227
@ GHOST_kStandardCursorTopLeftCorner
Definition: GHOST_Types.h:257
@ GHOST_kStandardCursorBottomRightCorner
Definition: GHOST_Types.h:259
@ GHOST_kStandardCursorDefault
Definition: GHOST_Types.h:224
@ GHOST_kStandardCursorRightSide
Definition: GHOST_Types.h:256
@ GHOST_kStandardCursorRightArrow
Definition: GHOST_Types.h:225
@ GHOST_kStandardCursorTopRightCorner
Definition: GHOST_Types.h:258
@ GHOST_kStandardCursorDestroy
Definition: GHOST_Types.h:228
@ GHOST_kStandardCursorNumCursors
Definition: GHOST_Types.h:264
@ GHOST_kStandardCursorLeftSide
Definition: GHOST_Types.h:255
@ GHOST_kStandardCursorText
Definition: GHOST_Types.h:231
@ GHOST_kStandardCursorLeftArrow
Definition: GHOST_Types.h:226
unsigned int GHOST_TUns32
Definition: GHOST_Types.h:64
int GHOST_TInt32
Definition: GHOST_Types.h:63
unsigned short GHOST_TUns16
Definition: GHOST_Types.h:62
GHOST_TDrawingContextType
Definition: GHOST_Types.h:156
@ GHOST_kDrawingContextTypeOpenGL
Definition: GHOST_Types.h:158
GHOST_TSuccess
Definition: GHOST_Types.h:91
@ GHOST_kFailure
Definition: GHOST_Types.h:91
@ GHOST_kSuccess
Definition: GHOST_Types.h:91
GHOST_TGrabCursorMode
Definition: GHOST_Types.h:412
unsigned char GHOST_TUns8
Definition: GHOST_Types.h:60
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 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 type
_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 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)
GHOST_TSuccess setClientHeight(GHOST_TUns32 height)
void setTitle(const char *title)
bool getValid() const
GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)
GHOST_TSuccess setWindowCursorVisibility(bool visible)
GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor shape)
GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
GHOST_Context * newDrawingContext(GHOST_TDrawingContextType type)
void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32 &outX, GHOST_TInt32 &outY) const
std::string getTitle() const
GHOST_TSuccess invalidate(void)
GHOST_TWindowState getState() const
void getClientBounds(GHOST_Rect &bounds) const
void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32 &outX, GHOST_TInt32 &outY) const
GHOST_TSuccess setState(GHOST_TWindowState state)
void getWindowBounds(GHOST_Rect &bounds) const
GHOST_WindowSDL(GHOST_SystemSDL *system, const char *title, GHOST_TInt32 left, GHOST_TInt32 top, GHOST_TUns32 width, GHOST_TUns32 height, GHOST_TWindowState state, GHOST_TDrawingContextType type=GHOST_kDrawingContextTypeNone, const bool stereoVisual=false, const bool exclusive=false, const GHOST_IWindow *parentWindow=NULL)
GHOST_TSuccess setClientWidth(GHOST_TUns32 width)
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape)
GHOST_TUns16 getDPIHint()
GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode)
bool m_wantStereoVisual
Definition: GHOST_Window.h:396
GHOST_TSuccess setDrawingContextType(GHOST_TDrawingContextType type)
GHOST_TSuccess releaseNativeHandles()
virtual bool getValid() const
Definition: GHOST_Window.h:92
struct @203::@204 surface
static ulong state[N]
static int left
struct SELECTID_Context context
Definition: select_engine.c:47
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)