SDL Utility
Window Class Reference

Stores information about a window. You probably want RenderWindow. More...

#include <Window.hpp>

Inheritance diagram for Window:
RenderWindow

Public Types

enum  Flags {
  Fullscreen = ((Uint32)1 << 0) , OpenGL = ((Uint32)1 << 1) , Shown = ((Uint32)1 << 2) , Hidden = ((Uint32)1 << 3) ,
  Borderless = ((Uint32)1 << 4) , Resizable = ((Uint32)1 << 5) , Minimized = ((Uint32)1 << 6) , Maximized = ((Uint32)1 << 7) ,
  InputGrabbed = ((Uint32)1 << 8) , InputFocus = ((Uint32)1 << 9) , MouseFocus = ((Uint32)1 << 10) , Foregin = ((Uint32)1 << 11) ,
  FullscreenDesktop = (Fullscreen | ((Uint32)1 << 12))
}
 

Public Member Functions

 Window ()
 Default Constructor. No window is created. More...
 
 Window (Vector2u dimension, const std::string &title, Uint32 windowFlags)
 Creates a window with the given parameters. More...
 
 Window (const Window &other)=delete
 
 Window (Window &&other)=delete
 
virtual ~Window ()
 
void Create (Vector2u dimension, const std::string &title, Uint32 windowFlags)
 Creates the window. More...
 
void Close ()
 Destroys the window. More...
 
bool IsOpen () const
 Wether or not the window object is created. More...
 
bool PollEvent (SDL_Event *event)
 A non-blocking event polling function. More...
 
bool WaitEvent (SDL_Event *event)
 A blocking event polling function. More...
 
Vector2i GetPosition () const
 Returns the current position of the window. More...
 
void SetPosition (Vector2i position)
 Sets a new window position. More...
 
void SetPosition (int x, int y)
 Sets a new window position. More...
 
Vector2u GetSize () const
 Gets the current window size. More...
 
void SetSize (Vector2u size)
 Sets a new window size. More...
 
void SetSize (unsigned int width, unsigned int height)
 Sets a new window size. More...
 
std::string GetTitle () const
 Gets the current window title. More...
 
void SetTitle (std::string title)
 Sets a new window title. More...
 
SDL_Window *const GetWindow () const
 Returns a constant pointer to the SDL_Window. More...
 
void SetVisible (bool visible)
 Set the windows visibility. More...
 
void SetVsync (bool vsync)
 (De)activates VSync !globally! More...
 
void SetMouseCursorVisible (bool visible)
 Hides/Shows the mouse cursor inside the windos. More...
 
void SetMouseCursorGrabbed (bool grabbed)
 Traps the mouse cursor inside the window. More...
 
void SetIcon (Uint32 width, Uint32 height, const Uint8 *pixels)
 Sets the window icon to an array of RGBA values. More...
 
void SetIcon (Uint32 width, Uint32 height, const Uint32 *pixels)
 Sets the window icon to an array of RGBA values. More...
 
void SetIcon (SDL_Surface *icon)
 Sets the window icon to a SDL_Surface. More...
 
void SetMouseCursor (SDL_Cursor *cursor)
 Changes the mouse cursor. More...
 
void SetMouseCursor (const Cursor &cursor)
 Changes the mouse cursor. More...
 

Protected Member Functions

virtual void OnCreate ()
 This function is called after Create() finishes. More...
 
virtual bool OnResize ()
 This function is called after a SDL_WINDOWEVENT_RESIZED is polled. (PollEvent() must be called for this to work) More...
 
virtual void OnClose ()
 This function is called after Close() finishes. More...
 

Protected Attributes

SDL_Window * window
 

Detailed Description

Stores information about a window. You probably want RenderWindow.

Member Enumeration Documentation

◆ Flags

Enumerator
Fullscreen 
OpenGL 
Shown 
Hidden 
Borderless 
Resizable 
Minimized 
Maximized 
InputGrabbed 
InputFocus 
MouseFocus 
Foregin 
FullscreenDesktop 

Constructor & Destructor Documentation

◆ Window() [1/4]

Window::Window ( )

Default Constructor. No window is created.

◆ Window() [2/4]

Window::Window ( Vector2u  dimension,
const std::string &  title,
Uint32  windowFlags 
)

Creates a window with the given parameters.

Parameters
[in]dimensionA vector containing the width and height
[in]titleThe title of the create window

◆ Window() [3/4]

Window::Window ( const Window other)
delete

◆ Window() [4/4]

Window::Window ( Window &&  other)
delete

◆ ~Window()

virtual Window::~Window ( )
virtual

Member Function Documentation

◆ Close()

void Window::Close ( )

Destroys the window.

◆ Create()

void Window::Create ( Vector2u  dimension,
const std::string &  title,
Uint32  windowFlags 
)

Creates the window.

This function creates the SDL_Window object. If they were already created the function does nothing and returns. If it fails to create either, an ObjectCreationException is thrown.

