diff --git a/CMakeLists.txt b/CMakeLists.txt index bb3ea1d..262c9bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,11 @@ endif() set_target_properties(JUI PROPERTIES LINKER_LANGUAGE CXX) +CPMAddPackage( + NAME Event + URL https://git.redacted.cc/josh/Event/archive/Release-6.zip +) + CPMAddPackage( NAME J3ML URL https://git.redacted.cc/josh/j3ml/archive/Release-2.2.zip @@ -40,17 +45,26 @@ CPMAddPackage( URL https://git.redacted.cc/josh/jlog/archive/Prerelease-12.zip ) +CPMAddPackage( + NAME ReWindow + URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-3.zip +) + CPMAddPackage( NAME JGL URL https://git.redacted.cc/josh/JGL/archive/Prerelease-20.zip ) +target_include_directories(JUI PUBLIC ${Event_SOURCE_DIR}/include) target_include_directories(JUI PUBLIC ${J3ML_SOURCE_DIR}/include) target_include_directories(JUI PUBLIC ${jlog_SOURCE_DIR}/include) target_include_directories(JUI PUBLIC ${JGL_SOURCE_DIR}/include) +target_include_directories(JUI PUBLIC ${ReWindow_SOURCE_DIR}/include) install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME}) install(FILES ${JUI_HEADERS} DESTINATION include/${PROJECT_NAME}) +target_link_libraries(JUI PUBLIC Event J3ML jlog ReWindowLibrary JGL) + add_executable(RedactedJUIDemo main.cpp) target_link_libraries(RedactedJUIDemo PUBLIC JUI) \ No newline at end of file diff --git a/include/JUI/Scene.hpp b/include/JUI/Scene.hpp index e541e9a..6a5e1ab 100644 --- a/include/JUI/Scene.hpp +++ b/include/JUI/Scene.hpp @@ -1,8 +1,16 @@ #pragma once +#include namespace JUI { - -} \ No newline at end of file + // TODO: SceneSizingBehavior - FillToWindow, CustomSized + class Scene : public Widget { + public: + Scene(); + ~Scene() override {} + void Draw() override; + void Update(float delta) override; + }; +} diff --git a/include/JUI/Widget.hpp b/include/JUI/Widget.hpp index ff356cc..bafdcb7 100644 --- a/include/JUI/Widget.hpp +++ b/include/JUI/Widget.hpp @@ -1,8 +1,64 @@ -// -// Created by dawsh on 7/10/24. -// +#pragma once +#include +#include +#include +#include +#include -#ifndef WIDGET_HPP -#define WIDGET_HPP +namespace JUI +{ -#endif //WIDGET_HPP + class Widget + { + public: + Widget(); + Widget(Widget* parent); + virtual ~Widget() {} + public: + Event<> Focused; + Event<> Unfocused; + Event DescendantAdded; + Event DescendantRemoved; + Event AncestryChanged; + Event ChildAdded; + Event ChildRemoved; + Event Destroying; + public: + Widget* Add(Widget* newChild); + bool IsAncestorOf(Widget* w) const; + bool IsDescendantOf(Widget* w) const; + Widget* FindFirstChild(const std::string& name); + std::vector GetDescendants(); + std::vector GetAncestors(); + std::vector GetChildren(); + virtual Vector2 GetAbsoluteSize() const; + virtual Vector2 GetAbsolutePosition() const; + virtual float GetAbsoluteRotation() const; + Widget* GetParent() const; + + public: + virtual void Draw(); + virtual void Update(float delta); + Widget* GetFamilyTreeRoot() const; + protected: + UDim2 position; + UDim2 size; + Widget* parent = nullptr; + std::vector children; + float rotation = 0; + std::string name; + bool selected = false; + UDim pad_left = 0_px; + UDim pad_right = 0_px; + UDim pad_top = 0_px; + UDim pad_bottom = 0_px; + UDim margin_left = 0_px; + UDim margin_right = 0_px; + UDim margin_top = 0_px; + UDim margin_bottom = 0_px; + Vector2 anchor_point = {0.f, 0.f}; + bool visible = true; + Widget* next = nullptr; + Widget* prev = nullptr; + }; +} diff --git a/main.cpp b/main.cpp index 4f9de56..1c56ece 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,76 @@ +/// Josh's User Interface Library +/// A C++20 Library for creating, styling, and rendering of a UI/UX widgets. +/// Developed and Maintained by Josh O'Leary @ Redacted Software. +/// Special Thanks to William Tomasine II and Maxine Hayes. +/// (c) 2024 Redacted Software +/// This work is dedicated to the public domain. + +/// @file main.cpp +/// @desc Demo Program Entry Point +/// @edit 2024-07-11 + #include +#include +#include +#include + + +class JUIDevelopmentTestWindow : public ReWindow::RWindow { +public: + JUIDevelopmentTestWindow(const std::string& title, int w, int h) : ReWindow::RWindow(title, w, h) {} + void OnRefresh(float elapsed) override { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + + JGL::J2D::Begin(); + JGL::J2D::FillRect(JGL::Color3(255,0,0), {0,0}, {50, 50}); + JGL::J2D::End(); + glSwapBuffers(); + } + + bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent &e) override { + + } +}; int main() { + + + auto* window = new JUIDevelopmentTestWindow("Test Window", 600, 480); + + + + window->setRenderer(RenderingAPI::OPENGL); + + + + window->Open(); + + gladLoadGL(); + JGL::InitTextEngine(); + + + + glClearColor(0.f, 0.f, 0.f, 0.f); + glViewport(0,0,600,480); + + + + + window->setFullscreen(false); + window->setVsyncEnabled(false); + window->setResizable(true); + + + + + while (window->isAlive()) { + window->pollEvents(); + window->refresh(); + } std::cout << "Hello, World!" << std::endl; return 0; } diff --git a/src/JUI/Scene.cpp b/src/JUI/Scene.cpp new file mode 100644 index 0000000..c28f856 --- /dev/null +++ b/src/JUI/Scene.cpp @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/src/JUI/Widget.cpp b/src/JUI/Widget.cpp new file mode 100644 index 0000000..e0cc6de --- /dev/null +++ b/src/JUI/Widget.cpp @@ -0,0 +1 @@ +#include \ No newline at end of file