Total overhaul
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m27s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m27s
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <J3ML/J3ML.hpp>
|
#include "J3ML/J3ML.hpp"
|
||||||
|
|
||||||
namespace ReWindow {
|
namespace ReWindow {
|
||||||
class FullscreenGraphicsMode;
|
class FullscreenGraphicsMode;
|
@@ -11,6 +11,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace ReWindow {
|
namespace ReWindow {
|
||||||
|
class GamepadState {
|
||||||
|
public:
|
||||||
|
std::map<GamepadButton, bool> PressedButtons;
|
||||||
|
};
|
||||||
|
|
||||||
class Gamepad;
|
class Gamepad;
|
||||||
class Xbox360Gamepad;
|
class Xbox360Gamepad;
|
||||||
class XboxOneGamepad;
|
class XboxOneGamepad;
|
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <J3ML/LinearAlgebra.hpp>
|
#include "J3ML/LinearAlgebra.hpp"
|
||||||
namespace ReWindow {
|
namespace ReWindow {
|
||||||
class GamepadButton;
|
class GamepadButton;
|
||||||
class GamepadTrigger;
|
class GamepadTrigger;
|
@@ -6,9 +6,9 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <rewindow/data/X11Scancodes.h>
|
#include "rewindow/X11Scancodes.hpp"
|
||||||
#include <rewindow/data/WindowsScancodes.h>
|
#include "rewindow/WindowsScancodes.hpp"
|
||||||
#include <J3ML/LinearAlgebra.hpp>
|
#include "J3ML/LinearAlgebra.hpp"
|
||||||
|
|
||||||
|
|
||||||
class Key
|
class Key
|
@@ -13,6 +13,10 @@
|
|||||||
|
|
||||||
namespace ReWindow
|
namespace ReWindow
|
||||||
{
|
{
|
||||||
|
class KeyboardState {
|
||||||
|
public:
|
||||||
|
std::map<Key, bool> PressedKeys;
|
||||||
|
};
|
||||||
class InputDevice {};
|
class InputDevice {};
|
||||||
|
|
||||||
class Keyboard : public InputDevice
|
class Keyboard : public InputDevice
|
80
include/ReWindow/Mouse.hpp
Normal file
80
include/ReWindow/Mouse.hpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/// 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 keyboard.h
|
||||||
|
/// @desc A class that models the functionality of a mouse / pointer device.
|
||||||
|
/// @edit 2024-07-29
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
namespace ReWindow
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class InputDevice {}; // TODO: Remember to break InputDevice into it's own file and not define it twice!!!
|
||||||
|
|
||||||
|
class Pointer : public InputDevice {};
|
||||||
|
|
||||||
|
|
||||||
|
class Mouse : public Pointer
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
223
include/ReWindow/RWindow.hpp
Normal file
223
include/ReWindow/RWindow.hpp
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
#include "Event.h"
|
||||||
|
#include <map>
|
||||||
|
#include <thread>
|
||||||
|
#include "Key.hpp"
|
||||||
|
#include "rewindow/Cursors.hpp"
|
||||||
|
#include "MouseButton.hpp"
|
||||||
|
#include "GamepadButton.hpp"
|
||||||
|
#include "J3ML/LinearAlgebra.hpp"
|
||||||
|
#include "WindowEvents.hpp"
|
||||||
|
#include <format>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
#include <experimental/propagate_const>
|
||||||
|
|
||||||
|
|
||||||
|
namespace ReWindow {
|
||||||
|
enum class RenderingAPI: uint8_t {
|
||||||
|
OPENGL = 0,
|
||||||
|
//Vulkan is unimplemented.
|
||||||
|
VULKAN = 1,
|
||||||
|
};
|
||||||
|
//
|
||||||
|
|
||||||
|
class RWindowImpl;
|
||||||
|
class XLibImpl;
|
||||||
|
class Win32Impl;
|
||||||
|
class RWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReWindow::RWindow {
|
||||||
|
private:
|
||||||
|
RWindowImpl* Impl = nullptr;
|
||||||
|
public:
|
||||||
|
//RWindow() = default;
|
||||||
|
//RWindow();
|
||||||
|
|
||||||
|
static RWindowImpl* GetPlatformImplementation(const RWindowParams& args) {
|
||||||
|
|
||||||
|
#if UNIX
|
||||||
|
return new XLibImpl(args);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if WIN32
|
||||||
|
return new Win32Impl(args);
|
||||||
|
#endif
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
explicit RWindow(const RWindowParams& params)
|
||||||
|
: Impl(GetPlatformImplementation(params)) { }
|
||||||
|
|
||||||
|
RWindow()
|
||||||
|
: RWindow({
|
||||||
|
.title = "Redacted Window",
|
||||||
|
.width = 640, .height = 480,
|
||||||
|
.fullscreen = false,
|
||||||
|
.resizable = true,
|
||||||
|
.vsync = false
|
||||||
|
}) { }
|
||||||
|
|
||||||
|
// TODO: Is this one valid?
|
||||||
|
explicit RWindow(RWindowImpl* wImpl)
|
||||||
|
: Impl(wImpl) { }
|
||||||
|
|
||||||
|
RWindow(RWindowImpl* wImpl, RenderImpl* wRenderImpl)
|
||||||
|
: Impl(wImpl), Renderer(wRenderImpl) { }
|
||||||
|
|
||||||
|
/*
|
||||||
|
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, wRenderer, wFullscreen, wResizable, wVsync) {};
|
||||||
|
*/
|
||||||
|
~RWindow() = default;
|
||||||
|
public:
|
||||||
|
// Platform dependant
|
||||||
|
void Open() { Impl->Open(); };
|
||||||
|
void Close() { Impl->Close(); };
|
||||||
|
void PollEvents() { Impl->PollEvents(); };
|
||||||
|
void Refresh() { Impl->Refresh(); };
|
||||||
|
public:
|
||||||
|
// Shared
|
||||||
|
/// Returns whether the window currently has mouse and/or keyboard focus.
|
||||||
|
[[nodiscard]] bool IsFocused() const { return Impl->IsFocused(); };
|
||||||
|
/// Returns whether the window is currently in Fullscreen.
|
||||||
|
// TODO: Support Fullscreen, FullscreenWindowed, and Windowed?
|
||||||
|
[[nodiscard]] bool IsFullscreen() const { return Impl->IsFullscreen(); } ;
|
||||||
|
/// Returns whether the window can be resized.
|
||||||
|
[[nodiscard]] bool IsResizable() const { return Impl->IsResizable(); } ;
|
||||||
|
/// Returns whether V-Sync is enabled.
|
||||||
|
[[nodiscard]] bool IsVsyncEnabled() const { return Impl->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() const { return Impl->IsAlive(); } ;
|
||||||
|
// Should have IsOpen since window could be closed then reopened
|
||||||
|
public:
|
||||||
|
// Platform dependant
|
||||||
|
/// Sets whether or not to make the window fullscreen.
|
||||||
|
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
|
||||||
|
void SetFullscreen(bool fs) { Impl->SetFullscreen(fs); };
|
||||||
|
/// Sets whether or not to make the window resizable.
|
||||||
|
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
|
||||||
|
void SetResizable(bool resizable) { Impl->SetResizable(resizable); };
|
||||||
|
/// Sets whether or not to enable vertical synchronization.
|
||||||
|
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
|
||||||
|
void SetVsyncEnabled(bool vsync) { Impl->SetVsyncEnabled(vsync); };
|
||||||
|
/// Requests the operating system to change the window size.
|
||||||
|
/// @param width
|
||||||
|
/// @param height
|
||||||
|
void SetSize(int width, int height) { Impl->SetSize(width, height); };
|
||||||
|
/// Requests the operating system to change the window size.
|
||||||
|
/// @param size
|
||||||
|
void SetSize(const Vector2& size) { Impl->SetSize(size); };
|
||||||
|
|
||||||
|
// Shared
|
||||||
|
/// Sets the title of this window.
|
||||||
|
void SetTitle(const std::string& title) { Impl->SetTitle(title); };
|
||||||
|
public:
|
||||||
|
// Shared
|
||||||
|
[[nodiscard]] std::string GetTitle() const { return Impl->GetTitle(); } ;
|
||||||
|
/// Returns the position of the window's top-left corner relative to the display
|
||||||
|
[[nodiscard]] Vector2 GetPos() const { return Impl->GetPos(); } ;
|
||||||
|
/// Returns the known size of the window, in {x,y} pixel measurement.
|
||||||
|
[[nodiscard]] Vector2 GetSize() const { return Impl->GetSize(); } ;
|
||||||
|
/// Returns the horizontal length of the renderable area in pixels.
|
||||||
|
[[nodiscard]] int GetWidth() const { return Impl->GetWidth(); } ;
|
||||||
|
/// Returns the vertical length of the renderable area, in pixels.
|
||||||
|
[[nodiscard]] int GetHeight() const { return Impl->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() const { return Impl->GetDeltaTime(); } ;
|
||||||
|
/// Returns the approximate frames-per-second using delta time.
|
||||||
|
[[nodiscard]] float GetRefreshRate() const { return Impl->GetRefreshRate(); } ;
|
||||||
|
/// Returns the number of frames ran since the windows' creation.
|
||||||
|
[[nodiscard]] float GetRefreshCounter() const { return Impl->GetRefreshCounter(); } ;
|
||||||
|
public:
|
||||||
|
// Figure out what to do with these later
|
||||||
|
void Raise() const { Impl->Raise(); };
|
||||||
|
void Lower() const { Impl->Lower(); };
|
||||||
|
void DestroyOSWindowHandle() { Impl->DestroyOSWindowHandle(); };
|
||||||
|
void SetCursorVisible(bool cursor_enable) { Impl->SetCursorVisible(cursor_enable); };
|
||||||
|
Vector2 GetAccurateMouseCoordinates() const { return Impl->GetAccurateMouseCoordinates(); } ;
|
||||||
|
void GLSwapBuffers() { Impl->GLSwapBuffers(); };
|
||||||
|
void Fullscreen() { Impl->Fullscreen(); };
|
||||||
|
void RestoreFromFullscreen() { Impl->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 Impl->SetCursorStyle(style); } ;
|
||||||
|
Vector2 GetPositionOfRenderableArea() const { return Impl->GetPositionOfRenderableArea(); } ;
|
||||||
|
std::string getGraphicsDriverVendor() { return Impl->getGraphicsDriverVendor(); };
|
||||||
|
void SetFlag(RWindowFlags flag, bool state) { Impl->SetFlag(flag, state); };
|
||||||
|
void processKeyRelease (Key key) { Impl->processKeyRelease(key); };
|
||||||
|
void processKeyPress (Key key) { Impl->processKeyPress(key); };
|
||||||
|
void processOnClose() { Impl->processOnClose(); };
|
||||||
|
void processOnOpen() { Impl->processOnOpen(); };
|
||||||
|
void processMousePress(const MouseButton& btn) { Impl->processMousePress(btn); };
|
||||||
|
void processMouseRelease(const MouseButton& btn) { Impl->processMouseRelease(btn); };
|
||||||
|
void processFocusIn() { Impl->processFocusIn(); };
|
||||||
|
void processFocusOut() { Impl->processFocusOut(); };
|
||||||
|
void processMouseMove(Vector2 last_pos, Vector2 new_pos) { Impl->processMouseMove(last_pos, new_pos); };
|
||||||
|
void processMouseWheel(int scrolls) { Impl->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 Impl->GetMouseCoordinates(); };
|
||||||
|
bool GetFlag(RWindowFlags flag) const { return Impl->GetFlag(flag); };
|
||||||
|
//bool IsAlive() const { return Impl->
|
||||||
|
//IsAlive(); };
|
||||||
|
void SetSizeWithoutEvent(const Vector2& size) { Impl->SetSizeWithoutEvent(size); };
|
||||||
|
void LogEvent(const RWindowEvent& e) { Impl->LogEvent(e); };
|
||||||
|
RWindowEvent GetLastEvent() const { return Impl->GetLastEvent(); }
|
||||||
|
void SetLastKnownWindowSize(const Vector2& size) { Impl->SetLastKnownWindowSize(size); };
|
||||||
|
void SetRenderer(RenderingAPI api) { Impl->SetRenderer(api); };
|
||||||
|
bool IsKeyDown(Key key) const { return Impl->IsKeyDown(key); };
|
||||||
|
bool IsMouseButtonDown(const MouseButton &button) const { return Impl->IsMouseButtonDown(button); };
|
||||||
|
void ManagedRefresh() { Impl->ManagedRefresh(); };
|
||||||
|
float ComputeElapsedFrameTimeSeconds(std::chrono::steady_clock::time_point start, std::chrono::steady_clock::time_point end) { return Impl->ComputeElapsedFrameTimeSeconds(start, end); };
|
||||||
|
std::chrono::steady_clock::time_point GetTimestamp() { return Impl->GetTimestamp(); };
|
||||||
|
void UpdateFrameTiming(float frame_time) { Impl->UpdateFrameTiming(frame_time); };
|
||||||
|
//bool IsResizable() const { return Impl->
|
||||||
|
//IsResizable(); };
|
||||||
|
//bool IsFullscreen() const { return Impl->
|
||||||
|
//IsFullscreen(); };
|
||||||
|
//bool IsFocused() const { return Impl->
|
||||||
|
//IsFocused(); };
|
||||||
|
//bool IsVsyncEnabled() const { return Impl->
|
||||||
|
//IsVsyncEnabled(); };
|
||||||
|
void ForceClose() { Impl->ForceClose(); };
|
||||||
|
void ForceCloseAndTerminateProgram() { Impl->ForceCloseAndTerminateProgram(); };
|
||||||
|
int GetMouseWheelPersistent() const { return Impl->GetMouseWheelPersistent();}
|
||||||
|
[[nodiscard]] bool IsOpen() const { return Impl->IsOpen();}
|
||||||
|
[[nodiscard]] bool IsClosing() const { return Impl->IsClosing();}
|
||||||
|
|
||||||
|
};
|
167
include/ReWindow/RWindowImpl.hpp
Normal file
167
include/ReWindow/RWindowImpl.hpp
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace ReWindow { class RWindowImpl; }
|
||||||
|
|
||||||
|
class ReWindow::RWindowImpl {
|
||||||
|
protected: // Should maybe make private
|
||||||
|
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";
|
||||||
|
|
||||||
|
Vector2 lastKnownWindowSize {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 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 RWindowParams& params)
|
||||||
|
: RWindowImpl(params.title, params.width, params.height, RenderingAPI::OPENGL, params.fullscreen, p)
|
||||||
|
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);
|
||||||
|
~RWindowImpl();
|
||||||
|
public:
|
||||||
|
virtual void Open();
|
||||||
|
virtual void Close();
|
||||||
|
virtual void PollEvents();
|
||||||
|
virtual void Refresh();
|
||||||
|
public:
|
||||||
|
bool IsFocused() const;
|
||||||
|
bool IsFullscreen() const;
|
||||||
|
bool IsResizable() const;
|
||||||
|
bool IsVsyncEnabled() const;
|
||||||
|
bool IsAlive() const;
|
||||||
|
public:
|
||||||
|
void SetFullscreen(bool fs);
|
||||||
|
void SetResizable(bool fs);
|
||||||
|
void SetVsyncEnabled(bool vsync);
|
||||||
|
void SetSize(int width, int height);
|
||||||
|
void SetSize(const Vector2& size);
|
||||||
|
// Added here for now
|
||||||
|
void SetPos(int x, int y);
|
||||||
|
void SetPos(const Vector2& pos);
|
||||||
|
//
|
||||||
|
virtual void SetTitle(const std::string& title);
|
||||||
|
public:
|
||||||
|
std::string GetTitle() const;
|
||||||
|
Vector2 GetPos() const;
|
||||||
|
Vector2 GetSize() const;
|
||||||
|
int GetWidth() const;
|
||||||
|
int GetHeight() const;
|
||||||
|
float GetDeltaTime() const;
|
||||||
|
float GetRefreshRate() const;
|
||||||
|
float GetRefreshCounter() const;
|
||||||
|
public:
|
||||||
|
// Figure out what to do with these later
|
||||||
|
void Raise() const;
|
||||||
|
void Lower() const;
|
||||||
|
void DestroyOSWindowHandle();
|
||||||
|
void SetCursorVisible(bool cursor_enable);
|
||||||
|
Vector2 GetAccurateMouseCoordinates() const;
|
||||||
|
void GLSwapBuffers();
|
||||||
|
void Fullscreen();
|
||||||
|
void 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;
|
||||||
|
Vector2 GetPositionOfRenderableArea() const;
|
||||||
|
std::string getGraphicsDriverVendor();
|
||||||
|
void SetFlag(RWindowFlags flag, bool state);
|
||||||
|
// Make protected
|
||||||
|
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;}
|
||||||
|
};
|
15
include/ReWindow/RWindowParams.hpp
Normal file
15
include/ReWindow/RWindowParams.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace ReWindow {
|
||||||
|
struct RWindowParams
|
||||||
|
{
|
||||||
|
std::string title;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
bool fullscreen;
|
||||||
|
bool resizable;
|
||||||
|
bool vsync;
|
||||||
|
};
|
||||||
|
}
|
5
include/ReWindow/Win32Impl.hpp
Normal file
5
include/ReWindow/Win32Impl.hpp
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class ReWindow::Win32Impl : ReWindow::RWindowImpl {
|
||||||
|
public:
|
||||||
|
};
|
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <rewindow/types/key.h>
|
#include "Key.hpp"
|
||||||
#include <rewindow/types/mousebutton.h>
|
#include "MouseButton.hpp"
|
||||||
|
|
||||||
namespace ReWindow {
|
namespace ReWindow {
|
||||||
|
|
37
include/ReWindow/XLibImpl.hpp
Normal file
37
include/ReWindow/XLibImpl.hpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ReWindow/RWindowImpl.hpp>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <X11/Xutil.h>
|
||||||
|
#include <GL/glx.h>
|
||||||
|
#include "J3ML/LinearAlgebra.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace ReWindow { class XLibImpl; };
|
||||||
|
|
||||||
|
class ReWindow::XLibImpl : ReWindow::RWindowImpl {
|
||||||
|
Window window;
|
||||||
|
XEvent xev;
|
||||||
|
Display* display = XOpenDisplay(nullptr);
|
||||||
|
int defaultScreen = DefaultScreen(display);
|
||||||
|
XVisualInfo* visual;
|
||||||
|
XSetWindowAttributes xSetWindowAttributes;
|
||||||
|
XWindowAttributes windowAttributes;
|
||||||
|
Atom wmDeleteWindow;
|
||||||
|
// Make it start as floating because fuck tiling WMs
|
||||||
|
Atom windowTypeAtom;
|
||||||
|
Atom windowTypeUtilityAtom;
|
||||||
|
XSizeHints hints;
|
||||||
|
GLXContext glContext;
|
||||||
|
Cursor invisible_cursor = 0;
|
||||||
|
Vector2 render_area_position = {0, 0};
|
||||||
|
Vector2 position = {0, 0};
|
||||||
|
bool should_poll_x_for_mouse_pos = true;
|
||||||
|
public:
|
||||||
|
void Open() override;
|
||||||
|
void Close() override;
|
||||||
|
void PollEvents() override;
|
||||||
|
void SetTitle(const std::string &title) override;
|
||||||
|
void Refresh() override;
|
||||||
|
};
|
||||||
|
|
@@ -1,26 +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 keyboard.h
|
|
||||||
/// @desc A class that models the functionality of a mouse / pointer device.
|
|
||||||
/// @edit 2024-07-29
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
namespace ReWindow
|
|
||||||
{
|
|
||||||
|
|
||||||
class InputDevice {}; // TODO: Remember to break InputDevice into it's own file and not define it twice!!!
|
|
||||||
|
|
||||||
class Pointer : public InputDevice {};
|
|
||||||
|
|
||||||
|
|
||||||
class Mouse : public Pointer
|
|
||||||
{
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
@@ -1,462 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <cstdint>
|
|
||||||
#include <vector>
|
|
||||||
#include <Event.h>
|
|
||||||
#include <map>
|
|
||||||
#include <thread>
|
|
||||||
#include <rewindow/types/key.h>
|
|
||||||
#include <rewindow/types/cursors.h>
|
|
||||||
#include <rewindow/types/mousebutton.h>
|
|
||||||
#include <rewindow/types/gamepadbutton.h>
|
|
||||||
#include <J3ML/LinearAlgebra.hpp>
|
|
||||||
#include <rewindow/types/WindowEvents.hpp>
|
|
||||||
#include <format>
|
|
||||||
#include <queue>
|
|
||||||
|
|
||||||
#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 ReWindow::RWindowImpl {
|
|
||||||
private:
|
|
||||||
// Class for platform specific "global" variables, information, functionality, etc
|
|
||||||
// It is private as it should not be accessed outside the Impl. It has also
|
|
||||||
// purposefully been left undefined, so implementors can define it as they see fit.
|
|
||||||
// Make sure to do proper cleanup of the class and pointer if utilized. It should
|
|
||||||
// be handled with care.
|
|
||||||
//
|
|
||||||
// Example for initialization:
|
|
||||||
// RWindowImpl::RWindowImpl(ARGS) : pPlatform( new Platform ) { XYZ }
|
|
||||||
//
|
|
||||||
// Example for destruction:
|
|
||||||
// RWindowImpl::~RWindowImpl() {
|
|
||||||
// if (pPlatform) { delete pPlatform; };
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Example for definition:
|
|
||||||
// class RWindowImpl::Platform {
|
|
||||||
// public:
|
|
||||||
// Platform() = default;
|
|
||||||
// public:
|
|
||||||
// int a;
|
|
||||||
// int b;
|
|
||||||
// int c;
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// - Maxine
|
|
||||||
class Platform;
|
|
||||||
Platform* pPlatform = nullptr;
|
|
||||||
protected: // Should maybe make private
|
|
||||||
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";
|
|
||||||
|
|
||||||
Vector2 lastKnownWindowSize {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 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);
|
|
||||||
~RWindowImpl();
|
|
||||||
public:
|
|
||||||
void Open();
|
|
||||||
void Close();
|
|
||||||
void PollEvents();
|
|
||||||
void Refresh();
|
|
||||||
public:
|
|
||||||
bool IsFocused() const;
|
|
||||||
bool IsFullscreen() const;
|
|
||||||
bool IsResizable() const;
|
|
||||||
bool IsVsyncEnabled() const;
|
|
||||||
bool IsAlive() const;
|
|
||||||
public:
|
|
||||||
void SetFullscreen(bool fs);
|
|
||||||
void SetResizable(bool fs);
|
|
||||||
void SetVsyncEnabled(bool vsync);
|
|
||||||
void SetSize(int width, int height);
|
|
||||||
void SetSize(const Vector2& size);
|
|
||||||
// Added here for now
|
|
||||||
void SetPos(int x, int y);
|
|
||||||
void SetPos(const Vector2& pos);
|
|
||||||
//
|
|
||||||
void SetTitle(const std::string& title);
|
|
||||||
public:
|
|
||||||
std::string GetTitle() const;
|
|
||||||
Vector2 GetPos() const;
|
|
||||||
Vector2 GetSize() const;
|
|
||||||
int GetWidth() const;
|
|
||||||
int GetHeight() const;
|
|
||||||
float GetDeltaTime() const;
|
|
||||||
float GetRefreshRate() const;
|
|
||||||
float GetRefreshCounter() const;
|
|
||||||
public:
|
|
||||||
// Figure out what to do with these later
|
|
||||||
void Raise() const;
|
|
||||||
void Lower() const;
|
|
||||||
void DestroyOSWindowHandle();
|
|
||||||
void SetCursorVisible(bool cursor_enable);
|
|
||||||
Vector2 GetAccurateMouseCoordinates() const;
|
|
||||||
void GLSwapBuffers();
|
|
||||||
void Fullscreen();
|
|
||||||
void 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;
|
|
||||||
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 {
|
|
||||||
public:
|
|
||||||
//RWindow() = default;
|
|
||||||
//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, wRenderer, wFullscreen, wResizable, wVsync) {};
|
|
||||||
~RWindow() = default;
|
|
||||||
public:
|
|
||||||
// Platform dependant
|
|
||||||
void Open() { RWindowImpl::Open(); };
|
|
||||||
void Close() { RWindowImpl::Close(); };
|
|
||||||
void PollEvents() { RWindowImpl::PollEvents(); };
|
|
||||||
void Refresh() { RWindowImpl::Refresh(); };
|
|
||||||
public:
|
|
||||||
// Shared
|
|
||||||
/// Returns whether the window currently has mouse and/or keyboard focus.
|
|
||||||
[[nodiscard]] bool IsFocused() const { return RWindowImpl::IsFocused(); };
|
|
||||||
/// Returns whether the window is currently in Fullscreen.
|
|
||||||
// TODO: Support Fullscreen, FullscreenWindowed, and Windowed?
|
|
||||||
[[nodiscard]] bool IsFullscreen() const { return RWindowImpl::IsFullscreen(); } ;
|
|
||||||
/// Returns whether the window can be resized.
|
|
||||||
[[nodiscard]] bool IsResizable() const { return RWindowImpl::IsResizable(); } ;
|
|
||||||
/// Returns whether V-Sync is enabled.
|
|
||||||
[[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() const { return RWindowImpl::IsAlive(); } ;
|
|
||||||
// Should have IsOpen since window could be closed then reopened
|
|
||||||
public:
|
|
||||||
// Platform dependant
|
|
||||||
/// Sets whether or not to make the window fullscreen.
|
|
||||||
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
|
|
||||||
void SetFullscreen(bool fs) { RWindowImpl::SetFullscreen(fs); };
|
|
||||||
/// Sets whether or not to make the window resizable.
|
|
||||||
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
|
|
||||||
void SetResizable(bool resizable) { RWindowImpl::SetResizable(resizable); };
|
|
||||||
/// Sets whether or not to enable vertical synchronization.
|
|
||||||
/// @note This is implemented per-OS, and as such, it simply requests the OS to do what we want. No guarantee about follow-through can be given.
|
|
||||||
void SetVsyncEnabled(bool vsync) { RWindowImpl::SetVsyncEnabled(vsync); };
|
|
||||||
/// Requests the operating system to change the window size.
|
|
||||||
/// @param width
|
|
||||||
/// @param height
|
|
||||||
void SetSize(int width, int height) { RWindowImpl::SetSize(width, height); };
|
|
||||||
/// Requests the operating system to change the window size.
|
|
||||||
/// @param size
|
|
||||||
void SetSize(const Vector2& size) { RWindowImpl::SetSize(size); };
|
|
||||||
|
|
||||||
// Shared
|
|
||||||
/// Sets the title of this window.
|
|
||||||
void SetTitle(const std::string& title) { RWindowImpl::SetTitle(title); };
|
|
||||||
public:
|
|
||||||
// Shared
|
|
||||||
[[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() const { return RWindowImpl::GetPos(); } ;
|
|
||||||
/// Returns the known size of the window, in {x,y} pixel measurement.
|
|
||||||
[[nodiscard]] Vector2 GetSize() const { return RWindowImpl::GetSize(); } ;
|
|
||||||
/// Returns the horizontal length of the renderable area in pixels.
|
|
||||||
[[nodiscard]] int GetWidth() const { return RWindowImpl::GetWidth(); } ;
|
|
||||||
/// Returns the vertical length of the renderable area, in pixels.
|
|
||||||
[[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() const { return RWindowImpl::GetDeltaTime(); } ;
|
|
||||||
/// Returns the approximate frames-per-second using delta time.
|
|
||||||
[[nodiscard]] float GetRefreshRate() const { return RWindowImpl::GetRefreshRate(); } ;
|
|
||||||
/// Returns the number of frames ran since the windows' creation.
|
|
||||||
[[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();}
|
|
||||||
|
|
||||||
};
|
|
6
main.cpp
6
main.cpp
@@ -1,7 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <rewindow/types/window.h>
|
#include <ReWindow/RWindow.hpp>
|
||||||
#include <rewindow/types/display.h>
|
#include <ReWindow/Display.hpp>
|
||||||
#include <rewindow/logger/logger.h>
|
#include <ReWindow/Logger.hpp>
|
||||||
|
|
||||||
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Windows :/
|
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Windows :/
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#include <rewindow/types/gamepadbutton.h>
|
#include <ReWindow/GamepadButton.hpp>
|
||||||
|
|
||||||
bool ReWindow::GamepadButton::operator ==(const GamepadButton &rhs) const {
|
bool ReWindow::GamepadButton::operator ==(const GamepadButton &rhs) const {
|
||||||
return this->GetMnemonicButtonCode() == rhs.GetMnemonicButtonCode();
|
return this->GetMnemonicButtonCode() == rhs.GetMnemonicButtonCode();
|
@@ -1,5 +1,5 @@
|
|||||||
#include <rewindow/types/key.h>
|
#include <ReWindow/Key.hpp>
|
||||||
//#include <rewindow/logger.h>
|
//#include <ReWindow/logger.h>
|
||||||
//std::vector<Key> Key::keyboard = {};
|
//std::vector<Key> Key::keyboard = {};
|
||||||
|
|
||||||
std::vector<Key> Key::GetKeyboard() { return keyboard; }
|
std::vector<Key> Key::GetKeyboard() { return keyboard; }
|
@@ -1,4 +1,4 @@
|
|||||||
#include "rewindow/logger/logger.h"
|
#include <ReWindow/Logger.hpp>
|
||||||
|
|
||||||
namespace ReWindow::Logger {
|
namespace ReWindow::Logger {
|
||||||
using namespace jlog;
|
using namespace jlog;
|
@@ -1,7 +1,7 @@
|
|||||||
#include <rewindow/types/mousebutton.h>
|
#include <ReWindow/MouseButton.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include "rewindow/logger/logger.h"
|
#include <ReWindow/Logger.hpp>
|
||||||
|
|
||||||
|
|
||||||
MouseButton::MouseButton(const std::string& charcode, unsigned int index) {
|
MouseButton::MouseButton(const std::string& charcode, unsigned int index) {
|
@@ -1,56 +1,4 @@
|
|||||||
#include <rewindow/types/window.h>
|
#include <ReWindow/RWindowImpl.hpp>
|
||||||
#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";
|
|
||||||
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 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 RWindowImpl::GetMouseCoordinates() const {
|
Vector2 RWindowImpl::GetMouseCoordinates() const {
|
||||||
return currentMouse.Position;
|
return currentMouse.Position;
|
||||||
@@ -293,15 +241,39 @@ bool RWindowImpl::IsFocused() const {
|
|||||||
processOnClose();
|
processOnClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RWindowImpl::ForceClose() {
|
void RWindowImpl::Open() {
|
||||||
Close();
|
open = true;
|
||||||
DestroyOSWindowHandle();
|
processOnOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RWindowImpl::ForceCloseAndTerminateProgram() {
|
void RWindowImpl::ForceClose() {
|
||||||
ForceClose();
|
Close();
|
||||||
exit(0);
|
DestroyOSWindowHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RWindowImpl::ForceCloseAndTerminateProgram() {
|
||||||
|
ForceClose();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RWindowImpl::PollEvents()
|
||||||
|
{
|
||||||
|
previousKeyboard = currentKeyboard;
|
||||||
|
previousMouse.Buttons = currentMouse.Buttons;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RWindowImpl::Refresh()
|
||||||
|
{
|
||||||
|
PollEvents();
|
||||||
|
OnRefresh(delta_time);
|
||||||
|
|
||||||
|
// Only call once and cache the result.
|
||||||
|
currentMouse.Position = GetAccurateMouseCoordinates();
|
||||||
|
|
||||||
|
/// TODO: Implement optional minimum epsilon to trigger a Mouse Update.
|
||||||
|
if (currentMouse.Position != previousMouse.Position) {
|
||||||
|
processMouseMove(previousMouse.Position, currentMouse.Position);
|
||||||
|
previousMouse.Position = currentMouse.Position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -1,6 +1,6 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <gl/GL.h>
|
#include <gl/GL.h>
|
||||||
#include <rewindow/types/window.h>
|
#include <ReWindow/RWindow.hpp>
|
||||||
|
|
||||||
using namespace ReWindow;
|
using namespace ReWindow;
|
||||||
|
|
7
src/ReWindow/WindowEvents.cpp
Normal file
7
src/ReWindow/WindowEvents.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include <ReWindow/WindowEvents.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
namespace ReWindow
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@@ -4,10 +4,10 @@
|
|||||||
#include <GL/glx.h>
|
#include <GL/glx.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <rewindow/types/window.h>
|
#include <ReWindow/RWindow.hpp>
|
||||||
#include <rewindow/types/cursors.h>
|
#include <ReWindow/Cursors.hpp>
|
||||||
#include <J3ML/J3ML.hpp>
|
#include <J3ML/J3ML.hpp>
|
||||||
#include <rewindow/logger/logger.h>
|
#include <ReWindow/Logger.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -79,6 +79,60 @@ RWindowImpl::~RWindowImpl() {
|
|||||||
DestroyOSWindowHandle();
|
DestroyOSWindowHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void XLibImpl::SetTitle(const std::string &title) {
|
||||||
|
RWindowImpl::SetTitle(title);
|
||||||
|
XStoreName(pPlatform->display, pPlatform->window, title.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void XLibImpl::Open() {
|
||||||
|
|
||||||
|
pPlatform->xSetWindowAttributes.border_pixel = BlackPixel(pPlatform->display, pPlatform->defaultScreen);
|
||||||
|
pPlatform->xSetWindowAttributes.background_pixel = BlackPixel(pPlatform->display, pPlatform->defaultScreen);
|
||||||
|
pPlatform->xSetWindowAttributes.override_redirect = True;
|
||||||
|
pPlatform->xSetWindowAttributes.event_mask = ExposureMask;
|
||||||
|
//SetVsyncEnabled(vsync);
|
||||||
|
if (renderer == RenderingAPI::OPENGL) {
|
||||||
|
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
|
||||||
|
pPlatform->visual = glXChooseVisual(pPlatform->display, pPlatform->defaultScreen, glAttributes);
|
||||||
|
pPlatform->glContext = glXCreateContext(pPlatform->display, pPlatform->visual, nullptr, GL_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
pPlatform->xSetWindowAttributes.colormap = XCreateColormap(pPlatform->display, RootWindow(pPlatform->display, pPlatform->defaultScreen), pPlatform->visual->visual, AllocNone);
|
||||||
|
|
||||||
|
pPlatform->window = XCreateWindow(pPlatform->display, RootWindow(pPlatform->display, pPlatform->defaultScreen), 0, 0, width, height, 0, pPlatform->visual->depth,
|
||||||
|
InputOutput, pPlatform->visual->visual, CWBackPixel | CWColormap | CWBorderPixel | NoEventMask,
|
||||||
|
&pPlatform->xSetWindowAttributes);
|
||||||
|
// Set window to floating because fucking tiling WMs
|
||||||
|
pPlatform->windowTypeAtom = XInternAtom(pPlatform->display, "_NET_WM_WINDOW_TYPE", False);
|
||||||
|
pPlatform->windowTypeUtilityAtom = XInternAtom(pPlatform->display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
|
||||||
|
XChangeProperty(pPlatform->display, pPlatform->window, pPlatform->windowTypeAtom, XA_ATOM, 32, PropModeReplace,
|
||||||
|
(unsigned char *)&pPlatform->windowTypeUtilityAtom, 1);
|
||||||
|
//
|
||||||
|
XSelectInput(pPlatform->display, pPlatform->window,
|
||||||
|
ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
||||||
|
PointerMotionMask |
|
||||||
|
PointerMotionHintMask | FocusChangeMask | StructureNotifyMask | SubstructureRedirectMask |
|
||||||
|
SubstructureNotifyMask | CWColormap );
|
||||||
|
XMapWindow(pPlatform->display, pPlatform->window);
|
||||||
|
XStoreName(pPlatform->display, pPlatform->window, title.c_str());
|
||||||
|
pPlatform->wmDeleteWindow = XInternAtom(pPlatform->display, "WM_DELETE_WINDOW", False);
|
||||||
|
XSetWMProtocols(pPlatform->display, pPlatform->window, &pPlatform->wmDeleteWindow, 1);
|
||||||
|
|
||||||
|
if (renderer == RenderingAPI::OPENGL)
|
||||||
|
glXMakeCurrent(pPlatform->display, pPlatform->window, pPlatform->glContext);
|
||||||
|
|
||||||
|
// Get the position of the renderable area relative to the rest of the window.
|
||||||
|
XGetWindowAttributes(pPlatform->display, pPlatform->window, &pPlatform->windowAttributes);
|
||||||
|
pPlatform->render_area_position = { (float) pPlatform->windowAttributes.x, (float) pPlatform->windowAttributes.y };
|
||||||
|
RWindowImpl::Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void XLibImpl::Close()
|
||||||
|
{
|
||||||
|
RWindowImpl::Close();
|
||||||
|
}
|
||||||
|
|
||||||
//using namespace ReWindow;
|
//using namespace ReWindow;
|
||||||
|
|
||||||
void RWindowImpl::Raise() const {
|
void RWindowImpl::Raise() const {
|
||||||
@@ -158,7 +212,7 @@ void RWindowImpl::SetFlag(RWindowFlags flag, bool state) {
|
|||||||
Logger::Debug(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
|
Logger::Debug(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RWindowImpl::PollEvents() {
|
void XLibImpl::PollEvents() {
|
||||||
while(XPending(pPlatform->display)) {
|
while(XPending(pPlatform->display)) {
|
||||||
XNextEvent(pPlatform->display, &pPlatform->xev);
|
XNextEvent(pPlatform->display, &pPlatform->xev);
|
||||||
|
|
||||||
@@ -277,28 +331,17 @@ void RWindowImpl::PollEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
previousKeyboard = currentKeyboard;
|
RWindowImpl::PollEvents();
|
||||||
previousMouse.Buttons = currentMouse.Buttons;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RWindowImpl::Refresh() {
|
void XLibImpl::Refresh() {
|
||||||
// Essentially allows more than one window to be drawable
|
// Essentially allows more than one window to be drawable
|
||||||
// https://www.khronos.org/opengl/wiki/Programming_OpenGL_in_Linux:_GLX_and_Xlib
|
// https://www.khronos.org/opengl/wiki/Programming_OpenGL_in_Linux:_GLX_and_Xlib
|
||||||
// https://registry.khronos.org/OpenGL-Refpages/gl2.1/xhtml/glXMakeCurrent.xml
|
// https://registry.khronos.org/OpenGL-Refpages/gl2.1/xhtml/glXMakeCurrent.xml
|
||||||
glXMakeCurrent(pPlatform->display, pPlatform->window, pPlatform->glContext);
|
glXMakeCurrent(pPlatform->display, pPlatform->window, pPlatform->glContext);
|
||||||
|
|
||||||
PollEvents();
|
RWindowImpl::Refresh();
|
||||||
OnRefresh(delta_time);
|
|
||||||
|
|
||||||
// Only call once and cache the result.
|
|
||||||
currentMouse.Position = GetAccurateMouseCoordinates();
|
|
||||||
|
|
||||||
/// TODO: Implement optional minimum epsilon to trigger a Mouse Update.
|
|
||||||
if (currentMouse.Position != previousMouse.Position) {
|
|
||||||
processMouseMove(previousMouse.Position, currentMouse.Position);
|
|
||||||
previousMouse.Position = currentMouse.Position;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -416,54 +459,11 @@ void RWindowImpl::SetCursorStyle(CursorStyle style) const {
|
|||||||
XDefineCursor(pPlatform->display, pPlatform->window, c);
|
XDefineCursor(pPlatform->display, pPlatform->window, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RWindowImpl::Open() {
|
|
||||||
pPlatform->xSetWindowAttributes.border_pixel = BlackPixel(pPlatform->display, pPlatform->defaultScreen);
|
|
||||||
pPlatform->xSetWindowAttributes.background_pixel = BlackPixel(pPlatform->display, pPlatform->defaultScreen);
|
|
||||||
pPlatform->xSetWindowAttributes.override_redirect = True;
|
|
||||||
pPlatform->xSetWindowAttributes.event_mask = ExposureMask;
|
|
||||||
//SetVsyncEnabled(vsync);
|
|
||||||
if (renderer == RenderingAPI::OPENGL) {
|
|
||||||
GLint glAttributes[] = {GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None};
|
|
||||||
pPlatform->visual = glXChooseVisual(pPlatform->display, pPlatform->defaultScreen, glAttributes);
|
|
||||||
pPlatform->glContext = glXCreateContext(pPlatform->display, pPlatform->visual, nullptr, GL_TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
pPlatform->xSetWindowAttributes.colormap = XCreateColormap(pPlatform->display, RootWindow(pPlatform->display, pPlatform->defaultScreen), pPlatform->visual->visual, AllocNone);
|
|
||||||
|
|
||||||
pPlatform->window = XCreateWindow(pPlatform->display, RootWindow(pPlatform->display, pPlatform->defaultScreen), 0, 0, width, height, 0, pPlatform->visual->depth,
|
|
||||||
InputOutput, pPlatform->visual->visual, CWBackPixel | CWColormap | CWBorderPixel | NoEventMask,
|
|
||||||
&pPlatform->xSetWindowAttributes);
|
|
||||||
// Set window to floating because fucking tiling WMs
|
|
||||||
pPlatform->windowTypeAtom = XInternAtom(pPlatform->display, "_NET_WM_WINDOW_TYPE", False);
|
|
||||||
pPlatform->windowTypeUtilityAtom = XInternAtom(pPlatform->display, "_NET_WM_WINDOW_TYPE_UTILITY", False);
|
|
||||||
XChangeProperty(pPlatform->display, pPlatform->window, pPlatform->windowTypeAtom, XA_ATOM, 32, PropModeReplace,
|
|
||||||
(unsigned char *)&pPlatform->windowTypeUtilityAtom, 1);
|
|
||||||
//
|
|
||||||
XSelectInput(pPlatform->display, pPlatform->window,
|
|
||||||
ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
|
||||||
PointerMotionMask |
|
|
||||||
PointerMotionHintMask | FocusChangeMask | StructureNotifyMask | SubstructureRedirectMask |
|
|
||||||
SubstructureNotifyMask | CWColormap );
|
|
||||||
XMapWindow(pPlatform->display, pPlatform->window);
|
|
||||||
XStoreName(pPlatform->display, pPlatform->window, title.c_str());
|
|
||||||
pPlatform->wmDeleteWindow = XInternAtom(pPlatform->display, "WM_DELETE_WINDOW", False);
|
|
||||||
XSetWMProtocols(pPlatform->display, pPlatform->window, &pPlatform->wmDeleteWindow, 1);
|
|
||||||
|
|
||||||
if (renderer == RenderingAPI::OPENGL)
|
|
||||||
glXMakeCurrent(pPlatform->display, pPlatform->window, pPlatform->glContext);
|
|
||||||
|
|
||||||
// Get the position of the renderable area relative to the rest of the window.
|
|
||||||
XGetWindowAttributes(pPlatform->display, pPlatform->window, &pPlatform->windowAttributes);
|
|
||||||
pPlatform->render_area_position = { (float) pPlatform->windowAttributes.x, (float) pPlatform->windowAttributes.y };
|
|
||||||
|
|
||||||
open = true;
|
|
||||||
|
|
||||||
processOnOpen();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RWindowImpl::SetTitle(const std::string &title) {
|
void RWindowImpl::SetTitle(const std::string &title) {
|
||||||
this->title = title;
|
this->title = title;
|
||||||
XStoreName(pPlatform->display, pPlatform->window, title.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@@ -1,4 +1,4 @@
|
|||||||
#include <rewindow/types/display.h>
|
#include <ReWindow/Display.hpp>
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/extensions/Xrandr.h>
|
#include <X11/extensions/Xrandr.h>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#include <rewindow/types/display.h>
|
#include <ReWindow/Display.hpp>
|
||||||
|
|
||||||
using namespace ReWindow;
|
using namespace ReWindow;
|
||||||
|
|
||||||
|
@@ -1,7 +0,0 @@
|
|||||||
#include <rewindow/types/WindowEvents.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
namespace ReWindow
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
Reference in New Issue
Block a user