nomlib
Loading...
Searching...
No Matches
nom::RenderWindow Class Reference
Inheritance diagram for nom::RenderWindow:
[legend]

Public Types

typedef RenderWindow SelfType
typedef SelfType * RawPtr

Public Member Functions

 RenderWindow (void)
 Default constructor; initialize an object to sane, but invalid defaults.
 ~RenderWindow (void)
 Destructor; the current rendering context for the object is freed at this time.
 RenderWindow (const SelfType &copy)=delete
 Copy constructor.
SelfType & operator= (const SelfType &other)=delete
 Copy assignment operator.
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.
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.
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.
SDL_SURFACE::RawPtr window_surface (void) const
 Obtain a SDL_Surface pointer from this Window.
bool valid (void) const
 Get validity of the window and rendering context.
bool window_valid (void) const
 Is this object initialized – not nullptr?
Point2i position () const
 Get the window's current position.
Size2i size (void) const
 Get this window's size dimensions.
const uint8 bits_per_pixel (void) const
 Obtain the BPP (bits per pixel) of this window.
uint32 window_flags (void) const
uint32 pixel_format (void) const
const IntRect display_bounds (void) const
bool display_modes (DisplayModeList &modes) const
 Get the display mode capabilities of the window.
int refresh_rate () const
 Get a video mode's refresh rate for the display of the window.
void set_size (int32 width, int32 height)
void set_position (const Point2i &window_pos)
 Set the window's position.
bool flip (void) const
bool fullscreen (void) const
 Getter for fullscreen_ state variable.
void set_fullscreen (bool state)
 Set new fullscreen state.
bool toggle_fullscreen (void)
 Set this window full screen if it is windowed, and windowed if it is full screen.
bool toggle_fullscreen (uint32 flags)
const std::string window_title (void) const
void set_window_title (const std::string &title)
bool set_window_icon (const std::string &filename)
 Set an icon for this window.
uint32 window_id (void) const
int window_display_id () const
 Get the display index associated with this window.
std::string display_name () const
 Get the display name associated with this window.
SDL_Window * mouse_focus (void) const
 Get the window which currently has mouse focus.
void enable_screensaver (void)
void disable_screensaver (void)
bool screen_saver (void)
void maximize_window (void)
void minimize_window (void)
void raise_window (void)
void restore_window (void)
void show_window (void)
void hide_window (void)
void set_window_grab (bool grab)
void set_minimum_window_size (int min_width, int min_height)
void set_maximum_window_size (int max_width, int max_height)
bool save_png_file (const std::string &filename) const
 Output a screen-shot of the window as a PNG file.
bool save_screenshot (const std::string &filename) const
void make_current (void)
Public Member Functions inherited from nom::Renderer
 Renderer (void)
 Default constructor; initializes instance to sane defaults.
virtual ~Renderer (void)
 Lazy destructor with nothing to do.
bool create (SDL_WINDOW::RawPtr window, int rendering_driver=DEFAULT_RENDERING_DRIVER, uint32 renderer_flags=DEFAULT_RENDERER_FLAGS)
SDL_Renderer * renderer (void) const
 Get a raw pointer to the SDL_Renderer in use.
bool renderer_valid (void) const
 Is this object initialized? Valid when NOT nullptr.
Size2i logical_size () const
 Get the current logical resolution size.
const Point2f scale () const
 Get the drawing scale for the rendering context.
const IntRect viewport (void) const
 Get the current viewport dimensions.
const SDL_BlendMode blend_mode (void) const
 Obtain the blending mode used for drawing.
Size2i output_size (void) const
 Get the renderer's output size dimensions.
IntRect clip_bounds () const
 Obtain the renderer's clipping rectangle bounds (in pixels).
const RendererInfo caps (void) const
 Obtain information specific to your rendering hardware capabilities.
bool reset_render_target () const
 Set the current rendering target back to the default renderer.
bool set_render_target (const Texture *texture) const
 Set a texture as the current rendering target.
void update (void) const
 Update the renderer surface on the attached window.
