Files
ReWindow/src/platform/windows/Window.cpp
Redacted c0ee42b782
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m27s
RWindow::Flash windows.
2025-01-28 18:40:46 -05:00

125 lines
3.6 KiB
C++

#include <Windows.h>
#include <gl/GL.h>
#include <rewindow/types/window.h>
class ReWindow::RWindow::Platform {
public:
HINSTANCE hInstance;
HWND hwnd;
HDC hdc;
};
using namespace ReWindow;
bool fullscreenmode = false;
bool open = false;
void RWindow::Raise() { SetWindowPos(platform->hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); }
void RWindow::Lower() { SetWindowPos(platform->hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); }
void RWindow::Flash() {
if (!GetFlag(WindowFlag::IN_FOCUS)) {
FLASHWINFO fi;
fi.cbSize = sizeof(FLASHWINFO);
fi.hwnd = platform->hwnd;
fi.dwFlags = FLASHW_ALL;
fi.uCount = 0;
fi.dwTimeout = 0;
FlashWindowEx(&fi);
}
}
void RWindow::DestroyOSWindowHandle() {
DestroyWindow(platform->hwnd);
}
void RWindow::SetFlag(WindowFlag flag, bool state) {
flags[(int) flag] = state;
if (flag == WindowFlag::RESIZABLE && !state) {
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::SetResizable(bool resizable) {
SetFlag(WindowFlag::RESIZABLE, resizable);;
}
void RWindow::PollEvents() {
MSG msg;
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
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);
}
IPair RWindow::GetAccurateMouseCoordinates() const {
POINT point;
GetCursorPos(&point);
ScreenToClient(platform->hwnd, &point);
return { point.x, point.y };
}
void RWindow::SetCursorVisible(bool cursor_enable) {
cursor_visible = cursor_enable;
}
bool RWindow::GetCursorVisible() {
return cursor_visible;
}
IPair RWindow::GetSize() const {
RECT rect;
GetClientRect(platform->hwnd, &rect);
return { (rect.right - rect.left), (rect.bottom - rect.top) };
}
void RWindow::SetPos(int x, int y) {
SetWindowPos(platform->hwnd, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
void RWindow::SetPos(const IPair& pos) {
SetPos(pos.x, pos.y);
}
void RWindow::Fullscreen() {
// Implement fullscreen
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);
}
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);
}
void RWindow::SetCursorStyle(CursorStyle style) const {}
RWindow::RWindow() {
extant = this;
platform = new Platform();
}
RWindow::RWindow(const std::string& wTitle, int wWidth, int wHeight,
bool wFullscreen, bool wResizable, bool wVsync) :
title(wTitle), width(wWidth), height(wHeight), fullscreen_mode(wFullscreen), resizable(wResizable),
vsync(wVsync), flags{false,wFullscreen,wResizable,wVsync} {
extant = this;
platform = new Platform();
}