Skip to content

Commit 8097e77

Browse files
refactor a few windowing things
1 parent 1fa40e6 commit 8097e77

File tree

7 files changed

+223
-247
lines changed

7 files changed

+223
-247
lines changed

include/nbl/ui/IWindow.h

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class IWindow : public core::IReferenceCounted
4141
class IEventCallback : public core::IReferenceCounted
4242
{
4343
public:
44+
// TODO: rethink our boolean returns
4445
[[nodiscard]] inline bool onWindowShown(IWindow* w)
4546
{
4647
auto canShow = onWindowShown_impl();
@@ -107,6 +108,7 @@ class IWindow : public core::IReferenceCounted
107108
{
108109
return onWindowClosed_impl();
109110
}
111+
110112
inline void onGainedMouseFocus(IWindow* w)
111113
{
112114
onGainedMouseFocus_impl();
@@ -160,18 +162,9 @@ class IWindow : public core::IReferenceCounted
160162
NBL_API2 virtual void onKeyboardConnected_impl(core::smart_refctd_ptr<IKeyboardEventChannel>&& kbch) {}
161163
NBL_API2 virtual void onKeyboardDisconnected_impl(IKeyboardEventChannel* mch) {}
162164
};
163-
struct SCreationParams
164-
{
165-
//IWindow(core::smart_refctd_ptr<IEventCallback>&& _cb, core::smart_refctd_ptr<system::ISystem>&& _sys, uint32_t _w = 0u, uint32_t _h = 0u, E_CREATE_FLAGS _flags = static_cast<E_CREATE_FLAGS>(0)) :
166-
core::smart_refctd_ptr<IEventCallback> callback;
167-
core::smart_refctd_ptr<system::ISystem> system;
168-
int32_t x, y;
169-
uint32_t width = 0u, height = 0u;
170-
E_CREATE_FLAGS flags = static_cast<E_CREATE_FLAGS>(0);
171-
uint32_t eventChannelCapacityLog2[IInputEventChannel::ET_COUNT];
172-
std::string windowCaption;
173-
};
174-
friend struct IEventCallback;
165+
166+
friend class IEventCallback;
167+
inline void setEventCallback(core::smart_refctd_ptr<IEventCallback>&& evCb) { m_cb = std::move(evCb); }
175168

176169
inline bool isFullscreen() { return (m_flags.value & ECF_FULLSCREEN); }
177170
inline bool isHidden() { return (m_flags.value & ECF_HIDDEN); }
@@ -193,28 +186,33 @@ class IWindow : public core::IReferenceCounted
193186

194187
NBL_API2 virtual IClipboardManager* getClipboardManager() = 0;
195188
NBL_API2 virtual ICursorControl* getCursorControl() = 0;
196-
NBL_API2 virtual IWindowManager* getManager() = 0;
189+
NBL_API2 virtual IWindowManager* getManager() const = 0;
197190

198191
inline IEventCallback* getEventCallback() const { return m_cb.get(); }
199192

200193
NBL_API2 virtual void setCaption(const std::string_view& caption) = 0;
194+
195+
struct SCreationParams
196+
{
197+
core::smart_refctd_ptr<IEventCallback> callback;
198+
int32_t x, y;
199+
uint32_t width = 0u, height = 0u;
200+
E_CREATE_FLAGS flags = E_CREATE_FLAGS::ECF_NONE;
201+
uint32_t eventChannelCapacityLog2[IInputEventChannel::ET_COUNT];
202+
std::string windowCaption;
203+
};
201204
protected:
202205
// TODO need to update constructors of all derived CWindow* classes
203206
inline IWindow(SCreationParams&& params) :
204-
m_cb(std::move(params.callback)), m_sys(std::move(params.system)), m_width(params.width), m_height(params.height), m_x(params.x), m_y(params.y), m_flags(params.flags)
207+
m_cb(std::move(params.callback)), m_width(params.width), m_height(params.height), m_x(params.x), m_y(params.y), m_flags(params.flags)
205208
{
206-
207209
}
208-
209-
NBL_API2 virtual ~IWindow() = default;
210+
inline virtual ~IWindow() = default;
210211

211212
core::smart_refctd_ptr<IEventCallback> m_cb;
212-
core::smart_refctd_ptr<system::ISystem> m_sys;
213213
uint32_t m_width = 0u, m_height = 0u;
214214
int32_t m_x, m_y; // gonna add it here until further instructions XD
215215
core::bitflag<E_CREATE_FLAGS> m_flags = static_cast<E_CREATE_FLAGS>(0u);
216-
public:
217-
inline void setEventCallback(core::smart_refctd_ptr<IEventCallback>&& evCb) { m_cb = std::move(evCb); }
218216
};
219217

220218
}

