More Pimpl work
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m54s

This commit is contained in:
2024-12-13 13:18:48 -05:00
parent 5ff4fb2a73
commit 1f17244662
2 changed files with 61 additions and 45 deletions

View File

@@ -59,12 +59,28 @@ public:
void Close();
void PollEvents();
void Refresh();
public:
bool IsFocused();
bool IsFullscreen();
bool IsResizable();
bool IsVsyncEnabled();
bool IsAlive();
public:
void SetFullscreen(bool fs);
void SetResizable(bool fs);
void SetVsyncEnabled(bool vsync);
void SetSize(int width, int height);
void SetSize(const Vector2& size);
void SetTitle(const std::string& title);
public:
std::string GetTitle();
Vector2 GetPos();
Vector2 GetSize();
int GetWidth();
int GetHeight();
float GetDeltaTime();
float GetRefreshRate();
float GetRefreshCounter();
};
class ReWindow::RWindow : private RWindowImpl {
@@ -79,62 +95,62 @@ public:
~RWindow();
public:
// Platform dependant
void Open();
void Close();
void PollEvents();
void Refresh();
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;
[[nodiscard]] bool IsFocused() { RWindowImpl::IsFocused(); } const;
/// Returns whether the window is currently in Fullscreen.
// TODO: Support Fullscreen, FullscreenWindowed, and Windowed?
[[nodiscard]] bool IsFullscreen() const;
[[nodiscard]] bool IsFullscreen() { RWindowImpl::IsFullscreen(); } const;
/// Returns whether the window can be resized.
[[nodiscard]] bool IsResizable() const;
[[nodiscard]] bool IsResizable() { RWindowImpl::IsResizable(); } const;
/// Returns whether V-Sync is enabled.
[[nodiscard]] bool IsVsyncEnabled() const;
[[nodiscard]] bool IsVsyncEnabled() { RWindowImpl::IsVsyncEnabled(); } const;
/// Returns whether the window is considered to be alive. Once dead, any logic loop should be terminated, and the cleanup procedure should run.
[[nodiscard]] bool IsAlive() const;
[[nodiscard]] bool IsAlive() { RWindowImpl::IsAlive(); } const;
// 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);
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);
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);
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);
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);
void SetSize(const Vector2& size) { RWindowImpl::SetSize(size); };
// Shared
/// Sets the title of this window.
void SetTitle(const std::string& title);
void SetTitle(const std::string& title) { RWindowImpl::SetTitle(title); };
public:
// Shared
[[nodiscard]] std::string GetTitle() const;
[[nodiscard]] std::string GetTitle() { return RWindowImpl::GetTitle(); } const;
/// Returns the position of the window's top-left corner relative to the display
Vector2 GetPos() const;
[[nodiscard]] Vector2 GetPos() { return RWindowImpl::GetPos(); } const;
/// Returns the known size of the window, in {x,y} pixel measurement.
Vector2 GetSize() const;
[[nodiscard]] Vector2 GetSize() { return RWindowImpl::GetSize(); } const;
/// Returns the horizontal length of the renderable area in pixels.
[[nodiscard]] int GetWidth() const;
[[nodiscard]] int GetWidth() { return RWindowImpl::GetWidth(); } const;
/// Returns the vertical length of the renderable area, in pixels.
[[nodiscard]] int GetHeight() const;
[[nodiscard]] int GetHeight() { return RWindowImpl::GetHeight(); } const;
/// 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;
[[nodiscard]] float GetDeltaTime() { return RWindowImpl::GetDeltaTime(); } const;
/// Returns the approximate frames-per-second using delta time.
[[nodiscard]] float GetRefreshRate() const;
[[nodiscard]] float GetRefreshRate() { return RWindowImpl::GetRefreshRate(); } const;
/// Returns the number of frames ran since the windows' creation.
[[nodiscard]] float GetRefreshCounter() const;
[[nodiscard]] float GetRefreshCounter() { return RWindowImpl::GetRefreshCounter(); } const;
};

View File

