Adding dev notes and documenting the public API.

This commit is contained in:
2024-07-15 13:01:27 -04:00
parent ebf939d747
commit b4c4827c9c
3 changed files with 63 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Enable Package Managers
include(cmake/CPM.cmake)
include(cmake/CPM.cmake)
CPMAddPackage(
NAME J3ML

View File

@@ -117,9 +117,18 @@ namespace ReWindow
using namespace WindowEvents;
/// General To Do List
/// TODO: Implement accurate timekeeping on refresh. Have mechanism to expose to user (hook into their game engine's timestepping)
/// TODO: Clean up public API to express the cross-platform, multi-graphics-mode ethos of this project.
///
class RWindow {
public:
/// We keep and support both mechanisms for extending behavior to suit:
/// 1. Derived windows with added functionality.
/// 2. Binding functions to a pre-existing window.
#pragma region Callbacks
/// Bindable Non-intrusive event handlers
/// Use these when you can't override the base window class
@@ -133,8 +142,9 @@ namespace ReWindow
Event<MouseButtonDownEvent> OnMouseButtonDownEvent;
Event<MouseButtonUpEvent> OnMouseButtonUpEvent;
#pragma endregion
#pragma region Overrides
/// Intrusive virtual methods intended to be overridden in a derived class.
/// Do not stuff any logic into these. Someone WILL override it and forget to call the base.
virtual void OnFocusLost(const RWindowEvent& e) {}
virtual void OnFocusGain(const RWindowEvent& e) {}
virtual void OnRefresh(float elapsed) {}
@@ -147,40 +157,52 @@ namespace ReWindow
virtual void OnMouseButtonUp(const MouseButtonUpEvent&) {}
#pragma endregion
/// The default constructor sets a default size and window title.
RWindow();
/// Constructs a window by explicitly setting title, width and height.
RWindow(const std::string& title, int width, int height);
/// Constructs a window as above with the additional argument of explicitly setting which render API is to be used.
RWindow(const std::string& title, int width, int height, RenderingAPI renderer);
Vector2 GetMouseCoordinates() const {
return getCursorPos();
}
/// Returns a Vector2 representing mouse coordinates relative to the top-left corner of the window.
Vector2 GetMouseCoordinates() const;
// TODO: Is this part of the API interface? Can it be moved to protected?
void liftKey (Key key) {
currentKeyboard.PressedKeys[key] = false;
auto event = ReWindow::WindowEvents::KeyUpEvent(key);
OnKeyUp(event);
}
// TODO: Is this part of the API interface? Can it be moved to protected?
void pressKey (Key key) {
currentKeyboard.PressedKeys[key] = true;
auto eventData = KeyDownEvent(key);
OnKeyDown(eventData);
}
/// Sets which rendering API is to be used with this window.
void setRenderer(RenderingAPI api);
/// Initializes all state with the window manager and rendering API, then opens the window.
void Open();
/// Cleans up and closes the window without destroying the handle.
void Close();
void CloseAndReopenInPlace();
// TODO: Must be implemented from scratch as a Motif Window in x11
void MessageBox();
void MessageBox(); // TODO: Must be implemented from scratch as a Motif Window in x11
/// Returns whether the window currently has mouse and/or keyboard focus.
bool isFocused() const;
bool isFullscreen() const;
bool isResizable() const;
bool isVsyncEnabled() const;
bool isAlive() const;
bool isAlive() const; // TODO: Always returns true.
/// Sets whether the mouse is visible when inside the window.
void setMouseVisible(bool visible);
void setMouseLocked();
void setMouseCenter();
@@ -196,27 +218,55 @@ namespace ReWindow
std::string getTitle() const;
int getWidth() const; // Honestly no idea if we'll keep these or still go with getSize.
int getHeight() const; // getSize wasn't working for me for logging. -maxine
// TODO: Move out of public API, consumers should use setFullscreen()
void fullscreen();
// TODO: Move out of public API, consumers should use setFullscreen()
void restoreFromFullscreen();
// TODO: Josh hates parameter-flags, it's not 1995 :/
bool getFlag(RWindowFlags flag) const;
// TODO: Josh hates parameter-flags, it's not 1995 :/
void setFlag(RWindowFlags flag, bool state);
//void init(RenderingAPI api, const char* title, int width, int height, bool vsync);
/// Tells the underlying window manager to destroy this window and drop the handle.
/// The window, in theory, can not be re-opened after this.
/// TODO: Create a destructor and move to there?
/// TODO: What's the semantic difference between this and Close()?
void destroyWindow();
/// Reads events from the underlying window manager.
/// TODO: Move out of public API, consumers should call refresh or ideally an update() call.
void pollEvents();
/// Updates the window and handles timing internally.
void refresh();
void setSize(int width, int height);
void setSize(const Vector2& size);
/// Returns the position of the window's top-left corner relative to the display
Vector2 getPos() const;
Vector2 getSize() const; // I want to know why this is made platform specific. Is that even necessary? -maxine
// I want to know why this is made platform specific. Is that even necessary? -maxine
// Because each OS / WM implements it with a different API. - josh
// If we stored ourselves a copy (accurately) of the window's size, we could implement it into the shared layer
// But this is at BEST, unreliable.
Vector2 getSize() const;
void setPos(int x, int y);
void setPos(const Vector2& pos);
Vector2 getCursorPos() const;
/// Pull the window to the top, such that it is displayed on top of everything else.
/// NOTE: The implementation is window-manager defined, and thus there is no guarantee of it always working.
void raise() const;
/// Push the window lower, such that it is effectively hidden behind other windows.
/// NOTE: The implementation is window-manager defined, and thus there is no guarantee of it always working.
void lower() const;
void setCursorStyle(CursorStyle style) const;
void setCursorCustomIcon() const;
/// Calls OpenGL's SwapBuffers routine.
/// NOTE: This is only used when the underlying rendering API is set to OpenGL.
static void glSwapBuffers();
private:
Vector2 lastKnownWindowSize {0, 0};

View File

@@ -33,6 +33,10 @@ RWindow::RWindow(const std::string& title, int width, int height) : flags{false,
RWindow::RWindow(const std::string& title, int width, int height, RenderingAPI renderer) :
title(title), width(width), height(height), renderer(renderer) {}
Vector2 RWindow::GetMouseCoordinates() const {
return getCursorPos();
}
bool RWindow::getFlag(RWindowFlags flag) const {return flags[(int)flag];}
bool RWindow::isAlive() const {