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
#include <cstdint>
#include <vector>
#include <Event.h>
#include <queue>
#include <map>
#include <thread>
#include <Event.h>
#include <ReWindow/types/Key.h>
#include <ReWindow/types/Cursors.h>
#include <ReWindow/types/MouseButton.h>
#include <ReWindow/types/WindowEvents.h>
#include <queue>
// TODO: Hide this eventually if possible.
#ifdef WIN32
#include <Windows.h>
#endif
namespace ReWindow {
struct KeyboardState { std::map<Key, bool> PressedKeys; };
@@ -49,10 +45,11 @@ public:
/// 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.
class ReWindow::RWindow {
protected:
class Platform;
friend class Platform;
Platform* platform;
inline static RWindow* extant;
int width = 640;
@@ -242,9 +239,6 @@ public:
/// Returns the vertical length of this window, in pixels.
[[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.
/// The window, in theory, can not be re-opened after this.
void DestroyOSWindowHandle();
@@ -337,12 +331,7 @@ public:
/// Updates internals to account for the latest calculated frame time.
void UpdateFrameTiming(float frame_time);
#ifdef WIN32
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
#endif
protected:
/// These unfortunately *have* to be public because of the poor design of the windows event loop.
void processKeyRelease(Key key);
void processKeyPress(Key key);
/// @note This will be invoked **before** the window-close procedure begins.
@@ -355,6 +344,7 @@ protected:
void processFocusOut();
void processMouseMove(const std::pair<int, int>& last_pos, const std::pair<int, int>& new_pos);
void processMouseWheel(int scrolls);
void SetSizeWithoutEvent(const std::pair<int, int>& size);
/// Virtual functions which *must* be overridden based on the Renderer.
public:

View File

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

View File

@@ -3,7 +3,6 @@
#include <ReWindow/types/Window.h>
#include <ReWindow/Logger.h>
class ReWindow::RWindow::Platform {
public:
HINSTANCE hInstance;
@@ -11,14 +10,12 @@ public:
HDC hdc;
std::pair<int, int> window_size_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;
// TODO get rid of this.
bool local_focused = true;
bool local_toggling_cursor_focused = false;
void RWindow::SetSize(int newWidth, int newHeight) {
if (!resizable)
return;
@@ -41,7 +38,7 @@ void RWindow::SetSize(int newWidth, int newHeight) {
void RWindow::SetCursorFocused(bool state) {
local_toggling_cursor_focused = state;
toggling_cursor_focus = state;
if (state)
cursor_focused = true;
@@ -49,7 +46,7 @@ void RWindow::SetCursorFocused(bool state) {
else if (!state && cursor_focused) {
ClipCursor(nullptr);
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))
TranslateMessage(&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) );
switch (uMsg) {
case WM_CLOSE: {
@@ -119,10 +115,10 @@ LRESULT CALLBACK RWindow::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
case WM_SETFOCUS: {
window->processFocusIn();
local_focused = true;
window->focused = true;
if (window->GetCursorFocused())
local_toggling_cursor_focused = true;
window->toggling_cursor_focus = true;
// Cancels window flashing.
// 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()) {
ClipCursor(nullptr);
local_toggling_cursor_focused = true;
window->toggling_cursor_focus = true;
}
local_focused = false;
window->focused = false;
}
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.
case WM_MOUSEMOVE: {
if (local_toggling_cursor_focused) {
if (window->toggling_cursor_focus) {
RECT rect;
if (GetClientRect(hwnd, &rect)) {
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 };
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);
WNDCLASS wc = { };
wc.lpfnWndProc = RWindow::WindowProc;
wc.lpfnWndProc = RWindow::Platform::WindowProc;
wc.hInstance = platform->hInstance;
wc.lpszClassName = "RWindowClass";
RegisterClass(&wc);