Fix for windows.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 6m33s

This commit is contained in:
2025-01-27 11:55:19 -05:00
parent 85d84c2828
commit 7593c5f2c7
3 changed files with 58 additions and 28 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#ifdef _WIN32
#include <Windows.h>
#include <ReWindow/types/Window.h>
using namespace ReWindow;
//Event loop.

View File

@@ -2,19 +2,26 @@
#include <ReWindow/data/WindowsEventLoop.h>
#include <GL/gl.h>
class RWindow::Platform {
public:
HINSTANCE hInstance;
HWND hwnd;
HDC hdc;
};
using namespace ReWindow;
HGLRC glContext;
void OpenGLWindow::Open() {
w32Vars.hInstance = GetModuleHandle(nullptr);
bool OpenGLWindow::Open() {
platform->hInstance = GetModuleHandle(nullptr);
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = w32Vars.hInstance;
wc.hInstance = platform->hInstance;
wc.lpszClassName = "RWindowClass";
RegisterClass(&wc);
w32Vars.hwnd = CreateWindowEx(
platform->hwnd = CreateWindowEx(
0,
"RWindowClass",
title.c_str(),
@@ -22,10 +29,10 @@ void OpenGLWindow::Open() {
CW_USEDEFAULT, CW_USEDEFAULT, width, height,
nullptr,
nullptr,
w32Vars.hInstance,
platform->hInstance,
nullptr
);
SetWindowLongPtr(w32Vars.hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
SetWindowLongPtr(platform->hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
@@ -45,13 +52,16 @@ void OpenGLWindow::Open() {
0, 0, 0
};
w32Vars.hdc = GetDC(w32Vars.hwnd);
int pixelFormat = ChoosePixelFormat(w32Vars.hdc, &pfd);
SetPixelFormat(w32Vars.hdc, pixelFormat, &pfd);
glContext = wglCreateContext(w32Vars.hdc);
wglMakeCurrent(w32Vars.hdc, glContext);
ShowWindow(w32Vars.hwnd, SW_SHOW);
platform->hdc = GetDC(platform->hwnd);
int pixelFormat = ChoosePixelFormat(platform->hdc, &pfd);
SetPixelFormat(platform->hdc, pixelFormat, &pfd);
glContext = wglCreateContext(platform->hdc);
wglMakeCurrent(platform->hdc, glContext);
ShowWindow(platform->hwnd, SW_SHOW);
open = true;
// TODO don't link directly to OpenGL.
return true;
}
std::string OpenGLWindow::GetGraphicsDriverVendor() {
@@ -59,7 +69,7 @@ std::string OpenGLWindow::GetGraphicsDriverVendor() {
}
void OpenGLWindow::SwapBuffers() {
::SwapBuffers(w32Vars.hdc);
::SwapBuffers(platform->hdc);
}
void OpenGLWindow::SetVsyncEnabled(bool b) {

View File

@@ -1,28 +1,34 @@
#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(w32Vars.hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); }
void RWindow::Lower() { SetWindowPos(w32Vars.hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); }
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::DestroyOSWindowHandle() {
DestroyWindow(w32Vars.hwnd);
DestroyWindow(platform->hwnd);
}
void RWindow::SetFlag(WindowFlag flag, bool state) {
flags[(int) flag] = state;
if (flag == WindowFlag::RESIZABLE && !state) {
RECT rect;
GetWindowRect(w32Vars.hwnd, &rect);
LONG style = GetWindowLong(w32Vars.hwnd, GWL_STYLE);
GetWindowRect(platform->hwnd, &rect);
LONG style = GetWindowLong(platform->hwnd, GWL_STYLE);
style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
SetWindowLong(w32Vars.hwnd, GWL_STYLE, style);
SetWindowPos(w32Vars.hwnd, nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
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);
}
}
@@ -44,13 +50,13 @@ void RWindow::SetSize(int newWidth, int newHeight) {
this->width = newWidth;
this->height = newHeight;
SetWindowPos(w32Vars.hwnd, nullptr, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
SetWindowPos(platform->hwnd, nullptr, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
}
IPair RWindow::GetAccurateMouseCoordinates() const {
POINT point;
GetCursorPos(&point);
ScreenToClient(w32Vars.hwnd, &point);
ScreenToClient(platform->hwnd, &point);
return { point.x, point.y };
}
@@ -65,12 +71,12 @@ bool RWindow::GetCursorVisible() {
IPair RWindow::GetSize() const {
RECT rect;
GetClientRect(w32Vars.hwnd, &rect);
GetClientRect(platform->hwnd, &rect);
return { (rect.right - rect.left), (rect.bottom - rect.top) };
}
void RWindow::SetPos(int x, int y) {
SetWindowPos(w32Vars.hwnd, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
SetWindowPos(platform->hwnd, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
}
void RWindow::SetPos(const IPair& pos) {
@@ -79,15 +85,28 @@ void RWindow::SetPos(const IPair& pos) {
void RWindow::Fullscreen() {
// Implement fullscreen
SetWindowLong(w32Vars.hwnd, GWL_STYLE, GetWindowLong(w32Vars.hwnd, GWL_STYLE) & ~WS_OVERLAPPEDWINDOW);
SetWindowPos(w32Vars.hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
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(w32Vars.hwnd, GWL_STYLE, GetWindowLong(w32Vars.hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
SetWindowPos(w32Vars.hwnd, nullptr, 0, 0, width, height, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
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();
}