@@ -38,7 +38,7 @@ bool should_poll_x_for_mouse_pos = true;
using namespace ReWindow;
void RWindow::Raise() const {
void RWindowImpl::Raise() const {
Logger::Debug(std::format("Raising window '{}'", this->title));
// Get the position of the renderable area relative to the rest of the window.
@@ -48,13 +48,13 @@ void RWindow::Raise() const {
XRaiseWindow(display, window);
}
void RWindow::Lower() const
void RWindowImpl::Lower() const
{
Logger::Debug(std::format("Lowering window '{}'", this->title));
XLowerWindow(display, window);
}
void RWindow::DestroyOSWindowHandle() {
void RWindowImpl::DestroyOSWindowHandle() {
Logger::Debug(std::format("Destroying window '{}'", this->title));
XDestroySubwindows(display, window);
Logger::Debug(std::format("Destroyed window '{}'", this->title));
@@ -67,7 +67,7 @@ void RWindow::DestroyOSWindowHandle() {
//void RWindow::
void RWindow::SetCursorVisible(bool cursor_enable) {
void RWindowImpl::SetCursorVisible(bool cursor_enable) {
cursor_visible = cursor_enable;
if (invisible_cursor == 0) {
Pixmap blank_pixmap = XCreatePixmap(display, window, 1, 1, 1);
@@ -83,7 +83,7 @@ void RWindow::SetCursorVisible(bool cursor_enable) {
XUndefineCursor(display, window);
}
void RWindow::SetResizable(bool sizable) {
void RWindowImpl::SetResizable(bool sizable) {
XGetWindowAttributes(display,window,&windowAttributes);
@@ -100,7 +100,7 @@ void RWindow::SetResizable(bool sizable) {
}
void RWindow::SetFlag(RWindowFlags flag, bool state) {
void RWindowImpl::SetFlag(RWindowFlags flag, bool state) {
XGetWindowAttributes(display,window,&windowAttributes);
flags[(int) flag] = state;
//Once you've done this you cannot make it resizable again.
@@ -114,7 +114,7 @@ void RWindow::SetFlag(RWindowFlags flag, bool state) {
Logger::Debug(std::format("Set flag '{}' to state '{}' for window '{}'", RWindowFlagToStr(flag), state, this->title));
}
void RWindow::PollEvents() {
void RWindowImpl::PollEvents() {
while(XPending(display)) {
XNextEvent(display, &xev);
@@ -233,7 +233,7 @@ void RWindow::PollEvents() {
// Might make the window go off the screen on some window managers.
void RWindow::SetSize(int newWidth, int newHeight) {
void RWindowImpl::SetSize(int newWidth, int newHeight) {
if (!resizable) return;
this->width = newWidth;
@@ -243,7 +243,7 @@ void RWindow::SetSize(int newWidth, int newHeight) {
Logger::Info(std::format("Set size for '{}' to {} x {}", this->title, newWidth, newHeight));
}
Vector2 RWindow::GetAccurateMouseCoordinates() const {
Vector2 RWindowImpl::GetAccurateMouseCoordinates() const {
Window root_return, child_return;
int root_x_ret, root_y_ret;
@@ -263,7 +263,7 @@ Vector2 RWindow::GetAccurateMouseCoordinates() const {
}
Vector2 RWindow::GetSize() const {
Vector2 RWindowImpl::GetSize() const {
return {(float) this->width, (float) this->height};
}
@@ -273,26 +273,26 @@ Vector2 RWindow::GetSize() const {
//}
// TODO: implement integer vector2/3 types
Vector2 RWindow::GetPos() const {
Vector2 RWindowImpl::GetPos() const {
return position;
}
void RWindow::SetPos(int x, int y) {
void RWindowImpl::SetPos(int x, int y) {
XMoveWindow(display, window, x, y);
position = { (float) x, (float) y };
}
void RWindow::SetPos(const Vector2& pos) {
void RWindowImpl::SetPos(const Vector2& pos) {
SetPos(pos.x, pos.y);
}
void RWindow::GLSwapBuffers() {
void RWindowImpl::GLSwapBuffers() {
glXSwapBuffers(display,window);
}
void RWindow::Fullscreen() {
void RWindowImpl::Fullscreen() {
Logger::Info(std::format("Fullscreening '{}'", this->title));
fullscreen_mode = true;
@@ -313,7 +313,7 @@ void RWindow::Fullscreen() {
Logger::Debug(std::format("Fullscreened '{}'", this->title));
}
void RWindow::RestoreFromFullscreen() {
void RWindowImpl::RestoreFromFullscreen() {
Logger::Debug(std::format("Restoring '{}' from Fullscreen", this->title));
fullscreen_mode = false;
XEvent xev;
@@ -331,20 +331,20 @@ void RWindow::RestoreFromFullscreen() {
Logger::Debug(std::format("Restored '{}' from Fullscreen", this->title));
}
void RWindow::SetVsyncEnabled(bool b) {
void RWindowImpl::SetVsyncEnabled(bool b) {
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddressARB((const GLubyte*)"glXSwapIntervalEXT");
glXSwapIntervalEXT(display, window, b);
}
void RWindow::SetCursorStyle(CursorStyle style) const {
void RWindowImpl::SetCursorStyle(CursorStyle style) const {
u32 x11_cursor_resolved_enum = static_cast<u32>(style.X11Cursor);
Cursor c = XCreateFontCursor(display, x11_cursor_resolved_enum);
XDefineCursor(display, window, c);
}
void RWindow::Open() {
void RWindowImpl::Open() {
xSetWindowAttributes.border_pixel = BlackPixel(display, defaultScreen);
xSetWindowAttributes.background_pixel = BlackPixel(display, defaultScreen);
xSetWindowAttributes.override_redirect = True;
@@ -389,18 +389,18 @@ void RWindow::Open() {
processOnOpen();
}
void RWindow::SetTitle(const std::string &title) {
void RWindowImpl::SetTitle(const std::string &title) {
this->title = title;
XStoreName(display, window, title.c_str());
}
Vector2 RWindow::GetPositionOfRenderableArea() const {
Vector2 RWindowImpl::GetPositionOfRenderableArea() const {
return render_area_position;
}
std::string RWindow::getGraphicsDriverVendor() {
std::string RWindowImpl::getGraphicsDriverVendor() {
return std::string(reinterpret_cast<const char*>(glGetString(GL_VENDOR)));
}