Compare commits

...

5 Commits

Author SHA1 Message Date
82e4ae39a9 Update Window.cpp
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m43s
2025-07-14 15:55:00 -04:00
93707dbd71 Remove need expose windows.h
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 7m6s
2025-07-14 04:51:15 -04:00
1f8bd9b6c2 Fix breaking change on linux due to inclusion of Windows header.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m33s
2025-07-13 18:14:48 -05:00
74fc93c4e1 Merge pull request 'Make WindowProc a static member, so we can hide processEvent...() methods.' (#29) from protect-events into main
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m21s
Reviewed-on: #29
2025-07-13 19:12:16 -04:00
f75825eb28 Make WindowProc a static member, so we can hide processEvent...() methods.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m41s
2025-07-13 18:11:07 -05:00
4 changed files with 20 additions and 25 deletions

View File

@@ -1,14 +1,14 @@
#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>
namespace ReWindow {
@@ -47,7 +47,9 @@ public:
class ReWindow::RWindow {
protected:
class Platform;
friend class Platform;
Platform* platform;
inline static RWindow* extant;
int width = 640;
@@ -237,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();
@@ -332,8 +331,7 @@ public:
/// Updates internals to account for the latest calculated frame time.
void UpdateFrameTiming(float frame_time);
public:
/// These unfortunately *have* to be public because of the poor design of the windows event loop.
protected:
void processKeyRelease(Key key);
void processKeyPress(Key key);
/// @note This will be invoked **before** the window-close procedure begins.
@@ -346,6 +344,7 @@ public:
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

@@ -5,6 +5,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <thread>
class ReWindow::RWindow::Platform {
public:

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 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 WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM 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 WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM 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 WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM 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 WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM 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 = WindowProc;
wc.lpfnWndProc = RWindow::Platform::WindowProc;
wc.hInstance = platform->hInstance;
wc.lpszClassName = "RWindowClass";
RegisterClass(&wc);