bool clear (void) const
bool fill (const Color4i &color)
bool set_logical_size (int width, int height)
bool set_logical_size (const Size2i &size)
bool set_scale (const Point2f &scale_factor)
 Set the drawing scale for this rendering context.
bool set_viewport (const IntRect &bounds)
bool set_color (const Color4i &color)
bool set_blend_mode (const SDL_BlendMode mode)
bool set_clip_bounds (const IntRect &bounds)
 Set new clipping rectangle bounds for the rendering target.
void * pixels () const
 Obtain pixels buffer of the entire rendering target.

Static Public Member Functions

static SDL_WINDOW::RawPtr window_id (uint32 id)
static std::string display_name (int display_id)
 Get the display name associated with a window.
static SDL_Renderer * context (void)
 Obtain the active rendering context.
static int num_video_displays ()
 Get the number of available video displays.
Static Public Member Functions inherited from nom::Renderer
static const RendererInfo caps (SDL_Renderer *target)
 Obtain information specific to your rendering hardware capabilities.

Static Public Attributes

static const Point2i DEFAULT_WINDOW_POS
static const Point2i WINDOW_POS_CENTERED
static const uint32 DEFAULT_WINDOW_FLAGS = 0
Static Public Attributes inherited from nom::Renderer
static const int DEFAULT_RENDERING_DRIVER = -1
 The index of the default rendering driver to use.
static const uint32 DEFAULT_RENDERER_FLAGS

Static Private Member Functions

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 any given time for generating resources – nom::Texture, nom::Image, etc.

Private Attributes

SDL_WINDOW::UniquePtr window_
uint32 window_id_
 The unique identifier as recognized internally by SDL.
int window_display_id_
 The unique identifier given to the display.
bool enabled_
 State of the window (visible or not).
bool fullscreen_
 Toggle window & full-screen states.

Static Private Attributes

static SDL_Renderer * context_

Additional Inherited Members

Protected Attributes inherited from nom::Renderer
std::unique_ptr< SDL_Renderer, void(*)(SDL_Renderer *)> renderer_

Detailed Description

Definition at line 56 of file RenderWindow.hpp.

Member Typedef Documentation

◆ RawPtr

typedef SelfType* nom::RenderWindow::RawPtr

Definition at line 60 of file RenderWindow.hpp.

◆ SelfType

typedef RenderWindow nom::RenderWindow::SelfType

Definition at line 59 of file RenderWindow.hpp.

Constructor & Destructor Documentation

◆ ~RenderWindow()

nom::RenderWindow::~RenderWindow ( void )

Destructor; the current rendering context for the object is freed at this time.

Remarks
The rendering context becomes invalid when the owning window object is freed. Note that any and all resources that were created using this context will also become invalid at this point.

◆ RenderWindow()

nom::RenderWindow::RenderWindow ( const SelfType & copy)
delete

Copy constructor.

Remarks
This resource has been marked non-copyable.

Member Function Documentation

◆ context()

SDL_Renderer * nom::RenderWindow::context ( void )
static

Obtain the active rendering context.

Returns
Pointer to the SDL_Renderer structure containing the active rendering context.
Remarks
Used internally within nomlib for automatically using the active context – set by nom::RenderWindow::make_current.

◆ create()

bool nom::RenderWindow::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.

Parameters
posThe position of the window, relative to the video display bounds.
display_indexThe video display to position the window on.
See also
nom::RenderWindow::DEFAULT_WINDOW_POS, nom::RenderWindow::WINDOW_POS_CENTERED
nom::RenderWindow::::display_bounds, nom::RenderWindow::::display_modes

◆ disable_screensaver()

void nom::RenderWindow::disable_screensaver ( void )

Prevent the screen from being blanked by a screen saver.

It is automatically re-enabled by SDL upon exit.

Todo
Test me

◆ display_bounds()

const IntRect nom::RenderWindow::display_bounds ( void ) const

Get the desktop area represented by a display monitor

The primary desktop display is located at 0, 0.

Returns
nom::IntRect object filled with the display bounds.
Todo
Test me

