Compare commits

...

5 Commits

Author SHA1 Message Date
ee408c2fe6 Merge remote-tracking branch 'origin/main'
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 6m44s
2024-12-11 11:03:47 -06:00
f50280824d Add inputservice.hpp 2024-12-11 11:03:34 -06:00
74d5f13c06 Temporary Input namespace which will become part of ReInput subproject later.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m54s
2024-12-11 01:36:56 -05:00
1950aee948 Further cleanup (Not stable), WIP RenderingAPI refactor, WIP windows fixes.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Has been cancelled
2024-12-06 15:22:04 -05:00
2d9f7e08b0 Refactored window finalization logic.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 6m6s
2024-12-06 13:14:20 -05:00
8 changed files with 316 additions and 161 deletions

View File

@@ -0,0 +1,5 @@
#pragma once
namespace InputService {
};

View File

@@ -4,7 +4,11 @@
namespace ReWindow::Logger {
using namespace jlog;
using Logger = GenericLogger;
extern GenericLogger Fatal;
extern GenericLogger Debug;
extern Logger Info;
extern Logger Fatal;
extern Logger Error;
extern Logger Warning;
extern Logger Debug;
}

View File

@@ -11,10 +11,9 @@ namespace ReWindow {
using precision_timestamp = precision_clock::time_point;
class TimestampedEvent {
private:
public:
precision_timestamp Timestamp;
explicit TimestampedEvent(precision_timestamp timestamp) : Timestamp(timestamp) {}
TimestampedEvent() : Timestamp(precision_clock::now())
{ }
};
@@ -24,15 +23,43 @@ namespace ReWindow {
RWindowEvent() : TimestampedEvent() { }
};
class KeyboardEvent : public RWindowEvent {
class InputDeviceEvent : public RWindowEvent {
public:
InputDeviceEvent() : RWindowEvent() { }
};
class KeyboardEvent : public InputDeviceEvent {
public:
Key key;
KeyState state;
KeyboardEvent(Key key, KeyState state) : RWindowEvent(), key(key), state(state) {}
KeyboardEvent(const Key& key, KeyState state) : InputDeviceEvent(), key(key), state(state) {}
};
class MouseEvent : public RWindowEvent {};
class MouseEvent : public InputDeviceEvent {};
class GamepadEvent : public RWindowEvent {};
class GamepadEvent : public InputDeviceEvent {};
class MouseButtonEvent : public MouseEvent {
public:
MouseButton Button;
bool Pressed; // TODO: replace with MouseButtonState enum
MouseButtonEvent() = default;
MouseButtonEvent(const MouseButton& button, bool pressed) : MouseEvent(), Button(button), Pressed(pressed) {}
};
class MouseButtonDownEvent : public MouseButtonEvent {
public:
MouseButton Button;
MouseButtonDownEvent() = default;
MouseButtonDownEvent(const MouseButton& button) : MouseButtonEvent(button, true) {}
};
class MouseButtonUpEvent : public MouseButtonEvent {
public:
MouseButtonUpEvent() = default;
MouseButtonUpEvent(const MouseButton& button) : MouseButtonEvent(button, true) {}
};
class MouseMoveEvent : public MouseEvent {
public:
@@ -46,12 +73,12 @@ namespace ReWindow {
class KeyDownEvent : public KeyboardEvent {
public:
KeyDownEvent(Key key) : KeyboardEvent(key, KeyState::Pressed) {}
explicit KeyDownEvent(const Key& key) : KeyboardEvent(key, KeyState::Pressed) {}
};
class KeyUpEvent : public KeyboardEvent {
public:
KeyUpEvent(Key key) : KeyboardEvent(key, KeyState::Released) {}
explicit KeyUpEvent(const Key& key) : KeyboardEvent(key, KeyState::Released) {}
};
class MouseWheelEvent : public MouseEvent
@@ -62,22 +89,9 @@ namespace ReWindow {
MouseWheelEvent(int wheel) : MouseEvent(), WheelMovement(wheel) {}
};
class MouseButtonDownEvent : public MouseEvent {
public:
MouseButton Button;
MouseButtonDownEvent() = default;
MouseButtonDownEvent(MouseButton button) : MouseEvent(), Button(button) {}
};
class MouseButtonUpEvent : public MouseEvent {
public:
MouseButton Button;
MouseButtonUpEvent() = default;
MouseButtonUpEvent(MouseButton button) : MouseEvent(), Button(button) {}
};
class WindowResizeRequestEvent : public RWindowEvent
class WindowResizeRequestEvent : public MouseButtonEvent
{
public:
Vector2 Size;

View File

@@ -11,6 +11,7 @@
#include <J3ML/LinearAlgebra.hpp>
#include <rewindow/types/WindowEvents.hpp>
#include <format>
#include <queue>
enum class RWindowFlags: uint8_t {
@@ -99,17 +100,72 @@ namespace ReWindow
}
};
// TODO: Refactor RenderingAPI into a polymorphic class interface for greater reusability.
class IRenderer {
public:
virtual void Initialize();
virtual void SwapBuffers();
virtual std::string GetDriverVendor();
virtual void SetVsync(bool enabled);
virtual void SetViewportSize(int width, int height);
virtual void MakeCurrent();
};
class VulkanRenderBase : public IRenderer {};
class GLRenderBase : public IRenderer {};
class GLXRenderer : public GLRenderBase {};
class WGLRenderer : public GLRenderBase {};
// Temporary static input service namespace, TODO: this will be refactored as part of ReInput later.
namespace Input {
inline Event<KeyboardEvent> OnKeyboardEvent;
inline Event<KeyboardEvent> OnKeyEvent;
inline Event<KeyDownEvent> OnKeyDown;
inline Event<KeyUpEvent> OnKeyUp;
inline Event<MouseMoveEvent> OnMouseEvent;
inline Event<MouseButtonEvent> OnMouseButtonEvent;
inline Event<MouseMoveEvent> OnMouseMove;
inline Event<MouseButtonDownEvent> OnMouseDown;
inline Event<MouseButtonUpEvent> OnMouseUp;
inline Event<MouseWheelEvent> OnMouseWheel;
bool IsKeyDown(const Key& key);
bool IsMouseButtonDown(const MouseButton& button);
Vector2 GetMousePosition();
Vector2 GetWindowSize();
}
/// 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 RWindow {
public:
#pragma region Constructors
/// The default constructor sets a default size and window title.
RWindow();
/// Constructs a window by explicitly setting title, width and height.
RWindow(const std::string& title, int width, int height);
/// The default constructor does not set any members, and are left uninitialized.
RWindow() = default;
/// Constructs a window by explicitly setting the title, width, height, and optionally; rendering API, fullscreen, resizable, and vsync.
/// @param wTitle The window title text.
/// @param wWidth
/// @param wHeight
/// @param wRenderer
/// @param wFullscreen
/// @param wResizable
/// @param wVsync
explicit RWindow(const std::string& wTitle, int wWidth = 640, int wHeight = 480,
RenderingAPI wRenderer = RenderingAPI::OPENGL,
bool wFullscreen = false,
bool wResizable = true,
bool wVsync = false);
/// Constructs a window as above with the additional argument of explicitly setting which render API is to be used.
RWindow(const std::string& title, int width, int height, RenderingAPI renderer);
/// The destructor deallocates and cleans up any memory used by the RWindow program.
/// @note If the window handle is not already destroyed, it will be done here.
~RWindow();
#pragma endregion
#pragma region Static Accessors
static RWindow* GetExtant();
#pragma endregion
/// Bindables are provided for hooking into window instances conveniently, without the need to derive and override for simple use cases.
@@ -168,9 +224,20 @@ namespace ReWindow
/// Calling this function, therefore, creates the real 'window' object on the operating system.
void Open();
/// Cleans up and closes the window without destroying the handle.
/// Tells the window that we want to close, without directly forcing it to. This gives us time to finalize any work we are performing.
[[nodiscard]] bool IsOpen() const { return open;}
[[nodiscard]] bool IsClosing() const { return closing;}
/// Cleans up and closes the window object.
void Close();
/// Closes the window immediately, potentially without allowing finalization to occur.
void ForceClose();
void ForceCloseAndTerminateProgram();
void CloseAndReopenInPlace();
void MessageBox(); // TODO: Must be implemented from scratch as a Motif Window in x11
@@ -237,7 +304,7 @@ namespace ReWindow
/// 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 DestroyWindow();
void DestroyOSWindowHandle();
/// Reads events from the operating system, and processes them accordingly.
/// TODO: Move out of public API, consumers should call Refresh or ideally an update() call.
@@ -321,6 +388,12 @@ namespace ReWindow
/// Returns the number of frames ran since the windows' creation.
[[nodiscard]] float GetRefreshCounter() const;
protected:
void LogEvent(const RWindowEvent& e) { eventLog.push_back(e);}
//void EnqueueEvent(const RWindowEvent& e) { eventQueue.push(e);}
RWindowEvent GetLastEvent() const {
return eventLog.back();
}
/// Requests the operating system to make the window fullscreen. Saves the previous window size as well.
void Fullscreen();
@@ -329,47 +402,44 @@ namespace ReWindow
protected:
#pragma region Data
int width = 1280;
int height = 720;
bool open = false; // Is the underlying OS-Window-Handle actually open.
bool resizable = true;
bool fullscreen_mode = false;
bool focused = true;
bool vsync = false;
bool cursor_visible = true;
bool closing = false;
float delta_time = 0.f;
float refresh_rate = 0.f;
unsigned int refresh_count = 0;
std::string title = "Redacted Window";
int width = 1280;
int height = 720;
bool fullscreen_mode = false;
bool focused = true;
bool vsync = false;
bool cursor_visible = true;
bool open = false;
bool resizable = true;
Vector2 lastKnownWindowSize {0, 0};
bool flags[5];
std::vector<RWindowEvent> eventLog;
KeyboardState currentKeyboard; // Current Frame's Keyboard State
KeyboardState previousKeyboard; // Previous Frame's Keyboard State
MouseState currentMouse;
MouseState previousMouse;
std::vector<RWindowEvent> eventLog; // history of all logged window events.
std::queue<RWindowEvent> eventQueue; //
KeyboardState currentKeyboard; // current frame keyboard state.
KeyboardState previousKeyboard; // previous frame keyboard state.
MouseState currentMouse; // purrent frame mouse state.
MouseState previousMouse; // previous frame mouse state
RenderingAPI renderer = RenderingAPI::OPENGL;
//Vector2 mouse_coords = {0, 0};
//Vector2 last_mouse_coords = {0, 0};
// TODO: Implement ringbuffer / circular vector class of some sort.
float refresh_rate_prev_1 = 0.f;
float refresh_rate_prev_2 = 0.f;
float refresh_rate_prev_3 = 0.f;
float refresh_rate_prev_4 = 0.f;
float refresh_rate_prev_5 = 0.f;
float delta_time = 0.f;
float refresh_rate = 0.f;
unsigned int refresh_count = 0;
// TODO: Implement ringbuffer / circular vector class of some sort.
float refresh_rate_prev_1 = 0.f;
float refresh_rate_prev_2 = 0.f;
float refresh_rate_prev_3 = 0.f;
float refresh_rate_prev_4 = 0.f;
float refresh_rate_prev_5 = 0.f;
float avg_refresh_rate = 0.0f;
float avg_refresh_rate = 0.0f;
#pragma endregion
#pragma region Internals
/// Returns the most accurate and recent available mouse coordinates.

View File

@@ -47,7 +47,6 @@ class MyWindow : public ReWindow::RWindow {
if (IsMouseButtonDown(MouseButtons::Middle))
std::cout << "Middle Mouse Button" << std::endl;
if (IsMouseButtonDown(MouseButtons::Mouse4))
std::cout << "Mouse4 Mouse Button" << std::endl;
@@ -62,43 +61,26 @@ class MyWindow : public ReWindow::RWindow {
}
bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override {
std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
//std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
return true;
}
void OnMouseButtonDown(const ReWindow::MouseButtonDownEvent &e) override
{
std::cout << "Overload Down: " << e.Button.Mnemonic << std::endl;
//std::cout << "Overload Down: " << e.Button.Mnemonic << std::endl;
RWindow::OnMouseButtonDown(e);
}
void OnMouseButtonUp(const ReWindow::MouseButtonUpEvent &e) override
{
std::cout << "Overload Up: " << e.Button.Mnemonic << std::endl;
//std::cout << "Overload Up: " << e.Button.Mnemonic << std::endl;
RWindow::OnMouseButtonUp(e);
}
};
int main() {
auto* window = new MyWindow("Test Window", 600, 480);
jlog::Debug(std::format("New window '{}' created. width={} height={}", window->GetTitle(), window->GetWidth(),
window->GetHeight()));
window->SetRenderer(RenderingAPI::OPENGL);
jlog::Debug(std::format("Rendering API OPENGL set for window '{}'", window->GetTitle()));
window->Open();
jlog::Debug(std::format("Opened window '{}'", window->GetTitle()));
// TODO: Cannot set flags until after window is open
// Make this work somehow
jlog::Debug("TODO: Cannot set flags until after window is open");
window->SetFullscreen(false);
window->SetVsyncEnabled(true);
window->SetResizable(true);
window->SetCursorVisible(false);
/*
/*
std::vector<ReWindow::Display> d = ReWindow::Display::getDisplaysFromWindowManager();
for (ReWindow::Display& display : d) {
@@ -123,6 +105,26 @@ int main() {
}
*/
auto* window = new MyWindow("Test Window", 600, 480);
jlog::Debug(std::format("New window '{}' created. width={} height={}", window->GetTitle(), window->GetWidth(),
window->GetHeight()));
window->SetRenderer(RenderingAPI::OPENGL);
jlog::Debug(std::format("Rendering API OPENGL set for window '{}'", window->GetTitle()));
window->Open();
jlog::Debug(std::format("Opened window '{}'", window->GetTitle()));
// TODO: Cannot set flags until after window is open
// Make this work somehow
jlog::Debug("TODO: Cannot set flags until after window is open");
window->SetFullscreen(false);
window->SetVsyncEnabled(true);
window->SetResizable(true);
window->SetCursorVisible(false);
ReWindow::Logger::Debug(std::format("Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} QUIT={}",
window->GetTitle(),
window->GetFlag(RWindowFlags::IN_FOCUS),
@@ -146,10 +148,12 @@ int main() {
std::cout << window->GetMouseWheelPersistent() << std::endl;
};
while (window->IsAlive()) {
window->PollEvents();
while (!window->IsClosing()) {
//window->PollEvents();
window->ManagedRefresh();
}
delete window;
// Alternatively:
/*
* while (window->IsAlive()) {
@@ -164,6 +168,9 @@ int main() {
* }
*
*/
//exit(0);
return 0;
}
/*

View File

@@ -2,6 +2,10 @@
namespace ReWindow::Logger {
using namespace jlog;
GenericLogger Fatal {"ReWindow::fatal", GlobalLogFile, Colors::Reds::Crimson, Colors::Gray, Colors::Gray, Colors::Reds::Crimson, Colors::White};
GenericLogger Debug {"ReWindow::debug", GlobalLogFile, Colors::Purples::Purple, Colors::Gray, Colors::Gray, Colors::Purples::Purple, Colors::White};
using namespace Colors;
using Logger = GenericLogger;
Logger Info {"ReWindow", GlobalLogFile, Gray, Gray, Gray, Gray};
Logger Fatal {"ReWindow::fatal", GlobalLogFile, Reds::Crimson, Gray, Gray, Reds::Crimson, White};
Logger Debug {"ReWindow::debug", GlobalLogFile, Purples::Purple, Gray, Gray, Purples::Purple, White};
}

View File

@@ -54,12 +54,15 @@ void RWindow::Lower() const
XLowerWindow(display, window);
}
void RWindow::DestroyWindow() {
void RWindow::DestroyOSWindowHandle() {
Logger::Debug(std::format("Destroying window '{}'", this->title));
XDestroySubwindows(display, window);
Logger::Debug(std::format("Destroyed window '{}'", this->title));
XDestroyWindow(display, window);
delete this;
system("xset r on"); // Re-set X-server parameter to enable key-repeat.
open = false;
}
//void RWindow::
@@ -116,18 +119,14 @@ void RWindow::PollEvents() {
XNextEvent(display, &xev);
if (xev.type == ClientMessage)
Logger::Debug(std::format("Recieved event '{}'", "ClientMessage"));
Logger::Info(std::format("Event '{}'", "ClientMessage"));
if (xev.xclient.message_type == XInternAtom(display, "WM_PROTOCOLS", False) && static_cast<Atom>(xev.xclient.data.l[0]) == wmDeleteWindow) {
processOnClose();
DestroyWindow();
system("xset r on");
exit(0);
Close();
}
if (xev.type == FocusIn) {
Logger::Debug(std::format("Recieved event '{}'", "FocusIn"));
Logger::Debug(std::format("Event'{}'", "FocusIn"));
XAutoRepeatOff(display);
SetFlag(RWindowFlags::IN_FOCUS, true);
@@ -141,7 +140,7 @@ void RWindow::PollEvents() {
}
if (xev.type == FocusOut) {
Logger::Debug(std::format("Recieved event '{}'", "FocusOut"));
Logger::Debug(std::format("Event '{}'", "FocusOut"));
XAutoRepeatOn(display);
SetFlag(RWindowFlags::IN_FOCUS, false);
@@ -152,14 +151,14 @@ void RWindow::PollEvents() {
}
if (xev.type == KeyRelease) {
Logger::Debug(std::format("Recieved event '{}'", "KeyRelease"));
Logger::Debug(std::format("Event '{}'", "KeyRelease"));
auto scancode = (X11Scancode) xev.xkey.keycode;
auto key = GetKeyFromX11Scancode(scancode);
processKeyRelease(key);
}
if (xev.type == KeyPress) {
Logger::Debug(std::format("Recieved event '{}'", "KeyPress"));
Logger::Debug(std::format("Event '{}'", "KeyPress"));
auto scancode = (X11Scancode) xev.xkey.keycode;
auto key = GetKeyFromX11Scancode(scancode);
processKeyPress(key);
@@ -172,7 +171,7 @@ void RWindow::PollEvents() {
// and only call on ButtonPress, otherwise it will appear to duplicate the mouse wheel scroll.
if (xev.xbutton.button != 4 && xev.xbutton.button != 5) {
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
Logger::Debug(std::format("Recieved event '{}'", "ButtonRelease"));
Logger::Debug(std::format("Event '{}'", "ButtonRelease"));
processMouseRelease(button);
}
}
@@ -190,7 +189,7 @@ void RWindow::PollEvents() {
{
MouseButton button = GetMouseButtonFromXButton(xev.xbutton.button);
Logger::Debug(std::format("Window event: MouseButtonPress {}", button.Mnemonic));
Logger::Debug(std::format("Event: MouseButtonPress {}", button.Mnemonic));
processMousePress(button);
}
@@ -198,18 +197,18 @@ void RWindow::PollEvents() {
if (xev.type == Expose)
{
Logger::Debug(std::format("Recieved event '{}'", "Expose"));
Logger::Debug(std::format("Event '{}'", "Expose"));
}
// NOTE: This event is functionally useless, as it only informs of the very beginning and end of a mouse movement.
if (xev.type == MotionNotify)
{
Logger::Debug(std::format("Recieved event '{}'", "MotionNotify"));
Logger::Debug(std::format("Event '{}'", "MotionNotify"));
}
if (xev.type == ConfigureNotify) {
if (this->width != xev.xconfigurerequest.width || this->height != xev.xconfigurerequest.height) {
Logger::Debug(std::format("Recieved event '{}'", "ResizeRequest"));
Logger::Debug(std::format("Event '{}'", "ResizeRequest"));
this->width = xev.xconfigurerequest.width;
this->height = xev.xconfigurerequest.height;
@@ -241,7 +240,7 @@ void RWindow::SetSize(int newWidth, int newHeight) {
this->height = newHeight;
XResizeWindow(display, window, newWidth, newHeight);
XFlush(display);
Logger::Debug(std::format("Set size for window '{}'. width={} height={}", this->title, newWidth, newHeight));
Logger::Info(std::format("Set size for '{}' to {} x {}", this->title, newWidth, newHeight));
}
Vector2 RWindow::GetAccurateMouseCoordinates() const {
@@ -293,9 +292,8 @@ void RWindow::GLSwapBuffers() {
}
void RWindow::Fullscreen() {
Logger::Debug(std::format("Fullscreening window '{}'", this->title));
Logger::Info(std::format("Fullscreening '{}'", this->title));
fullscreen_mode = true;
XEvent xev;
@@ -312,11 +310,11 @@ void RWindow::Fullscreen() {
xev.xclient.data.l[1] = fullscreen_mode;
xev.xclient.data.l[2] = 0;
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
Logger::Debug(std::format("Fullscreened window '{}'", this->title));
Logger::Debug(std::format("Fullscreened '{}'", this->title));
}
void RWindow::RestoreFromFullscreen() {
Logger::Debug(std::format("Restoring window '{}' from Fullscreen", this->title));
Logger::Debug(std::format("Restoring '{}' from Fullscreen", this->title));
fullscreen_mode = false;
XEvent xev;
Atom wm_state = XInternAtom(display, "_NET_WM_STATE", False);
@@ -330,7 +328,7 @@ void RWindow::RestoreFromFullscreen() {
xev.xclient.data.l[1] = fullscreen_mode;
xev.xclient.data.l[2] = 0;
XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
Logger::Debug(std::format("Restored window '{}' from Fullscreen", this->title));
Logger::Debug(std::format("Restored '{}' from Fullscreen", this->title));
}
void RWindow::SetVsyncEnabled(bool b) {
@@ -385,8 +383,8 @@ void RWindow::Open() {
// Get the position of the renderable area relative to the rest of the window.
XGetWindowAttributes(display, window, &windowAttributes);
render_area_position = { (float) windowAttributes.x, (float) windowAttributes.y };
open = true;
open = true;
processOnOpen();
}

View File

@@ -15,22 +15,21 @@ std::string RWindowFlagToStr(RWindowFlags flag) {
using namespace ReWindow;
RWindow::RWindow() {
title = "ReWindow Application";
width = 640;
height = 480;
//RWindow::singleton = this;
static RWindow* extant;
RWindow::RWindow(const std::string& wTitle, int wWidth, int wHeight, RenderingAPI wRenderer, bool wFullscreen, bool wResizable, bool wVsync)
: title(wTitle), width(wWidth), height(wHeight), renderer(wRenderer), fullscreen_mode(wFullscreen), resizable(wResizable), vsync(wVsync),
flags{false,wFullscreen,wResizable,wVsync} {
extant = this;
}
RWindow::RWindow(const std::string& title, int width, int height) : flags{false,false,false,false} {
this->title = title;
this->width = width;
this->height = height;
//RWindow::singleton = this;
RWindow::~RWindow() {
if (open)
DestroyOSWindowHandle();
}
RWindow::RWindow(const std::string& title, int width, int height, RenderingAPI renderer) :
title(title), width(width), height(height), renderer(renderer) {}
Vector2 RWindow::GetMouseCoordinates() const {
return currentMouse.Position;
@@ -41,10 +40,9 @@ bool RWindow::GetFlag(RWindowFlags flag) const {
}
bool RWindow::IsAlive() const {
return true;
return (!closing) && open;
}
void RWindow::SetFullscreen(bool fs) {
if (fs)
Fullscreen();
@@ -52,11 +50,13 @@ void RWindow::SetFullscreen(bool fs) {
RestoreFromFullscreen();
}
#pragma region Event Processors Implementation
void RWindow::processFocusIn()
{
RWindowEvent event {};
OnFocusGain(event);
OnFocusGainEvent(event);
LogEvent(event);
}
void RWindow::processFocusOut()
@@ -64,31 +64,39 @@ void RWindow::processFocusOut()
RWindowEvent event {};
OnFocusLost(event);
OnFocusLostEvent(event);
LogEvent(event);
}
void RWindow::processMousePress(const MouseButton& btn)
{
currentMouse.Set(btn, true);
auto eventData = MouseButtonDownEvent(btn);
OnMouseButtonDown(eventData);
OnMouseButtonDownEvent(eventData);
auto event = MouseButtonDownEvent(btn);
OnMouseButtonDown(event);
OnMouseButtonDownEvent(event);
Input::OnMouseButtonEvent(MouseButtonEvent(btn, true));
Input::OnMouseDown(event);
LogEvent(event);
}
void RWindow::processMouseMove(Vector2 last_pos, Vector2 new_pos)
{
currentMouse.Position = new_pos;
auto eventData = MouseMoveEvent(new_pos);
OnMouseMove(eventData);
OnMouseMoveEvent(eventData);
auto event = MouseMoveEvent(new_pos);
OnMouseMove(event);
OnMouseMoveEvent(event);
Input::OnMouseMove(event);
LogEvent(event);
}
void RWindow::processMouseRelease(const MouseButton& btn)
{
currentMouse.Set(btn, false);
auto eventData = MouseButtonUpEvent(btn);
OnMouseButtonUp(eventData);
OnMouseButtonUpEvent(eventData);
auto event = MouseButtonUpEvent(btn);
OnMouseButtonUp(event);
OnMouseButtonUpEvent(event);
Input::OnMouseButtonEvent(MouseButtonEvent(btn, false));
Input::OnMouseUp(event);
LogEvent(event);
}
@@ -96,9 +104,41 @@ void RWindow::processKeyRelease(Key key) {
currentKeyboard.PressedKeys[key] = false;
auto event = KeyUpEvent(key);
OnKeyUp(event);
OnKeyUpEvent(key);
OnKeyUpEvent(event);
Input::OnKeyboardEvent(KeyboardEvent(key, KeyState::Released));
Input::OnKeyEvent(KeyboardEvent(key, KeyState::Released));
Input::OnKeyUp(event);
LogEvent(event);
}
void RWindow::processKeyPress(Key key) {
currentKeyboard.PressedKeys[key] = true;
auto event = KeyDownEvent(key);
OnKeyDown(event);
OnKeyDownEvent(event);
Input::OnKeyDown(event);
Input::OnKeyboardEvent(KeyboardEvent(key, KeyState::Pressed));
Input::OnKeyEvent(KeyboardEvent(key, KeyState::Pressed));
LogEvent(event);
}
void RWindow::processOnClose()
{
auto event = RWindowEvent();
OnClosing();
OnClosingEvent();
LogEvent(event);
}
void RWindow::processOnOpen()
{
auto event = RWindowEvent();
OnOpen();
OnOpenEvent();
LogEvent(event);
}
#pragma endregion
std::string RWindow::GetTitle() const {
return this->title;
@@ -152,24 +192,6 @@ bool RWindow::IsMouseButtonDown(const MouseButton &button) const {
return currentMouse.IsDown(button);
}
void RWindow::processKeyPress(Key key) {
currentKeyboard.PressedKeys[key] = true;
auto eventData = KeyDownEvent(key);
OnKeyDown(eventData);
OnKeyDownEvent(key);
}
void RWindow::processOnClose()
{
OnClosing();
OnClosingEvent();
}
void RWindow::processOnOpen()
{
OnOpen();
OnOpenEvent();
}
void RWindow::ManagedRefresh()
{
@@ -194,7 +216,6 @@ void RWindow::Refresh() {
processMouseMove(previousMouse.Position, currentMouse.Position);
previousMouse.Position = currentMouse.Position;
}
}
float RWindow::ComputeElapsedFrameTimeSeconds(std::chrono::steady_clock::time_point start, std::chrono::steady_clock::time_point end) {
@@ -232,11 +253,6 @@ void RWindow::processMouseWheel(int scrolls)
}
void RWindow::Close() {
/// TODO: Implement closing the window without destroying the handle.
processOnClose();
}
bool RWindow::IsResizable() const {
return resizable;
}
@@ -259,3 +275,40 @@ bool RWindow::IsFocused() const {
float RWindow::GetRefreshCounter() const { return refresh_count; }
void RWindow::Close() {
closing = true;
processOnClose();
}
void RWindow::ForceClose() {
Close();
DestroyOSWindowHandle();
}
RWindow * RWindow::GetExtant() {
return extant;
}
void RWindow::ForceCloseAndTerminateProgram() {
ForceClose();
exit(0);
}
bool Input::IsKeyDown(const Key &key) {
return extant->IsKeyDown(key);
}
bool Input::IsMouseButtonDown(const MouseButton &button) {
return extant->IsMouseButtonDown(button);
}
Vector2 Input::GetMousePosition() {
return extant->GetMouseCoordinates();
}
Vector2 Input::GetWindowSize() {
return extant->GetSize();
}