BARE2D
Window.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <SDL2/SDL.h>
4 
5 #include "BAREErrors.hpp"
6 
7 namespace BARE2D {
8 
9  /**
10  * @class Window
11  * @brief It's a graphical window, holds the contexts for GL and SDL.
12  */
13  class Window
14  {
15  public:
16  Window();
17  ~Window();
18 
19  /**
20  * @brief This is a graphical window. It holds information about the GL context, as well as the SDL window context. Takes some flags on creation (SDL_WindowFlags):
21  * - SDL_WINDOW_FULLSCREEN
22  * - FULLSCREN_DESKTOP
23  * - OPENGL
24  * - VULKAN
25  * - SHOWN
26  * - HIDDEN
27  * - BORDERLESS
28  * - RESIZABLE
29  * - MIN/MAXIMIZED
30  * - INPUT_GRABBED
31  * - INPUT_FOCUS
32  * - MOUSE_FOCUS
33  * - FOREIGN
34  * - ALLOW_HIGHDPI
35  * - MOUSE_CAPTURE
36  * - ALWAYS_ON_TOP
37  * - SKIP_TASKBAR
38  * - UTILITY
39  * - TOOLTIP
40  * - POPUP_MENU
41  * These can be ORed together to transfer them to this function
42  * @return Returns an error (if one is created)
43  */
44  void create(unsigned int flags);
45 
46  /**
47  * @brief Sets the title of the window.
48  * @param newTitle The new title to be set!
49  */
50  void setTitle(std::string newTitle);
51 
52  /**
53  * @brief Sets the size of the window (defaults to 600x400)
54  * @param width
55  * @param height
56  */
57  void setSize(unsigned int width, unsigned int height);
58 
59  /**
60  * @brief Swaps the buffer of the SDL window - used to draw to one while the other displays, so no flickering is seen
61  */
62  void swapBuffer();
63 
64  /**
65  * @brief Returns the width of the window
66  */
67  unsigned int getWidth() const;
68 
69  /**
70  * @brief Returns the height of the window.
71  */
72  unsigned int getHeight() const;
73 
74  private:
75  SDL_Window* m_SDLWindow = nullptr;
76  SDL_GLContext m_GLContext = nullptr;
77 
78  unsigned int m_width = 600, m_height = 400;
79  std::string m_title = "BARE2D Window";
80  };
81 }
82 
BARE2D::Window::setSize
void setSize(unsigned int width, unsigned int height)
Sets the size of the window (defaults to 600x400)
Definition: Window.cpp:77
BARE2D
Definition: App.cpp:13
BARE2D::Window::m_title
std::string m_title
Definition: Window.hpp:79
BARE2D::Window::Window
Window()
Definition: Window.cpp:9
BARE2D::Window::m_width
unsigned int m_width
Definition: Window.hpp:78
BARE2D::Window::setTitle
void setTitle(std::string newTitle)
Sets the title of the window.
Definition: Window.cpp:72
BARE2D::Window::create
void create(unsigned int flags)
This is a graphical window. It holds information about the GL context, as well as the SDL window cont...
Definition: Window.cpp:20
BARE2D::Window::m_SDLWindow
SDL_Window * m_SDLWindow
Definition: Window.hpp:75
BARE2D::Window::~Window
~Window()
Definition: Window.cpp:13
BAREErrors.hpp
BARE2D::Window
It's a graphical window, holds the contexts for GL and SDL.
Definition: Window.hpp:13
BARE2D::Window::m_height
unsigned int m_height
Definition: Window.hpp:78
BARE2D::Window::swapBuffer
void swapBuffer()
Swaps the buffer of the SDL window - used to draw to one while the other displays,...
Definition: Window.cpp:89
BARE2D::Window::getWidth
unsigned int getWidth() const
Returns the width of the window.
Definition: Window.cpp:93
BARE2D::Window::getHeight
unsigned int getHeight() const
Returns the height of the window.
Definition: Window.cpp:97
BARE2D::Window::m_GLContext
SDL_GLContext m_GLContext
Definition: Window.hpp:76