WIndows fix bug in RestoreFromFullscreen
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m30s

This commit is contained in:
2025-07-12 17:56:33 -04:00
parent 13dfa1216d
commit 9352e813ad
5 changed files with 108 additions and 84 deletions

View File

@@ -220,13 +220,12 @@ public:
/// @note Execution of the parent window is stopped while the message box is up.
void DialogOK(const std::string& title, const std::string& message);
/// Sets whether or not to make the window fullscreen.
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
/// Sets whether the window is fullscreen.
void SetFullscreen(bool fs);
/// Sets whether or not to make the window resizable.
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
void SetResizable(bool resizable);
/// Sets whether the window can be resized by the user.
/// @note Resize events will still be sent if fullscreen is toggled.
void DisableResizing();
/// Sets the title of this window.
void SetTitle(const std::string& title);
@@ -265,7 +264,7 @@ public:
void SetSize(const std::pair<int, int>& size);
/// Returns the position of the window's top-left corner relative to the display
[[nodiscard]] std::pair<int, int> GetPos() const;
[[nodiscard]] std::pair<int, int> GetPosition() const;
/// Returns the known size of the window, in {x,y} pixel measurement.
[[nodiscard]] std::pair<int, int> GetSize() const;

View File

@@ -53,7 +53,7 @@ int main() {
Logger::Debug("TODO: Cannot set flags until after window is open");
window->SetVsyncEnabled(true);
window->SetResizable(true);
window->DisableResizing();
window->SetKeyRepeatEnabled(false);
Logger::Debug(std::format

View File

@@ -197,17 +197,15 @@ void RWindow::SetCursorVisible(bool cursor_enable) {
XUndefineCursor(platform->display, platform->window);
}
void RWindow::SetResizable(bool sizable) {
void RWindow::DisableResizing() {
XGetWindowAttributes(platform->display, platform->window, &platform->windowAttributes);
this->resizable = sizable;
if (!sizable) {
Logger::Debug("Once you've done this you cannot make it resizable again.");
platform->hints.flags = PMinSize | PMaxSize;
platform->hints.min_width = platform->hints.max_width = platform->windowAttributes.width;
platform->hints.min_height = platform->hints.max_height = platform->windowAttributes.height;
XSetWMNormalHints(platform->display, platform->window, &platform->hints);
}
platform->hints.flags = PMinSize | PMaxSize;
platform->hints.min_width = platform->hints.max_width = platform->windowAttributes.width;
platform->hints.min_height = platform->hints.max_height = platform->windowAttributes.height;
XSetWMNormalHints(platform->display, platform->window, &platform->hints);
this->resizable = false;
}
void RWindow::PollEvents() {
@@ -411,16 +409,13 @@ bool RWindow::IsVisible() const {
return platform->window_visible;
}
std::pair<int, int> RWindow::GetSize() const {
return { this->width, this->height };
}
// TODO: implement integer std::pair<int, int>/3 types
std::pair<int, int> RWindow::GetPos() const {
std::pair<int, int> RWindow::GetPosition() const {
return platform->position;
}
std::pair<int, int> RWindow::GetSize() const { return { this->width, this->height }; }
void RWindow::SetPosition(int x, int y) {
XMoveWindow(platform->display, platform->window, x, y);
platform->position = {x, y};

View File

@@ -3,6 +3,7 @@
#include <ReWindow/Logger.h>
using namespace ReWindow;
RWindow::~RWindow() {
if (open)
DestroyOSWindowHandle();
@@ -112,21 +113,21 @@ int RWindow::GetWidth() const { return this->width; }
int RWindow::GetHeight() const { return this->height; }
bool RWindow::IsResizable() const { return resizable; }
bool RWindow::IsResizable() const { return resizable; }
bool RWindow::IsFullscreen() const { return fullscreen_mode; }
bool RWindow::IsFullscreen() const { return fullscreen_mode; }
bool RWindow::IsFocused() const { return focused; }
bool RWindow::IsFocused() const { return focused; }
bool RWindow::IsVsyncEnabled() const { return vsync; }
bool RWindow::IsVsyncEnabled() const { return vsync; }
float RWindow::GetDeltaTime() const { return delta_time; }
float RWindow::GetDeltaTime() const { return delta_time; }
float RWindow::GetRefreshRate() const { return refresh_rate; }
float RWindow::GetRefreshRate() const { return refresh_rate; }
bool RWindow::SetCursorPosition(const int x, const int y) { return SetCursorPosition({x, y}); }
unsigned long long RWindow::GetRefreshCount() const { return refresh_count; }
unsigned long long RWindow::GetRefreshCount() const { return refresh_count; }
void RWindow::SetSizeWithoutEvent(const std::pair<int, int>& size) {
width = size.first;
@@ -152,15 +153,14 @@ bool RWindow::IsMouseButtonDown(const MouseButton& button) const {
}
void RWindow::ManagedRefresh()
{
auto begin = GetTimestamp();
Refresh();
auto end = GetTimestamp();
void RWindow::ManagedRefresh() {
auto begin = GetTimestamp();
Refresh();
auto end = GetTimestamp();
float dt = ComputeElapsedFrameTimeSeconds(begin, end);
float dt = ComputeElapsedFrameTimeSeconds(begin, end);
UpdateFrameTiming(dt);
UpdateFrameTiming(dt);
}
void RWindow::Refresh() {
@@ -187,7 +187,7 @@ float RWindow::ComputeElapsedFrameTimeSeconds(std::chrono::steady_clock::time_po
return frame_time_s;
}
std::chrono::steady_clock::time_point RWindow::GetTimestamp() {
std::chrono::steady_clock::time_point RWindow::GetTimestamp() {
return std::chrono::steady_clock::now();
}
@@ -204,8 +204,7 @@ void RWindow::UpdateFrameTiming(float frame_time) {
}
void RWindow::processMouseWheel(int scrolls)
{
void RWindow::processMouseWheel(int scrolls) {
currentMouse.Wheel += scrolls;
auto ev = MouseWheelEvent(scrolls);
OnMouseWheel(ev);
@@ -214,46 +213,46 @@ void RWindow::processMouseWheel(int scrolls)
previousMouse.Wheel = currentMouse.Wheel;
}
void RWindow::Close() {
void RWindow::Close() {
closing = true;
processOnClose();
}
}
void RWindow::ForceClose() {
void RWindow::ForceClose() {
Close();
DestroyOSWindowHandle();
}
}
bool MouseState::IsDown(const MouseButton& btn) const {
if (btn == MouseButtons::Left) return Buttons.LMB;
if (btn == MouseButtons::Right) return Buttons.RMB;
if (btn == MouseButtons::Middle) return Buttons.MMB;
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
bool MouseState::IsDown(const MouseButton& btn) const {
if (btn == MouseButtons::Left) return Buttons.LMB;
if (btn == MouseButtons::Right) return Buttons.RMB;
if (btn == MouseButtons::Middle) return Buttons.MMB;
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
return false; // Unknown button?
}
return false; // Unknown button?
}
void MouseState::Set(const MouseButton& btn, bool state) {
if (btn == MouseButtons::Left) Buttons.LMB = state;
if (btn == MouseButtons::Right) Buttons.RMB = state;
if (btn == MouseButtons::Middle) Buttons.MMB = state;
if (btn == MouseButtons::Mouse4) Buttons.SideButton1 = state;
if (btn == MouseButtons::Mouse5) Buttons.SideButton2 = state;
void MouseState::Set(const MouseButton& btn, bool state) {
if (btn == MouseButtons::Left) Buttons.LMB = state;
if (btn == MouseButtons::Right) Buttons.RMB = state;
if (btn == MouseButtons::Middle) Buttons.MMB = state;
if (btn == MouseButtons::Mouse4) Buttons.SideButton1 = state;
if (btn == MouseButtons::Mouse5) Buttons.SideButton2 = state;
//if (btn == MouseButtons::MWheelUp) Buttons.MWheelUp = state;
//if (btn == MouseButtons::MWheelDown) Buttons.MWheelDown = state;
}
}
bool &MouseState::operator [](const MouseButton& btn) {
if (btn == MouseButtons::Left) return Buttons.LMB;
if (btn == MouseButtons::Right) return Buttons.RMB;
if (btn == MouseButtons::Middle) return Buttons.MMB;
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
bool &MouseState::operator [](const MouseButton& btn) {
if (btn == MouseButtons::Left) return Buttons.LMB;
if (btn == MouseButtons::Right) return Buttons.RMB;
if (btn == MouseButtons::Middle) return Buttons.MMB;
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
throw std::invalid_argument("Attempted to handle unmapped mouse button.");
}
throw std::invalid_argument("Attempted to handle unmapped mouse button.");
}

View File

@@ -9,6 +9,8 @@ public:
HINSTANCE hInstance;
HWND hwnd;
HDC hdc;
std::pair<int, int> window_size_before_fullscreen;
std::pair<int, int> window_position_before_fullscreen;
};
using namespace ReWindow;
@@ -253,16 +255,18 @@ void RWindow::DestroyOSWindowHandle() {
DestroyWindow(platform->hwnd);
}
void RWindow::SetResizable(bool resizable) {
if (!resizable) {
RECT rect;
GetWindowRect(platform->hwnd, &rect);
LONG style = GetWindowLong(platform->hwnd, GWL_STYLE);
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
SetWindowLong(platform->hwnd, GWL_STYLE, style);
SetWindowPos(platform->hwnd, nullptr, rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
}
void RWindow::DisableResizing() {
RECT rect;
GetWindowRect(platform->hwnd, &rect);
LONG style = GetWindowLong(platform->hwnd, GWL_STYLE);
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
SetWindowLong(platform->hwnd, GWL_STYLE, style);
SetWindowPos(platform->hwnd, nullptr, rect.left, rect.top, rect.right - rect.left,
rect.bottom - rect.top, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
this->resizable = false;
}
void RWindow::SetSize(int newWidth, int newHeight) {
@@ -292,13 +296,20 @@ void RWindow::SetKeyRepeatEnabled(bool state) {
key_repeat = state;
}
std::pair<int, int> RWindow::GetSize() const {
RECT rect;
GetClientRect(platform->hwnd, &rect);
return { (rect.right - rect.left), (rect.bottom - rect.top) };
}
std::pair<int, int> RWindow::GetPosition() const {
RECT rect;
if (GetWindowRect(platform->hwnd, &rect))
return { rect.left, rect.top };
return { -1, -1 };
}
void RWindow::SetPosition(int x, int y) {
SetWindowPos(platform->hwnd, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
@@ -308,16 +319,36 @@ void RWindow::SetPosition(const std::pair<int, int>& pos) {
}
void RWindow::Fullscreen() {
// Implement fullscreen
platform->window_position_before_fullscreen = GetPosition();
platform->window_size_before_fullscreen = GetSize();
platform->window_position_before_fullscreen = this->GetPosition();
SetWindowLong(platform->hwnd, GWL_STYLE, GetWindowLong(platform->hwnd, GWL_STYLE) & ~WS_OVERLAPPEDWINDOW);
SetWindowPos(platform->hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
fullscreen_mode = true;
}
void RWindow::RestoreFromFullscreen() {
// Implement restore from fullscreen
SetWindowLong(platform->hwnd, GWL_STYLE, GetWindowLong(platform->hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
SetWindowPos(platform->hwnd, nullptr, 0, 0, width, height, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
RECT rect = {0, 0, platform->window_size_before_fullscreen.first, platform->window_size_before_fullscreen.second };
AdjustWindowRectEx(&rect, GetWindowLong(platform->hwnd, GWL_STYLE), FALSE, GetWindowLong(platform->hwnd, GWL_EXSTYLE));
int window_width = rect.right - rect.left;
int window_height = rect.bottom - rect.top;
SetWindowPos(
platform->hwnd,
nullptr,
platform->window_position_before_fullscreen.first,
platform->window_position_before_fullscreen.second,
window_width,
window_height,
SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER
);
DisableResizing();
fullscreen_mode = false;
}