nomlib
Loading...
Searching...
No Matches
RenderWindow.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. 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
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON 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
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_GRAPHICS_RENDER_WINDOW_HPP
30#define NOMLIB_GRAPHICS_RENDER_WINDOW_HPP
31
32#include <vector>
33#include <memory>
34
35#include <SDL.h>
36
37#include "nomlib/config.hpp"
38#include "nomlib/math/Rect.hpp"
39#include "nomlib/math/Color4.hpp"
40#include "nomlib/math/Point2.hpp"
41#include "nomlib/graphics/DisplayMode.hpp"
42#include "nomlib/graphics/Renderer.hpp"
43#include "nomlib/graphics/Image.hpp"
44#include "nomlib/system/SDL_helpers.hpp"
45#include "nomlib/core/clock.hpp"
46#include "nomlib/system/File.hpp"
47
48namespace nom {
49
52{
53 void operator()(void* ptr);
54};
55
57{
58 public:
59 typedef RenderWindow SelfType;
60 typedef SelfType* RawPtr;
61
62 static const Point2i DEFAULT_WINDOW_POS;
63 static const Point2i WINDOW_POS_CENTERED;
64 static const uint32 DEFAULT_WINDOW_FLAGS = 0;
65
68 RenderWindow( void );
69
77
81 RenderWindow( const SelfType& copy ) = delete;
82
86 SelfType& operator =( const SelfType& other ) = delete;
87
89 bool create( const std::string& window_title, const Size2i& res,
90 uint32 window_flags,
91 int rendering_driver = DEFAULT_RENDERING_DRIVER,
92 uint32 renderer_flags = DEFAULT_RENDERER_FLAGS );
93
106 bool create( const std::string& window_title, const Point2i& pos,
107 int display_index, const Size2i& res, uint32 window_flags,
108 int rendering_driver = DEFAULT_RENDERING_DRIVER,
109 uint32 renderer_flags = DEFAULT_RENDERER_FLAGS );
110
112 RenderWindow::RawPtr get ( void );
113
115 SDL_WINDOW::RawPtr window ( void ) const;
116
118 SDL_SURFACE::RawPtr window_surface ( void ) const;
119
121 bool valid( void ) const;
122
124 bool window_valid( void ) const;
125
127 Point2i position() const;
128
132 Size2i size( void ) const;
133
135 const uint8 bits_per_pixel ( void ) const;
136
137 uint32 window_flags ( void ) const;
138
139 uint32 pixel_format ( void ) const;
140
148 const IntRect display_bounds ( void ) const;
149
161 bool display_modes(DisplayModeList& modes) const;
162
168 int refresh_rate() const;
169
170 void set_size ( int32 width, int32 height );
171
173 void set_position(const Point2i& window_pos);
174
180 bool flip ( void ) const;
181
183 bool fullscreen ( void ) const;
184
186 void set_fullscreen ( bool state );
187
192 bool toggle_fullscreen ( void );
193
198 bool toggle_fullscreen ( uint32 flags );
199
200 const std::string window_title ( void ) const;
201
202 void set_window_title ( const std::string& title );
203
208 bool set_window_icon ( const std::string& filename );
209
213 uint32 window_id( void ) const;
214
224 static SDL_WINDOW::RawPtr window_id( uint32 id );
225
232 int window_display_id() const;
233
240 static std::string display_name(int display_id);
241
248 std::string display_name() const;
249
253 SDL_Window* mouse_focus( void ) const;
254
258 void enable_screensaver ( void );
259
265 void disable_screensaver ( void );
266
272 bool screen_saver ( void );
273
277 void maximize_window ( void );
278
282 void minimize_window ( void );
283
287 void raise_window ( void );
288
292 void restore_window ( void );
293
297 void show_window ( void );
298
302 void hide_window ( void );
303
309 void set_window_grab(bool grab);
310
317 void set_minimum_window_size ( int min_width, int min_height );
318
325 void set_maximum_window_size ( int max_width, int max_height );
326
334 bool save_png_file(const std::string& filename) const;
335
349 bool save_screenshot(const std::string& filename) const;
350
354 void make_current ( void );
355
363 static SDL_Renderer* context( void );
364
369 static int num_video_displays();
370
371 private:
375 static void set_context ( RenderWindow::RawPtr window );
376
377 static SDL_Renderer* context_;
378
379 SDL_WINDOW::UniquePtr window_;
380
383
386
389
392};
393
394namespace priv {
395
400extern RenderWindow* render_dev_;
401
402} // namespace priv
403
404RenderWindow* render_interface();
405void set_render_interface(RenderWindow& win);
406
407} // namespace nom
408
409#endif // include guard defined
void restore_window(void)
void enable_screensaver(void)
int window_display_id_
The unique identifier given to the display.
bool create(const std::string &window_title, const Size2i &res, uint32 window_flags, int rendering_driver=DEFAULT_RENDERING_DRIVER, uint32 renderer_flags=DEFAULT_RENDERER_FLAGS)
Initialize a native platform window and renderer.
const IntRect display_bounds(void) const
static std::string display_name(int display_id)
Get the display name associated with a window.
const uint8 bits_per_pixel(void) const
Obtain the BPP (bits per pixel) of this window.
bool screen_saver(void)
static int num_video_displays()
Get the number of available video displays.
bool enabled_
State of the window (visible or not).
Point2i position() const
Get the window's current position.
int window_display_id() const
Get the display index associated with this window.
void minimize_window(void)
void hide_window(void)
void disable_screensaver(void)
static void set_context(RenderWindow::RawPtr window)
Set a new nom::RenderWindow as the active rendering context; we must always have a context active at ...
bool flip(void) const
bool save_png_file(const std::string &filename) const
Output a screen-shot of the window as a PNG file.
void set_window_grab(bool grab)
bool save_screenshot(const std::string &filename) const
bool create(const std::string &window_title, const Point2i &pos, int display_index, const Size2i &res, uint32 window_flags, int rendering_driver=DEFAULT_RENDERING_DRIVER, uint32 renderer_flags=DEFAULT_RENDERER_FLAGS)
Initialize a native platform window and renderer.
bool toggle_fullscreen(uint32 flags)
SDL_SURFACE::RawPtr window_surface(void) const
Obtain a SDL_Surface pointer from this Window.
RenderWindow::RawPtr get(void)
Obtain a pointer to this Window object.
SDL_WINDOW::RawPtr window(void) const
Returns a raw pointer to the SDL_Window struct in use for this object.
void maximize_window(void)
void show_window(void)
uint32 window_id(void) const
~RenderWindow(void)
Destructor; the current rendering context for the object is freed at this time.
static SDL_WINDOW::RawPtr window_id(uint32 id)
bool set_window_icon(const std::string &filename)
Set an icon for this window.
bool fullscreen_
Toggle window & full-screen states.
void set_position(const Point2i &window_pos)
Set the window's position.
SDL_Window * mouse_focus(void) const
Get the window which currently has mouse focus.
void make_current(void)
void set_fullscreen(bool state)
Set new fullscreen state.
void set_minimum_window_size(int min_width, int min_height)
int refresh_rate() const
Get a video mode's refresh rate for the display of the window.
bool toggle_fullscreen(void)
Set this window full screen if it is windowed, and windowed if it is full screen.
void raise_window(void)
RenderWindow(void)
Default constructor; initialize an object to sane, but invalid defaults.
bool window_valid(void) const
Is this object initialized – not nullptr?
void set_maximum_window_size(int max_width, int max_height)
bool valid(void) const
Get validity of the window and rendering context.
RenderWindow(const SelfType &copy)=delete
Copy constructor.
SelfType & operator=(const SelfType &other)=delete
Copy assignment operator.
bool display_modes(DisplayModeList &modes) const
Get the display mode capabilities of the window.
uint32 window_id_
The unique identifier as recognized internally by SDL.
static SDL_Renderer * context(void)
Obtain the active rendering context.
Size2i size(void) const
Get this window's size dimensions.
bool fullscreen(void) const
Getter for fullscreen_ state variable.
std::string display_name() const
Get the display name associated with this window.
static const int DEFAULT_RENDERING_DRIVER
The index of the default rendering driver to use.
Definition Renderer.hpp:62
Renderer(void)
Default constructor; initializes instance to sane defaults.
Custom deleter for void* return of Renderer::pixels().