Got most of RWindow refactored. Had to hack the fuck out of it to test it.
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m38s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 1m38s
This commit is contained in:
@@ -15,14 +15,112 @@
|
||||
|
||||
#include <experimental/propagate_const>
|
||||
|
||||
// Figure out what to do with this shit
|
||||
enum class RWindowFlags: uint8_t {
|
||||
IN_FOCUS,
|
||||
FULLSCREEN,
|
||||
RESIZABLE,
|
||||
VSYNC,
|
||||
QUIT,
|
||||
MAX_FLAG
|
||||
};
|
||||
|
||||
// Just throwing this in the header for now
|
||||
std::string RWindowFlagToStr(RWindowFlags flag); /*{
|
||||
switch (flag) {
|
||||
case RWindowFlags::IN_FOCUS: return "IN_FOCUS";
|
||||
case RWindowFlags::FULLSCREEN: return "FULLSCREEN";
|
||||
case RWindowFlags::RESIZABLE: return "RESIZEABLE";
|
||||
case RWindowFlags::VSYNC: return "VSYNC";
|
||||
case RWindowFlags::QUIT: return "QUIT";
|
||||
case RWindowFlags::MAX_FLAG: return "MAX_FLAG";
|
||||
default:
|
||||
return "unimplemented flag";
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
using J3ML::LinearAlgebra::Vector2;
|
||||
|
||||
namespace ReWindow {
|
||||
|
||||
|
||||
class KeyboardState {
|
||||
public:
|
||||
std::map<Key, bool> PressedKeys;
|
||||
};
|
||||
|
||||
class GamepadState {
|
||||
public:
|
||||
std::map<GamepadButton, bool> PressedButtons;
|
||||
};
|
||||
|
||||
class MouseState {
|
||||
public:
|
||||
struct
|
||||
{
|
||||
bool LMB = false;
|
||||
bool RMB = false;
|
||||
bool MMB = false;
|
||||
bool SideButton1 = false;
|
||||
bool SideButton2 = false;
|
||||
bool MWheelUp = false;
|
||||
bool MWheelDown = false;
|
||||
} Buttons;
|
||||
|
||||
|
||||
Vector2 Position;
|
||||
int Wheel = 0;
|
||||
|
||||
[[nodiscard]] bool 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;
|
||||
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
|
||||
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
|
||||
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
|
||||
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
|
||||
|
||||
return false; // Unknown button?
|
||||
}
|
||||
|
||||
void Set(const MouseButton& btn, bool state)
|
||||
{
|
||||
if (btn == MouseButtons::Left) Buttons.LMB = state;
|
||||
if (btn == MouseButtons::Right) Buttons.RMB = state;
|
||||
if (btn == MouseButtons::Middle) Buttons.MMB = state;
|
||||
if (btn == MouseButtons::Mouse4) Buttons.SideButton1 = state;
|
||||
if (btn == MouseButtons::Mouse5) Buttons.SideButton2 = state;
|
||||
//if (btn == MouseButtons::MWheelUp) Buttons.MWheelUp = state;
|
||||
//if (btn == MouseButtons::MWheelDown) Buttons.MWheelDown = state;
|
||||
}
|
||||
|
||||
bool& 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;
|
||||
if (btn == MouseButtons::Mouse4) return Buttons.SideButton1;
|
||||
if (btn == MouseButtons::Mouse5) return Buttons.SideButton2;
|
||||
//if (btn == MouseButtons::MWheelUp) return Buttons.MWheelUp;
|
||||
//if (btn == MouseButtons::MWheelDown) return Buttons.MWheelDown;
|
||||
|
||||
throw std::runtime_error("Attempted to handle unmapped mouse button");
|
||||
}
|
||||
};
|
||||
|
||||
enum class RenderingAPI: uint8_t {
|
||||
OPENGL = 0,
|
||||
//Vulkan is unimplemented.
|
||||
VULKAN = 1,
|
||||
};
|
||||
//
|
||||
|
||||
class RWindowImpl;
|
||||
class RWindow;
|
||||
}
|
||||
|
||||
class platform;
|
||||
|
||||
class ReWindow::RWindowImpl {
|
||||
private:
|
||||
// Class for platform specific "global" variables, information, functionality, etc
|
||||
@@ -80,9 +178,19 @@ protected: // Should maybe make private
|
||||
float refresh_rate_prev_5 = 0.f;
|
||||
|
||||
float avg_refresh_rate = 0.0f;
|
||||
|
||||
// Figure out what to do with this shit later
|
||||
bool flags[5];
|
||||
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;
|
||||
//
|
||||
public:
|
||||
explicit RWindowImpl(const std::string& wTitle,
|
||||
int wWidth = 640, int wHeight = 480,
|
||||
RenderingAPI wRenderer = RenderingAPI::OPENGL,
|
||||
bool wFullscreen = false,
|
||||
bool wResizable = true,
|
||||
bool wVsync = false);
|
||||
@@ -93,11 +201,11 @@ public:
|
||||
void PollEvents();
|
||||
void Refresh();
|
||||
public:
|
||||
bool IsFocused();
|
||||
bool IsFullscreen();
|
||||
bool IsResizable();
|
||||
bool IsVsyncEnabled();
|
||||
bool IsAlive();
|
||||
bool IsFocused() const;
|
||||
bool IsFullscreen() const;
|
||||
bool IsResizable() const;
|
||||
bool IsVsyncEnabled() const;
|
||||
bool IsAlive() const;
|
||||
public:
|
||||
void SetFullscreen(bool fs);
|
||||
void SetResizable(bool fs);
|
||||
@@ -133,6 +241,74 @@ public:
|
||||
void SetCursorStyle(CursorStyle style) const;
|
||||
Vector2 GetPositionOfRenderableArea() const;
|
||||
std::string getGraphicsDriverVendor();
|
||||
void SetFlag(RWindowFlags flag, bool state);
|
||||
void processKeyRelease (Key key);
|
||||
void processKeyPress (Key key);
|
||||
void processOnClose();
|
||||
void processOnOpen();
|
||||
void processMousePress(const MouseButton& btn);
|
||||
void processMouseRelease(const MouseButton& btn);
|
||||
void processFocusIn();
|
||||
void processFocusOut();
|
||||
void processMouseMove(Vector2 last_pos, Vector2 new_pos);
|
||||
void processMouseWheel(int scrolls);
|
||||
virtual void OnOpen() {}
|
||||
virtual void OnClosing() {}
|
||||
virtual void OnFocusLost(const RWindowEvent& e) {}
|
||||
virtual void OnFocusGain(const RWindowEvent& e) {}
|
||||
virtual void OnRefresh(float elapsed) {}
|
||||
virtual void OnResizeSuccess() {}
|
||||
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&) {}
|
||||
Event<> OnOpenEvent;
|
||||
Event<> OnClosingEvent;
|
||||
Event<RWindowEvent> OnFocusLostEvent;
|
||||
Event<RWindowEvent> OnFocusGainEvent;
|
||||
Event<float> OnRefreshEvent;
|
||||
Event<WindowResizeRequestEvent> OnResizeRequestEvent;
|
||||
Event<KeyDownEvent> OnKeyDownEvent;
|
||||
Event<KeyUpEvent> OnKeyUpEvent;
|
||||
Event<MouseMoveEvent> OnMouseMoveEvent;
|
||||
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;
|
||||
Event<MouseButtonUpEvent> OnMouseButtonUpEvent;
|
||||
Event<MouseWheelEvent> OnMouseWheelEvent;
|
||||
|
||||
Vector2 GetMouseCoordinates() const;
|
||||
bool GetFlag(RWindowFlags flag) const;
|
||||
//bool IsAlive() const;
|
||||
void SetSizeWithoutEvent(const Vector2& size);
|
||||
std::vector<RWindowEvent> eventLog;
|
||||
std::queue<RWindowEvent> eventQueue;
|
||||
void LogEvent(const RWindowEvent& e) { eventLog.push_back(e);};
|
||||
RWindowEvent GetLastEvent() const {
|
||||
return eventLog.back();
|
||||
};
|
||||
void SetLastKnownWindowSize(const Vector2& size);
|
||||
void SetRenderer(RenderingAPI api);
|
||||
bool IsKeyDown(Key key) const;
|
||||
bool IsMouseButtonDown(const MouseButton &button) const;
|
||||
void ManagedRefresh();
|
||||
float ComputeElapsedFrameTimeSeconds(std::chrono::steady_clock::time_point start, std::chrono::steady_clock::time_point end);
|
||||
std::chrono::steady_clock::time_point GetTimestamp();
|
||||
void UpdateFrameTiming(float frame_time);
|
||||
/*
|
||||
bool IsResizable() const;
|
||||
bool IsFullscreen() const;
|
||||
bool IsFocused() const;
|
||||
bool IsVsyncEnabled() const;
|
||||
*/
|
||||
void ForceClose();
|
||||
void ForceCloseAndTerminateProgram();
|
||||
int GetMouseWheelPersistent() const { return currentMouse.Wheel;}
|
||||
[[nodiscard]] bool IsOpen() const { return open;}
|
||||
[[nodiscard]] bool IsClosing() const { return closing;}
|
||||
|
||||
|
||||
};
|
||||
|
||||
class ReWindow::RWindow : private RWindowImpl {
|
||||
@@ -141,10 +317,11 @@ public:
|
||||
//RWindow();
|
||||
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) :
|
||||
RWindowImpl(wTitle, wWidth, wHeight, wFullscreen, wResizable, wVsync) {};
|
||||
RWindowImpl(wTitle, wWidth, wHeight, wRenderer, wFullscreen, wResizable, wVsync) {};
|
||||
~RWindow();
|
||||
public:
|
||||
// Platform dependant
|
||||
@@ -155,16 +332,16 @@ public:
|
||||
public:
|
||||
// Shared
|
||||
/// Returns whether the window currently has mouse and/or keyboard focus.
|
||||
[[nodiscard]] bool IsFocused() { RWindowImpl::IsFocused(); } const;
|
||||
[[nodiscard]] bool IsFocused() const { return RWindowImpl::IsFocused(); };
|
||||
/// Returns whether the window is currently in Fullscreen.
|
||||
// TODO: Support Fullscreen, FullscreenWindowed, and Windowed?
|
||||
[[nodiscard]] bool IsFullscreen() { RWindowImpl::IsFullscreen(); } const;
|
||||
[[nodiscard]] bool IsFullscreen() const { return RWindowImpl::IsFullscreen(); } ;
|
||||
/// Returns whether the window can be resized.
|
||||
[[nodiscard]] bool IsResizable() { RWindowImpl::IsResizable(); } const;
|
||||
[[nodiscard]] bool IsResizable() const { return RWindowImpl::IsResizable(); } ;
|
||||
/// Returns whether V-Sync is enabled.
|
||||
[[nodiscard]] bool IsVsyncEnabled() { RWindowImpl::IsVsyncEnabled(); } const;
|
||||
[[nodiscard]] bool IsVsyncEnabled() const { return RWindowImpl::IsVsyncEnabled(); } ;
|
||||
/// 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() { RWindowImpl::IsAlive(); } const;
|
||||
[[nodiscard]] bool IsAlive() const { return RWindowImpl::IsAlive(); } ;
|
||||
// Should have IsOpen since window could be closed then reopened
|
||||
public:
|
||||
// Platform dependant
|
||||
@@ -190,20 +367,96 @@ public:
|
||||
void SetTitle(const std::string& title) { RWindowImpl::SetTitle(title); };
|
||||
public:
|
||||
// Shared
|
||||
[[nodiscard]] std::string GetTitle() { return RWindowImpl::GetTitle(); } const;
|
||||
[[nodiscard]] std::string GetTitle() const { return RWindowImpl::GetTitle(); } ;
|
||||
/// Returns the position of the window's top-left corner relative to the display
|
||||
[[nodiscard]] Vector2 GetPos() { return RWindowImpl::GetPos(); } const;
|
||||
[[nodiscard]] Vector2 GetPos() const { return RWindowImpl::GetPos(); } ;
|
||||
/// Returns the known size of the window, in {x,y} pixel measurement.
|
||||
[[nodiscard]] Vector2 GetSize() { return RWindowImpl::GetSize(); } const;
|
||||
[[nodiscard]] Vector2 GetSize() const { return RWindowImpl::GetSize(); } ;
|
||||
/// Returns the horizontal length of the renderable area in pixels.
|
||||
[[nodiscard]] int GetWidth() { return RWindowImpl::GetWidth(); } const;
|
||||
[[nodiscard]] int GetWidth() const { return RWindowImpl::GetWidth(); } ;
|
||||
/// Returns the vertical length of the renderable area, in pixels.
|
||||
[[nodiscard]] int GetHeight() { return RWindowImpl::GetHeight(); } const;
|
||||
[[nodiscard]] int GetHeight() const { return RWindowImpl::GetHeight(); } ;
|
||||
/// Returns the amount of time, in seconds, between the current and last frame.
|
||||
/// Technically, no, it returns the elapsed time of the frame, start to finish.
|
||||
[[nodiscard]] float GetDeltaTime() { return RWindowImpl::GetDeltaTime(); } const;
|
||||
[[nodiscard]] float GetDeltaTime() const { return RWindowImpl::GetDeltaTime(); } ;
|
||||
/// Returns the approximate frames-per-second using delta time.
|
||||
[[nodiscard]] float GetRefreshRate() { return RWindowImpl::GetRefreshRate(); } const;
|
||||
[[nodiscard]] float GetRefreshRate() const { return RWindowImpl::GetRefreshRate(); } ;
|
||||
/// Returns the number of frames ran since the windows' creation.
|
||||
[[nodiscard]] float GetRefreshCounter() { return RWindowImpl::GetRefreshCounter(); } const;
|
||||
[[nodiscard]] float GetRefreshCounter() const { return RWindowImpl::GetRefreshCounter(); } ;
|
||||
public:
|
||||
// Figure out what to do with these later
|
||||
void Raise() const { RWindowImpl::Raise(); };
|
||||
void Lower() const { RWindowImpl::Lower(); };
|
||||
void DestroyOSWindowHandle() { RWindowImpl::DestroyOSWindowHandle(); };
|
||||
void SetCursorVisible(bool cursor_enable) { RWindowImpl::SetCursorVisible(cursor_enable); };
|
||||
Vector2 GetAccurateMouseCoordinates() const { return RWindowImpl::GetAccurateMouseCoordinates(); } ;
|
||||
void GLSwapBuffers() { RWindowImpl::GLSwapBuffers(); };
|
||||
void Fullscreen() { RWindowImpl::Fullscreen(); };
|
||||
void RestoreFromFullscreen() { RWindowImpl::RestoreFromFullscreen(); };
|
||||
// I know this doesn't modify the class, but it indirectly modifies the window
|
||||
// Making it const just seems deceptive.
|
||||
void SetCursorStyle(CursorStyle style) const { return RWindowImpl::SetCursorStyle(style); } ;
|
||||
Vector2 GetPositionOfRenderableArea() const { return RWindowImpl::GetPositionOfRenderableArea(); } ;
|
||||
std::string getGraphicsDriverVendor() { return RWindowImpl::getGraphicsDriverVendor(); };
|
||||
void SetFlag(RWindowFlags flag, bool state) { RWindowImpl::SetFlag(flag, state); };
|
||||
void processKeyRelease (Key key) { RWindowImpl::processKeyRelease(key); };
|
||||
void processKeyPress (Key key) { RWindowImpl::processKeyPress(key); };
|
||||
void processOnClose() { RWindowImpl::processOnClose(); };
|
||||
void processOnOpen() { RWindowImpl::processOnOpen(); };
|
||||
void processMousePress(const MouseButton& btn) { RWindowImpl::processMousePress(btn); };
|
||||
void processMouseRelease(const MouseButton& btn) { RWindowImpl::processMouseRelease(btn); };
|
||||
void processFocusIn() { RWindowImpl::processFocusIn(); };
|
||||
void processFocusOut() { RWindowImpl::processFocusOut(); };
|
||||
void processMouseMove(Vector2 last_pos, Vector2 new_pos) { RWindowImpl::processMouseMove(last_pos, new_pos); };
|
||||
void processMouseWheel(int scrolls) { RWindowImpl::processMouseWheel(scrolls); };
|
||||
virtual void OnOpen() {}
|
||||
virtual void OnClosing() {}
|
||||
virtual void OnFocusLost(const RWindowEvent& e) {}
|
||||
virtual void OnFocusGain(const RWindowEvent& e) {}
|
||||
virtual void OnRefresh(float elapsed) {}
|
||||
virtual void OnResizeSuccess() {}
|
||||
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&) {}
|
||||
Event<> OnOpenEvent;
|
||||
Event<> OnClosingEvent;
|
||||
Event<RWindowEvent> OnFocusLostEvent;
|
||||
Event<RWindowEvent> OnFocusGainEvent;
|
||||
Event<float> OnRefreshEvent;
|
||||
Event<WindowResizeRequestEvent> OnResizeRequestEvent;
|
||||
Event<KeyDownEvent> OnKeyDownEvent;
|
||||
Event<KeyUpEvent> OnKeyUpEvent;
|
||||
Event<MouseMoveEvent> OnMouseMoveEvent;
|
||||
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;
|
||||
Event<MouseButtonUpEvent> OnMouseButtonUpEvent;
|
||||
Event<MouseWheelEvent> OnMouseWheelEvent;
|
||||
|
||||
Vector2 GetMouseCoordinates() const { return RWindowImpl::GetMouseCoordinates(); };
|
||||
bool GetFlag(RWindowFlags flag) const { return RWindowImpl::GetFlag(flag); };
|
||||
//bool IsAlive() const { return RWindowImpl::IsAlive(); };
|
||||
void SetSizeWithoutEvent(const Vector2& size) { RWindowImpl::SetSizeWithoutEvent(size); };
|
||||
void LogEvent(const RWindowEvent& e) { RWindowImpl::LogEvent(e); };
|
||||
RWindowEvent GetLastEvent() const { return RWindowImpl::GetLastEvent(); }
|
||||
void SetLastKnownWindowSize(const Vector2& size) { RWindowImpl::SetLastKnownWindowSize(size); };
|
||||
void SetRenderer(RenderingAPI api) { RWindowImpl::SetRenderer(api); };
|
||||
bool IsKeyDown(Key key) const { return RWindowImpl::IsKeyDown(key); };
|
||||
bool IsMouseButtonDown(const MouseButton &button) const { return RWindowImpl::IsMouseButtonDown(button); };
|
||||
void ManagedRefresh() { RWindowImpl::ManagedRefresh(); };
|
||||
float ComputeElapsedFrameTimeSeconds(std::chrono::steady_clock::time_point start, std::chrono::steady_clock::time_point end) { return RWindowImpl::ComputeElapsedFrameTimeSeconds(start, end); };
|
||||
std::chrono::steady_clock::time_point GetTimestamp() { return RWindowImpl::GetTimestamp(); };
|
||||
void UpdateFrameTiming(float frame_time) { RWindowImpl::UpdateFrameTiming(frame_time); };
|
||||
//bool IsResizable() const { return RWindowImpl::IsResizable(); };
|
||||
//bool IsFullscreen() const { return RWindowImpl::IsFullscreen(); };
|
||||
//bool IsFocused() const { return RWindowImpl::IsFocused(); };
|
||||
//bool IsVsyncEnabled() const { return RWindowImpl::IsVsyncEnabled(); };
|
||||
void ForceClose() { RWindowImpl::ForceClose(); };
|
||||
void ForceCloseAndTerminateProgram() { RWindowImpl::ForceCloseAndTerminateProgram(); };
|
||||
int GetMouseWheelPersistent() const { return RWindowImpl::GetMouseWheelPersistent();}
|
||||
[[nodiscard]] bool IsOpen() const { return RWindowImpl::IsOpen();}
|
||||
[[nodiscard]] bool IsClosing() const { return RWindowImpl::IsClosing();}
|
||||
|
||||
};
|
2
main.cpp
2
main.cpp
@@ -109,7 +109,7 @@ int main() {
|
||||
jlog::Debug(std::format("New window '{}' created. width={} height={}", window->GetTitle(), window->GetWidth(),
|
||||
window->GetHeight()));
|
||||
|
||||
window->SetRenderer(RenderingAPI::OPENGL);
|
||||
window->SetRenderer(ReWindow::RenderingAPI::OPENGL);
|
||||
jlog::Debug(std::format("Rendering API OPENGL set for window '{}'", window->GetTitle()));
|
||||
|
||||
window->Open();
|
||||
|
@@ -63,10 +63,11 @@ public:
|
||||
bool should_poll_x_for_mouse_pos = true;
|
||||
};
|
||||
|
||||
RWindowImpl::RWindowImpl(const std::string &wTitle, int wWidth, int wHeight, bool wFullscreen, bool wResizable, bool wVsync) : pPlatform(new Platform) {
|
||||
RWindowImpl::RWindowImpl(const std::string &wTitle, int wWidth, int wHeight, RenderingAPI wRenderer, bool wFullscreen, bool wResizable, bool wVsync) : pPlatform(new Platform) {
|
||||
title = wTitle;
|
||||
width = wWidth;
|
||||
height = wHeight;
|
||||
renderer = wRenderer;
|
||||
fullscreen_mode = wFullscreen;
|
||||
resizable = wResizable;
|
||||
vsync = wVsync;
|
||||
@@ -143,21 +144,19 @@ void RWindowImpl::SetResizable(bool sizable) {
|
||||
}
|
||||
|
||||
// Fuck you
|
||||
/*
|
||||
void RWindowImpl::SetFlag(RWindowFlags flag, bool state) {
|
||||
XGetWindowAttributes(display,window,&windowAttributes);
|
||||
XGetWindowAttributes(pPlatform->display,pPlatform->window,&pPlatform->windowAttributes);
|
||||
flags[(int) flag] = state;
|
||||
//Once you've done this you cannot make it resizable again.
|
||||
if (flag == RWindowFlags::RESIZABLE && !state) {
|
||||
Logger::Debug("Once you've done this you cannot make it resizable again.");
|
||||
hints.flags = PMinSize | PMaxSize;
|
||||
hints.min_width = hints.max_width = windowAttributes.width;
|
||||
hints.min_height = hints.max_height = windowAttributes.height;
|
||||
XSetWMNormalHints(display, window, &hints);
|
||||
pPlatform->hints.flags = PMinSize | PMaxSize;
|
||||
pPlatform->hints.min_width = pPlatform->hints.max_width = pPlatform->windowAttributes.width;
|
||||
pPlatform->hints.min_height = pPlatform->hints.max_height = pPlatform->windowAttributes.height;
|
||||
XSetWMNormalHints(pPlatform->display, pPlatform->window, &pPlatform->hints);
|
||||
}
|
||||
Logger::Debug(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
|
||||
}
|
||||
*/
|
||||
|
||||
void RWindowImpl::PollEvents() {
|
||||
while(XPending(pPlatform->display)) {
|
||||
|
@@ -1,5 +1,20 @@
|
||||
#include <rewindow/types/window.h>
|
||||
#include <rewindow/types/window.h>
|
||||
#include "rewindow/logger/logger.h"
|
||||
/*
|
||||
std::string RWindowFlagToStr(RWindowFlags flag) {
|
||||
switch (flag) {
|
||||
case RWindowFlags::IN_FOCUS: return "IN_FOCUS";
|
||||
case RWindowFlags::FULLSCREEN: return "FULLSCREEN";
|
||||
case RWindowFlags::RESIZABLE: return "RESIZEABLE";
|
||||
case RWindowFlags::VSYNC: return "VSYNC";
|
||||
case RWindowFlags::QUIT: return "QUIT";
|
||||
case RWindowFlags::MAX_FLAG: return "MAX_FLAG";
|
||||
default:
|
||||
return "unimplemented flag";
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
std::string RWindowFlagToStr(RWindowFlags flag) {
|
||||
switch (flag) {
|
||||
case RWindowFlags::IN_FOCUS: return "IN_FOCUS";
|
||||
@@ -13,34 +28,43 @@ std::string RWindowFlagToStr(RWindowFlags flag) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
using namespace ReWindow;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
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} {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
RWindow::~RWindow() {
|
||||
/*
|
||||
if (open)
|
||||
DestroyOSWindowHandle();
|
||||
*/
|
||||
RWindowImpl::~RWindowImpl();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector2 RWindow::GetMouseCoordinates() const {
|
||||
Vector2 RWindowImpl::GetMouseCoordinates() const {
|
||||
return currentMouse.Position;
|
||||
}
|
||||
|
||||
bool RWindow::GetFlag(RWindowFlags flag) const {
|
||||
bool RWindowImpl::GetFlag(RWindowFlags flag) const {
|
||||
return flags[(int) flag];
|
||||
}
|
||||
|
||||
bool RWindow::IsAlive() const {
|
||||
bool RWindowImpl::IsAlive() const {
|
||||
return (!closing) && open;
|
||||
}
|
||||
|
||||
void RWindow::SetFullscreen(bool fs) {
|
||||
void RWindowImpl::SetFullscreen(bool fs) {
|
||||
if (fs)
|
||||
Fullscreen();
|
||||
else
|
||||
@@ -48,7 +72,7 @@ void RWindow::SetFullscreen(bool fs) {
|
||||
}
|
||||
|
||||
#pragma region Event Processors Implementation
|
||||
void RWindow::processFocusIn()
|
||||
void RWindowImpl::processFocusIn()
|
||||
{
|
||||
RWindowEvent event {};
|
||||
OnFocusGain(event);
|
||||
@@ -56,7 +80,7 @@ void RWindow::processFocusIn()
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processFocusOut()
|
||||
void RWindowImpl::processFocusOut()
|
||||
{
|
||||
RWindowEvent event {};
|
||||
OnFocusLost(event);
|
||||
@@ -64,7 +88,7 @@ void RWindow::processFocusOut()
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processMousePress(const MouseButton& btn)
|
||||
void RWindowImpl::processMousePress(const MouseButton& btn)
|
||||
{
|
||||
currentMouse.Set(btn, true);
|
||||
auto event = MouseButtonDownEvent(btn);
|
||||
@@ -74,7 +98,7 @@ void RWindow::processMousePress(const MouseButton& btn)
|
||||
|
||||
}
|
||||
|
||||
void RWindow::processMouseMove(Vector2 last_pos, Vector2 new_pos)
|
||||
void RWindowImpl::processMouseMove(Vector2 last_pos, Vector2 new_pos)
|
||||
{
|
||||
currentMouse.Position = new_pos;
|
||||
auto event = MouseMoveEvent(new_pos);
|
||||
@@ -83,7 +107,7 @@ void RWindow::processMouseMove(Vector2 last_pos, Vector2 new_pos)
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processMouseRelease(const MouseButton& btn)
|
||||
void RWindowImpl::processMouseRelease(const MouseButton& btn)
|
||||
{
|
||||
currentMouse.Set(btn, false);
|
||||
auto event = MouseButtonUpEvent(btn);
|
||||
@@ -93,7 +117,7 @@ void RWindow::processMouseRelease(const MouseButton& btn)
|
||||
|
||||
}
|
||||
|
||||
void RWindow::processKeyRelease(Key key) {
|
||||
void RWindowImpl::processKeyRelease(Key key) {
|
||||
currentKeyboard.PressedKeys[key] = false;
|
||||
auto event = KeyUpEvent(key);
|
||||
OnKeyUp(event);
|
||||
@@ -101,7 +125,7 @@ void RWindow::processKeyRelease(Key key) {
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processKeyPress(Key key) {
|
||||
void RWindowImpl::processKeyPress(Key key) {
|
||||
currentKeyboard.PressedKeys[key] = true;
|
||||
auto event = KeyDownEvent(key);
|
||||
OnKeyDown(event);
|
||||
@@ -109,7 +133,7 @@ void RWindow::processKeyPress(Key key) {
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processOnClose()
|
||||
void RWindowImpl::processOnClose()
|
||||
{
|
||||
auto event = RWindowEvent();
|
||||
OnClosing();
|
||||
@@ -117,7 +141,7 @@ void RWindow::processOnClose()
|
||||
LogEvent(event);
|
||||
}
|
||||
|
||||
void RWindow::processOnOpen()
|
||||
void RWindowImpl::processOnOpen()
|
||||
{
|
||||
auto event = RWindowEvent();
|
||||
OnOpen();
|
||||
@@ -127,60 +151,60 @@ void RWindow::processOnOpen()
|
||||
|
||||
#pragma endregion
|
||||
|
||||
std::string RWindow::GetTitle() const {
|
||||
std::string RWindowImpl::GetTitle() const {
|
||||
return this->title;
|
||||
}
|
||||
|
||||
/*
|
||||
Vector2 RWindow::GetSize() const
|
||||
Vector2 RWindowImpl::GetSize() const
|
||||
{
|
||||
return {this->width, this->height};
|
||||
}
|
||||
*/
|
||||
|
||||
int RWindow::GetWidth() const
|
||||
int RWindowImpl::GetWidth() const
|
||||
{
|
||||
return this->width;
|
||||
}
|
||||
|
||||
int RWindow::GetHeight() const
|
||||
int RWindowImpl::GetHeight() const
|
||||
{
|
||||
return this->height;
|
||||
}
|
||||
|
||||
void RWindow::SetSizeWithoutEvent(const Vector2& size) {
|
||||
void RWindowImpl::SetSizeWithoutEvent(const Vector2& size) {
|
||||
width = size.x;
|
||||
height = size.y;
|
||||
}
|
||||
|
||||
void RWindow::SetLastKnownWindowSize(const Vector2& size) {
|
||||
void RWindowImpl::SetLastKnownWindowSize(const Vector2& size) {
|
||||
lastKnownWindowSize = size;
|
||||
}
|
||||
|
||||
void RWindow::SetRenderer(RenderingAPI api) {
|
||||
void RWindowImpl::SetRenderer(RenderingAPI api) {
|
||||
renderer = api;
|
||||
}
|
||||
|
||||
void RWindow::SetSize(const Vector2& size) {
|
||||
void RWindowImpl::SetSize(const Vector2& size) {
|
||||
this->width = size.x;
|
||||
this->height = size.y;
|
||||
this->SetSize(size.x, size.y);
|
||||
}
|
||||
|
||||
bool RWindow::IsKeyDown(Key key) const {
|
||||
bool RWindowImpl::IsKeyDown(Key key) const {
|
||||
if (currentKeyboard.PressedKeys.contains(key))
|
||||
return currentKeyboard.PressedKeys.at(key);
|
||||
|
||||
return false; // NOTE: Key may not be mapped!!
|
||||
}
|
||||
|
||||
bool RWindow::IsMouseButtonDown(const MouseButton &button) const {
|
||||
bool RWindowImpl::IsMouseButtonDown(const MouseButton &button) const {
|
||||
// TODO: Implement MouseButton map
|
||||
return currentMouse.IsDown(button);
|
||||
}
|
||||
|
||||
|
||||
void RWindow::ManagedRefresh()
|
||||
void RWindowImpl::ManagedRefresh()
|
||||
{
|
||||
auto begin = GetTimestamp();
|
||||
Refresh();
|
||||
@@ -191,7 +215,7 @@ void RWindow::ManagedRefresh()
|
||||
UpdateFrameTiming(dt);
|
||||
}
|
||||
|
||||
void RWindow::Refresh() {
|
||||
void RWindowImpl::Refresh() {
|
||||
PollEvents();
|
||||
OnRefresh(delta_time);
|
||||
|
||||
@@ -205,18 +229,18 @@ void RWindow::Refresh() {
|
||||
}
|
||||
}
|
||||
|
||||
float RWindow::ComputeElapsedFrameTimeSeconds(std::chrono::steady_clock::time_point start, std::chrono::steady_clock::time_point end) {
|
||||
float RWindowImpl::ComputeElapsedFrameTimeSeconds(std::chrono::steady_clock::time_point start, std::chrono::steady_clock::time_point end) {
|
||||
auto frame_time = end - start;
|
||||
unsigned long int frame_time_us = std::chrono::duration_cast<std::chrono::microseconds>(frame_time).count();
|
||||
float frame_time_s = frame_time_us / (1000.f * 1000.f);
|
||||
return frame_time_s;
|
||||
}
|
||||
|
||||
std::chrono::steady_clock::time_point RWindow::GetTimestamp() {
|
||||
std::chrono::steady_clock::time_point RWindowImpl::GetTimestamp() {
|
||||
return std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
void RWindow::UpdateFrameTiming(float frame_time) {
|
||||
void RWindowImpl::UpdateFrameTiming(float frame_time) {
|
||||
delta_time = frame_time;
|
||||
refresh_rate = 1.f / delta_time;
|
||||
refresh_rate_prev_5 = refresh_rate_prev_4;
|
||||
@@ -229,7 +253,7 @@ void RWindow::UpdateFrameTiming(float frame_time) {
|
||||
}
|
||||
|
||||
|
||||
void RWindow::processMouseWheel(int scrolls)
|
||||
void RWindowImpl::processMouseWheel(int scrolls)
|
||||
{
|
||||
currentMouse.Wheel += scrolls;
|
||||
auto ev = MouseWheelEvent(scrolls);
|
||||
@@ -240,39 +264,39 @@ void RWindow::processMouseWheel(int scrolls)
|
||||
}
|
||||
|
||||
|
||||
bool RWindow::IsResizable() const {
|
||||
bool RWindowImpl::IsResizable() const {
|
||||
return resizable;
|
||||
}
|
||||
|
||||
bool RWindow::IsFullscreen() const {
|
||||
bool RWindowImpl::IsFullscreen() const {
|
||||
return fullscreen_mode;
|
||||
}
|
||||
|
||||
bool RWindow::IsFocused() const {
|
||||
bool RWindowImpl::IsFocused() const {
|
||||
return focused;
|
||||
}
|
||||
|
||||
bool RWindow::IsVsyncEnabled() const {
|
||||
bool RWindowImpl::IsVsyncEnabled() const {
|
||||
return vsync;
|
||||
}
|
||||
|
||||
float RWindow::GetDeltaTime() const { return delta_time; }
|
||||
float RWindowImpl::GetDeltaTime() const { return delta_time; }
|
||||
|
||||
float RWindow::GetRefreshRate() const { return refresh_rate; }
|
||||
float RWindowImpl::GetRefreshRate() const { return refresh_rate; }
|
||||
|
||||
float RWindow::GetRefreshCounter() const { return refresh_count; }
|
||||
float RWindowImpl::GetRefreshCounter() const { return refresh_count; }
|
||||
|
||||
void RWindow::Close() {
|
||||
void RWindowImpl::Close() {
|
||||
closing = true;
|
||||
processOnClose();
|
||||
}
|
||||
|
||||
void RWindow::ForceClose() {
|
||||
void RWindowImpl::ForceClose() {
|
||||
Close();
|
||||
DestroyOSWindowHandle();
|
||||
}
|
||||
|
||||
void RWindow::ForceCloseAndTerminateProgram() {
|
||||
void RWindowImpl::ForceCloseAndTerminateProgram() {
|
||||
ForceClose();
|
||||
exit(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user