include/nbl/ui/IWindowAndroid.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,21 @@
44
#include "nbl/ui/IWindow.h"
55

66
#ifdef _NBL_PLATFORM_ANDROID_
7-
8-
#include <android/native_window.h>
9-
107
namespace nbl::ui
118
{
129

1310
class NBL_API2 IWindowAndroid : public IWindow
1411
{
15-
protected:
16-
virtual ~IWindowAndroid() = default;
17-
inline IWindowAndroid(SCreationParams&& params) : IWindow(std::move(params)) {}
18-
1912
public:
20-
using IWindow::IWindow;
21-
2213
using native_handle_t = struct ANativeWindow*;
23-
2414
virtual const native_handle_t& getNativeHandle() const = 0;
15+
16+
protected:
17+
virtual ~IWindowAndroid() = default;
18+
inline IWindowAndroid(SCreationParams&& params) : IWindow(std::move(params)) {}
2519
};
2620

2721
}
28-
2922
#endif // _NBL_PLATFORM_ANDROID_
3023

3124
#endif

include/nbl/ui/IWindowManager.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
#ifndef _NBL_UI_I_WINDOWMANAGER_
2-
#define _NBL_UI_I_WINDOWMANAGER_
1+
#ifndef _NBL_UI_I_WINDOWMANAGER_INCLUDED_
2+
#define _NBL_UI_I_WINDOWMANAGER_INCLUDED_
33

4-
#include <nbl/core/IReferenceCounted.h>
5-
#include "IWindow.h"
4+
#include "nbl/ui/IWindow.h"
65

