zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Window.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <zeni_graphics.h>
19 
20 #ifdef _WINDOWS
21 #include <SDL/SDL_syswm.h>
22 #include <Windows.h>
23 #include <WinUser.h>
24 #endif
25 
26 #include <algorithm>
27 #include <iostream>
28 
29 #include <Zeni/Define.h>
30 
31 #if defined(_DEBUG) && defined(_WINDOWS)
32 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
33 #define new DEBUG_NEW
34 #endif
35 
36 #include <Zeni/Singleton.hxx>
37 
38 namespace Zeni {
39 
40  template class Singleton<Window>;
41 
42 #ifndef ANDROID
43  static bool window_mode_lt(const Point2i &lhs, const Point2i &rhs) {
44  return lhs.x < rhs.x || (lhs.x == rhs.x && lhs.y < rhs.y);
45  }
46 #endif
47 
48  Window * Window::create() {
49  Window * window = 0;
50 
51 #ifndef ANDROID
52  File_Ops &fo = get_File_Ops();
53 
54  const String appdata_path = fo.get_appdata_path();
55 
56  const String user_normal = appdata_path + "config/zenilib.xml";
57  const String user_backup = user_normal + ".bak";
58  const String local_normal = "config/zenilib.xml";
59  const String local_backup = local_normal + ".bak";
60 
61  static bool last_resort_taken = false;
62 #endif
63 
64 #ifndef ANDROID
65  try {
66  switch(Video::get_video_mode()) {
68 #ifndef DISABLE_GL_SHADER
71  break;
72 #endif
73 #ifndef DISABLE_DX9
76  break;
77 #endif
78 #ifndef DISABLE_GL_FIXED
81  break;
82 #endif
83  default:
84  throw Window_Init_Failure();
85  }
86 #endif
87 
88  window = new Window;
89 #ifndef ANDROID
90  }
91  catch(Window_Init_Failure &) {
92  if(fo.copy_file(user_backup, user_normal) && fo.delete_file(user_backup)) {
93  std::cerr << '\'' << user_normal << "' backup restored due to initialization failure.\n";
94  Video::preinit_from_file(user_normal);
95  get_Window();
96  }
97  else if(fo.copy_file(local_backup, local_normal) && fo.delete_file(local_backup)) {
98  std::cerr << '\'' << local_normal << "' backup restored due to initialization failure.\n";
99  Video::preinit_from_file(local_normal);
100  get_Window();
101  }
102  else if(!last_resort_taken) {
104 
105  last_resort_taken = true;
106 
107  get_Window();
108  }
109  else
110  throw;
111  }
112 
113  last_resort_taken = false;
114 #endif
115 
116  return window;
117  }
118 
119  Singleton<Window>::Uninit Window::g_uninit;
120  Singleton<Window>::Reinit Window::g_reinit;
121 
123 #ifdef ANDROID
124  : m_display(EGL_NO_DISPLAY),
125  m_surface(EGL_NO_SURFACE),
126  m_context(EGL_NO_CONTEXT)
127 #else
128  :
129 #if SDL_VERSION_ATLEAST(1,3,0)
130  m_window(0),
131 #else
132  m_display_surface(0),
133 #endif
134  m_icon_surface(0)
135 #endif
136  {
137  if(!g_enabled)
138  throw Window_Init_Failure();
139 
140  Core::remove_post_reinit(&g_reinit);
141 
142  Core &cr = get_Core();
143 
144 #ifndef ANDROID
146  throw Window_Init_Failure();
147 
149 
150  // Initialize Window Mode Listing
151 #if SDL_VERSION_ATLEAST(1,3,0)
152  const int num_modes = SDL_GetNumDisplayModes(0);
153  for(int i = 0; i != num_modes; ++i) {
155  SDL_GetDisplayMode(0, i, &mode);
156  if(m_modes.empty() || m_modes.rbegin()->x != mode.w || m_modes.rbegin()->y != mode.h)
157  m_modes.push_back(Point2i(mode.w, mode.h));
158  }
159 #else
160  SDL_PixelFormat fmt;
161  memset(&fmt, 0, sizeof(SDL_PixelFormat));
162  fmt.BitsPerPixel = 32;
163  for(SDL_Rect ** mode = SDL_ListModes(&fmt, SDL_FULLSCREEN | SDL_OPENGL); mode && *mode; ++mode)
164  m_modes.push_back(Point2i((*mode)->w, (*mode)->h));
165 #endif
166 
167  if(m_modes.empty())
168  throw Window_Init_Failure();
169 
170  std::sort(m_modes.begin(), m_modes.end(), &window_mode_lt);
171 #endif
172 
173  cr.set_screen_saver(false);
174 
175 #ifdef ANDROID
176  /*
177  * Here specify the attributes of the desired configuration.
178  * Below, we select an EGLConfig with at least 8 bits per color
179  * component compatible with on-screen windows
180  */
181  m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
182 
183  eglInitialize(m_display, 0, 0);
184 
185  /* Here, the application chooses the configuration it desires. In this
186  * sample, we have a very simplified selection process, where we pick
187  * the first EGLConfig that matches our criteria */
188  const EGLint attribs[] = {
190  EGL_BLUE_SIZE, 8,
191  EGL_GREEN_SIZE, 8,
192  EGL_RED_SIZE, 8,
193  EGL_NONE
194  };
196  EGLint numConfigs;
197  eglChooseConfig(m_display, attribs, &config, 1, &numConfigs);
198 
199  /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
200  * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
201  * As soon as we picked a EGLConfig, we can safely reconfigure the
202  * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
203  EGLint format;
204  eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format);
205 
206  ANativeWindow_setBuffersGeometry(get_Core().get_state().window, 0, 0, format);
207 
208  m_surface = eglCreateWindowSurface(m_display, config, get_Core().get_state().window, NULL);
209  m_context = eglCreateContext(m_display, config, NULL, NULL);
210 
211  if(eglMakeCurrent(m_display, m_surface, m_surface, m_context) == EGL_FALSE) {
212  ZENI_LOGW("Unable to eglMakeCurrent");
213 
214  if(m_display != EGL_NO_DISPLAY) {
216  if(m_context != EGL_NO_CONTEXT) {
217  eglDestroyContext(m_display, m_context);
218  }
219  if(m_surface != EGL_NO_SURFACE) {
220  eglDestroySurface(m_display, m_surface);
221  }
222  eglTerminate(m_display);
223  }
224  m_context = EGL_NO_CONTEXT;
225  m_surface = EGL_NO_SURFACE;
226  m_display = EGL_NO_DISPLAY;
227 
228  throw Window_Init_Failure();
229  }
230 
231  EGLint w, h;
232  eglQuerySurface(m_display, m_surface, EGL_WIDTH, &w);
233  eglQuerySurface(m_display, m_surface, EGL_HEIGHT, &h);
234 
235  g_screen_size.x = w;
236  g_screen_size.y = h;
237 #else
238  // Initialize SDL + Variables
239 #if SDL_VERSION_ATLEAST(2,0,0)
240  SDL_Rect rect;
241  SDL_GetDisplayBounds(0, &rect);
242  const Sint32 current_w = rect.w;
243  const Sint32 current_h = rect.h;
244 #else
245  const SDL_VideoInfo *VideoInfo = SDL_GetVideoInfo();
246  const Sint32 current_w = VideoInfo->current_w;
247  const Sint32 current_h = VideoInfo->current_h;
248 #endif
249 
250 #if !SDL_VERSION_ATLEAST(1,3,0)
251  set_tt();
252  set_icon();
253 #endif
254 
255  const Point2i &max_res = *m_modes.rbegin();
256 
257  if(g_screen_size.x < 0)
258  g_screen_size.x = max_res.x;
259  else if(g_screen_size.x == 0)
260  g_screen_size.x = current_w;
261  else if(g_screen_size.x < MINIMUM_SCREEN_WIDTH)
262  g_screen_size.x = MINIMUM_SCREEN_WIDTH;
263  else if(g_screen_size.x > max_res.x)
264  g_screen_size.x = max_res.x;
265 
266  if(g_screen_size.y < 0)
267  g_screen_size.y = max_res.y;
268  else if(g_screen_size.y == 0)
269  g_screen_size.y = current_h;
270  else if(g_screen_size.y < MINIMUM_SCREEN_HEIGHT)
271  g_screen_size.y = MINIMUM_SCREEN_HEIGHT;
272  else if(g_screen_size.y > max_res.y)
273  g_screen_size.y = max_res.y;
274 
275 #if !SDL_VERSION_ATLEAST(1,3,0)
276  // Vertical sync can only be specified before Window creation on some platforms
277  if(get_opengl_flag())
278  SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, Video::get_vertical_sync());
279 #endif
280 
281 // #ifdef REQUIRE_GL_ES
282 // {
283 // int err;
284 // #ifdef _WINDOWS
285 // err = SDL_GL_LoadLibrary("opengl32.dll");
286 // #else
287 // err = SDL_GL_LoadLibrary("libGL.so");
288 // #endif
289 // if(err)
290 // throw Video_Init_Failure();
291 // }
292 // #endif
293 
294  // Initialize Window
295 #if SDL_VERSION_ATLEAST(1,3,0)
296  m_window = SDL_CreateWindow(get_m_title().c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, g_screen_size.x, g_screen_size.y,
298  (g_screen_full ? SDL_WINDOW_FULLSCREEN
299  : ((g_screen_show_frame ? SDL_WINDOW_OPENGL : SDL_WINDOW_BORDERLESS) |
300  (g_screen_resizable ? SDL_WINDOW_RESIZABLE : SDL_WINDOW_OPENGL))));
301 #else
302 #ifdef _MACOSX
303  if(g_screen_full)
304  g_screen_size = Point2i();
305 #endif
306  m_display_surface = SDL_SetVideoMode(g_screen_size.x, g_screen_size.y, 32,
307  SDL_OPENGL |
308  (g_screen_full ? SDL_FULLSCREEN
309  : (VideoInfo->wm_available ? ((g_screen_show_frame ? SDL_OPENGL : SDL_NOFRAME) |
310  (g_screen_resizable ? SDL_RESIZABLE : SDL_OPENGL))
311  : SDL_OPENGL)));
312 #endif
314 
315 #if SDL_VERSION_ATLEAST(1,3,0)
316  if(!m_window) {
317 #else
318  if(!m_display_surface) {
319 #endif
320  throw Window_Init_Failure();
321  }
322 
323 #if SDL_VERSION_ATLEAST(1,3,0)
324  set_tt();
325  set_icon();
326 
327  SDL_ShowWindow(m_window);
328 #else
329  g_screen_size.x = m_display_surface->w;
330  g_screen_size.y = m_display_surface->h;
331 #endif
332 
333  // Force the window to be active and in the foreground, if possible (Windows only)
334 #ifdef _WINDOWS
335  SDL_SysWMinfo wmInfo;
336  SDL_VERSION(&wmInfo.version);
337 #if SDL_VERSION_ATLEAST(2,0,0)
338  SDL_GetWindowWMInfo(m_window, &wmInfo);
339  HWND hWnd = wmInfo.info.win.window;
340 #else
341  SDL_GetWMInfo(&wmInfo);
342  HWND hWnd = wmInfo.window;
343 #endif
344 
345  if(FAILED(SetForegroundWindow(hWnd)))
346  SetActiveWindow(hWnd);
347 #endif
348 #endif
349 
350  cr.lend_pre_uninit(&g_uninit);
351  cr.lend_post_reinit(&g_reinit);
352  }
353 
355 #ifdef ANDROID
356  if(m_display != EGL_NO_DISPLAY) {
358  if(m_context != EGL_NO_CONTEXT) {
359  eglDestroyContext(m_display, m_context);
360  }
361  if(m_surface != EGL_NO_SURFACE) {
362  eglDestroySurface(m_display, m_surface);
363  }
364  eglTerminate(m_display);
365  }
366  m_context = EGL_NO_CONTEXT;
367  m_surface = EGL_NO_SURFACE;
368  m_display = EGL_NO_DISPLAY;
369 #else
370 #if SDL_VERSION_ATLEAST(1,3,0)
372  Core::remove_pre_uninit(&g_uninit);
373 
374  if(m_window)
375  SDL_DestroyWindow(m_window);
376  m_window = 0;
377 
379 
380  alert_window_destroyed();
381 #else
382  SDL_FreeSurface(m_display_surface);
383  m_display_surface = 0;
384 #endif
385 
387 #endif
388 
389  get_Core().set_screen_saver(true);
390  }
391 
393  return Singleton<Window>::get();
394  }
395 
396  void Window::set_enabled(const bool &enabled) {
397  g_enabled = enabled;
398  }
399 
400 #ifndef ANDROID
401  void Window::preinit_resolution(const Point2i &resolution) {
402  g_screen_size = resolution;
403  }
404 
405  void Window::preinit_full_screen(const bool &full_screen) {
406  g_screen_full = full_screen;
407  }
408 
409  void Window::preinit_show_frame(const bool &show_frame_) {
410  g_screen_show_frame = show_frame_;
411  }
412 
413  void Window::preinit_resizable(const bool &resizable_) {
414  g_screen_resizable = resizable_;
415  }
416 
418  preinit_resolution(Point2i(video["Resolution"]["Width"].to_int(),
419  video["Resolution"]["Height"].to_int()));
420  preinit_full_screen(video["Full_Screen"].to_bool());
421  }
422 
424  g_screen_full = false;
425  g_screen_size.x = FAILSAFE_SCREEN_WIDTH;
426  g_screen_size.y = FAILSAFE_SCREEN_HEIGHT;
427  }
428 
429  const bool & Window::get_opengl_flag() {
430  return g_opengl_flag;
431  }
432 
433  void Window::set_opengl_flag(const bool &on) {
434  g_opengl_flag = on;
435  }
436 
437  void Window::set_tt(const String &title, const String &taskmsg) {
438  get_m_title() = title;
439  get_m_taskmsg() = taskmsg;
440 
441  if(is_initialized())
442  get().set_tt();
443  }
444 
445  void Window::set_title(const String &title) {
446  get_m_title() = title;
447 
448  if(is_initialized())
449  get().set_tt();
450  }
451 
452  void Window::set_taskmsg(const String &taskmsg) {
453  get_m_taskmsg() = taskmsg;
454 
455  if(is_initialized())
456  get().set_tt();
457  }
458 
459  bool Window::set_icon(const String &filename) {
460  get_m_icon() = filename;
461 
462  return !is_initialized() || get().set_icon();
463  }
464 
467  return MOUSE_RELATIVE;
468 
469  const bool mouse_hidden = (SDL_ShowCursor(SDL_QUERY) != SDL_ENABLE) == SDL_TRUE;
470 
471  SDL_Window * const window = get_Window().get_window();
472  if(window && SDL_GetWindowGrab(window) == SDL_TRUE)
473  return mouse_hidden ? MOUSE_GRABBED_AND_HIDDEN : MOUSE_GRABBED;
474  else
475  return mouse_hidden ? MOUSE_HIDDEN : MOUSE_NORMAL;
476  }
477 
478  void Window::set_mouse_state(const Window::Mouse_State &mouse_state) {
479  if(mouse_state == MOUSE_RELATIVE)
481  else {
483 
484  SDL_ShowCursor((mouse_state & MOUSE_HIDDEN) ? SDL_DISABLE : SDL_ENABLE);
485 
486  SDL_Window * const window = get_Window().get_window();
487  if(window)
488  SDL_SetWindowGrab(window, (mouse_state & MOUSE_GRABBED) ? SDL_TRUE : SDL_FALSE);
489  }
490  }
491 
492 #if SDL_VERSION_ATLEAST(1,3,0)
493  void Window::alert_window_destroyed() {
494  m_window = 0;
495  }
496 #endif
497 
498  void Window::alert_window_resized(const Point2i &resolution) {
499  g_screen_size = resolution;
500 
501 #ifndef TEMP_DISABLE
502 #if !defined(_WINDOWS)
503 #if SDL_VERSION_ATLEAST(1,3,0)
504 // if(m_window)
505 // SDL_DestroyWindow(m_window);
506 // m_window = 0;
507 #endif
508 
509  // Initialize Window
510 #if SDL_VERSION_ATLEAST(1,3,0)
511 // m_window = SDL_CreateWindow(get_m_title().c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, g_screen_size.x, g_screen_size.y,
512 // SDL_WINDOW_OPENGL |
513 // (g_screen_full ? SDL_WINDOW_FULLSCREEN
514 // : ((g_screen_show_frame ? SDL_WINDOW_OPENGL : SDL_WINDOW_BORDERLESS) |
515 // (g_screen_resizable ? SDL_WINDOW_RESIZABLE : SDL_WINDOW_OPENGL))));
516 #else
517  const SDL_VideoInfo *VideoInfo = SDL_GetVideoInfo();
518 
519  m_display_surface = SDL_SetVideoMode(g_screen_size.x, g_screen_size.y, 32,
520  SDL_OPENGL |
521  (g_screen_full ? SDL_FULLSCREEN
522  : (VideoInfo->wm_available ? ((g_screen_show_frame ? SDL_OPENGL : SDL_NOFRAME) |
523  (g_screen_resizable ? SDL_RESIZABLE : SDL_OPENGL))
524  : SDL_OPENGL)));
525 #endif
527 
528 #if SDL_VERSION_ATLEAST(1,3,0)
529  if(!m_window) {
530 #else
531  if(!m_display_surface) {
532 #endif
533  throw Window_Init_Failure();
534  }
535 
536 #if SDL_VERSION_ATLEAST(1,3,0)
537  set_tt();
538  set_icon();
539 
540  SDL_ShowWindow(m_window);
541 #else
542  g_screen_size.x = m_display_surface->w;
543  g_screen_size.y = m_display_surface->h;
544 #endif
545 #endif
546 #endif
547  }
548 
549  void Window::set_tt() {
550 #if SDL_VERSION_ATLEAST(1,3,0)
551  if(get_window())
552  SDL_SetWindowTitle(get_window(), get_m_title().c_str());
553 #elif !defined(ANDROID)
554  const SDL_VideoInfo *VideoInfo = SDL_GetVideoInfo();
555  if(VideoInfo->wm_available)
556  SDL_WM_SetCaption(get_m_title().c_str(), get_m_taskmsg().c_str());
557 #endif
558  }
559 
560  bool Window::set_icon() {
561 #if !defined(ANDROID) && !defined(_MACOSX)
562 #if !SDL_VERSION_ATLEAST(1,3,0)
563  const SDL_VideoInfo *VideoInfo = SDL_GetVideoInfo();
564  if(!VideoInfo->wm_available)
565  return false;
566 #endif
567 
568  if(m_icon_surface) {
569  SDL_FreeSurface(m_icon_surface);
570  m_icon_surface = 0;
571  }
572 
573  Image icon(get_m_icon());
574  if(icon.color_space() != Image::RGBA) {
575  std::cerr << "Display window icon must be RGBA.\n";
576  return false;
577  }
578 
579  m_icon_surface = SDL_CreateRGBSurfaceFrom(icon.get_data(), icon.width(), icon.height(), 32, 4 * icon.width(), 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
580  if(!m_icon_surface) {
581  std::cerr << "Could not load display window icon.\n";
582  return false;
583  }
584 
585 #if SDL_VERSION_ATLEAST(1,3,0)
586  if(get_window())
587  SDL_SetWindowIcon(get_window(), m_icon_surface);
588 #else
589  SDL_WM_SetIcon(m_icon_surface, NULL);
590 #endif
591 #endif
592 
593  return true;
594  }
595 
596  String & Window::get_m_title() {
597  static String title = "zenilib Application";
598  return title;
599  }
600 
601  String & Window::get_m_taskmsg() {
602  static String taskmsg = "zenilib Application";
603  return taskmsg;
604  }
605 
606  String & Window::get_m_icon() {
607 #ifdef _MACOSX
608  static String icon = "icons/icon_mac.png";
609 #else
610  static String icon = "icons/icon.png";
611 #endif
612  return icon;
613  }
614 
615  bool Window::g_screen_full = false;
616  bool Window::g_screen_show_frame = true;
617  bool Window::g_screen_resizable = true;
618  bool Window::g_opengl_flag = true;
619 #endif
620 
621  bool Window::g_enabled = true;
622 
623  Point2i Window::g_screen_size;
624 
625 }
DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo *info)
This function allows access to driver-dependent window information.
Definition: SDL_video.c:3002
Mouse_State get_mouse_state() const
Find out if the mouse cursor is grabbed/hidden/relative.
Definition: Window.cpp:465
DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface)
Definition: SDL_surface.c:1053
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
#define SDL_WINDOWPOS_CENTERED
Definition: SDL_video.h:128
static void assert_no_error()
If there is an SDL error, print it and assert(false)
Definition: Core.cpp:122
int32_t Sint32
A signed 32-bit integer type.
Definition: SDL_stdinc.h:141
static void preinit_show_frame(const bool &show_frame_=true)
Show a frame around the rendering window when in windowed mode.
Definition: Window.cpp:409
#define MINIMUM_SCREEN_WIDTH
Definition: Define.h:126
#define EGL_RED_SIZE
Definition: egl.h:100
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:7294
#define EGL_WINDOW_BIT
Definition: egl.h:149
EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
void * EGLConfig
Definition: egl.h:46
#define NULL
Definition: ftobjs.h:61
#define MINIMUM_SCREEN_HEIGHT
Definition: Define.h:127
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
#define EGL_NO_SURFACE
Definition: egl.h:71
static void set_title(const String &title)
Set the window title.
Definition: Window.cpp:445
DECLSPEC int SDLCALL SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
Definition: SDL_mouse.c:698
#define EGL_SURFACE_TYPE
Definition: egl.h:114
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
static void set_taskmsg(const String &taskmsg)
Set the taskbar message.
Definition: Window.cpp:452
DECLSPEC SDL_bool SDLCALL SDL_GetWindowGrab(SDL_Window *window)
Get a window&#39;s input grab mode.
Definition: SDL_video.c:2037
const Uint8 * get_data() const
Get access to the raw image data.
Definition: Image.hxx:29
The structure that defines a display mode.
Definition: SDL_video.h:53
SDL_version version
Definition: SDL_syswm.h:161
#define EGL_NONE
Definition: egl.h:119
#define memset
Definition: SDL_malloc.c:633
#define SDL_ENABLE
Definition: SDL_events.h:688
static bool is_initialized()
DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex)
Returns the number of available display modes.
Definition: SDL_video.c:713
void set_mouse_state(const Mouse_State &mouse_state)
Definition: Window.cpp:478
khronos_int32_t EGLint
Definition: eglplatform.h:127
static void preinit_resizable(const bool &resizable_=true)
Allow the frame to be dynamically resized when in windows mode.
Definition: Window.cpp:413
#define EGL_HEIGHT
Definition: egl.h:167
static void preinit_full_screen(const bool &full_screen=false)
Set the rendering window to be full screen at launch.
Definition: Window.cpp:405
static void remove_post_reinit(Event::Handler *const &handler)
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
const GLint * attribs
Definition: glew.h:13064
void lend_post_reinit(Event::Handler *const &handler)
Definition: Singleton.hxx:76
void lend_pre_uninit(Event::Handler *const &handler)
Definition: Singleton.hxx:56
Image.
Definition: Image.h:52
#define EGL_NO_DISPLAY
Definition: egl.h:70
DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_Window *window, SDL_bool grabbed)
Set a window&#39;s input grab mode.
Definition: SDL_video.c:2021
void ZENI_LOGW(const Zeni::String &str)
Definition: Android.h:56
#define EGL_BLUE_SIZE
Definition: egl.h:98
#define EGL_NATIVE_VISUAL_ID
Definition: egl.h:110
#define EGL_DEFAULT_DISPLAY
Definition: egl.h:68
DECLSPEC void SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon)
Set the icon for a window.
Definition: SDL_video.c:1445
static void set_tt(const String &title, const String &taskmsg)
Set the window title and taskbar message.
Definition: Window.cpp:437
EGLAPI EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
Definition: SDL_version.h:79
EGLAPI EGLBoolean EGLAPIENTRY eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value)
Set an OpenGL window attribute before window creation.
Definition: SDL_video.c:2469
static void preinit_resolution(const Point2i &resolution=Point2i(800, 600))
Set the rendering window to have a given resolution.
Definition: Window.cpp:401
The Core Singleton.
Definition: Core.h:53
static void remove_pre_uninit(Event::Handler *const &handler)
#define EGL_NO_CONTEXT
Definition: egl.h:69
#define FAILSAFE_SCREEN_WIDTH
Definition: Define.h:124
static void set_enabled(const bool &enabled)
Enable/Disable the use of rendering; This will not close the rendering window once it is open...
Definition: Window.cpp:396
void set_screen_saver(const bool &enabled)
Enable/Disable the screen saver.
Definition: Core.cpp:99
static bool set_icon(const String &filename)
Set the window icon.
Definition: Window.cpp:459
DECLSPEC void SDLCALL SDL_ShowWindow(SDL_Window *window)
Show a window.
Definition: SDL_video.c:1722
Uint8 BitsPerPixel
Definition: SDL_pixels.h:276
DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex, SDL_DisplayMode *mode)
Fill in information about a specific display mode.
Definition: SDL_video.c:721
DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags)
Definition: SDL.c:103
static TYPE & get()
Definition: Singleton.hxx:31
DECLSPEC void SDLCALL SDL_SetWindowTitle(SDL_Window *window, const char *title)
Set the title of a window, in UTF-8 format.
Definition: SDL_video.c:1417
Color_Space color_space() const
Determine the Color_Space of the raw image data.
Definition: Image.hxx:25
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
DECLSPEC int SDLCALL SDL_GetDisplayBounds(int displayIndex, SDL_Rect *rect)
Get the desktop area represented by a display, with the primary display located at 0...
Definition: SDL_video.c:638
static VIDEO_MODE get_video_mode()
Get the currently selected video mode.
Definition: Video.hxx:33
int w
Definition: SDL_rect.h:66
DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
Definition: SDL_surface.c:122
union SDL_SysWMinfo::@78 info
EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
#define EGL_FALSE
Definition: egl.h:64
DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
Definition: SDL_mouse.c:430
void alert_window_resized(const Point2i &resolution)
Tell Window that it has been resized.
Definition: Window.cpp:498
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
#define SDL_DISABLE
Definition: SDL_events.h:687
#define SDL_INIT_VIDEO
Definition: SDL.h:110
DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void)
Query whether relative mouse mode is enabled.
Definition: SDL_mouse.c:478
EGLAPI EGLDisplay EGLAPIENTRY eglGetDisplay(EGLNativeDisplayType display_id)
DECLSPEC SDL_Window *SDLCALL SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)
Create a window with the specified position, dimensions, and flags.
Definition: SDL_video.c:1190
static void preinit_from_file(const String &filename)
Set rendering options from a file.
Definition: Video.cpp:336
int width() const
Get the number of pixels in the image in the x-direction.
Definition: Image.hxx:41
int h
Definition: SDL_rect.h:66
static bool print_error()
If there is an SDL error, print it and then clear it; returns true iff there was an error...
Definition: Core.cpp:132
static void set_opengl_flag(const bool &on=true)
Definition: Window.cpp:433
EGLConfig config
Definition: eglext.h:257
int height() const
Get the number of pixels in the image in the y-direction.
Definition: Image.hxx:45
#define EGL_GREEN_SIZE
Definition: egl.h:99
Core & get_Core()
Get access to the singleton.
Definition: Core.cpp:71
DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window *window)
Destroy a window.
Definition: SDL_video.c:2154
static bool get_vertical_sync()
Determine whether vertical sync is enabled.
Definition: Video.hxx:53
static const bool & get_opengl_flag()
Definition: Window.cpp:429
GLint GLint GLint GLint GLint w
Definition: gl2ext.h:1215
#define SDL_QUERY
Definition: SDL_events.h:685
int i
Definition: pngrutil.c:1377
static bool window_mode_lt(const Point2i &lhs, const Point2i &rhs)
Definition: Window.cpp:43
static void set_failsafe_defaults()
Set failsafe default options.
Definition: Window.cpp:423
File_Ops & get_File_Ops()
Get access to the singleton.
Definition: File_Ops.cpp:118
#define FAILSAFE_SCREEN_HEIGHT
Definition: Define.h:125
EGLAPI EGLContext EGLAPIENTRY eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
static void preinit_from_xml(const XML_Element_c &video)
Set rendering options from an XML data structure.
Definition: Window.cpp:417
The Window Management Singleton.
Definition: Window.h:53
GLenum mode
Definition: glew.h:2394
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:63
#define EGL_WIDTH
Definition: egl.h:168
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags)
Definition: SDL.c:241
A 2D Point represented with integers.
Definition: Coordinate.h:85