SDL Utility
Window.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 #include <string>
9 #include <chrono>
10 
11 #include "Util.hpp"
12 #include "structures/Vector2.hpp"
13 
14 struct SDL_Window;
15 union SDL_Event;
16 struct SDL_Surface;
17 struct SDL_Cursor;
18 
20 class Cursor;
21 
25 class Window
26 {
27 public:
28  enum Flags {
29  Fullscreen = ((Uint32)1 << 0),
30  OpenGL = ((Uint32)1 << 1),
31  Shown = ((Uint32)1 << 2),
32  Hidden = ((Uint32)1 << 3),
33  Borderless = ((Uint32)1 << 4),
34  Resizable = ((Uint32)1 << 5),
35  Minimized = ((Uint32)1 << 6),
36  Maximized = ((Uint32)1 << 7),
37  InputGrabbed = ((Uint32)1 << 8),
38  InputFocus = ((Uint32)1 << 9),
39  MouseFocus = ((Uint32)1 << 10),
40  Foregin = ((Uint32)1 << 11),
42  };
43 public:
47  Window();
48 
55  Window(Vector2u dimension, const std::string& title,
56  Uint32 windowFlags);
57 
58  Window(const Window& other) = delete;
59  Window(Window&& other) = delete;
60 
61  virtual ~Window();
62 
73  void Create(Vector2u dimension, const std::string& title,
74  Uint32 windowFlags);
75 
79  void Close();
80 
86  bool IsOpen() const;
87 
94  bool PollEvent(SDL_Event* event);
95 
102  bool WaitEvent(SDL_Event* event);
103 
104 
111 
117  void SetPosition(Vector2i position);
118 
125  void SetPosition(int x, int y);
126 
127 
133  Vector2u GetSize() const;
134 
140  void SetSize(Vector2u size);
141 
148  void SetSize(unsigned int width, unsigned int height);
149 
150 
156  std::string GetTitle() const;
157 
163  void SetTitle(std::string title);
164 
170  SDL_Window* const GetWindow() const;
171 
177  void SetVisible(bool visible);
178 
184  void SetVsync(bool vsync);
185 
191  void SetMouseCursorVisible(bool visible);
192 
198  void SetMouseCursorGrabbed(bool grabbed);
199 
207  void SetIcon(Uint32 width, Uint32 height, const Uint8* pixels);
208 
216  void SetIcon(Uint32 width, Uint32 height, const Uint32* pixels);
217 
223  void SetIcon(SDL_Surface* icon);
224 
230  void SetMouseCursor(SDL_Cursor* cursor);
231 
237  void SetMouseCursor(const Cursor& cursor);
238 
239 protected:
240  SDL_Window* window;
241 
242 protected:
246  virtual void OnCreate();
247 
255  virtual bool OnResize();
256 
260  virtual void OnClose();
261 };
262 SDLU_END
Basic utility macros, typedefs...
uint8_t Uint8
Definition: Util.hpp:17
#define SDLU_BEGIN
Definition: Util.hpp:32
uint32_t Uint32
Definition: Util.hpp:23
Provides a structure for simple vector calculations.
Definition: Cursor.hpp:12
Stores information about a window. You probably want RenderWindow.
Definition: Window.hpp:26
Window(Vector2u dimension, const std::string &title, Uint32 windowFlags)
Creates a window with the given parameters.
bool PollEvent(SDL_Event *event)
A non-blocking event polling function.
virtual void OnCreate()
This function is called after Create() finishes.
virtual void OnClose()
This function is called after Close() finishes.
void SetPosition(int x, int y)
Sets a new window position.
Window(const Window &other)=delete
bool WaitEvent(SDL_Event *event)
A blocking event polling function.
void SetIcon(Uint32 width, Uint32 height, const Uint32 *pixels)
Sets the window icon to an array of RGBA values.
void SetTitle(std::string title)
Sets a new window title.
void SetMouseCursor(SDL_Cursor *cursor)
Changes the mouse cursor.
void Close()
Destroys the window.
void SetIcon(Uint32 width, Uint32 height, const Uint8 *pixels)
Sets the window icon to an array of RGBA values.
Window(Window &&other)=delete
void SetSize(Vector2u size)
Sets a new window size.
void SetVisible(bool visible)
Set the windows visibility.
virtual ~Window()
virtual bool OnResize()
This function is called after a SDL_WINDOWEVENT_RESIZED is polled. (PollEvent() must be called for th...
Window()
Default Constructor. No window is created.
Vector2i GetPosition() const
Returns the current position of the window.
void SetVsync(bool vsync)
(De)activates VSync !globally!
void SetPosition(Vector2i position)
Sets a new window position.
void SetSize(unsigned int width, unsigned int height)
Sets a new window size.
void SetIcon(SDL_Surface *icon)
Sets the window icon to a SDL_Surface.
bool IsOpen() const
Wether or not the window object is created.
void SetMouseCursorGrabbed(bool grabbed)
Traps the mouse cursor inside the window.
SDL_Window * window
Definition: Window.hpp:240
void SetMouseCursor(const Cursor &cursor)
Changes the mouse cursor.
std::string GetTitle() const
Gets the current window title.
Flags
Definition: Window.hpp:28
@ OpenGL
Definition: Window.hpp:30
@ Shown
Definition: Window.hpp:31
@ FullscreenDesktop
Definition: Window.hpp:41
@ Hidden
Definition: Window.hpp:32
@ InputGrabbed
Definition: Window.hpp:37
@ MouseFocus
Definition: Window.hpp:39
@ InputFocus
Definition: Window.hpp:38
@ Fullscreen
Definition: Window.hpp:29
@ Minimized
Definition: Window.hpp:35
@ Borderless
Definition: Window.hpp:33
@ Resizable
Definition: Window.hpp:34
@ Maximized
Definition: Window.hpp:36
@ Foregin
Definition: Window.hpp:40
void SetMouseCursorVisible(bool visible)
Hides/Shows the mouse cursor inside the windos.
SDL_Window *const GetWindow() const
Returns a constant pointer to the SDL_Window.
void Create(Vector2u dimension, const std::string &title, Uint32 windowFlags)
Creates the window.
Vector2u GetSize() const
Gets the current window size.
A struct to handle basic 2D vector operations.
Definition: Vector2.hpp:22