31 #if defined(_DEBUG) && defined(_WINDOWS)
32 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
40 template class Singleton<Window>;
44 return lhs.
x < rhs.
x || (lhs.
x == rhs.
x && lhs.
y < rhs.
y);
48 Window * Window::create() {
54 const String appdata_path = fo.get_appdata_path();
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";
61 static bool last_resort_taken =
false;
68 #ifndef DISABLE_GL_SHADER
78 #ifndef DISABLE_GL_FIXED
84 throw Window_Init_Failure();
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";
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";
102 else if(!last_resort_taken) {
105 last_resort_taken =
true;
113 last_resort_taken =
false;
119 Singleton<Window>::Uninit Window::g_uninit;
120 Singleton<Window>::Reinit Window::g_reinit;
129 #if SDL_VERSION_ATLEAST(1,3,0)
132 m_display_surface(0),
151 #if SDL_VERSION_ATLEAST(1,3,0)
153 for(
int i = 0;
i != num_modes; ++
i) {
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));
164 m_modes.push_back(
Point2i((*mode)->w, (*mode)->h));
206 ANativeWindow_setBuffersGeometry(
get_Core().get_state().window, 0, 0, format);
239 #if SDL_VERSION_ATLEAST(2,0,0)
242 const Sint32 current_w = rect.
w;
243 const Sint32 current_h = rect.
h;
245 const SDL_VideoInfo *VideoInfo = SDL_GetVideoInfo();
246 const Sint32 current_w = VideoInfo->current_w;
247 const Sint32 current_h = VideoInfo->current_h;
250 #if !SDL_VERSION_ATLEAST(1,3,0)
255 const Point2i &max_res = *m_modes.rbegin();
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;
263 else if(g_screen_size.x > max_res.
x)
264 g_screen_size.x = max_res.
x;
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;
272 else if(g_screen_size.y > max_res.
y)
273 g_screen_size.y = max_res.
y;
275 #if !SDL_VERSION_ATLEAST(1,3,0)
277 if(get_opengl_flag())
295 #if SDL_VERSION_ATLEAST(1,3,0)
306 m_display_surface = SDL_SetVideoMode(g_screen_size.x, g_screen_size.y, 32,
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))
315 #if SDL_VERSION_ATLEAST(1,3,0)
318 if(!m_display_surface) {
323 #if SDL_VERSION_ATLEAST(1,3,0)
329 g_screen_size.x = m_display_surface->w;
330 g_screen_size.y = m_display_surface->h;
337 #if SDL_VERSION_ATLEAST(2,0,0)
339 HWND hWnd = wmInfo.
info.win.window;
341 SDL_GetWMInfo(&wmInfo);
342 HWND hWnd = wmInfo.window;
345 if(FAILED(SetForegroundWindow(hWnd)))
346 SetActiveWindow(hWnd);
370 #if SDL_VERSION_ATLEAST(1,3,0)
380 alert_window_destroyed();
383 m_display_surface = 0;
402 g_screen_size = resolution;
406 g_screen_full = full_screen;
410 g_screen_show_frame = show_frame_;
414 g_screen_resizable = resizable_;
419 video[
"Resolution"][
"Height"].to_int()));
424 g_screen_full =
false;
430 return g_opengl_flag;
438 get_m_title() = title;
439 get_m_taskmsg() = taskmsg;
446 get_m_title() = title;
453 get_m_taskmsg() = taskmsg;
492 #if SDL_VERSION_ATLEAST(1,3,0)
493 void Window::alert_window_destroyed() {
499 g_screen_size = resolution;
502 #if !defined(_WINDOWS)
503 #if SDL_VERSION_ATLEAST(1,3,0)
510 #if SDL_VERSION_ATLEAST(1,3,0)
517 const SDL_VideoInfo *VideoInfo = SDL_GetVideoInfo();
519 m_display_surface = SDL_SetVideoMode(g_screen_size.
x, g_screen_size.
y, 32,
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))
528 #if SDL_VERSION_ATLEAST(1,3,0)
531 if(!m_display_surface) {
536 #if SDL_VERSION_ATLEAST(1,3,0)
542 g_screen_size.
x = m_display_surface->
w;
543 g_screen_size.
y = m_display_surface->
h;
549 void Window::set_tt() {
550 #if SDL_VERSION_ATLEAST(1,3,0)
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());
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)
573 Image icon(get_m_icon());
575 std::cerr <<
"Display window icon must be RGBA.\n";
580 if(!m_icon_surface) {
581 std::cerr <<
"Could not load display window icon.\n";
585 #if SDL_VERSION_ATLEAST(1,3,0)
589 SDL_WM_SetIcon(m_icon_surface,
NULL);
596 String & Window::get_m_title() {
597 static String title =
"zenilib Application";
601 String & Window::get_m_taskmsg() {
602 static String taskmsg =
"zenilib Application";
606 String & Window::get_m_icon() {
608 static String icon =
"icons/icon_mac.png";
610 static String icon =
"icons/icon.png";
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;
621 bool Window::g_enabled =
true;
DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMinfo *info)
This function allows access to driver-dependent window information.
Mouse_State get_mouse_state() const
Find out if the mouse cursor is grabbed/hidden/relative.
DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface *surface)
EGLAPI EGLBoolean EGLAPIENTRY eglTerminate(EGLDisplay dpy)
#define SDL_WINDOWPOS_CENTERED
static void assert_no_error()
If there is an SDL error, print it and assert(false)
int32_t Sint32
A signed 32-bit integer type.
static void preinit_show_frame(const bool &show_frame_=true)
Show a frame around the rendering window when in windowed mode.
#define MINIMUM_SCREEN_WIDTH
GLfloat GLfloat GLfloat GLfloat h
EGLAPI EGLBoolean EGLAPIENTRY eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
EGLAPI EGLSurface EGLAPIENTRY eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
#define MINIMUM_SCREEN_HEIGHT
EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
static void set_title(const String &title)
Set the window title.
DECLSPEC int SDLCALL SDL_ShowCursor(int toggle)
Toggle whether or not the cursor is shown.
GLenum GLsizei const GLuint GLboolean enabled
static void set_taskmsg(const String &taskmsg)
Set the taskbar message.
DECLSPEC SDL_bool SDLCALL SDL_GetWindowGrab(SDL_Window *window)
Get a window's input grab mode.
const Uint8 * get_data() const
Get access to the raw image data.
The structure that defines a display mode.
static bool is_initialized()
DECLSPEC int SDLCALL SDL_GetNumDisplayModes(int displayIndex)
Returns the number of available display modes.
void set_mouse_state(const Mouse_State &mouse_state)
static void preinit_resizable(const bool &resizable_=true)
Allow the frame to be dynamically resized when in windows mode.
static void preinit_full_screen(const bool &full_screen=false)
Set the rendering window to be full screen at launch.
static void remove_post_reinit(Event::Handler *const &handler)
EGLAPI EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
void lend_post_reinit(Event::Handler *const &handler)
void lend_pre_uninit(Event::Handler *const &handler)
DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_Window *window, SDL_bool grabbed)
Set a window's input grab mode.
void ZENI_LOGW(const Zeni::String &str)
#define EGL_NATIVE_VISUAL_ID
#define EGL_DEFAULT_DISPLAY
DECLSPEC void SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon)
Set the icon for a window.
static void set_tt(const String &title, const String &taskmsg)
Set the window title and taskbar message.
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.
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.
static void preinit_resolution(const Point2i &resolution=Point2i(800, 600))
Set the rendering window to have a given resolution.
static void remove_pre_uninit(Event::Handler *const &handler)
#define FAILSAFE_SCREEN_WIDTH
static void set_enabled(const bool &enabled)
Enable/Disable the use of rendering; This will not close the rendering window once it is open...
void set_screen_saver(const bool &enabled)
Enable/Disable the screen saver.
static bool set_icon(const String &filename)
Set the window icon.
DECLSPEC void SDLCALL SDL_ShowWindow(SDL_Window *window)
Show a window.
DECLSPEC int SDLCALL SDL_GetDisplayMode(int displayIndex, int modeIndex, SDL_DisplayMode *mode)
Fill in information about a specific display mode.
DECLSPEC int SDLCALL SDL_InitSubSystem(Uint32 flags)
DECLSPEC void SDLCALL SDL_SetWindowTitle(SDL_Window *window, const char *title)
Set the title of a window, in UTF-8 format.
Color_Space color_space() const
Determine the Color_Space of the raw image data.
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
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...
static VIDEO_MODE get_video_mode()
Get the currently selected video mode.
DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
union SDL_SysWMinfo::@78 info
EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurface(EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint *value)
DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled)
Set relative mouse mode.
void alert_window_resized(const Point2i &resolution)
Tell Window that it has been resized.
Window & get_Window()
Get access to the singleton.
DECLSPEC SDL_bool SDLCALL SDL_GetRelativeMouseMode(void)
Query whether relative mouse mode is enabled.
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.
static void preinit_from_file(const String &filename)
Set rendering options from a file.
int width() const
Get the number of pixels in the image in the x-direction.
static bool print_error()
If there is an SDL error, print it and then clear it; returns true iff there was an error...
static void set_opengl_flag(const bool &on=true)
int height() const
Get the number of pixels in the image in the y-direction.
Core & get_Core()
Get access to the singleton.
DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window *window)
Destroy a window.
static bool get_vertical_sync()
Determine whether vertical sync is enabled.
static const bool & get_opengl_flag()
GLint GLint GLint GLint GLint w
static bool window_mode_lt(const Point2i &lhs, const Point2i &rhs)
static void set_failsafe_defaults()
Set failsafe default options.
File_Ops & get_File_Ops()
Get access to the singleton.
#define FAILSAFE_SCREEN_HEIGHT
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.
The Window Management Singleton.
A rectangle, with the origin at the upper left.
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
DECLSPEC void SDLCALL SDL_QuitSubSystem(Uint32 flags)
A 2D Point represented with integers.