◆ display_modes()

bool nom::RenderWindow::display_modes ( DisplayModeList & modes) const

Get the display mode capabilities of the window.

Parameters
modesThe object reference to fill with the list of display video modes.
Returns
Boolean TRUE if the enumeration of display video models was successful, and boolean FALSE if the enumeration was non-successful.
Remarks
The display video modes will be sorted from greater to least.
See also
nom::DisplayMode, SDL_DisplayMode

◆ display_name() [1/2]

std::string nom::RenderWindow::display_name ( ) const

Get the display name associated with this window.

Returns
The name of the display on success, and a NULL-terminated string on failure.
Remarks
The display name is platform-dependent.

◆ display_name() [2/2]

std::string nom::RenderWindow::display_name ( int display_id)
static

Get the display name associated with a window.

Returns
The name of the display on success, and a NULL-terminated string on failure.
Remarks
The display name is platform-dependent.

◆ enable_screensaver()

void nom::RenderWindow::enable_screensaver ( void )

Allow the screen to be blanked by a screen saver.

Todo
Test me

◆ flip()

bool nom::RenderWindow::flip ( void ) const

Update the surface of the screen inside the window

(For use only with SDL Surfaces API)

Equivalent to SDL 1.2 API SDL_Flip()

◆ hide_window()

void nom::RenderWindow::hide_window ( void )

Hide this window

Todo
Test me

◆ make_current()

void nom::RenderWindow::make_current ( void )

Set the current Window as the active rendering context; this must be called before doing any drawing (this includes creation of textures) when using multiple rendering windows.

◆ maximize_window()

void nom::RenderWindow::maximize_window ( void )

Maximize this window.

Todo
Test me

◆ minimize_window()

void nom::RenderWindow::minimize_window ( void )

Minimize this window.

Todo
Test me

◆ mouse_focus()

SDL_Window * nom::RenderWindow::mouse_focus ( void ) const

Get the window which currently has mouse focus.

Returns
The window with mouse focus.

◆ num_video_displays()

int nom::RenderWindow::num_video_displays ( )
static

Get the number of available video displays.

Returns
The number of video displays – a number greater than or equal to one (1) on success, or a negative number on failure.

◆ operator=()

SelfType & nom::RenderWindow::operator= ( const SelfType & other)
delete

Copy assignment operator.

Remarks
This resource has been marked non-copyable.

◆ raise_window()

void nom::RenderWindow::raise_window ( void )

Raise this window.

Todo
Test me

◆ refresh_rate()

int nom::RenderWindow::refresh_rate ( ) const

Get a video mode's refresh rate for the display of the window.

Returns
The video mode vertical refresh rate, in hertz, or zero (0) if unspecified on success, or negative one (-1) on failure, such as if the enumeration of the current display video mode for the window failed.

◆ restore_window()

void nom::RenderWindow::restore_window ( void )

Restore this window.

Todo
Test me

◆ save_png_file()

bool nom::RenderWindow::save_png_file ( const std::string & filename) const

Output a screen-shot of the window as a PNG file.

Parameters
filenameAbsolute or relative file path.
Todo
Restructure code shared with ::save_screenshot.
See also
RenderWindow::save_screenshot, Image::save_png.

◆ save_screenshot()

bool nom::RenderWindow::save_screenshot ( const std::string & filename) const

Save a screen shot of the window as a PNG file

Parameters
filenameAbsolute or relative file path
Returns
std::string containing the complete file path to the saved image on success – a null-terminated string on failure.
Remarks
This method automatically appends a unique ID onto the end of the given filename string.
Todo
Pixels pitch calculation (see screenshot.initialize call)
See also
RenderWindow::save_png_file, Image::save_png.

◆ screen_saver()

bool nom::RenderWindow::screen_saver ( void )

Get the status of the OS screensaver.

Returns
TRUE if enabled; FALSE if disabled.
Todo
Test me

◆ set_maximum_window_size()

void nom::RenderWindow::set_maximum_window_size ( int max_width,
int max_height )

Set the maximum size of the window's client area.

