Cleanup
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m54s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m54s
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
/// ReWindowLibrary
|
||||
/// A C++20 Library for creating and managing windows in a platform-independent manner
|
||||
/// Developed and Maintained by the boys @ Redacted Software.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file gamepad.h
|
||||
/// @desc A class that models the functionality of a gamepad / controller device.
|
||||
/// @edit 2024-07-29
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace ReWindow {
|
||||
class Gamepad;
|
||||
class Xbox360Gamepad;
|
||||
class XboxOneGamepad;
|
||||
class PS4Gamepad;
|
||||
class Ultimate8BitDoPro2Gamepad;
|
||||
}
|
||||
|
||||
class ReWindow::Gamepad {
|
||||
public:
|
||||
virtual ~Gamepad() = default;
|
||||
};
|
||||
|
||||
class ReWindow::XboxOneGamepad : public Gamepad {};
|
||||
class ReWindow::PS4Gamepad : public Gamepad {};
|
@@ -1,104 +0,0 @@
|
||||
/// ReWindowLibrary
|
||||
/// A C++20 Library for creating and managing windows in a platform-independent manner
|
||||
/// Developed and Maintained by the boys @ Redacted Software.
|
||||
/// (c) 2024 Redacted Software
|
||||
/// This work is dedicated to the public domain.
|
||||
|
||||
/// @file gamepadbutton.h
|
||||
/// @desc GamepadButton class and enumerations to define standard buttons found on a Gamepad
|
||||
/// @edit 2024-07-29
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
namespace ReWindow {
|
||||
class GamepadButton;
|
||||
class GamepadTrigger;
|
||||
class GamepadThumbstick;
|
||||
}
|
||||
|
||||
class ReWindow::GamepadButton {
|
||||
protected:
|
||||
std::string mnemonic_btn_code;
|
||||
public:
|
||||
explicit GamepadButton(std::string mnemonic) : mnemonic_btn_code(std::move(mnemonic)){}
|
||||
[[nodiscard]] std::string GetMnemonicButtonCode() const;
|
||||
|
||||
/// Compares two GamepadButtons by their mnemonic button codes, not their activation state.
|
||||
bool operator ==(const GamepadButton& rhs) const;
|
||||
};
|
||||
|
||||
class ReWindow::GamepadTrigger {
|
||||
protected:
|
||||
std::string mnemonic_trigger_code;
|
||||
/// A float value between 0 and 1 representing how much the trigger has been pushed in by.
|
||||
float position = 0.0f;
|
||||
|
||||
/// The minimum possible movement of the trigger from the at-rest position.
|
||||
/// Movements less than this won't count.
|
||||
float dead_zone = 0.0f;
|
||||
public:
|
||||
void SetDeadzone(float minimum = 0.01f);
|
||||
[[nodiscard]] float GetActuation() const;
|
||||
public:
|
||||
explicit GamepadTrigger(std::string mnemonic) : mnemonic_trigger_code(std::move(mnemonic)){}
|
||||
};
|
||||
|
||||
class ReWindow::GamepadThumbstick {
|
||||
protected:
|
||||
std::string mnemonic_stick_code;
|
||||
// X -1 is all the way left, X +1 is all the way right.
|
||||
// Y -1 is all the way down, Y +1 is all the way up.
|
||||
std::pair<float, float> position = {0.0f, 0.0f};
|
||||
|
||||
// The minimum possible movement from the center in any direction.
|
||||
float dead_zone = 0.0f;
|
||||
public:
|
||||
[[nodiscard]] std::pair<float, float> GetPosition() const;
|
||||
void SetDeadzone(float minimum = 0.01f);
|
||||
public:
|
||||
explicit GamepadThumbstick(std::string mnemonic) : mnemonic_stick_code(std::move(mnemonic)){}
|
||||
};
|
||||
|
||||
namespace ReWindow::GamepadButtons {
|
||||
static const GamepadButton Triangle("△");
|
||||
static const GamepadButton Square("□");
|
||||
static const GamepadButton Circle("○");
|
||||
static const GamepadButton Cross("X");
|
||||
|
||||
// If you like xbox :shrug:
|
||||
static const GamepadButton Y = Triangle;
|
||||
static const GamepadButton X = Square;
|
||||
static const GamepadButton A = Cross;
|
||||
static const GamepadButton B = Circle;
|
||||
|
||||
static const GamepadButton LButton("LB");
|
||||
static const GamepadButton RButton("RB");
|
||||
|
||||
/* For controllers where L2 & R2 is a button or counts as one when pressed all the way down.
|
||||
* Gamecube & PS2 controllers do this. - Redacted. */
|
||||
static const GamepadButton LButton2("LB2");
|
||||
static const GamepadButton RButton2("RB2");
|
||||
|
||||
// The buttons when you press in the sticks.
|
||||
static const GamepadButton LButton3("LB3");
|
||||
static const GamepadButton RButton3("RB3");
|
||||
|
||||
// Will eventually need to handle making it not possible to, for ex. Press left and right at the same time.
|
||||
static const GamepadButton DPadUp("DPU");
|
||||
static const GamepadButton DPadDown("DPD");
|
||||
static const GamepadButton DPadLeft("DPL");
|
||||
static const GamepadButton DPadRight("DPR");
|
||||
|
||||
static const GamepadButton Select("SEL");
|
||||
static const GamepadButton Start("START");
|
||||
}
|
||||
|
||||
namespace ReWindow::GamepadTriggers {
|
||||
static const ReWindow::GamepadTrigger Left {"LT"};
|
||||
static const ReWindow::GamepadTrigger Right {"RT"};
|
||||
}
|
||||
|
||||
namespace ReWindow::GamepadThumbsticks {
|
||||
static const GamepadThumbstick Left {"LS"};
|
||||
static const GamepadThumbstick Right {"RS"};
|
||||
}
|
@@ -7,14 +7,12 @@
|
||||
#include <ReWindow/types/Key.h>
|
||||
#include <ReWindow/types/Cursors.h>
|
||||
#include <ReWindow/types/MouseButton.h>
|
||||
#include <ReWindow/types/GamepadButton.h>
|
||||
#include <ReWindow/types/WindowEvents.h>
|
||||
#include <queue>
|
||||
|
||||
|
||||
namespace ReWindow {
|
||||
struct KeyboardState { std::map<Key, bool> PressedKeys; };
|
||||
struct GamepadState { std::map<GamepadButton, bool> PressedButtons; };
|
||||
|
||||
class MouseState;
|
||||
class RWindow;
|
||||
@@ -52,10 +50,11 @@ protected:
|
||||
Platform* platform;
|
||||
inline static RWindow* extant;
|
||||
|
||||
int width = 1280;
|
||||
int height = 720;
|
||||
int width = 640;
|
||||
int height = 480;
|
||||
|
||||
bool open = false; // Is the underlying OS-Window-Handle actually open.
|
||||
bool closing = false;
|
||||
bool resizable = true;
|
||||
bool fullscreen_mode = false;
|
||||
bool focused = true;
|
||||
@@ -63,22 +62,18 @@ protected:
|
||||
bool cursor_visible = true;
|
||||
bool cursor_focused = false;
|
||||
bool toggling_cursor_focus = false;
|
||||
bool closing = false;
|
||||
bool key_repeat = false;
|
||||
|
||||
float delta_time = 0.f;
|
||||
float refresh_rate = 0.f;
|
||||
unsigned int refresh_count = 0;
|
||||
std::pair<int, int> render_area_position = {0, 0};
|
||||
unsigned long long refresh_count = 0;
|
||||
std::string title = "Redacted Window";
|
||||
|
||||
std::pair<int, int> lastKnownWindowSize {0, 0};
|
||||
std::vector<RWindowEvent> eventLog; // history of all logged window events.
|
||||
std::queue<RWindowEvent> eventQueue; //
|
||||
MouseState currentMouse; // purrent frame mouse state.
|
||||
MouseState previousMouse; // previous frame mouse state
|
||||
|
||||
// TODO: Why tf are these on the header and not just in the cpp?
|
||||
float refresh_rate_prev_1 = 0.f;
|
||||
float refresh_rate_prev_2 = 0.f;
|
||||
float refresh_rate_prev_3 = 0.f;
|
||||
@@ -89,9 +84,9 @@ protected:
|
||||
/// Returns the most accurate and recent available mouse coordinates relative to the top left corner of the renderable area (not including the title bar).
|
||||
/// @note Call this version at most **once** per-frame. It polls the X-Window server and therefore is quite slow.
|
||||
/// @see getCursorPos();
|
||||
[[nodiscard]] std::pair<int, int> GetAccurateMouseCoordinates() const;
|
||||
[[nodiscard]] std::pair<int, int> GetAccurateCursorCoordinates() const;
|
||||
protected:
|
||||
void LogEvent(const RWindowEvent& e) { eventLog.push_back(e);}
|
||||
void LogEvent(const RWindowEvent& e) { eventLog.push_back(e); }
|
||||
//void EnqueueEvent(const RWindowEvent& e) { eventQueue.push(e);}
|
||||
[[nodiscard]] RWindowEvent GetLastEvent() const { return eventLog.back(); }
|
||||
/// Requests the operating system to make the window fullscreen. Saves the previous window size as well.
|
||||
@@ -138,30 +133,39 @@ public:
|
||||
/// These methods can also be overridden in derived classes.
|
||||
/// Called upon the window requesting to open.
|
||||
virtual void OnOpen() {}
|
||||
|
||||
/// Called right before the window closes.
|
||||
virtual void OnClosing() {}
|
||||
|
||||
/// Called when the window loses focus.
|
||||
virtual void OnFocusLost(const RWindowEvent& e) {}
|
||||
|
||||
/// Called when the window gains focus.
|
||||
virtual void OnFocusGain(const RWindowEvent& e) {}
|
||||
|
||||
/// Called when the window is 'refreshed', in other words, a render pass is completed.
|
||||
virtual void OnRefresh(float elapsed) {}
|
||||
|
||||
/// Called when a resize request has succeeded.
|
||||
virtual void OnResizeSuccess() {}
|
||||
|
||||
/// Called when a resize request is sent to the operating system.
|
||||
virtual bool OnResizeRequest(const WindowResizeRequestEvent& e) { return true;}
|
||||
|
||||
virtual void OnKeyDown(const KeyDownEvent&) {}
|
||||
|
||||
virtual void OnKeyUp(const KeyUpEvent&) {}
|
||||
|
||||
virtual void OnMouseMove(const MouseMoveEvent&) {}
|
||||
|
||||
virtual void OnMouseButtonDown(const MouseButtonDownEvent&) {}
|
||||
|
||||
virtual void OnMouseButtonUp(const MouseButtonUpEvent&) {}
|
||||
|
||||
virtual void OnMouseWheel(const MouseWheelEvent&) {}
|
||||
|
||||
/// Returns an std::pair<int, int> representing mouse coordinates relative to the top-left corner of the window.
|
||||
/// This result is cached from the operating-system, and as such may be out-of-date.
|
||||
/// @see GetAccurateMouseCoordinates().
|
||||
[[nodiscard]] std::pair<int, int> GetMouseCoordinates() const;
|
||||
[[nodiscard]] int GetMouseWheelPersistent() const { return currentMouse.Wheel; }
|
||||
|
||||
[[nodiscard]] bool IsOpen() const { return open; }
|
||||
|
||||
|
||||
@@ -170,30 +174,40 @@ public:
|
||||
[[nodiscard]] bool IsVisible() const;
|
||||
|
||||
[[nodiscard]] bool IsClosing() const { return closing; }
|
||||
|
||||
/// Returns whether the window currently has mouse and/or keyboard focus.
|
||||
[[nodiscard]] bool IsFocused() const;
|
||||
|
||||
/// Returns whether the window is currently in Fullscreen.
|
||||
// TODO: Support Fullscreen, FullscreenWindowed, and Windowed?
|
||||
[[nodiscard]] bool IsFullscreen() const;
|
||||
|
||||
/// Returns whether the window can be resized.
|
||||
[[nodiscard]] bool IsResizable() const;
|
||||
|
||||
/// Returns whether V-Sync is enabled.
|
||||
[[nodiscard]] bool IsVsyncEnabled() const;
|
||||
|
||||
/// Returns whether the window is considered to be alive. Once dead, any logic loop should be terminated, and the cleanup procedure should run.
|
||||
[[nodiscard]] bool IsAlive() const;
|
||||
|
||||
/// Returns whether the given key is currently being pressed.
|
||||
[[nodiscard]] bool IsKeyDown(Key key) const;
|
||||
|
||||
/// Returns whether the given mouse button is currently being pressed.
|
||||
[[nodiscard]] bool IsMouseButtonDown(const MouseButton &button) const;
|
||||
[[nodiscard]] bool IsMouseButtonDown(const MouseButton& button) const;
|
||||
|
||||
[[nodiscard]] float GetDeltaTime() const;
|
||||
|
||||
/// Returns the approximate frames-per-second using delta time.
|
||||
[[nodiscard]] float GetRefreshRate() const;
|
||||
|
||||
/// Returns the number of frames ran since the windows' creation.
|
||||
[[nodiscard]] float GetRefreshCounter() const;
|
||||
[[nodiscard]] unsigned long long GetRefreshCount() const;
|
||||
|
||||
/// Cleans up and closes the window object.
|
||||
void Close();
|
||||
|
||||
/// Closes the window immediately, potentially without allowing finalization to occur.
|
||||
void ForceClose();
|
||||
|
||||
@@ -220,12 +234,12 @@ public:
|
||||
|
||||
/// Returns the horizontal length of this window, in pixels.
|
||||
[[nodiscard]] int GetWidth() const;
|
||||
|
||||
/// 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);
|
||||
void SetLastKnownWindowSize(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.
|
||||
@@ -245,6 +259,7 @@ public:
|
||||
/// @param width
|
||||
/// @param height
|
||||
void SetSize(int width, int height);
|
||||
|
||||
/// Requests the operating system to change the window size.
|
||||
/// @param size
|
||||
void SetSize(const std::pair<int, int>& size);
|
||||
@@ -255,17 +270,14 @@ public:
|
||||
/// Returns the known size of the window, in {x,y} pixel measurement.
|
||||
[[nodiscard]] std::pair<int, int> GetSize() const;
|
||||
|
||||
/// Returns the position of the "renderable area" of the window relative to it's top left corner.
|
||||
/// (used to account for the width or the border & title bar).
|
||||
[[nodiscard]] std::pair<int, int> GetPositionOfRenderableArea() const;
|
||||
|
||||
/// Requests the operating system to move the window to the specified coordinates on the display.
|
||||
/// @param x The horizontal screen position to place the window at.
|
||||
/// @param y The vertical screen position to place the window at.
|
||||
void SetPos(int x, int y);
|
||||
void SetPosition(int x, int y);
|
||||
|
||||
/// Requests the operating system to move the window to the specified coordinates on the display.
|
||||
/// @param pos A std::pair<int, int> representing the x,y coordinates of the desired window destination. Fractional values are ignored.
|
||||
void SetPos(const std::pair<int, int>& pos);
|
||||
void SetPosition(const std::pair<int, int>& pos);
|
||||
|
||||
/// Pull the window to the top, such that it is displayed on top of everything else.
|
||||
/// NOTE: The implementation is defined per-OS, and thus there is no guarantee of it always working.
|
||||
@@ -275,15 +287,23 @@ public:
|
||||
/// NOTE: The implementation is defined per-OS, and thus there is no guarantee of it always working.
|
||||
void Lower();
|
||||
|
||||
// TODO verify functionality if the cursor is invisible.
|
||||
void SetCursorStyle(CursorStyle style) const;
|
||||
|
||||
void SetCursorCustomIcon() const;
|
||||
|
||||
/// @returns Where the cursor was just before we teleported it to the center.
|
||||
/// @note On some remote desktop software you won't actually see the cursor move, It does work though. - Redacted.
|
||||
/// @note The centering is delayed until the next time our window is in focus and the cursor is on top of it.
|
||||
/// @note This is useful for 3D games.
|
||||
std::pair<int, int> SetCursorCenter();
|
||||
|
||||
/// Set the position of the cursor relative to the top-left corner of the renderable area.
|
||||
/// @returns False if the cursor could not be guaranteed to be teleported.
|
||||
/// @note our window *must* be visible and in focus.
|
||||
/// @note Moving the cursor outside of our window is unsupported.
|
||||
[[nodiscard]] bool SetCursorPosition(const std::pair<int, int>& position);
|
||||
[[nodiscard]] bool SetCursorPosition(int x, int y);
|
||||
|
||||
/// Tells the operating system to not allow the cursor to go off our window.
|
||||
/// @note This is useful for 3D games.
|
||||
void SetCursorFocused(bool state);
|
||||
@@ -292,12 +312,17 @@ public:
|
||||
/// @note This is useful for 3D games.
|
||||
void SetCursorVisible(bool cursor_enable);
|
||||
|
||||
/// @returns Whether ther cursor is visible.
|
||||
/// @returns Whether the cursor is visible.
|
||||
bool GetCursorVisible();
|
||||
|
||||
/// @returns Whether the cursor is focused (cannot go off of our window).
|
||||
bool GetCursorFocused();
|
||||
|
||||
/// Returns an std::pair<int, int> representing mouse coordinates relative to the top-left corner of the window.
|
||||
/// This result is cached from the operating-system each time poll events is called.
|
||||
/// @see GetAccurateMouseCoordinates().
|
||||
[[nodiscard]] std::pair<int, int> GetCursorPosition() const;
|
||||
|
||||
/// Returns the current time, represented as a high-resolution std::chrono alias.
|
||||
static std::chrono::steady_clock::time_point GetTimestamp();
|
||||
|
||||
@@ -308,8 +333,8 @@ public:
|
||||
void UpdateFrameTiming(float frame_time);
|
||||
public:
|
||||
/// These unfortunately *have* to be public because of the poor design of the windows event loop.
|
||||
void processKeyRelease (Key key);
|
||||
void processKeyPress (Key key);
|
||||
void processKeyRelease(Key key);
|
||||
void processKeyPress(Key key);
|
||||
/// @note This will be invoked **before** the window-close procedure begins.
|
||||
void processOnClose();
|
||||
/// @note This will be invoked **after** the window-open procedure completes.
|
||||
@@ -351,7 +376,7 @@ public:
|
||||
[[nodiscard]] virtual bool SoftwareRendered() { return false; }
|
||||
};
|
||||
|
||||
// TODO in the event that we can't find OpenGL or the Open() fails, have a way to say so without throwing an exception.
|
||||
// TODO Set flags in window constructor.
|
||||
class ReWindow::OpenGLWindow : public RWindow {
|
||||
protected:
|
||||
uint8_t gl_major, gl_minor;
|
||||
|
44
main.cpp
44
main.cpp
@@ -15,9 +15,13 @@ class MyWindow : public OpenGLWindow {
|
||||
|
||||
void OnKeyDown(const KeyDownEvent& e) override {}
|
||||
|
||||
void OnRefresh(float elapsed) override {
|
||||
SwapBuffers();
|
||||
bool OnResizeRequest(const WindowResizeRequestEvent& e) override { return true; }
|
||||
|
||||
void OnMouseButtonDown(const MouseButtonDownEvent& e) override { RWindow::OnMouseButtonDown(e); }
|
||||
|
||||
void OnMouseButtonUp(const MouseButtonUpEvent& e) override { RWindow::OnMouseButtonUp(e); }
|
||||
|
||||
void OnRefresh(float elapsed) override {
|
||||
if (IsMouseButtonDown(MouseButtons::Left))
|
||||
std::cout << "Left Mouse Button" << std::endl;
|
||||
|
||||
@@ -33,28 +37,10 @@ class MyWindow : public OpenGLWindow {
|
||||
if (IsMouseButtonDown(MouseButtons::Mouse5))
|
||||
std::cout << "Mouse5 Mouse Button" << std::endl;
|
||||
|
||||
|
||||
if (IsKeyDown(Keys::N))
|
||||
std::cout << "Gotteem" << std::endl;
|
||||
|
||||
RWindow::OnRefresh(elapsed);
|
||||
}
|
||||
|
||||
bool OnResizeRequest(const WindowResizeRequestEvent& e) override {
|
||||
//std::cout << "resized to " << e.Size.x << ", " << e.Size.y << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnMouseButtonDown(const MouseButtonDownEvent &e) override
|
||||
{
|
||||
//std::cout << "Overload Down: " << e.Button.Mnemonic << std::endl;
|
||||
RWindow::OnMouseButtonDown(e);
|
||||
}
|
||||
|
||||
void OnMouseButtonUp(const MouseButtonUpEvent &e) override
|
||||
{
|
||||
//std::cout << "Overload Up: " << e.Button.Mnemonic << std::endl;
|
||||
RWindow::OnMouseButtonUp(e);
|
||||
SwapBuffers();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -69,16 +55,16 @@ int main() {
|
||||
window->SetFullscreen(false);
|
||||
window->SetVsyncEnabled(true);
|
||||
window->SetResizable(true);
|
||||
//window->SetCursorVisible(true);
|
||||
window->SetKeyRepeatEnabled(false);
|
||||
//window->SetCursorCenter();
|
||||
//window->DialogOK("MessageBox", "Generic message from a ReWindow MessageBox.");
|
||||
window->SetCursorFocused(true);
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
|
||||
Logger::Debug(std::format("Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} KEY_REPEAT={} QUIT={}",
|
||||
window->GetTitle(), window->IsFocused(), window->IsFullscreen(),
|
||||
window->IsResizable(), window->IsVsyncEnabled(), window->IsKeyRepeat(), window->IsClosing()) );
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
|
||||
Logger::Debug(std::format
|
||||
(
|
||||
"Window '{}' flags: IN_FOCUS={} FULLSCREEN={} RESIZEABLE={} VSYNC={} KEY_REPEAT={} QUIT={}",
|
||||
window->GetTitle(), window->IsFocused(), window->IsFullscreen(), window->IsResizable(),
|
||||
window->IsVsyncEnabled(), window->IsKeyRepeat(), window->IsClosing())
|
||||
);
|
||||
|
||||
|
||||
window->OnKeyDownEvent += [&] (KeyDownEvent e) { jlog::Debug(e.key.Mnemonic); };
|
||||
|
@@ -9,7 +9,7 @@ namespace InputService
|
||||
return RWindow::GetExtant()->IsMouseButtonDown(button);
|
||||
}
|
||||
std::pair<int, int> GetMousePosition() {
|
||||
return RWindow::GetExtant()->GetMouseCoordinates();
|
||||
return RWindow::GetExtant()->GetCursorPosition();
|
||||
}
|
||||
std::pair<int, int> GetWindowSize() {
|
||||
return RWindow::GetExtant()->GetSize();
|
||||
|
@@ -174,7 +174,6 @@ bool OpenGLWindow::Open() {
|
||||
XSetWMProtocols(platform->display, platform->window, &platform->wmDeleteWindow, 1);
|
||||
|
||||
XGetWindowAttributes(platform->display, platform->window, &platform->windowAttributes);
|
||||
render_area_position = { platform->windowAttributes.x, platform->windowAttributes.y };
|
||||
|
||||
open = true;
|
||||
processOnOpen();
|
||||
|
@@ -223,7 +223,6 @@ bool VulkanWindow::Open() {
|
||||
XSetWMProtocols(platform->display, platform->window, &platform->wmDeleteWindow, 1);
|
||||
|
||||
XGetWindowAttributes(platform->display, platform->window, &platform->windowAttributes);
|
||||
render_area_position = { platform->windowAttributes.x, platform->windowAttributes.y };
|
||||
|
||||
open = true;
|
||||
processOnOpen();
|
||||
|
@@ -22,12 +22,34 @@ public:
|
||||
Cursor invisible_cursor = 0;
|
||||
XWMHints* wm_hints = nullptr;
|
||||
bool window_visible = true;
|
||||
std::pair<int, int> position = {0, 0};
|
||||
std::pair<int, int> position = { 0, 0 };
|
||||
};
|
||||
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
bool RWindow::SetCursorPosition(const std::pair<int, int>& position) {
|
||||
if (!IsFocused())
|
||||
return false;
|
||||
|
||||
if (!IsVisible())
|
||||
return false;
|
||||
|
||||
if (position.first > GetWidth() || position.first < 0)
|
||||
return false;
|
||||
|
||||
if (position.second > GetHeight() || position.second < 0)
|
||||
return false;
|
||||
|
||||
// TODO XWarpPointer has no way to verify it actually happened.
|
||||
XWarpPointer(platform->display, None, platform->window, 0, 0, 0, 0, position.first, position.second);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RWindow::SetCursorPosition(const int x, const int y) {
|
||||
return SetCursorPosition({x, y});
|
||||
}
|
||||
|
||||
void RWindow::SetKeyRepeatEnabled(bool state) {
|
||||
key_repeat = state;
|
||||
|
||||
@@ -49,8 +71,8 @@ void RWindow::Flash() {
|
||||
}
|
||||
|
||||
RWindow::RWindow() {
|
||||
platform = new Platform();
|
||||
extant = this;
|
||||
platform = new Platform();
|
||||
extant = this;
|
||||
}
|
||||
|
||||
void RWindow::SetCursorFocused(bool state) {
|
||||
@@ -64,7 +86,7 @@ void RWindow::SetCursorFocused(bool state) {
|
||||
}
|
||||
|
||||
std::pair<int, int> RWindow::SetCursorCenter() {
|
||||
auto current_pos = GetAccurateMouseCoordinates();
|
||||
auto current_pos = GetAccurateCursorCoordinates();
|
||||
XWarpPointer(platform->display, None, platform->window, 0, 0, 0, 0, width / 2, height / 2);
|
||||
return current_pos;
|
||||
}
|
||||
@@ -77,7 +99,6 @@ void RWindow::Raise() {
|
||||
Logger::Debug(std::format("Raising window '{}'", this->title));
|
||||
// Get the position of the renderable area relative to the rest of the window.
|
||||
XGetWindowAttributes(platform->display, platform->window, &platform->windowAttributes);
|
||||
render_area_position = { platform->windowAttributes.x, platform->windowAttributes.y };
|
||||
XRaiseWindow(platform->display, platform->window);
|
||||
}
|
||||
|
||||
@@ -161,6 +182,7 @@ void RWindow::DestroyOSWindowHandle() {
|
||||
XDestroyWindow(platform->display, platform->window);
|
||||
|
||||
XCloseDisplay(platform->display);
|
||||
delete platform;
|
||||
}
|
||||
|
||||
void RWindow::SetCursorVisible(bool cursor_enable) {
|
||||
@@ -229,7 +251,6 @@ void RWindow::PollEvents() {
|
||||
|
||||
// Get the position of the renderable area relative to the rest of the window.
|
||||
XGetWindowAttributes(platform->display, platform->window, &platform->windowAttributes);
|
||||
render_area_position = {platform->windowAttributes.x, platform->windowAttributes.y};
|
||||
processFocusIn();
|
||||
focused = true;
|
||||
}
|
||||
@@ -339,7 +360,6 @@ void RWindow::PollEvents() {
|
||||
|
||||
auto eventData = WindowResizeRequestEvent();
|
||||
eventData.Size = {platform->xev.xconfigurerequest.width, platform->xev.xconfigurerequest.height};
|
||||
lastKnownWindowSize = eventData.Size;
|
||||
|
||||
OnResizeRequest(eventData);
|
||||
OnResizeRequestEvent(eventData);
|
||||
@@ -373,8 +393,7 @@ void RWindow::SetSize(int newWidth, int newHeight) {
|
||||
Logger::Info(std::format("Set size for '{}' to {} x {}", this->title, newWidth, newHeight));
|
||||
}
|
||||
|
||||
std::pair<int, int> RWindow::GetAccurateMouseCoordinates() const {
|
||||
|
||||
std::pair<int, int> RWindow::GetAccurateCursorCoordinates() const {
|
||||
Window root_return, child_return;
|
||||
int root_x_ret, root_y_ret;
|
||||
int win_x_ret, win_y_ret;
|
||||
@@ -398,26 +417,21 @@ bool RWindow::IsVisible() const {
|
||||
|
||||
|
||||
std::pair<int, int> RWindow::GetSize() const {
|
||||
return { this->width, this->height};
|
||||
return { this->width, this->height };
|
||||
}
|
||||
|
||||
//std::pair<int, int> RWindow::getLastKnownResize() const
|
||||
//{
|
||||
// return lastKnownWindowSize;
|
||||
//}
|
||||
|
||||
// TODO: implement integer std::pair<int, int>/3 types
|
||||
std::pair<int, int> RWindow::GetPos() const {
|
||||
return platform->position;
|
||||
}
|
||||
|
||||
void RWindow::SetPos(int x, int y) {
|
||||
void RWindow::SetPosition(int x, int y) {
|
||||
XMoveWindow(platform->display, platform->window, x, y);
|
||||
platform->position = {x, y};
|
||||
}
|
||||
|
||||
void RWindow::SetPos(const std::pair<int, int>& pos) {
|
||||
SetPos(pos.first, pos.second);
|
||||
void RWindow::SetPosition(const std::pair<int, int>& pos) {
|
||||
SetPosition(pos.first, pos.second);
|
||||
}
|
||||
|
||||
void RWindow::Fullscreen() {
|
||||
@@ -470,9 +484,3 @@ void RWindow::SetTitle(const std::string& title) {
|
||||
XStoreName(platform->display, platform->window, title.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::pair<int, int> RWindow::GetPositionOfRenderableArea() const {
|
||||
return render_area_position;
|
||||
}
|
||||
|
||||
|
@@ -8,9 +8,7 @@ RWindow::~RWindow() {
|
||||
DestroyOSWindowHandle();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::pair<int, int> RWindow::GetMouseCoordinates() const {
|
||||
std::pair<int, int> RWindow::GetCursorPosition() const {
|
||||
return currentMouse.Position;
|
||||
}
|
||||
|
||||
@@ -26,24 +24,21 @@ void RWindow::SetFullscreen(bool fs) {
|
||||
}
|
||||
|
||||
#pragma region Event Processors Implementation
|
||||
void RWindow::processFocusIn()
|
||||
{
|
||||
void RWindow::processFocusIn() {
|
||||
RWindowEvent event {};
|
||||
OnFocusGain(event);
|
||||
OnFocusGainEvent(event);
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processFocusOut()
|
||||
{
|
||||
void RWindow::processFocusOut() {
|
||||
RWindowEvent event {};
|
||||
OnFocusLost(event);
|
||||
OnFocusLostEvent(event);
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processMousePress(const MouseButton& btn)
|
||||
{
|
||||
void RWindow::processMousePress(const MouseButton& btn) {
|
||||
currentMouse.Set(btn, true);
|
||||
auto event = MouseButtonDownEvent(btn);
|
||||
OnMouseButtonDown(event);
|
||||
@@ -53,8 +48,7 @@ void RWindow::processMousePress(const MouseButton& btn)
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processMouseMove(const std::pair<int, int>& last_pos, const std::pair<int, int>& new_pos)
|
||||
{
|
||||
void RWindow::processMouseMove(const std::pair<int, int>& last_pos, const std::pair<int, int>& new_pos) {
|
||||
currentMouse.Position = new_pos;
|
||||
auto event = MouseMoveEvent(new_pos);
|
||||
OnMouseMove(event);
|
||||
@@ -63,8 +57,7 @@ void RWindow::processMouseMove(const std::pair<int, int>& last_pos, const std::p
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processMouseRelease(const MouseButton& btn)
|
||||
{
|
||||
void RWindow::processMouseRelease(const MouseButton& btn) {
|
||||
currentMouse.Set(btn, false);
|
||||
auto event = MouseButtonUpEvent(btn);
|
||||
OnMouseButtonUp(event);
|
||||
@@ -97,16 +90,14 @@ void RWindow::processKeyPress(Key key) {
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processOnClose()
|
||||
{
|
||||
void RWindow::processOnClose() {
|
||||
auto event = RWindowEvent();
|
||||
OnClosing();
|
||||
OnClosingEvent();
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processOnOpen()
|
||||
{
|
||||
void RWindow::processOnOpen() {
|
||||
auto event = RWindowEvent();
|
||||
OnOpen();
|
||||
OnOpenEvent();
|
||||
@@ -115,36 +106,31 @@ void RWindow::processOnOpen()
|
||||
|
||||
#pragma endregion
|
||||
|
||||
std::string RWindow::GetTitle() const {
|
||||
return this->title;
|
||||
}
|
||||
std::string RWindow::GetTitle() const { return this->title; }
|
||||
|
||||
/*
|
||||
std::pair<int, int> RWindow::GetSize() const
|
||||
{
|
||||
return {this->width, this->height};
|
||||
}
|
||||
*/
|
||||
int RWindow::GetWidth() const { return this->width; }
|
||||
|
||||
int RWindow::GetWidth() const
|
||||
{
|
||||
return this->width;
|
||||
}
|
||||
int RWindow::GetHeight() const { return this->height; }
|
||||
|
||||
int RWindow::GetHeight() const
|
||||
{
|
||||
return this->height;
|
||||
}
|
||||
bool RWindow::IsResizable() const { return resizable; }
|
||||
|
||||
bool RWindow::IsFullscreen() const { return fullscreen_mode; }
|
||||
|
||||
bool RWindow::IsFocused() const { return focused; }
|
||||
|
||||
bool RWindow::IsVsyncEnabled() const { return vsync; }
|
||||
|
||||
float RWindow::GetDeltaTime() const { return delta_time; }
|
||||
|
||||
float RWindow::GetRefreshRate() const { return refresh_rate; }
|
||||
|
||||
unsigned long long RWindow::GetRefreshCount() const { return refresh_count; }
|
||||
|
||||
void RWindow::SetSizeWithoutEvent(const std::pair<int, int>& size) {
|
||||
width = size.first;
|
||||
height = size.second;
|
||||
}
|
||||
|
||||
void RWindow::SetLastKnownWindowSize(const std::pair<int, int>& size) {
|
||||
lastKnownWindowSize = size;
|
||||
}
|
||||
|
||||
void RWindow::SetSize(const std::pair<int, int>& size) {
|
||||
this->width = size.first;
|
||||
this->height = size.second;
|
||||
@@ -180,9 +166,8 @@ void RWindow::Refresh() {
|
||||
OnRefresh(delta_time);
|
||||
|
||||
// Only call once and cache the result.
|
||||
currentMouse.Position = GetAccurateMouseCoordinates();
|
||||
currentMouse.Position = GetAccurateCursorCoordinates();
|
||||
|
||||
/// TODO: Implement optional minimum epsilon to trigger a Mouse Update.
|
||||
if (currentMouse.Position != previousMouse.Position) {
|
||||
processMouseMove(previousMouse.Position, currentMouse.Position);
|
||||
previousMouse.Position = currentMouse.Position;
|
||||
@@ -227,29 +212,6 @@ void RWindow::processMouseWheel(int scrolls)
|
||||
previousMouse.Wheel = currentMouse.Wheel;
|
||||
}
|
||||
|
||||
|
||||
bool RWindow::IsResizable() const {
|
||||
return resizable;
|
||||
}
|
||||
|
||||
bool RWindow::IsFullscreen() const {
|
||||
return fullscreen_mode;
|
||||
}
|
||||
|
||||
bool RWindow::IsFocused() const {
|
||||
return focused;
|
||||
}
|
||||
|
||||
bool RWindow::IsVsyncEnabled() const {
|
||||
return vsync;
|
||||
}
|
||||
|
||||
float RWindow::GetDeltaTime() const { return delta_time; }
|
||||
|
||||
float RWindow::GetRefreshRate() const { return refresh_rate; }
|
||||
|
||||
float RWindow::GetRefreshCounter() const { return refresh_count; }
|
||||
|
||||
void RWindow::Close() {
|
||||
closing = true;
|
||||
processOnClose();
|
||||
@@ -260,7 +222,7 @@ bool RWindow::IsFocused() const {
|
||||
DestroyOSWindowHandle();
|
||||
}
|
||||
|
||||
bool MouseState::IsDown(const MouseButton &btn) const {
|
||||
bool MouseState::IsDown(const MouseButton& btn) const {
|
||||
if (btn == MouseButtons::Left) return Buttons.LMB;
|
||||
if (btn == MouseButtons::Right) return Buttons.RMB;
|
||||
if (btn == MouseButtons::Middle) return Buttons.MMB;
|
||||
@@ -282,7 +244,7 @@ bool RWindow::IsFocused() const {
|
||||
//if (btn == MouseButtons::MWheelDown) Buttons.MWheelDown = state;
|
||||
}
|
||||
|
||||
bool &MouseState::operator [](const MouseButton &btn) {
|
||||
bool &MouseState::operator [](const MouseButton& btn) {
|
||||
if (btn == MouseButtons::Left) return Buttons.LMB;
|
||||
if (btn == MouseButtons::Right) return Buttons.RMB;
|
||||
if (btn == MouseButtons::Middle) return Buttons.MMB;
|
||||
|
@@ -31,7 +31,7 @@ void RWindow::SetCursorFocused(bool state) {
|
||||
}
|
||||
|
||||
std::pair<int, int> RWindow::SetCursorCenter() {
|
||||
auto current_cursor_pos = GetAccurateMouseCoordinates();
|
||||
auto current_cursor_pos = GetAccurateCursorCoordinates();
|
||||
RECT client_rect;
|
||||
GetClientRect(platform->hwnd, &client_rect);
|
||||
POINT center((client_rect.right - client_rect.left) / 2, (client_rect.bottom - client_rect.top) / 2 );
|
||||
@@ -64,7 +64,6 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
window->SetSizeWithoutEvent({ LOWORD(lParam), HIWORD(lParam) });
|
||||
auto eventData = WindowResizeRequestEvent();
|
||||
eventData.Size = { window->GetWidth(), window->GetHeight() };
|
||||
window->SetLastKnownWindowSize({ window->GetWidth(), window->GetHeight() });
|
||||
// TODO: Implement eWindow->processOnResize()
|
||||
window->OnResizeRequest(eventData);
|
||||
window->OnResizeRequestEvent(eventData);
|
||||
@@ -250,7 +249,7 @@ void RWindow::SetSize(int newWidth, int newHeight) {
|
||||
SetWindowPos(platform->hwnd, nullptr, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
std::pair<int, int> RWindow::GetAccurateMouseCoordinates() const {
|
||||
std::pair<int, int> RWindow::GetAccurateCursorCoordinates() const {
|
||||
POINT point;
|
||||
GetCursorPos(&point);
|
||||
ScreenToClient(platform->hwnd, &point);
|
||||
@@ -276,24 +275,26 @@ std::pair<int, int> RWindow::GetSize() const {
|
||||
return { (rect.right - rect.left), (rect.bottom - rect.top) };
|
||||
}
|
||||
|
||||
void RWindow::SetPos(int x, int y) {
|
||||
void RWindow::SetPosition(int x, int y) {
|
||||
SetWindowPos(platform->hwnd, nullptr, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
||||
}
|
||||
|
||||
void RWindow::SetPos(const std::pair<int, int>& pos) {
|
||||
SetPos(pos.first, pos.second);
|
||||
void RWindow::SetPosition(const std::pair<int, int>& pos) {
|
||||
SetPosition(pos.first, pos.second);
|
||||
}
|
||||
|
||||
void RWindow::Fullscreen() {
|
||||
// Implement fullscreen
|
||||
SetWindowLong(platform->hwnd, GWL_STYLE, GetWindowLong(platform->hwnd, GWL_STYLE) & ~WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPos(platform->hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED | SWP_NOOWNERZORDER);
|
||||
fullscreen_mode = true;
|
||||
}
|
||||
|
||||
void RWindow::RestoreFromFullscreen() {
|
||||
// Implement restore from fullscreen
|
||||
SetWindowLong(platform->hwnd, GWL_STYLE, GetWindowLong(platform->hwnd, GWL_STYLE) | WS_OVERLAPPEDWINDOW);
|
||||
SetWindowPos(platform->hwnd, nullptr, 0, 0, width, height, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOOWNERZORDER);
|
||||
fullscreen_mode = false;
|
||||
}
|
||||
|
||||
void RWindow::SetCursorStyle(CursorStyle style) const {}
|
||||
|
@@ -1,26 +0,0 @@
|
||||
#include <ReWindow/types/GamepadButton.h>
|
||||
|
||||
using namespace ReWindow;
|
||||
bool GamepadButton::operator ==(const GamepadButton &rhs) const {
|
||||
return this->GetMnemonicButtonCode() == rhs.GetMnemonicButtonCode();
|
||||
}
|
||||
|
||||
std::string GamepadButton::GetMnemonicButtonCode() const {
|
||||
return mnemonic_btn_code;
|
||||
}
|
||||
|
||||
void GamepadThumbstick::SetDeadzone(float minimum) {
|
||||
dead_zone = minimum;
|
||||
}
|
||||
|
||||
std::pair<float, float> GamepadThumbstick::GetPosition() const {
|
||||
return position;
|
||||
}
|
||||
|
||||
void GamepadTrigger::SetDeadzone(float minimum) {
|
||||
dead_zone = minimum;
|
||||
}
|
||||
|
||||
float GamepadTrigger::GetActuation() const {
|
||||
return position;
|
||||
}
|
Reference in New Issue
Block a user