Window.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_SDL2_WINDOW_HPP
30 #define NOMLIB_SDL2_WINDOW_HPP
31 
32 #include <iostream>
33 #include <string>
34 #include <cstdlib>
35 #include <vector>
36 #include <memory>
37 
38 #include "SDL.h"
39 
40 #include "nomlib/config.hpp"
41 #include "nomlib/math/Coords.hpp"
42 #include "nomlib/math/Color.hpp"
43 #include "nomlib/math/Point2-inl.hpp"
44 #include "nomlib/graphics/VideoMode.hpp"
45 #include "nomlib/graphics/Renderer.hpp"
46 #include "nomlib/graphics/Image.hpp"
47 #include "nomlib/SDL_helpers.hpp"
48 
49 namespace nom {
50 
51 //class Renderer;
52 
53 class Window:
54  public Renderer
55 {
56  public:
57  typedef Window* RawPtr;
58 
59  Window ( void );
60  ~Window ( void );
61 
65  bool create (
66  const std::string& window_title, int32 width, int32 height,
67  uint32 window_flags,
68  uint32 context_flags = SDL_RENDERER_ACCELERATED
69  );
70 
72  Window::RawPtr get ( void );
73 
75  SDL_WINDOW::RawPtr window ( void ) const;
76 
78  SDL_SURFACE::RawPtr window_surface ( void ) const;
79 
81  bool window_valid ( void ) const;
82 
84  Point2i position ( void ) const;
85 
89  Point2i size ( void ) const;
90 
94  //const uint8 getDisplayColorBits ( void ) const;
95 
96  uint32 window_flags ( void ) const;
97  //uint16 getDisplayPitch ( void ) const;
98 
100  //void* pixels ( void ) const;
101 
102  uint32 pixel_format ( void ) const;
103 
111  const Coords display_bounds ( void ) const;
112 
118  VideoModeList getVideoModes ( void ) const;
119 
120  void set_position ( int32 x, int32 y );
121 
125  void draw ( SDL_SURFACE::RawPtr video_buffer, const Coords& bounds ) const;
126 
132  bool flip ( void ) const;
133 
135  bool fullscreen ( void ) const;
136 
138  void set_fullscreen ( bool state );
139 
147  bool toggle_fullscreen ( void );
148 
149  const std::string window_title ( void ) const;
150 
151  void set_window_title ( const std::string& title );
152 
154  bool set_window_icon ( const std::string& filename );
155 
159  uint32 window_id ( void ) const;
160 
166  static SDL_WINDOW::RawPtr window_id ( uint32 id );
167 
171  int window_display_id ( void ) const;
172 
176  void enable_screensaver ( void );
177 
183  void disable_screensaver ( void );
184 
190  bool screen_saver ( void );
191 
195  void maximize_window ( void );
196 
200  void minimize_window ( void );
201 
205  void raise_window ( void );
206 
210  void restore_window ( void );
211 
215  void show_window ( void );
216 
220  void hide_window ( void );
221 
227  void set_window_grab ( bool grab );
228 
235  void set_minimum_window_size ( int min_width, int min_height );
236 
243  void set_maximum_window_size ( int max_width, int max_height );
244 
249  bool save_screenshot ( const std::string& filename ) const;
250 
254  void set_active ( void );
255 
260  static SDL_RENDERER::RawPtr context ( void );
261 
268  static void set_context ( Window::RawPtr window );
269 
270  private:
271  static SDL_RENDERER::RawPtr context_;
272 
273  SDL_WINDOW::UniquePtr window_;
274 
276  uint32 window_id_;
277 
280 
282  bool enabled_;
283 
286 
289  //bool mustLock ( void ) const;
290 };
291 
292 
293 } // namespace nom
294 
295 #endif // include guard defined
void draw(SDL_SURFACE::RawPtr video_buffer, const Coords &bounds) const
Definition: Window.cpp:280
static SDL_RENDERER::RawPtr context(void)
Definition: Window.cpp:491
SDL_WINDOW::RawPtr window(void) const
Returns a raw pointer to the SDL_Window struct in use for this object.
Definition: Window.cpp:109
const Coords bounds(void) const
Definition: Renderer.cpp:135
uint32 window_id_
Cache the unique window identifier we get from SDL upon initialization.
Definition: Window.hpp:276
void disable_screensaver(void)
Definition: Window.cpp:403
bool create(const std::string &window_title, int32 width, int32 height, uint32 window_flags, uint32 context_flags=SDL_RENDERER_ACCELERATED)
Definition: Window.cpp:57
void set_minimum_window_size(int min_width, int min_height)
Definition: Window.cpp:448
bool save_screenshot(const std::string &filename) const
Definition: Window.cpp:458
const Coords display_bounds(void) const
Definition: Window.cpp:188
bool fullscreen(void) const
Getter for fullscreen_ state variable.
Definition: Window.cpp:315
bool flip(void) const
Definition: Window.cpp:305
bool enabled_
State of the window (visible or not)
Definition: Window.hpp:282
void maximize_window(void)
Definition: Window.cpp:413
bool fullscreen_
Toggle window &amp; full-screen states.
Definition: Window.hpp:285
SDL_SURFACE::RawPtr window_surface(void) const
Obtain a SDL_Surface pointer from this Window.
Definition: Window.cpp:114
void show_window(void)
Definition: Window.cpp:433
void hide_window(void)
Definition: Window.cpp:438
void restore_window(void)
Definition: Window.cpp:428
void raise_window(void)
Definition: Window.cpp:423
uint32 window_flags(void) const
Definition: Window.cpp:161
static void set_context(Window::RawPtr window)
Definition: Window.cpp:496
Video subsystem responsible for managing high-level graphics display (think: very fancy back-buffer)...
Definition: Renderer.hpp:49
uint32 pixel_format(void) const
Obtain a pointer to this object&#39;s pixels.
Definition: Window.cpp:183
Point2i position(void) const
Obtain this Window&#39;s position.
Definition: Window.cpp:126
int window_display_id_
Cache the display identifier we get from SDL upon initialization.
Definition: Window.hpp:279
void set_maximum_window_size(int max_width, int max_height)
Definition: Window.cpp:453
VideoModeList getVideoModes(void) const
Definition: Window.cpp:207
bool window_valid(void) const
Is this object initialized – not nullptr?
Definition: Window.cpp:119
bool toggle_fullscreen(void)
Definition: Window.cpp:327
uint32 window_id(void) const
Definition: Window.cpp:388
Coordinate values (x, y, z, width, height ) wrapper.
Definition: Coords.hpp:44
int window_display_id(void) const
Definition: Window.cpp:398
void enable_screensaver(void)
void set_fullscreen(bool state)
Set new fullscreen state.
Definition: Window.cpp:322
bool set_window_icon(const std::string &filename)
Set an icon for this window.
Definition: Window.cpp:366
void set_active(void)
Definition: Window.cpp:486
void minimize_window(void)
Definition: Window.cpp:418
Point2i size(void) const
Definition: Window.cpp:135
void set_window_grab(bool grab)
Definition: Window.cpp:443
bool screen_saver(void)
Definition: Window.cpp:408