Parameters
max_widthMaximum width of window in pixels
max_heightMaximum height of window in pixels
Todo
Test me

◆ set_minimum_window_size()

void nom::RenderWindow::set_minimum_window_size ( int min_width,
int min_height )

Set the minimum size of the window's client area.

Parameters
min_widthMinimum width of window in pixels
min_heightMinimum height of window in pixels
Todo
Test me

◆ set_window_grab()

void nom::RenderWindow::set_window_grab ( bool grab)

Set the window input grab mode.

Parameters
grabTRUE to grab input; FALSE to release input
Todo
Test me

◆ set_window_icon()

bool nom::RenderWindow::set_window_icon ( const std::string & filename)

Set an icon for this window.

Remarks
A nom::RenderWindow must first be initialized before using this method call; see nom::RenderWindow::create

◆ show_window()

void nom::RenderWindow::show_window ( void )

Show this window

Todo
Test me

◆ size()

Size2i nom::RenderWindow::size ( void ) const

Get this window's size dimensions.

Returns
Size2i object filled with the width and height fields.

◆ toggle_fullscreen() [1/2]

bool nom::RenderWindow::toggle_fullscreen ( uint32 flags)

Set this window full screen if it is windowed, and windowed if it is full screen.

Parameters
flagsSDL_WINDOW_FULLSCREEN_DESKTOP || SDL_WINDOW_FULLSCREEN

◆ toggle_fullscreen() [2/2]

bool nom::RenderWindow::toggle_fullscreen ( void )

Set this window full screen if it is windowed, and windowed if it is full screen.

Note
This method calls SDL_WINDOW_FULLSCREEN_DESKTOP

◆ window_display_id()

int nom::RenderWindow::window_display_id ( ) const

Get the display index associated with this window.

Returns
The index of the display containing the center of the window on success, and a negative error code on failure.
Remarks
The display identifier order is platform-dependent.

◆ window_id() [1/2]

SDL_WINDOW::RawPtr nom::RenderWindow::window_id ( uint32 id)
static

Obtain a pointer to a SDL_Window struct by ID.

Parameters
idUnique identifier used for the lookup
Returns
SDL_Window pointer if exists; NULL if no Window exists
Todo
Is there a reason why this is a static method???
Todo
Rename to window_from_id?

◆ window_id() [2/2]

uint32 nom::RenderWindow::window_id ( void ) const

Obtain this window's unique identifier

Returns
This window's unique identifier

Member Data Documentation

◆ context_

SDL_Renderer* nom::RenderWindow::context_
staticprivate

Definition at line 377 of file RenderWindow.hpp.

◆ DEFAULT_WINDOW_FLAGS

const uint32 nom::RenderWindow::DEFAULT_WINDOW_FLAGS = 0
static

Definition at line 64 of file RenderWindow.hpp.

◆ DEFAULT_WINDOW_POS

const Point2i nom::RenderWindow::DEFAULT_WINDOW_POS
static

Definition at line 62 of file RenderWindow.hpp.

◆ enabled_

bool nom::RenderWindow::enabled_
private

State of the window (visible or not).

Definition at line 388 of file RenderWindow.hpp.

◆ fullscreen_

bool nom::RenderWindow::fullscreen_
private

Toggle window & full-screen states.

Definition at line 391 of file RenderWindow.hpp.

◆ window_

SDL_WINDOW::UniquePtr nom::RenderWindow::window_
private

Definition at line 379 of file RenderWindow.hpp.

◆ window_display_id_

int nom::RenderWindow::window_display_id_
private

The unique identifier given to the display.

Definition at line 385 of file RenderWindow.hpp.

◆ window_id_

uint32 nom::RenderWindow::window_id_
private

The unique identifier as recognized internally by SDL.

Definition at line 382 of file RenderWindow.hpp.

◆ WINDOW_POS_CENTERED

const Point2i nom::RenderWindow::WINDOW_POS_CENTERED
static

Definition at line 63 of file RenderWindow.hpp.


The documentation for this class was generated from the following file: