Platform window enable/disable border support

This commit is contained in:
Dr. Chat 2015-07-21 22:13:06 -05:00
parent 9fcbd60e9b
commit c6e6894d9d
3 changed files with 29 additions and 2 deletions

View File

@ -53,6 +53,9 @@ class Window {
virtual bool is_fullscreen() const { return false; }
virtual void ToggleFullscreen(bool fullscreen) {}
virtual bool is_bordered() const { return false; }
virtual void SetBordered(bool enabled) {}
bool has_focus() const { return has_focus_; }
virtual void set_focus(bool value) { has_focus_ = value; }

View File

@ -159,8 +159,7 @@ bool Win32Window::set_title(const std::wstring& title) {
}
bool Win32Window::is_fullscreen() const {
DWORD style = GetWindowLong(hwnd_, GWL_STYLE);
return (style & WS_OVERLAPPEDWINDOW) != WS_OVERLAPPEDWINDOW;
return fullscreen_;
}
void Win32Window::ToggleFullscreen(bool fullscreen) {
@ -168,6 +167,8 @@ void Win32Window::ToggleFullscreen(bool fullscreen) {
return;
}
fullscreen_ = fullscreen;
DWORD style = GetWindowLong(hwnd_, GWL_STYLE);
if (fullscreen) {
// Kill our borders and resize to take up entire primary monitor.
@ -195,6 +196,25 @@ void Win32Window::ToggleFullscreen(bool fullscreen) {
}
}
bool Win32Window::is_bordered() const {
DWORD style = GetWindowLong(hwnd_, GWL_STYLE);
return (style & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW;
}
void Win32Window::SetBordered(bool enabled) {
if (is_fullscreen()) {
// Don't screw with the borders if we're fullscreen.
return;
}
DWORD style = GetWindowLong(hwnd_, GWL_STYLE);
if (enabled) {
SetWindowLong(hwnd_, GWL_STYLE, style | WS_OVERLAPPEDWINDOW);
} else {
SetWindowLong(hwnd_, GWL_STYLE, style & ~WS_OVERLAPPEDWINDOW);
}
}
void Win32Window::set_cursor_visible(bool value) {
if (is_cursor_visible_ == value) {
return;

View File

@ -34,6 +34,9 @@ class Win32Window : public Window {
bool is_fullscreen() const override;
void ToggleFullscreen(bool fullscreen) override;
bool is_bordered() const override;
void SetBordered(bool enabled) override;
void set_cursor_visible(bool value) override;
void set_focus(bool value) override;
@ -65,6 +68,7 @@ class Win32Window : public Window {
HWND hwnd_ = nullptr;
bool closing_ = false;
bool fullscreen_ = false;
WINDOWPLACEMENT windowed_pos_;
};