Fixed window sizing issue on Windows.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
@@ -292,7 +292,7 @@ public:
|
||||
void SetCursorCustomIcon() const;
|
||||
|
||||
/// @returns Where the cursor was just before we teleported it to the center.
|
||||
/// @note The centering is delayed until the next time our window is in focus and the cursor is on top of it.
|
||||
/// @note You should check if our window is in focus before doing this.
|
||||
/// @note This is useful for 3D games.
|
||||
std::pair<int, int> SetCursorCenter();
|
||||
|
||||
@@ -316,6 +316,7 @@ public:
|
||||
bool GetCursorVisible();
|
||||
|
||||
/// @returns Whether the cursor is focused (cannot go off of our window).
|
||||
/// @note Delayed until the next time our window is in focus.
|
||||
bool GetCursorFocused();
|
||||
|
||||
/// Returns an std::pair<int, int> representing mouse coordinates relative to the top-left corner of the window.
|
||||
|
13
main.cpp
13
main.cpp
@@ -14,11 +14,9 @@ class MyWindow : public OpenGLWindow {
|
||||
void OnMouseMove(const MouseMoveEvent& e) override {}
|
||||
|
||||
void OnKeyDown(const KeyDownEvent& e) override {
|
||||
if (e.key == Keys::F11) {
|
||||
if (e.key == Keys::F11)
|
||||
SetFullscreen(!IsFullscreen());
|
||||
std::cout << "ran" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool OnResizeRequest(const WindowResizeRequestEvent& e) override { return true; }
|
||||
|
||||
@@ -70,8 +68,11 @@ int main() {
|
||||
window->OnMouseButtonDownEvent += [&] (MouseButtonDownEvent e) { jlog::Debug(e.Button.Mnemonic + std::to_string(e.Button.ButtonIndex)); };
|
||||
window->OnMouseWheelEvent += [&, window] (MouseWheelEvent e) { std::cout << window->GetMouseWheelPersistent() << std::endl; };
|
||||
|
||||
while (!window->IsClosing())
|
||||
window->ManagedRefresh();
|
||||
while (!window->IsClosing()) {
|
||||
window->ManagedRefresh();
|
||||
if (window->IsFocused())
|
||||
window->SetCursorCenter();
|
||||
}
|
||||
|
||||
delete window;
|
||||
}
|
@@ -29,6 +29,10 @@ public:
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
void RWindow::SetSize(const std::pair<int, int>& size) {
|
||||
this->SetSize(size.first, size.second);
|
||||
}
|
||||
|
||||
bool RWindow::SetCursorPosition(const std::pair<int, int>& position) {
|
||||
if (!IsFocused())
|
||||
return false;
|
||||
@@ -379,7 +383,8 @@ void RWindow::PollEvents() {
|
||||
|
||||
// Might make the window go off the screen on some window managers.
|
||||
void RWindow::SetSize(int newWidth, int newHeight) {
|
||||
if (!resizable) return;
|
||||
if (!resizable)
|
||||
return;
|
||||
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
|
@@ -134,12 +134,6 @@ void RWindow::SetSizeWithoutEvent(const std::pair<int, int>& size) {
|
||||
height = size.second;
|
||||
}
|
||||
|
||||
void RWindow::SetSize(const std::pair<int, int>& size) {
|
||||
this->width = size.first;
|
||||
this->height = size.second;
|
||||
this->SetSize(size.first, size.second);
|
||||
}
|
||||
|
||||
bool RWindow::IsKeyDown(Key key) const {
|
||||
if (currentKeyboard.PressedKeys.contains(key))
|
||||
return currentKeyboard.PressedKeys.at(key);
|
||||
|
@@ -19,6 +19,27 @@ using namespace ReWindow;
|
||||
bool local_focused = true;
|
||||
bool local_toggling_cursor_focused = false;
|
||||
|
||||
void RWindow::SetSize(int newWidth, int newHeight) {
|
||||
if (!resizable)
|
||||
return;
|
||||
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
|
||||
DWORD style = GetWindowLong(platform->hwnd, GWL_STYLE);
|
||||
DWORD exStyle = GetWindowLong(platform->hwnd, GWL_EXSTYLE);
|
||||
|
||||
RECT rect = { 0, 0, newWidth, newHeight };
|
||||
AdjustWindowRectEx(&rect, style, FALSE, exStyle);
|
||||
|
||||
int totalWidth = rect.right - rect.left;
|
||||
int totalHeight = rect.bottom - rect.top;
|
||||
|
||||
SetWindowPos(platform->hwnd, nullptr, 0, 0, totalWidth, totalHeight,
|
||||
SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||
}
|
||||
|
||||
|
||||
void RWindow::SetCursorFocused(bool state) {
|
||||
local_toggling_cursor_focused = state;
|
||||
|
||||
@@ -269,14 +290,6 @@ void RWindow::DisableResizing() {
|
||||
this->resizable = false;
|
||||
}
|
||||
|
||||
void RWindow::SetSize(int newWidth, int newHeight) {
|
||||
if (!resizable) return;
|
||||
|
||||
this->width = newWidth;
|
||||
this->height = newHeight;
|
||||
SetWindowPos(platform->hwnd, nullptr, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
std::pair<int, int> RWindow::GetAccurateCursorCoordinates() const {
|
||||
POINT point;
|
||||
GetCursorPos(&point);
|
||||
@@ -325,6 +338,7 @@ void RWindow::Fullscreen() {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -349,8 +363,10 @@ void RWindow::RestoreFromFullscreen() {
|
||||
);
|
||||
|
||||
DisableResizing();
|
||||
|
||||
this->width = platform->window_position_before_fullscreen.first;
|
||||
this->height = platform->window_position_before_fullscreen.second;
|
||||
|
||||
fullscreen_mode = false;
|
||||
}
|
||||
|
||||
@@ -403,17 +419,24 @@ bool OpenGLWindow::Open() {
|
||||
wc.hInstance = platform->hInstance;
|
||||
wc.lpszClassName = "RWindowClass";
|
||||
RegisterClass(&wc);
|
||||
platform->hwnd = CreateWindowEx(
|
||||
0,
|
||||
"RWindowClass",
|
||||
title.c_str(),
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
|
||||
nullptr,
|
||||
nullptr,
|
||||
platform->hInstance,
|
||||
nullptr
|
||||
);
|
||||
|
||||
RECT rect = { 0, 0, width, height };
|
||||
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, FALSE, 0);
|
||||
|
||||
int win_width = rect.right - rect.left;
|
||||
int win_height = rect.bottom - rect.top;
|
||||
|
||||
platform->hwnd = CreateWindowEx(
|
||||
0,
|
||||
"RWindowClass",
|
||||
title.c_str(),
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, win_width, win_height,
|
||||
nullptr,
|
||||
nullptr,
|
||||
platform->hInstance,
|
||||
nullptr
|
||||
);
|
||||
SetWindowLongPtr(platform->hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
|
||||
PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR),
|
||||
|
Reference in New Issue
Block a user