Skip to content

Commit c146f33

Browse files
Introduce a IWindow::E_CREATE_FLAGS::ECF_CAN_RESIZE and change meaning of IWindow::E_CREATE_FLAGS::ECF_RESIZABLE
1 parent 54a4f53 commit c146f33

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

include/nbl/ui/IWindow.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class IWindow : public core::IReferenceCounted
3838
ECF_CAN_MAXIMIZE = 1u << 10,
3939
//! If disabled, the minimize button is grayed out
4040
ECF_CAN_MINIMIZE = 1u << 11,
41+
//! If disabled, the window can't be resized via the UI, only programmatically
42+
ECF_CAN_RESIZE = 1u << 12,
4143

4244
ECF_NONE = 0
4345
};
@@ -171,17 +173,18 @@ class IWindow : public core::IReferenceCounted
171173
friend class IEventCallback;
172174
inline void setEventCallback(core::smart_refctd_ptr<IEventCallback>&& evCb) { m_cb = std::move(evCb); }
173175

174-
inline bool isFullscreen() { return (m_flags.value & ECF_FULLSCREEN); }
175-
inline bool isHidden() { return (m_flags.value & ECF_HIDDEN); }
176-
inline bool isBorderless() { return (m_flags.value & ECF_BORDERLESS); }
177-
inline bool isResizable() { return (m_flags.value & ECF_RESIZABLE); }
178-
inline bool isMinimized() { return (m_flags.value & ECF_MINIMIZED); }
179-
inline bool isMaximized() { return (m_flags.value & ECF_MAXIMIZED); }
180-
inline bool hasMouseCaptured() { return (m_flags.value & ECF_MOUSE_CAPTURE); }
181-
inline bool hasInputFocus() { return (m_flags.value & ECF_INPUT_FOCUS); }
182-
inline bool hasMouseFocus() { return (m_flags.value & ECF_MOUSE_FOCUS); }
183-
inline bool isAlwaysOnTop() { return (m_flags.value & ECF_ALWAYS_ON_TOP); }
184-
inline bool isMaximizable() { return (m_flags.value & ECF_CAN_MAXIMIZE); }
176+
inline bool isFullscreen() { return (m_flags.value & ECF_FULLSCREEN); }
177+
inline bool isHidden() { return (m_flags.value & ECF_HIDDEN); }
178+
inline bool isBorderless() { return (m_flags.value & ECF_BORDERLESS); }
179+
inline bool canProgrammaticallyResize() { return (m_flags.value & ECF_RESIZABLE); }
180+
inline bool isMinimized() { return (m_flags.value & ECF_MINIMIZED); }
181+
inline bool isMaximized() { return (m_flags.value & ECF_MAXIMIZED); }
182+
inline bool hasMouseCaptured() { return (m_flags.value & ECF_MOUSE_CAPTURE); }
183+
inline bool hasInputFocus() { return (m_flags.value & ECF_INPUT_FOCUS); }
184+
inline bool hasMouseFocus() { return (m_flags.value & ECF_MOUSE_FOCUS); }
185+
inline bool isAlwaysOnTop() { return (m_flags.value & ECF_ALWAYS_ON_TOP); }
186+
inline bool isMaximizable() { return (m_flags.value & ECF_CAN_MAXIMIZE); }
187+
inline bool isResizable() { return (m_flags.value & ECF_CAN_RESIZE); }
185188

186189
inline core::bitflag<E_CREATE_FLAGS> getFlags() { return m_flags; }
187190

