GameKit  0.0.1a
C++ gamedev tools
Window.hpp
Go to the documentation of this file.
1 /*
2  * =====================================================================================
3  *
4  * Filename: Window.hpp
5  *
6  * Description:
7  *
8  * Created: 20/12/2014 00:16:51
9  *
10  * Author: Quentin Bazin, <quent42340@gmail.com>
11  *
12  * =====================================================================================
13  */
14 #ifndef GK_WINDOW_HPP_
15 #define GK_WINDOW_HPP_
16 
17 #include <memory>
18 #include <string>
19 
20 #include "gk/core/IntTypes.hpp"
21 #include "gk/core/SDLHeaders.hpp"
22 #include "gk/gl/RenderTarget.hpp"
23 
24 namespace gk {
25 
26 class Window : public RenderTarget {
27  public:
28  void open(const std::string &caption, u16 width, u16 height);
29 
30  void clear();
31  void display();
32 
33  void setVerticalSyncEnabled(bool enabled);
34 
35  Vector2u getSize() const override { return m_size; }
36 
37  void close() { m_isOpen = false; }
38  bool isOpen() const { return m_isOpen; }
39 
40  SDL_Window *window() const { return m_window.get(); }
41 
42  const View &getDefaultView() const override { return m_defaultView; }
43 
44  private:
45  using SDL_WindowPtr = std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)>;
46  using SDL_GLContextPtr = std::unique_ptr<void, decltype(&SDL_GL_DeleteContext)>;
47 
48  SDL_WindowPtr m_window{nullptr, SDL_DestroyWindow};
49  SDL_GLContextPtr m_context{nullptr, SDL_GL_DeleteContext};
50 
52 
53  bool m_isOpen;
54 
56 };
57 
58 } // namespace gk
59 
60 #endif // GK_WINDOW_HPP_
SDL_GLContextPtr m_context
Definition: Window.hpp:49
2D view that defines what is shown on screen
Definition: View.hpp:29
std::unique_ptr< SDL_Window, decltype(&SDL_DestroyWindow)> SDL_WindowPtr
Definition: Window.hpp:45
void setVerticalSyncEnabled(bool enabled)
Definition: Window.cpp:69
const View & getDefaultView() const override
Definition: Window.hpp:42
unsigned short u16
Definition: IntTypes.hpp:22
View m_defaultView
Definition: Window.hpp:55
void display()
Definition: Window.cpp:65
void open(const std::string &caption, u16 width, u16 height)
Definition: Window.cpp:21
std::unique_ptr< void, decltype(&SDL_GL_DeleteContext)> SDL_GLContextPtr
Definition: Window.hpp:46
SDL_Window * window() const
Definition: Window.hpp:40
bool isOpen() const
Definition: Window.hpp:38
SDL_WindowPtr m_window
Definition: Window.hpp:48
bool m_isOpen
Definition: Window.hpp:53
void close()
Definition: Window.hpp:37
Vector2u m_size
Definition: Window.hpp:51
Vector2u getSize() const override
Definition: Window.hpp:35
void clear()
Definition: Window.cpp:61