Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
window.h
1 #pragma once
2 
3 #define GLFW_EXPOSE_NATIVE_WIN32
4 
5 #include "util/string.h"
6 #include "util/tuple.h"
7 
8 #include <GLFW/glfw3.h>
9 #include <GLFW/glfw3native.h>
10 
11 #include "win32/key_code.h"
12 #include "win32/keyboard_state.h"
13 #include "win32/mouse_state.h"
14 #include "util/resolution.h"
15 
16 #include <DirectXMath.h>
17 
18 struct GLFWwindow;
19 
20 namespace blowbox
21 {
22  class Image;
23 
30  class Window
31  {
32  public:
33  Window();
34  ~Window();
35 
42  void Create(const Resolution& resolution, const String& window_title, Image* window_icon = nullptr);
43 
48  void SetWindowResolution(const Resolution& resolution);
49 
54  void SetWindowTitle(const String& window_title);
55 
61  void SetWindowSizeLimits(const Resolution& min_resolution, const Resolution& max_resolution);
62 
67  void SetWindowPosition(const DirectX::XMINT2& window_position);
68 
73  void SetWindowIcon(Image* window_icon);
74 
76  void Focus();
77 
80 
82  String GetWindowTitle() const;
83 
86 
88  DirectX::XMINT2 GetWindowPosition() const;
89 
91  Image* GetWindowIcon() const;
92 
94  bool GetWindowFocused() const;
95 
97  HWND GetWindowHandle() const;
98 
100  GLFWwindow* GetGLFWWindow();
101 
104 
107 
109  bool GetWindowShouldClose();
110 
119  static void GlfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int modifiers);
120 
126  static void GlfwCharCallback(GLFWwindow* window, unsigned int unicode_character);
127 
134  static void GlfwCursorPosCallback(GLFWwindow* window, double x, double y);
135 
143  static void GlfwMouseButtonCallback(GLFWwindow* window, int button, int action, int modifiers);
144 
151  static void GlfwScrollCallback(GLFWwindow* window, double x, double y);
152 
158  static void GlfwMouseEnterCallback(GLFWwindow* window, int entered);
159 
165  static void GlfwFocusCallback(GLFWwindow* window, int focused);
166 
167  private:
168  GLFWwindow* window_;
173 
176 
177  bool focused_;
178  };
179 }
Resolution max_resolution_
The maximum resolution of the window.
Definition: window.h:172
bool GetWindowFocused() const
Definition: window.cc:129
Image * window_icon_
The currently bound icon.
Definition: window.h:169
void SetWindowTitle(const String &window_title)
Sets the title of the window.
Definition: window.cc:55
static void GlfwKeyCallback(GLFWwindow *window, int key, int scancode, int action, int modifiers)
This is the callback function that is used for key input.
Definition: window.cc:165
static void GlfwFocusCallback(GLFWwindow *window, int focused)
This is the callback function that is used for when the mouse enters/leaves the window.
Definition: window.cc:228
void SetWindowPosition(const DirectX::XMINT2 &window_position)
Sets the position of the window.
Definition: window.cc:70
static void GlfwMouseEnterCallback(GLFWwindow *window, int entered)
This is the callback function that is used for when the mouse enters/leaves the window.
Definition: window.cc:220
bool GetWindowShouldClose()
Definition: window.cc:159
Image * GetWindowIcon() const
Definition: window.cc:123
Class for creating windows.
Definition: window.h:30
KeyboardState & GetKeyboardState()
Definition: window.cc:147
DirectX::XMINT2 GetWindowPosition() const
Definition: window.cc:115
GLFWwindow * window_
The underlying window that GLFW uses.
Definition: window.h:168
Resolution min_resolution_
The minimum resolution of the window.
Definition: window.h:171
String window_title_
The title of window.
Definition: window.h:170
Tuple< Resolution, Resolution > GetWindowSizeLimits() const
Definition: window.cc:109
eastl::tuple< Ts... > Tuple
Typedef for wrapping the EASTL tuple.
Definition: tuple.h:14
static void GlfwCursorPosCallback(GLFWwindow *window, double x, double y)
This is the callback function that is used for mouse movement input.
Definition: window.cc:189
static void GlfwCharCallback(GLFWwindow *window, unsigned int unicode_character)
This is the callback function that is used for character input.
Definition: window.cc:181
static void GlfwScrollCallback(GLFWwindow *window, double x, double y)
This is the callback function that is used for mouse scroll input.
Definition: window.cc:212
Keeps track of the state of the keyboard.
Definition: keyboard_state.h:18
void SetWindowResolution(const Resolution &resolution)
Sets the resolution of the window.
Definition: window.cc:49
eastl::string String
Typedef for wrapping the EASTL string.
Definition: string.h:13
Stores resolution information in pixels.
Definition: resolution.h:12
Resolution GetWindowResolution() const
Definition: window.cc:95
HWND GetWindowHandle() const
Definition: window.cc:135
void Create(const Resolution &resolution, const String &window_title, Image *window_icon=nullptr)
Creates the window. Resolution and window title are required. Window icon is optional.
Definition: window.cc:26
The main Blowbox namespace.
Definition: image.cc:8
String GetWindowTitle() const
Definition: window.cc:103
bool focused_
Whether the window is currently in input focus or not.
Definition: window.h:177
MouseState & GetMouseState()
Definition: window.cc:153
Load and access image files with the use of blowbox::Image.
Definition: image.h:36
void SetWindowSizeLimits(const Resolution &min_resolution, const Resolution &max_resolution)
Sets the size limits of the window.
Definition: window.cc:62
GLFWwindow * GetGLFWWindow()
Definition: window.cc:141
Keeps track of the state of the mouse.
Definition: mouse_state.h:18
void SetWindowIcon(Image *window_icon)
Sets the icon of the window.
Definition: window.cc:76
MouseState mouse_state_
The state of the mouse for this window.
Definition: window.h:175
void Focus()
Makes the window the focus of the input.
Definition: window.cc:89
static void GlfwMouseButtonCallback(GLFWwindow *window, int button, int action, int modifiers)
This is the callback function that is used for mouse movement input.
Definition: window.cc:196
KeyboardState keyboard_state_
The state of the keyboard for this window.
Definition: window.h:174