Parameters
[in]dimensionA vector containing the width and height
[in]titleThe title of the create window

◆ GetPosition()

Vector2i Window::GetPosition ( ) const

Returns the current position of the window.

Returns
A vector with the current position relative to the top left corner of the display

◆ GetSize()

Vector2u Window::GetSize ( ) const

Gets the current window size.

Returns
A vector with the windows size

◆ GetTitle()

std::string Window::GetTitle ( ) const

Gets the current window title.

Returns
The title of the widnow

◆ GetWindow()

SDL_Window* const Window::GetWindow ( ) const

Returns a constant pointer to the SDL_Window.

Returns
A constant pointer to SDL_Window

◆ IsOpen()

bool Window::IsOpen ( ) const

Wether or not the window object is created.

Returns
True if the window is open, False if not

◆ OnClose()

virtual void Window::OnClose ( )
protectedvirtual

This function is called after Close() finishes.

Reimplemented in RenderWindow.

◆ OnCreate()

virtual void Window::OnCreate ( )
protectedvirtual

This function is called after Create() finishes.

Reimplemented in RenderWindow.

◆ OnResize()

virtual bool Window::OnResize ( )
protectedvirtual

This function is called after a SDL_WINDOWEVENT_RESIZED is polled. (PollEvent() must be called for this to work)

Returns
True if the resize event should be popped from the event queue before returning the polled event to the user

Reimplemented in RenderWindow.

◆ PollEvent()

bool Window::PollEvent ( SDL_Event *  event)

A non-blocking event polling function.

Parameters
[out]eventAn object to write the latest event to
Returns
True if there was an event, False if there wasn't

◆ SetIcon() [1/3]

void Window::SetIcon ( SDL_Surface *  icon)

Sets the window icon to a SDL_Surface.

Parameters
[in]iconA SDL_Surface* holding the icon data

◆ SetIcon() [2/3]

void Window::SetIcon ( Uint32  width,
Uint32  height,
const Uint32 pixels 
)

Sets the window icon to an array of RGBA values.

Parameters
[in]widthWidth of the icon (in px)
[in]heightHeight of the icon (in px)
[in]pixelsArray of color data (RGBA as one 32-Bit integer value)

◆ SetIcon() [3/3]

void Window::SetIcon ( Uint32  width,
Uint32  height,
const Uint8 pixels 
)

Sets the window icon to an array of RGBA values.

Parameters
[in]widthWidth of the icon (in px)
[in]heightHeight of the icon (in px)
[in]pixelsArray of color data (RGBA as seperate 8-Bit integer values)

◆ SetMouseCursor() [1/2]

void Window::SetMouseCursor ( const Cursor cursor)

Changes the mouse cursor.

Parameters
[in]cursorThe cursor object holding cursor data

◆ SetMouseCursor() [2/2]

void Window::SetMouseCursor ( SDL_Cursor *  cursor)

Changes the mouse cursor.

Parameters
[in]cursorA pointer to a SDL_Cursor containing cursor data

◆ SetMouseCursorGrabbed()

void Window::SetMouseCursorGrabbed ( bool  grabbed)

Traps the mouse cursor inside the window.

Parameters
[in]grabbedWether to (un)trap the cursor

◆ SetMouseCursorVisible()

void Window::SetMouseCursorVisible ( bool  visible)

Hides/Shows the mouse cursor inside the windos.

Parameters
[in]visibleThe new visibility of the cursor

◆ SetPosition() [1/2]

void Window::SetPosition ( int  x,
int  y 
)

Sets a new window position.

Parameters
[in]xThe new x position
[in]yThe new y position

◆ SetPosition() [2/2]

void Window::SetPosition ( Vector2i  position)

Sets a new window position.

Parameters
[in]positionA vector with the new position

◆ SetSize() [1/2]

void Window::SetSize ( unsigned int  width,
unsigned int  height 
)

Sets a new window size.

Parameters
[in]widthThe new width of the window
[in]heightThe new height of the window

◆ SetSize() [2/2]

void Window::SetSize ( Vector2u  size)

Sets a new window size.

Parameters
[in]sizeA vector with the new size

◆ SetTitle()

void Window::SetTitle ( std::string  title)

Sets a new window title.

Parameters
[in]titleThe new window title

◆ SetVisible()

void Window::SetVisible ( bool  visible)

Set the windows visibility.

Parameters
[in]visibleThe new visibility setting

◆ SetVsync()

void Window::SetVsync ( bool  vsync)

(De)activates VSync !globally!

Parameters
[in]vsyncWether to enable or disable vsync

◆ WaitEvent()

bool Window::WaitEvent ( SDL_Event *  event)

A blocking event polling function.

Parameters
[out]eventAn object to write the latest event to
Returns
True if an event was polled

Member Data Documentation

◆ window

SDL_Window* Window::window
protected

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