Skip to content

Commit

Permalink
Replaced boolean properties in WindowDescriptor with WindowFlags enum…
Browse files Browse the repository at this point in the history
…eration (same for Canvas).
  • Loading branch information
LukasBanana committed Sep 4, 2023
1 parent 63e5ef8 commit 43c0912
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 158 deletions.
6 changes: 3 additions & 3 deletions examples/Cpp/ExampleBase/ExampleBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,12 @@ ExampleBase::ExampleBase(
window.SetTitle(title + " ( " + rendererName + " )");

// Change window descriptor to allow resizing
auto wndDesc = window.GetDesc();
wndDesc.resizable = true;
LLGL::WindowDescriptor wndDesc = window.GetDesc();
wndDesc.flags |= LLGL::WindowFlags::Resizable;
window.SetDesc(wndDesc);

// Change window behavior
auto behavior = window.GetBehavior();
LLGL::WindowBehavior behavior = window.GetBehavior();
behavior.disableClearOnResize = true;
behavior.moveAndResizeTimerID = 1;
window.SetBehavior(behavior);
Expand Down
7 changes: 3 additions & 4 deletions examples/Cpp/MultiRenderer/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ MyRenderer::MyRenderer(
{
windowDesc.position = subWindowOffset;
windowDesc.size = { static_cast<std::uint32_t>(viewport.width)/2, static_cast<std::uint32_t>(viewport.height)/2 };
windowDesc.borderless = true;
windowDesc.visible = true;
windowDesc.flags = (LLGL::WindowFlags::Visible | LLGL::WindowFlags::Borderless);
windowDesc.windowContext = (&mainWindowHandle);
windowDesc.windowContextSize = sizeof(mainWindowHandle);
}
Expand Down Expand Up @@ -289,9 +288,9 @@ int main(int argc, char* argv[])
{
mainWindowDesc.title = "LLGL Example: Multi Renderer ( OpenGL, Vulkan, Direct3D 11, Direct3D 12 )";
mainWindowDesc.size = resolution;
mainWindowDesc.centered = true;
mainWindowDesc.flags = LLGL::WindowFlags::Centered;
}
auto mainWindow = LLGL::Window::Create(mainWindowDesc);
std::unique_ptr<LLGL::Window> mainWindow = LLGL::Window::Create(mainWindowDesc);

// Create renderers
const int halfWidth = static_cast<int>(resolution.width/2);
Expand Down
25 changes: 22 additions & 3 deletions include/LLGL/CanvasFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,33 @@ namespace LLGL
{


//! Canvas descriptor structure.
/**
\brief Canvas creation flags.
\see CanvasDescriptor::flags
*/
struct CanvasFlags
{
enum
{
//! Specifies whether the canvas is borderless. This is required for a fullscreen swap-chain.
Borderless = (1 << 0),
};
};

/**
\brief Canvas descriptor structure.
\see Canvas::Create
*/
struct CanvasDescriptor
{
//! Canvas title as UTF16 string.
UTF8String title;

//! Specifies whether the canvas is borderless. This is required for a fullscreen swap-chain.
bool borderless = false;
/**
\brief Specifies the canvas creation flags. This can be a bitwise OR combination of the CanvasFlags entries.
\see CanvasFlags
*/
long flags = 0;
};


Expand Down
102 changes: 62 additions & 40 deletions include/LLGL/WindowFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,79 @@ namespace LLGL
{


//! Window descriptor structure.
/**
\brief Window creation flags.
\see WindowDescriptor::flags
*/
struct WindowFlags
{
enum
{
//! Specifies whether the window is visible at creation time.
Visible = (1 << 0),

//! Specifies whether the window is borderless. This is required for a fullscreen swap-chain.
Borderless = (1 << 1),

/**
\brief Specifies whether the window can be resized.
\remarks For every window representing the surface for a SwapChain which has been resized,
the video mode of that SwapChain must be updated with the resolution of the surface's content size.
This can be done by resizing the swap-chain buffers to the new resolution before the respective swap-chain is bound to a render pass,
or it can be handled by a window event listener inside a custom \c OnResize callback:
\code
// Alternative 1
class MyEventListener : public LLGL::Window::EventListener {
void OnResize(LLGL::Window& sender, const LLGL::Extent2D& clientAreaSize) override {
mySwapChain->ResizeBuffers(clientAreaSize);
}
};
myWindow->AddEventListener(std::make_shared<MyEventListener>());
// Alternative 2
mySwapChain->ResizeBuffers(myWindow->GetSize());
myCmdBuffer->BeginRenderPass(*mySwapChain);
\endcode
\note Not updating the swap-chain on a resized window is undefined behavior.
\see Surface::GetSize
\see Window::EventListener::OnResize
*/
Resizable = (1 << 2),

/**
\brief Specifies whether the window is centered within the desktop screen at creation time.
\remarks If this is specifies, the \c position field of the WindowDescriptor will be ignored.
*/
Centered = (1 << 4),

/**
\brief Specifies whether the window allows that files can be draged-and-droped onto the window.
\note Only supported on: MS/Windows.
*/
AcceptDropFiles = (1 << 3),
};
};

/**
\brief Window descriptor structure.
\see Window::Create
*/
struct WindowDescriptor
{
//! Window title as unicode string.
//! Window title in UTF-8 encoding.
UTF8String title;

//! Window position (relative to the client area).
Offset2D position;

//! Window size (this should be the client area size).
//! Specifies the content size, i.e. not including the frame and caption dimensions.
Extent2D size;

//! Specifies whether the window is visible at creation time. By default false.
bool visible = false;

//! Specifies whether the window is borderless. This is required for a fullscreen swap-chain. By default false.
bool borderless = false;

/**
\brief Specifies whether the window can be resized. By default false.
\remarks For every window representing the surface for a SwapChain which has been resized,
the video mode of that SwapChain must be updated with the resolution of the surface's content size.
This can be done by setting the video mode with the new resolution before the respective swap-chain is bound as render target,
or it can be handled by a window event listener on the 'OnResize' callback:
\code
// Alternative 1
class MyEventListener : public LLGL::Window::EventListener {
void OnResize(Window& sender, const Extent2D& clientAreaSize) override {
mySwapChain->ResizeBuffers(clientAreaSize);
}
};
myWindow->AddEventListener(std::make_shared<MyEventListener>());
// Alternative 2
mySwapChain->ResizeBuffers(myWindow->GetContentSize());
myCmdBuffer->BeginRenderPass(*mySwapChain);
\endcode
\note Not updating the swap-chain on a resized window is undefined behavior.
\see Surface::GetContentSize
\see Window::EventListener::OnResize
\brief Specifies the window creation flags. This can be a bitwise OR combination of the WindowFlags entries.
\see WindowFlags
*/
bool resizable = false;

/**
\brief Specifies whether the window allows that files can be draged-and-droped onto the window. By default false.
\note Only supported on: MS/Windows.
*/
bool acceptDropFiles = false;

//! Specifies whether the window is centered within the desktop screen. By default false.
bool centered = false;
long flags = 0;

/**
\brief Window context handle.
Expand Down
11 changes: 6 additions & 5 deletions sources/Platform/Linux/LinuxWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void LinuxWindow::Show(bool show)
else
XUnmapWindow(display_, wnd_);

if (desc_.borderless)
if ((desc_.flags & WindowFlags::Borderless) != 0)
XSetInputFocus(display_, (show ? wnd_ : None), RevertToParent, CurrentTime);
}

Expand Down Expand Up @@ -241,14 +241,15 @@ void LinuxWindow::OpenWindow()
else
valueMask |= CWBackPixel;

if (desc_.borderless) //WARNING -> input no longer works
const bool isBorderless = ((desc_.flags & WindowFlags::Borderless) != 0);
if (isBorderless) //TODO: -> input no longer works
{
valueMask |= CWOverrideRedirect;
attribs.override_redirect = true;
}

/* Get final window position */
if (desc_.centered)
if ((desc_.flags & WindowFlags::Centered) != 0)
desc_.position = GetScreenCenteredPosition(desc_.size);

/* Create X11 window */
Expand All @@ -271,11 +272,11 @@ void LinuxWindow::OpenWindow()
SetTitle(desc_.title);

/* Show window */
if (desc_.visible)
if ((desc_.flags & WindowFlags::Visible) != 0)
Show();

/* Prepare borderless window */
if (desc_.borderless)
if (isBorderless)
{
XGrabKeyboard(display_, wnd_, True, GrabModeAsync, GrabModeAsync, CurrentTime);
XGrabPointer(display_, wnd_, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, wnd_, None, CurrentTime);
Expand Down
32 changes: 19 additions & 13 deletions sources/Platform/MacOS/MacOSWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ static NSUInteger GetNSWindowStyleMask(const WindowDescriptor& desc)
{
NSUInteger mask = 0;

if (desc.borderless)
if ((desc.flags & WindowFlags::borderless) != 0)
mask |= g_WinStyleBorderless;
else
{
mask |= g_WinStyleTitleBar;
if (desc.resizable)
if ((desc.flags & WindowFlags::Resizable) != 0)
mask |= g_WinStyleResizable;
}

Expand Down Expand Up @@ -242,19 +242,19 @@ static void SetRelativeNSWindowPosition(NSWindow* wnd, const Offset2D& position,
if (![wndDelegate_ isFullscreenMode])
{
[wnd_ setStyleMask:GetNSWindowStyleMask(desc)];
[wndDelegate_ makeResizable:(desc.resizable)];
[wndDelegate_ makeResizable:((desc.flags & WindowFlags::Resizable) != 0)];

#if 0
/* Set window collection behavior for resize events */
if (desc.resizable)
if ((desc.flags & WindowFlags::Resizable) != 0)
[wnd_ setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary | NSWindowCollectionBehaviorManaged];
else
[wnd_ setCollectionBehavior:NSWindowCollectionBehaviorDefault];
#endif

//TOOD: incomplete -> must be ignored right now, otherwise window is moved on a resize event
#if 0
if (desc.centered)
if ((desc.flags & WindowFlags::Centered) != 0)
[wnd_ center];
else
SetPosition(desc.position);
Expand All @@ -272,9 +272,12 @@ static void SetRelativeNSWindowPosition(NSWindow* wnd, const Offset2D& position,
desc.title = GetTitle();
desc.position = GetPosition();
desc.size = GetSize();
desc.visible = IsShown();
desc.borderless = (([wnd_ styleMask] & g_WinStyleBorderless) != 0);
desc.resizable = (([wnd_ styleMask] & g_WinStyleResizable) != 0);
if (IsShown())
desc.flags |= WindowFlags::Visible;
if (([wnd_ styleMask] & g_WinStyleBorderless) != 0)
desc.flags |= WindowFlags::Borderless;
if (([wnd_ styleMask] & g_WinStyleResizable) != 0)
desc.flags |= WindowFlags::Resizable;
}
return desc;
}
Expand Down Expand Up @@ -307,32 +310,34 @@ static void SetRelativeNSWindowPosition(NSWindow* wnd, const Offset2D& position,

#if 0
/* Set window collection behavior for resize events */
if (desc.resizable)
if ((desc.flags & WindowFlags::Resizable) != 0)
[wnd setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary | NSWindowCollectionBehaviorManaged];
#endif

const bool isCentered = ((desc.flags & WindowFlags::Centered) != 0);

if (desc.windowContext != nullptr && desc.windowContextSize == sizeof(NativeHandle))
{
/* Add to parent window if specified */
if (NSWindow* parentWnd = reinterpret_cast<const NativeHandle*>(desc.windowContext)->window)
{
[parentWnd addChildWindow:wnd ordered:NSWindowAbove];
if (!desc.centered)
if (!isCentered)
SetRelativeNSWindowPosition(wnd, desc.position, parentWnd);
}
}
else
{
/* Move this window to the front of the screen list and center if requested */
[wnd makeKeyAndOrderFront:nil];
if (desc.centered)
if (isCentered)
[wnd center];
else
SetRelativeNSWindowPosition(wnd, desc.position);
}

/* Show window */
if (desc.visible)
if ((desc.flags & WindowFlags::Visible) != 0)
[wnd setIsVisible:YES];

return wnd;
Expand All @@ -341,7 +346,8 @@ static void SetRelativeNSWindowPosition(NSWindow* wnd, const Offset2D& position,
MacOSWindowDelegate* MacOSWindow::CreateNSWindowDelegate(const WindowDescriptor& desc)
{
/* Set window application delegate */
return [[MacOSWindowDelegate alloc] initWithWindow:this isResizable:(desc.resizable)];
const bool isResizable = ((desc.flags & WindowFlags::Resizable) != 0);
return [[MacOSWindowDelegate alloc] initWithWindow:this isResizable:isResizable];
}

void MacOSWindow::OnProcessEvents()
Expand Down
Loading

0 comments on commit 43c0912

Please sign in to comment.