Remove need expose windows.h
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 7m6s

This commit is contained in:
2025-07-14 04:51:15 -04:00
parent 1f8bd9b6c2
commit 93707dbd71
3 changed files with 18 additions and 33 deletions

View File

@@ -1,19 +1,15 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <vector> #include <vector>
#include <Event.h> #include <queue>
#include <map> #include <map>
#include <thread> #include <Event.h>
#include <ReWindow/types/Key.h> #include <ReWindow/types/Key.h>
#include <ReWindow/types/Cursors.h> #include <ReWindow/types/Cursors.h>
#include <ReWindow/types/MouseButton.h> #include <ReWindow/types/MouseButton.h>
#include <ReWindow/types/WindowEvents.h> #include <ReWindow/types/WindowEvents.h>
#include <queue>
// TODO: Hide this eventually if possible.
#ifdef WIN32
#include <Windows.h>
#endif
namespace ReWindow { namespace ReWindow {
struct KeyboardState { std::map<Key, bool> PressedKeys; }; struct KeyboardState { std::map<Key, bool> PressedKeys; };
@@ -49,10 +45,11 @@ public:
/// RWindow is a class implementation of a platform-independent window abstraction. /// RWindow is a class implementation of a platform-independent window abstraction.
/// This library also provides abstractions for user-input devices, and their interaction with the window. /// This library also provides abstractions for user-input devices, and their interaction with the window.
class ReWindow::RWindow { class ReWindow::RWindow {
protected: protected:
class Platform; class Platform;
friend class Platform;
Platform* platform; Platform* platform;
inline static RWindow* extant; inline static RWindow* extant;
int width = 640; int width = 640;
@@ -242,9 +239,6 @@ public:
/// Returns the vertical length of this window, in pixels. /// Returns the vertical length of this window, in pixels.
[[nodiscard]] int GetHeight() const; [[nodiscard]] int GetHeight() const;
/// This is unfortunately here because of the poor design of windows. Maybe once interfaces are done this won't be required anymore.
void SetSizeWithoutEvent(const std::pair<int, int>& size);
/// Tells the underlying window manager to destroy this window and drop the handle. /// Tells the underlying window manager to destroy this window and drop the handle.
/// The window, in theory, can not be re-opened after this. /// The window, in theory, can not be re-opened after this.
void DestroyOSWindowHandle(); void DestroyOSWindowHandle();
@@ -337,12 +331,7 @@ public:
/// Updates internals to account for the latest calculated frame time. /// Updates internals to account for the latest calculated frame time.
void UpdateFrameTiming(float frame_time); void UpdateFrameTiming(float frame_time);
#ifdef WIN32
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
#endif
protected: protected:
/// These unfortunately *have* to be public because of the poor design of the windows event loop.
void processKeyRelease(Key key); void processKeyRelease(Key key);
void processKeyPress(Key key); void processKeyPress(Key key);
/// @note This will be invoked **before** the window-close procedure begins. /// @note This will be invoked **before** the window-close procedure begins.
@@ -355,6 +344,7 @@ protected:
void processFocusOut(); void processFocusOut();
void processMouseMove(const std::pair<int, int>& last_pos, const std::pair<int, int>& new_pos); void processMouseMove(const std::pair<int, int>& last_pos, const std::pair<int, int>& new_pos);
void processMouseWheel(int scrolls); void processMouseWheel(int scrolls);
void SetSizeWithoutEvent(const std::pair<int, int>& size);
/// Virtual functions which *must* be overridden based on the Renderer. /// Virtual functions which *must* be overridden based on the Renderer.
public: public:

View File

@@ -73,6 +73,5 @@ int main() {
if (window->IsFocused()) if (window->IsFocused())
window->SetCursorCenter(); window->SetCursorCenter();
} }
delete window; delete window;
} }

View File

@@ -3,7 +3,6 @@
#include <ReWindow/types/Window.h> #include <ReWindow/types/Window.h>
#include <ReWindow/Logger.h> #include <ReWindow/Logger.h>
class ReWindow::RWindow::Platform { class ReWindow::RWindow::Platform {
public: public:
HINSTANCE hInstance; HINSTANCE hInstance;
@@ -11,14 +10,12 @@ public:
HDC hdc; HDC hdc;
std::pair<int, int> window_size_before_fullscreen; std::pair<int, int> window_size_before_fullscreen;
std::pair<int, int> window_position_before_fullscreen; std::pair<int, int> window_position_before_fullscreen;
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
}; };
using namespace ReWindow; using namespace ReWindow;
// TODO get rid of this.
bool local_focused = true;
bool local_toggling_cursor_focused = false;
void RWindow::SetSize(int newWidth, int newHeight) { void RWindow::SetSize(int newWidth, int newHeight) {
if (!resizable) if (!resizable)
return; return;
@@ -41,7 +38,7 @@ void RWindow::SetSize(int newWidth, int newHeight) {
void RWindow::SetCursorFocused(bool state) { void RWindow::SetCursorFocused(bool state) {
local_toggling_cursor_focused = state; toggling_cursor_focus = state;
if (state) if (state)
cursor_focused = true; cursor_focused = true;
@@ -49,7 +46,7 @@ void RWindow::SetCursorFocused(bool state) {
else if (!state && cursor_focused) { else if (!state && cursor_focused) {
ClipCursor(nullptr); ClipCursor(nullptr);
cursor_focused = false; cursor_focused = false;
local_toggling_cursor_focused = false; toggling_cursor_focus = false;
} }
} }
@@ -92,10 +89,9 @@ void RWindow::PollEvents() {
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
TranslateMessage(&msg), TranslateMessage(&msg),
DispatchMessage(&msg); DispatchMessage(&msg);
focused = local_focused;
} }
LRESULT CALLBACK RWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT CALLBACK RWindow::Platform::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
auto* window = reinterpret_cast<RWindow*>( GetWindowLongPtr(hwnd, GWLP_USERDATA) ); auto* window = reinterpret_cast<RWindow*>( GetWindowLongPtr(hwnd, GWLP_USERDATA) );
switch (uMsg) { switch (uMsg) {
case WM_CLOSE: { case WM_CLOSE: {
@@ -119,10 +115,10 @@ LRESULT CALLBACK RWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
case WM_SETFOCUS: { case WM_SETFOCUS: {
window->processFocusIn(); window->processFocusIn();
local_focused = true; window->focused = true;
if (window->GetCursorFocused()) if (window->GetCursorFocused())
local_toggling_cursor_focused = true; window->toggling_cursor_focus = true;
// Cancels window flashing. // Cancels window flashing.
// TODO check if we're flashing before this. // TODO check if we're flashing before this.
@@ -136,9 +132,9 @@ LRESULT CALLBACK RWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
if (window->GetCursorFocused()) { if (window->GetCursorFocused()) {
ClipCursor(nullptr); ClipCursor(nullptr);
local_toggling_cursor_focused = true; window->toggling_cursor_focus = true;
} }
local_focused = false; window->focused = false;
} }
case WM_SETCURSOR: { case WM_SETCURSOR: {
@@ -226,7 +222,7 @@ LRESULT CALLBACK RWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
//This is the same as "Motion Notify" in the X Window System. //This is the same as "Motion Notify" in the X Window System.
case WM_MOUSEMOVE: { case WM_MOUSEMOVE: {
if (local_toggling_cursor_focused) { if (window->toggling_cursor_focus) {
RECT rect; RECT rect;
if (GetClientRect(hwnd, &rect)) { if (GetClientRect(hwnd, &rect)) {
POINT top_left = { rect.left, rect.top }; POINT top_left = { rect.left, rect.top };
@@ -236,7 +232,7 @@ LRESULT CALLBACK RWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
RECT clip_rect = { top_left.x, top_left.y, bottom_right.x, bottom_right.y }; RECT clip_rect = { top_left.x, top_left.y, bottom_right.x, bottom_right.y };
if (ClipCursor(&clip_rect)) if (ClipCursor(&clip_rect))
local_toggling_cursor_focused = false; window->toggling_cursor_focus = false;
} }
} }
} }
@@ -415,7 +411,7 @@ bool OpenGLWindow::Open() {
platform->hInstance = GetModuleHandle(nullptr); platform->hInstance = GetModuleHandle(nullptr);
WNDCLASS wc = { }; WNDCLASS wc = { };
wc.lpfnWndProc = RWindow::WindowProc; wc.lpfnWndProc = RWindow::Platform::WindowProc;
wc.hInstance = platform->hInstance; wc.hInstance = platform->hInstance;
wc.lpszClassName = "RWindowClass"; wc.lpszClassName = "RWindowClass";
RegisterClass(&wc); RegisterClass(&wc);