Refactor InputService to separate header file.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m32s

This commit is contained in:
2024-12-11 15:16:21 -06:00
parent ee408c2fe6
commit 8d8e14ef40
5 changed files with 51 additions and 44 deletions

View File

@@ -43,11 +43,11 @@ file(GLOB_RECURSE HEADERS "include/logger/*.h" "include/logger/*.hpp")
if(UNIX AND NOT APPLE)
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/linux/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp" )
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/linux/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp" "src/rewindow/*.cpp" )
endif()
if(WIN32)
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp")
file(GLOB_RECURSE SOURCES "src/types/*.cpp" "src/platform/windows/*.cpp" "src/platform/shared/*.cpp" "src/logger/*.cpp" "src/rewindow/*.cpp")
endif()
include_directories("include")

View File

@@ -1,5 +1,23 @@
#pragma once
namespace InputService {
#include <Event.h>
#include <rewindow/types/WindowEvents.hpp>
namespace InputService {
using namespace ReWindow;
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();
};

View File

@@ -118,24 +118,6 @@ namespace ReWindow
// 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 {

View File

@@ -1,4 +1,5 @@
#include <rewindow/types/window.h>
#include <rewindow/inputservice.hpp>
#include "rewindow/logger/logger.h"
std::string RWindowFlagToStr(RWindowFlags flag) {
switch (flag) {
@@ -73,8 +74,8 @@ void RWindow::processMousePress(const MouseButton& btn)
auto event = MouseButtonDownEvent(btn);
OnMouseButtonDown(event);
OnMouseButtonDownEvent(event);
Input::OnMouseButtonEvent(MouseButtonEvent(btn, true));
Input::OnMouseDown(event);
InputService::OnMouseButtonEvent(MouseButtonEvent(btn, true));
InputService::OnMouseDown(event);
LogEvent(event);
}
@@ -84,7 +85,7 @@ void RWindow::processMouseMove(Vector2 last_pos, Vector2 new_pos)
auto event = MouseMoveEvent(new_pos);
OnMouseMove(event);
OnMouseMoveEvent(event);
Input::OnMouseMove(event);
InputService::OnMouseMove(event);
LogEvent(event);
}
@@ -94,8 +95,8 @@ void RWindow::processMouseRelease(const MouseButton& btn)
auto event = MouseButtonUpEvent(btn);
OnMouseButtonUp(event);
OnMouseButtonUpEvent(event);
Input::OnMouseButtonEvent(MouseButtonEvent(btn, false));
Input::OnMouseUp(event);
InputService::OnMouseButtonEvent(MouseButtonEvent(btn, false));
InputService::OnMouseUp(event);
LogEvent(event);
}
@@ -105,9 +106,9 @@ void RWindow::processKeyRelease(Key key) {
auto event = KeyUpEvent(key);
OnKeyUp(event);
OnKeyUpEvent(event);
Input::OnKeyboardEvent(KeyboardEvent(key, KeyState::Released));
Input::OnKeyEvent(KeyboardEvent(key, KeyState::Released));
Input::OnKeyUp(event);
InputService::OnKeyboardEvent(KeyboardEvent(key, KeyState::Released));
InputService::OnKeyEvent(KeyboardEvent(key, KeyState::Released));
InputService::OnKeyUp(event);
LogEvent(event);
}
@@ -116,9 +117,9 @@ void RWindow::processKeyPress(Key key) {
auto event = KeyDownEvent(key);
OnKeyDown(event);
OnKeyDownEvent(event);
Input::OnKeyDown(event);
Input::OnKeyboardEvent(KeyboardEvent(key, KeyState::Pressed));
Input::OnKeyEvent(KeyboardEvent(key, KeyState::Pressed));
InputService::OnKeyDown(event);
InputService::OnKeyboardEvent(KeyboardEvent(key, KeyState::Pressed));
InputService::OnKeyEvent(KeyboardEvent(key, KeyState::Pressed));
LogEvent(event);
}
@@ -297,18 +298,7 @@ bool RWindow::IsFocused() const {
}
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();
}

View File

@@ -0,0 +1,17 @@
#include <rewindow/inputservice.hpp>
#include <rewindow/types/window.h>
namespace InputService
{
bool IsKeyDown(const Key &key) {
return RWindow::GetExtant()->IsKeyDown(key);
}
bool IsMouseButtonDown(const MouseButton &button) {
return RWindow::GetExtant()->IsMouseButtonDown(button);
}
Vector2 GetMousePosition() {
return RWindow::GetExtant()->GetMouseCoordinates();
}
Vector2 GetWindowSize() {
return RWindow::GetExtant()->GetSize();
}
}