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 "export.hpp"
38#include "nomlib/config.hpp"
39#include "nomlib/math/Rect.hpp"
40#include "nomlib/math/Color4.hpp"
41#include "nomlib/math/Point2.hpp"
42#include "nomlib/graphics/DisplayMode.hpp"
43#include "nomlib/graphics/Renderer.hpp"
44#include "nomlib/graphics/Image.hpp"
45#include "nomlib/system/SDL_helpers.hpp"
46#include "nomlib/core/clock.hpp"
47#include "nomlib/system/File.hpp"
48
49namespace nom {
50
52struct NOM_EXPORT PixelsDeleter
53{
54 void operator()(void* ptr);
55};
56
57class NOM_EXPORT RenderWindow: public Renderer
58{
59 public:
60 typedef RenderWindow SelfType;
61 typedef SelfType* RawPtr;
62
63 static const Point2i DEFAULT_WINDOW_POS;
64 static const Point2i WINDOW_POS_CENTERED;
65 static const uint32 DEFAULT_WINDOW_FLAGS = 0;
66
69 RenderWindow( void );
70
78
82 RenderWindow( const SelfType& copy ) = delete;
83
87 SelfType& operator =( const SelfType& other ) = delete;
88
90 bool create( const std::string& window_title, const Size2i& res,
91 uint32 window_flags,
92 int rendering_driver = DEFAULT_RENDERING_DRIVER,
93 uint32 renderer_flags = DEFAULT_RENDERER_FLAGS );
94
107 bool create( const std::string& window_title, const Point2i& pos,
108 int display_index, const Size2i& res, uint32 window_flags,
109 int rendering_driver = DEFAULT_RENDERING_DRIVER,
110 uint32 renderer_flags = DEFAULT_RENDERER_FLAGS );
111
113 RenderWindow::RawPtr get ( void );
114
116 SDL_WINDOW::RawPtr window ( void ) const;
117
119 SDL_SURFACE::RawPtr window_surface ( void ) const;
120
122 bool valid( void ) const;
123
125 bool window_valid( void ) const;
126
128 Point2i position() const;
129
133 Size2i size( void ) const;
134
136 uint8 bits_per_pixel ( void ) const;
137
138 uint32 window_flags ( void ) const;
139
140 uint32 pixel_format ( void ) const;
141
149 const IntRect display_bounds ( void ) const;
150
162 bool display_modes(DisplayModeList& modes) const;
163
169 int refresh_rate() const;
170
171 void set_size ( int32 width, int32 height );
172
174 void set_position(const Point2i& window_pos);
175
181 bool flip ( void ) const;
182
184 bool fullscreen ( void ) const;
185
187 void set_fullscreen ( bool state );
188
193 bool toggle_fullscreen ( void );
194
199 bool toggle_fullscreen ( uint32 flags );
200
201 const std::string window_title ( void ) const;
202
203 void set_window_title ( const std::string& title );
204
209 bool set_window_icon ( const std::string& filename );
210
214 uint32 window_id( void ) const;
215
225 NOM_EXPORT static SDL_WINDOW::RawPtr window_id( uint32 id );
226
233 int window_display_id() const;
234
241 NOM_EXPORT static std::string display_name(int display_id);
242
249 std::string display_name() const;
250
254 SDL_Window* mouse_focus( void ) const;
255
259 void enable_screensaver ( void );
260
266 void disable_screensaver ( void );
267
273 bool screen_saver ( void );
274
278 void maximize_window ( void );
279
283 void minimize_window ( void );
284
288 void raise_window ( void );
289
293 void restore_window ( void );
294
298 void show_window ( void );
299
303 void hide_window ( void );
304
310 void set_window_grab(bool grab);
311
318 void set_minimum_window_size ( int min_width, int min_height );
319
326 void set_maximum_window_size ( int max_width, int max_height );
327
335 bool save_png_file(const std::string& filename) const;
336
350 bool save_screenshot(const std::string& filename) const;
351
355 void make_current ( void );
356
364 NOM_EXPORT static SDL_Renderer* context( void );
365
370 NOM_EXPORT static int num_video_displays();
371
372 private:
376 NOM_NO_EXPORT static void set_context ( RenderWindow::RawPtr window );
377
378 NOM_NO_EXPORT static SDL_Renderer* context_;
379
380 SDL_WINDOW::UniquePtr window_;
381
384
387
390
393};
394
395namespace priv {
396
401extern RenderWindow* render_dev_;
402
403} // namespace priv
404
405NOM_EXPORT RenderWindow* render_interface();
406NOM_EXPORT void set_render_interface(RenderWindow& win);
407
408} // namespace nom
409
410#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
bool screen_saver(void)
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)
static NOM_EXPORT std::string display_name(int display_id)
Get the display name associated with a window.
void hide_window(void)
void disable_screensaver(void)
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
static NOM_EXPORT int num_video_displays()
Get the number of available video displays.
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 NOM_EXPORT SDL_WINDOW::RawPtr window_id(uint32 id)
static NOM_EXPORT SDL_Renderer * context(void)
Obtain the active rendering context.
uint8 bits_per_pixel(void) const
Obtain the BPP (bits per pixel) of this window.
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?
static NOM_NO_EXPORT void set_context(RenderWindow::RawPtr window)
Set a new nom::RenderWindow as the active rendering context; we must always have a context active at ...
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.
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.
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.
Renderer(void)
Default constructor; initializes instance to sane defaults.
static NOM_EXPORT const int DEFAULT_RENDERING_DRIVER
The index of the default rendering driver to use.
Definition Renderer.hpp:63
Custom deleter for void* return of Renderer::pixels().