Nui Engine
A game engine framework
Loading...
Searching...
No Matches
Window.h
1#pragma once
2#include "Core/Common/CommonHeaders.h"
3#include "Core/Input/Input.h"
4#include <map>
5
6namespace Nui
7{
11 class Window
12 {
13 public:
14
18 enum class Style
19 {
24
29
34
39 };
40
45 struct Size
46 {
50 I32 X;
51
55 I32 Y;
56 };
57
58#define NUI_WNDPROC_ARGS Nui::Window*, UINT, WPARAM, LPARAM
59#define NUI_WNDPROC_NAMED_ARGS Nui::Window* window, UINT uMsg, WPARAM wParam, LPARAM lParam
60 using WndCallback = std::function<LRESULT(NUI_WNDPROC_ARGS)>;
61
62 public:
63
71 explicit Window(Window::Style style, WStringView title, Window::Size size = { 1280, 720 });
72
77 virtual ~Window();
78
83 HWND GetHWND() const;
84
89 HINSTANCE GetHinstance() const;
90
95 Size GetClientSize() const;
96
101 void SetWindowTitle(WString title);
102
107 bool Maximized() const;
108
113 bool Focused() const;
114
119 bool WantsToClose() const;
120
127 void AddCallback(U32 msg, WndCallback callback);
128
129 private:
134 void AdjustMaximizedClientRect(RECT& rect);
135
140 void MakeWindow();
141
149 LRESULT MessageRouter(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
150
158 static LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
159
167 LRESULT MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
168
174 LRESULT HitTest(POINT cursor);
175
176 private:
180 HWND m_hWnd;
181
185 HINSTANCE m_hInstance;
186
190 Style m_style;
191
195 Size m_size;
196
200 WString m_title;
201
205 bool m_isFocused;
206
213 std::map<U32, WndCallback> m_callbacks;
214 };
215}
Class representing a window in the application.
Definition Window.h:12
HWND GetHWND() const
Get the window handle.
Definition Window.cpp:94
Style
Window styles.
Definition Window.h:19
@ WindowedFullscreen
Create maximized resizeable window.
@ Borderless
Create a non-resizeable window without border.
@ Windowed
Create resizeable window.
@ BorderlessFullscreen
Create maximized non-resizeable window without border.
bool Focused() const
Check if the window has focus.
Definition Window.cpp:111
void AddCallback(U32 msg, WndCallback callback)
Add a window message callback.
Definition Window.cpp:133
Size GetClientSize() const
Get the client size.
Definition Window.cpp:231
Window(Window::Style style, WStringView title, Window::Size size={ 1280, 720 })
Create a new window.
Definition Window.cpp:77
bool WantsToClose() const
Runs the window message pump and checks if the window wants to close.
Definition Window.cpp:116
virtual ~Window()
Destroy the window.
Definition Window.cpp:88
HINSTANCE GetHinstance() const
Get the Hinstance of the window.
Definition Window.cpp:96
bool Maximized() const
Check if the window is maximized.
Definition Window.cpp:98
void SetWindowTitle(WString title)
Set the window title.
Definition Window.cpp:239
Window size.
Definition Window.h:46
I32 Y
Height.
Definition Window.h:55
I32 X
Width.
Definition Window.h:50