Window

namespace tnt
class render_lock
#include <Window.hpp>

A RAII class which clears the given window on its ctor, and calls Render on its destructor.

Public Functions

render_lock() noexcept = delete
render_lock(render_lock const&) noexcept = delete
render_lock &operator=(render_lock const&) noexcept = delete
render_lock(render_lock&&) noexcept = delete
render_lock &operator=(render_lock&&) noexcept = delete
render_lock(Window const &win) noexcept

Create a new render_lock.

Parameters
  • win: The window to clear/render.

~render_lock() noexcept

Private Members

SDL_Renderer *ren
class Window
#include <Window.hpp>

A class representing an application window.

Public Functions

Window(std::string_view title, int xpos, int ypos, int width, int height, Uint32 flags) noexcept

Creates a window with the given parameters.

Parameters
  • title: The title of the window.

  • xpos: The x position of the window.

  • ypos: The y position of the window.

  • width: The width of the window.

  • height: The height of the window.

  • flags: The flags the window should have.

Window(std::string_view title, int width, int height) noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
  • title: The title of the window.

  • width: The width of the window.

  • height: The height of the window.

~Window() noexcept

Destroys the window and clears the memory occupied by it.

operator SDL_Window*() noexcept

Returns the SDL_Window* of the Window.

Return

SDL_Window*

Note

SDL_Renderer* can be obtained by calling getRenderer().

SDL_Renderer *getRenderer() const noexcept

Returns the SDL_Renderer* of the Window.

Return

SDL_Renderer*

int getDisplayIndex() const noexcept

Get the display index of the window. The function returns the display index of the display containing the center of the window, or -1 on error.

Return

int

int setDisplayMode(const SDL_DisplayMode *mode) noexcept

Set the display mode used when a fullscreen window is visible. By default the window’s dimensions and the desktop format and refresh rate are used. The functions returns 0 on success, or -1 if setting the display mode failed.

Return

int

Parameters
  • mode: The mode to use, or NULL for the default mode.

SDL_DisplayMode *getDisplayMode() const noexcept

Fill in information about the display mode used when a fullscreen window is visible. Returns nullptr on error.

Return

SDL_DisplayMode*

int getWidth() const noexcept

Returns the width of the window.

Return

int

int getHeight() const noexcept

Returns the height of the window.

Return

int

void setWidth(int const width) noexcept

Change the width of the window.

See

tnt::Window::setHeight

See

tnt::Window::setSize

Parameters
  • width: The new width.

void setHeight(int const height) noexcept

Change the height of the window.

See

tnt::Window::setWidth

See

tnt::Window::setSize

Parameters
  • height: The new height.

void setSize(int const width, int const height) noexcept

Change the width and height of the window.

See

tnt::Window::setWidth

See

tnt::Window::setHeight

Parameters
  • width: The new width.

  • height: The new height.

Uint32 getPixelFormat() const noexcept

Get the pixel format associated with the window.

Return

unsigned int

Uint32 getID() const noexcept

Get the numeric ID of a window, for logging purposes.

Return

unsigned int

Uint32 getFlags() const noexcept

Get the window flags.

Return

unsigned int

void setTitle(char const *title) noexcept

Set the title of a window, in UTF-8 format.

Parameters
  • title: The desired title for the window.

char const *getTitle() const noexcept

Get the title of the window.

Return

const char*

void setIcon(SDL_Surface *icon) noexcept

Set a surface as the window icon.

Parameters
  • icon: The target SDL_Surface* to be set as an icon.

void setIcon(std::string_view icon) noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
  • icon: The path of the image to be used as icon.

int *getBordersSize() const noexcept

Get the size of a window’s borders (decorations) around the client area. The function’s 5-th return is 0 on success,.

Return

int* to an array with 5 members.

Note

if this function fails (returns -1), the size values of the other array members will be initialized to 0, 0, 0, 0 (if a non-NULL pointer is provided), as if the window in question was borderless.

void Clear() noexcept

Clear the current rendering target with the drawing color. This function clears the entire rendering target, ignoring the viewport and the clip rectangle.

void Render() noexcept

Update the screen with rendering performed.

void handleEvents(SDL_Event const &events) noexcept

Handle some window-related events.

Parameters
  • events: The events handler.

void setClearColor(SDL_Color const &color) noexcept

Set the color used for drawing operations (Rect, Line and Clear).

Parameters
  • color: The color used to draw on the Window’s renderer.

void setClearColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) noexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
  • r: Red.

  • g: Green.

  • b: Blue.

  • a: Alpha.

SDL_Color getClearColor() const noexcept

Get the color used for drawing operations.

Return

SDL_Color

bool isOpened() const noexcept

Check if the window is open so that events can be handled.

Return

bool

Private Members

bool running
int w
int h
SDL_Renderer *renderer
SDL_Window *window