jubilant-funicular
Window.h
1 #ifndef NTA_WINDOW_H_INCLUDED
2 #define NTA_WINDOW_H_INCLUDED
3 
4 #include <mutex>
5 
6 #include <SDL2/SDL.h>
7 
8 #include "nta/MyEngine.h"
9 #include "nta/Wrapper.h"
10 
11 namespace nta {
12  class WindowManager;
15  enum WindowFlags {
16  INVISIBLE = 0x1,
17  FULLSCREEN = 0x2,
18  BORDERLESS = 0x4,
19  NOTRESIZEABLE = 0x8,
20  HIGHDPI = 0x10
21  };
24  friend class ScreenManager;
25  GetSDLWindowKey() {}
27  GetSDLWindowKey& operator=(const GetSDLWindowKey&);
28  };
30  class Window {
31  private:
32  static WindowID m_keyboard_focus;
33  static std::mutex m_keyboard_mutex;
34  static WindowID m_mouse_focus;
35  static std::mutex m_mouse_mutex;
36 
38  void createWindow(crstring title, int width, int height, int flags = 0);
40  SDL_Window* m_window;
42  std::string m_title;
44  int m_width, m_height;
45  public:
47  Window();
48  ~Window();
50  SDL_Window* getSDLWindow(GetSDLWindowKey key) const;
52  glm::vec2 getDimensions() const;
54  std::string getTitle() const;
56  WindowID getID() const { return SDL_GetWindowID(m_window); }
58  int getWidth() const;
60  int getHeight() const;
61  bool hasKeyboardFocus() const { return getKeyboardFocus() == getID(); }
62  bool hasMouseFocus() const { return getMouseFocus() == getID(); }
64  void resize(int width, int height);
66  void setDimensions(int width, int height);
68  void swapBuffers() const;
69 
70  static WindowID getKeyboardFocus();
71  static WindowID getMouseFocus();
72  static void setKeyboardFocus(const WindowID& win);
73  static void setMouseFocus(const WindowID& win);
74 
75  friend class WindowManager;
76  };
77 }
78 
79 #endif // NTA_WINDOW_H_INCLUDED
nta::Window::setDimensions
void setDimensions(int width, int height)
updates the window's stored dimensions
Definition: Window.cpp:65
utils::Wrapper
Definition: Wrapper.h:96
nta::Window::m_title
std::string m_title
the title of the window
Definition: Window.h:42
nta::Window::getWidth
int getWidth() const
returns the width of the window
Definition: Window.cpp:55
nta::WindowFlags
WindowFlags
Flags used for creating a window.
Definition: Window.h:15
nta::Window::resize
void resize(int width, int height)
resizes the window
Definition: Window.cpp:61
nta::GetSDLWindowKey
Key for unlocking the GetSDLWindow() "private" function of class Window.
Definition: Window.h:23
nta::Window::Window
Window()
constructor and destructor
Definition: Window.cpp:20
nta::Window::getDimensions
glm::vec2 getDimensions() const
returns the window's dimensions
Definition: Window.cpp:49
nta::Window
Represent a window.
Definition: Window.h:30
nta::Window::getID
WindowID getID() const
return the window's id
Definition: Window.h:56
nta::Window::swapBuffers
void swapBuffers() const
updates the screen
Definition: Window.cpp:123
nta::Window::getSDLWindow
SDL_Window * getSDLWindow(GetSDLWindowKey key) const
returns the underlying window
Definition: Window.cpp:30
nta
Definition: Animation2D.h:6
nta::ScreenManager
Definition: ScreenManager.h:16
nta::Window::getTitle
std::string getTitle() const
returns the window's title
Definition: Window.cpp:52
nta::Window::m_window
SDL_Window * m_window
the window
Definition: Window.h:40
nta::Window::createWindow
void createWindow(crstring title, int width, int height, int flags=0)
creates a window
Definition: Window.cpp:69
nta::Window::m_width
int m_width
the dimensions of the window
Definition: Window.h:44
nta::Window::getHeight
int getHeight() const
returns the height of the window
Definition: Window.cpp:58