include/nbl/ui/IWindowManager.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class NBL_API2 IWindowManager : public virtual core::IReferenceCounted
2525
inline bool setWindowSize(IWindow* window, const uint32_t width, const uint32_t height)
2626
{
2727
auto cb = window->getEventCallback();
28-
if (window->getManager() != this || !window->isResizable())
28+
if (window->getManager()!=this || !window->canProgrammaticallyResize())
2929
return false;
3030

3131
return setWindowSize_impl(window, width, height);
@@ -34,7 +34,7 @@ class NBL_API2 IWindowManager : public virtual core::IReferenceCounted
3434
inline bool setWindowPosition(IWindow* window, const int32_t x, const int32_t y)
3535
{
3636
auto cb = window->getEventCallback();
37-
if (window->getManager() != this || !window->isResizable())
37+
if (window->getManager()!=this)
3838
return false;
3939

4040
return setWindowPosition_impl(window, x, y);
@@ -56,7 +56,7 @@ class NBL_API2 IWindowManager : public virtual core::IReferenceCounted
5656
inline bool show(IWindow* window)
5757
{
5858
auto cb = window->getEventCallback();
59-
if (window->getManager() != this || !window->isResizable() || !window->isHidden())
59+
if (window->getManager() != this || !window->isHidden())
6060
return false;
6161

6262
return setWindowVisible_impl(window, true);
@@ -65,7 +65,7 @@ class NBL_API2 IWindowManager : public virtual core::IReferenceCounted
6565
inline bool hide(IWindow* window)
6666
{
6767
auto cb = window->getEventCallback();
68-
if (window->getManager() != this || !window->isResizable() || window->isHidden())
68+
if (window->getManager() != this || window->isHidden())
6969
return false;
7070

7171
return setWindowVisible_impl(window, false);
@@ -74,7 +74,7 @@ class NBL_API2 IWindowManager : public virtual core::IReferenceCounted
7474
inline bool maximize(IWindow* window)
7575
{
7676
auto cb = window->getEventCallback();
77-
if (window->getManager() != this || !window->isResizable() || window->isMaximized())
77+
if (window->getManager() != this || window->isMaximized())
7878
return false;
7979

8080
return setWindowMaximized_impl(window, true);
@@ -83,7 +83,7 @@ class NBL_API2 IWindowManager : public virtual core::IReferenceCounted
8383
inline bool minimize(IWindow* window)
8484
{
8585
auto cb = window->getEventCallback();
86-
if (window->getManager() != this || !window->isResizable() || window->isMinimized())
86+
if (window->getManager() != this || window->isMinimized())
8787
return false;
8888

8989
return setWindowMaximized_impl(window, false);

src/nbl/ui/CWindowManagerWin32.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static inline DWORD getWindowStyle(const core::bitflag<IWindow::E_CREATE_FLAGS>
5858
style |= WS_VISIBLE;
5959
}
6060
style |= WS_OVERLAPPEDWINDOW;
61-
if (!flags.hasFlags(IWindow::ECF_RESIZABLE))
61+
if (!flags.hasFlags(IWindow::ECF_CAN_RESIZE))
6262
{
6363
style &= ~WS_SIZEBOX;
6464
}
@@ -76,6 +76,13 @@ static inline DWORD getWindowStyle(const core::bitflag<IWindow::E_CREATE_FLAGS>
7676

7777
core::smart_refctd_ptr<IWindow> CWindowManagerWin32::createWindow(IWindow::SCreationParams&& creationParams)
7878
{
79+
// this could be common to all `createWindow` impl
80+
if (creationParams.flags.hasFlags(IWindow::ECF_CAN_RESIZE) || creationParams.flags.hasFlags(IWindow::ECF_CAN_MAXIMIZE))
81+
creationParams.flags |= IWindow::ECF_RESIZABLE;
82+
// win32 minimize is weird, its a resize to 0,0
83+
if (creationParams.flags.hasFlags(IWindow::ECF_CAN_MINIMIZE))
84+
creationParams.flags |= IWindow::ECF_CAN_RESIZE;
85+
7986
CAsyncQueue::future_t<IWindowWin32::native_handle_t> future;
8087
m_windowThreadManager.request(&future, SRequestParams_CreateWindow{
8188
.windowCaption = std::move(creationParams.windowCaption),
@@ -84,7 +91,7 @@ core::smart_refctd_ptr<IWindow> CWindowManagerWin32::createWindow(IWindow::SCrea
8491
.x = creationParams.x,
8592
.y = creationParams.y,
8693
.flags = creationParams.flags
87-
});
94+
});
8895
if (auto handle = future.acquire())
8996
return core::make_smart_refctd_ptr<CWindowWin32>(std::move(creationParams),core::smart_refctd_ptr<CWindowManagerWin32>(this),*handle);
9097
return nullptr;

0 commit comments

Comments
 (0)