zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Window.h
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 
30 #ifndef ZENI_WINDOW_H
31 #define ZENI_WINDOW_H
32 
33 #include <Zeni/Core.h>
34 #include <Zeni/Coordinate.h>
35 #include <Zeni/Image.h>
36 #include <Zeni/Singleton.h>
37 
38 #include <SDL/SDL.h>
39 
40 #ifdef ANDROID
41 #include <EGL/egl.h>
42 #endif
43 
44 namespace Zeni {
45 
46  class ZENI_GRAPHICS_DLL Window;
47  class XML_Document;
48 
49 #ifdef _WINDOWS
50  ZENI_GRAPHICS_EXT template class ZENI_GRAPHICS_DLL Singleton<Window>;
51 #endif
52 
53  class ZENI_GRAPHICS_DLL Window : public Singleton<Window> {
54  friend class Singleton<Window>;
55 
56  static Window * create();
57 
58 #ifdef _WINDOWS
59 #pragma warning( push )
60 #pragma warning( disable : 4251 )
61 #endif
62  static Uninit g_uninit;
63  static Reinit g_reinit;
64 #ifdef _WINDOWS
65 #pragma warning( pop )
66 #endif
67 
68  protected:
69  Window();
70  ~Window();
71 
72  private:
73  // Undefined
74  Window(const Window &);
75  Window & operator=(const Window &);
76 
77  public:
78  // Accessors
79  inline static const bool & is_enabled();
80  inline static const Point2i & get_size();
81  inline static const int & get_width();
82  inline static const int & get_height();
83 #ifndef ANDROID
84  inline static const bool & is_full_screen();
85  inline static const bool & is_frame_visible();
86  inline static const bool & is_resizable();
87  inline const std::vector<Point2i> & get_resolutions() const;
88 
89  // Window Decorations
90  inline const String & get_title() const;
91  inline const String & get_taskmsg() const;
92  static void set_tt(const String &title, const String &taskmsg);
93  static void set_title(const String &title);
94  static void set_taskmsg(const String &taskmsg);
95  static bool set_icon(const String &filename);
96 
97  // Mouse Functions
98  enum Mouse_State {MOUSE_NORMAL, MOUSE_GRABBED = 1, MOUSE_HIDDEN = 2, MOUSE_GRABBED_AND_HIDDEN = 3, MOUSE_RELATIVE = 7};
99  Mouse_State get_mouse_state() const;
100  void set_mouse_state(const Mouse_State &mouse_state);
101 #endif
102 
103  // Enable/Disable use of the Rendering Device
104  static void set_enabled(const bool &enabled);
105 
106 #ifdef ANDROID
107  inline EGLDisplay & get_display();
108  inline EGLSurface & get_surface();
109  inline EGLContext & get_context();
110  private:
111  EGLDisplay m_display;
112  EGLSurface m_surface;
113  EGLContext m_context;
114 #else
115  // Call before any other Window functions; May throw Window_Initialized
116  static void preinit_resolution(const Point2i &resolution = Point2i(800, 600));
117  static void preinit_full_screen(const bool &full_screen = false);
118  static void preinit_show_frame(const bool &show_frame_ = true);
119  static void preinit_resizable(const bool &resizable_ = true);
120  static void preinit_from_xml(const XML_Element_c &video);
121 
122  // Re/uninitialize the Rendering Device
123  static void set_failsafe_defaults();
124 
125  static const bool & get_opengl_flag();
126  static void set_opengl_flag(const bool &on = true);
127 
128 #if SDL_VERSION_ATLEAST(1,3,0)
129  inline SDL_Window * get_window();
130  virtual void alert_window_destroyed();
131 #endif
132  void alert_window_resized(const Point2i &resolution);
133 
134  protected:
135 #if !SDL_VERSION_ATLEAST(1,3,0)
136  inline SDL_Surface * get_display_surface();
137 #endif
138 
139  private:
140  // Set title and taskmsg texts
141  void set_tt();
142  // Set icon
143  bool set_icon();
144 
145 #if SDL_VERSION_ATLEAST(1,3,0)
146  SDL_Window *m_window;
147 #else
148  SDL_Surface *m_display_surface;
149 #endif
150  SDL_Surface *m_icon_surface;
151 
152  static bool g_screen_full;
153  static bool g_screen_show_frame;
154  static bool g_screen_resizable;
155  static bool g_opengl_flag;
156 
157  static String & get_m_title();
158  static String & get_m_taskmsg();
159  static String & get_m_icon();
160 
161 #ifdef _WINDOWS
162 #pragma warning( push )
163 #pragma warning( disable : 4251 )
164 #endif
165  std::vector<Point2i> m_modes;
166 #ifdef _WINDOWS
167 #pragma warning( pop )
168 #endif
169 #endif
170 
171  static bool g_enabled;
172 
173  static Point2i g_screen_size;
174  };
175 
176  ZENI_GRAPHICS_DLL Window & get_Window();
177 
178  struct ZENI_GRAPHICS_DLL Window_Init_Failure : public Error {
179  Window_Init_Failure() : Error("Zeni Window Failed to Initialize Correctly") {}
180  };
181 
182 }
183 
184 #endif
GLenum GLsizei const GLuint GLboolean enabled
Definition: glew.h:2538
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
void * EGLDisplay
Definition: egl.h:48
void * EGLSurface
Definition: egl.h:49
void * EGLContext
Definition: egl.h:47
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
The Error Class.
Definition: Error.h:52
The Window Management Singleton.
Definition: Window.h:53
A 2D Point represented with integers.
Definition: Coordinate.h:85