76
namespace nbl::ui
87
{
98

10-
struct SDisplayInfo
11-
{
12-
int32_t x;
13-
int32_t y;
14-
uint32_t resX;
15-
uint32_t resY;
16-
std::string name; // this one is really more of a placeholder right now
17-
};
18-
199
class NBL_API2 IWindowManager : public core::IReferenceCounted
2010
{
2111
public:
2212
virtual core::smart_refctd_ptr<IWindow> createWindow(IWindow::SCreationParams&& creationParams) = 0;
23-
virtual SDisplayInfo getPrimaryDisplayInfo() const = 0;
2413

25-
virtual bool setWindowSize_impl(IWindow* window, uint32_t width, uint32_t height) = 0;
26-
virtual bool setWindowPosition_impl(IWindow* window, int32_t x, int32_t y) = 0;
27-
virtual bool setWindowRotation_impl(IWindow* window, bool landscape) = 0;
28-
virtual bool setWindowVisible_impl(IWindow* window, bool visible) = 0;
29-
virtual bool setWindowMaximized_impl(IWindow* window, bool maximized) = 0;
14+
//!
15+
struct SDisplayInfo
16+
{
17+
int32_t x;
18+
int32_t y;
19+
uint32_t resX;
20+
uint32_t resY;
21+
std::string name; // this one is really more of a placeholder right now
22+
};
23+
virtual SDisplayInfo getPrimaryDisplayInfo() const = 0;
3024

3125
inline bool setWindowSize(IWindow* window, const uint32_t width, const uint32_t height)
3226
{
@@ -99,6 +93,12 @@ class NBL_API2 IWindowManager : public core::IReferenceCounted
9993

10094
protected:
10195
virtual ~IWindowManager() = default;
96+
97+
virtual bool setWindowSize_impl(IWindow* window, uint32_t width, uint32_t height) = 0;
98+
virtual bool setWindowPosition_impl(IWindow* window, int32_t x, int32_t y) = 0;
99+
virtual bool setWindowRotation_impl(IWindow* window, bool landscape) = 0;
100+
virtual bool setWindowVisible_impl(IWindow* window, bool visible) = 0;
101+
virtual bool setWindowMaximized_impl(IWindow* window, bool maximized) = 0;
102102
};
103103

104104
}

include/nbl/ui/IWindowManagerWin32.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _NBL_UI_I_WINDOWMANAGER_WIN32_INCLUDED_
2+
#define _NBL_UI_I_WINDOWMANAGER_WIN32_INCLUDED_
3+
4+
#include "nbl/ui/IWindowManager.h"
5+
6+
#ifdef _NBL_PLATFORM_WINDOWS_
7+
namespace nbl::ui
8+
{
9+
10+
class IWindowManagerWin32 : public IWindowManager
11+
{
12+
public:
13+
NBL_API2 static core::smart_refctd_ptr<IWindowManagerWin32> create();
14+
};
15+
16+
}
17+
#endif
18+
#endif

include/nbl/ui/IWindowWin32.h

Lines changed: 10 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,24 @@
1-
#ifndef __NBL_I_WINDOW_WIN32_H_INCLUDED__
2-
#define __NBL_I_WINDOW_WIN32_H_INCLUDED__
3-
4-
#include "nbl/system/DefaultFuncPtrLoader.h"
5-
6-
#include "nbl/ui/IWindow.h"
1+
#ifndef _NBL_I_WINDOW_WIN32_H_INCLUDED_
2+
#define _NBL_I_WINDOW_WIN32_H_INCLUDED_
73

4+
#include "nbl/ui/IWindowManagerWin32.h"
85

96
#ifdef _NBL_PLATFORM_WINDOWS_
7+
// forward declare HWND
8+
struct HWND__;
109

1110
namespace nbl::ui
1211
{
1312

1413
class NBL_API2 IWindowWin32 : public IWindow
1514
{
16-
protected:
17-
virtual ~IWindowWin32() = default;
18-
inline IWindowWin32(SCreationParams&& params) : IWindow(std::move(params)) {}
19-
2015
public:
21-
using IWindow::IWindow;
22-
23-
using native_handle_t = HWND;
24-
16+
using native_handle_t = HWND__*;
2517
virtual const native_handle_t& getNativeHandle() const = 0;
26-
27-
static DWORD getWindowStyle(IWindow::E_CREATE_FLAGS flags)
28-
{
29-
DWORD style = WS_POPUP;
30-
31-
if ((flags & IWindow::ECF_FULLSCREEN) == 0)
32-
{
33-
if ((flags & IWindow::ECF_BORDERLESS) == 0)
34-
{
35-
style |= WS_BORDER;
36-
style |= (WS_SYSMENU | WS_CAPTION);
37-
}
38-
// ? not sure about those below
39-
style |= WS_CLIPCHILDREN;
40-
style |= WS_CLIPSIBLINGS;
41-
}
42-
if (flags & IWindow::ECF_MINIMIZED)
43-
{
44-
style |= WS_MINIMIZE;
45-
}
46-
if (flags & IWindow::ECF_MAXIMIZED)
47-
{
48-
style |= WS_MAXIMIZE;
49-
}
50-
if (flags & IWindow::ECF_ALWAYS_ON_TOP)
51-
{
52-
style |= WS_EX_TOPMOST;
53-
}
54-
if ((flags & IWindow::ECF_HIDDEN) == 0)
55-
{
56-
style |= WS_VISIBLE;
57-
}
58-
style |= WS_OVERLAPPEDWINDOW;
59-
60-
return style;
61-
}
18+
19+
protected:
20+
inline IWindowWin32(SCreationParams&& params) : IWindow(std::move(params)) {}
21+
virtual ~IWindowWin32() = default;
6222
};
6323

6424
}

0 commit comments

Comments
 (0)