From 54bd7896c70608946f5e6c1e636b7105cd650edf Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 11 Jul 2024 00:05:15 -0400 Subject: [PATCH] Implement files --- CMakeLists.txt | 56 ++++++++++++++++++++++++++++++++++++-- cmake/CPM.cmake | 24 ++++++++++++++++ include/JUI/JUI.hpp | 8 ++++++ include/JUI/Rect.hpp | 8 ++++++ include/JUI/Scene.hpp | 8 ++++++ include/JUI/Text.hpp | 8 ++++++ include/JUI/UDim.hpp | 56 ++++++++++++++++++++++++++++++++++++++ include/JUI/UDim2.hpp | 62 ++++++++++++++++++++++++++++++++++++++++++ include/JUI/Widget.hpp | 8 ++++++ src/JUI/JUI.cpp | 3 ++ src/JUI/UDim.cpp | 33 ++++++++++++++++++++++ src/JUI/UDim2.cpp | 6 ++++ 12 files changed, 277 insertions(+), 3 deletions(-) create mode 100644 cmake/CPM.cmake create mode 100644 include/JUI/JUI.hpp create mode 100644 include/JUI/Rect.hpp create mode 100644 include/JUI/Scene.hpp create mode 100644 include/JUI/Text.hpp create mode 100644 include/JUI/UDim.hpp create mode 100644 include/JUI/UDim2.hpp create mode 100644 include/JUI/Widget.hpp create mode 100644 src/JUI/JUI.cpp create mode 100644 src/JUI/UDim.cpp create mode 100644 src/JUI/UDim2.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 01279fa..bb3ea1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,56 @@ -cmake_minimum_required(VERSION 3.28) -project(RedactedJUI) +cmake_minimum_required(VERSION 3.18..3.28) +project(JUI + VERSION 1.1 + LANGUAGES CXX) + +if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR) + message(FATAL_ERROR "In-source builds are not allowed!") +endif() set(CMAKE_CXX_STANDARD 20) -add_executable(RedactedJUI main.cpp) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +# Enable Package Managers +include(cmake/CPM.cmake) + + +file(GLOB_RECURSE JUI_HEADERS "include/JUI/*.hpp" "include/JUI/*.h") +file(GLOB_RECURSE JUI_SRC "src/JUI/*.cpp" "src/JUI/*.c") + +include_directories("include") + +if (UNIX) + add_library(JUI SHARED ${JUI_SRC}) +endif() + +if (WIN32) + add_library(JUI STATIC ${JUI_SRC}) +endif() + +set_target_properties(JUI PROPERTIES LINKER_LANGUAGE CXX) + +CPMAddPackage( + NAME J3ML + URL https://git.redacted.cc/josh/j3ml/archive/Release-2.2.zip +) + +CPMAddPackage( + NAME jlog + URL https://git.redacted.cc/josh/jlog/archive/Prerelease-12.zip +) + +CPMAddPackage( + NAME JGL + URL https://git.redacted.cc/josh/JGL/archive/Prerelease-20.zip +) + +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) + +install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME}) +install(FILES ${JUI_HEADERS} DESTINATION include/${PROJECT_NAME}) + +add_executable(RedactedJUIDemo main.cpp) +target_link_libraries(RedactedJUIDemo PUBLIC JUI) \ No newline at end of file diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 0000000..d866ad7 --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.38.7) +set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) \ No newline at end of file diff --git a/include/JUI/JUI.hpp b/include/JUI/JUI.hpp new file mode 100644 index 0000000..b0571b5 --- /dev/null +++ b/include/JUI/JUI.hpp @@ -0,0 +1,8 @@ +// +// Created by dawsh on 7/10/24. +// + +#ifndef JUI_HPP +#define JUI_HPP + +#endif //JUI_HPP diff --git a/include/JUI/Rect.hpp b/include/JUI/Rect.hpp new file mode 100644 index 0000000..2451663 --- /dev/null +++ b/include/JUI/Rect.hpp @@ -0,0 +1,8 @@ +// +// Created by dawsh on 7/10/24. +// + +#ifndef RECT_HPP +#define RECT_HPP + +#endif //RECT_HPP diff --git a/include/JUI/Scene.hpp b/include/JUI/Scene.hpp new file mode 100644 index 0000000..e541e9a --- /dev/null +++ b/include/JUI/Scene.hpp @@ -0,0 +1,8 @@ +#pragma once + + +namespace JUI +{ + + +} \ No newline at end of file diff --git a/include/JUI/Text.hpp b/include/JUI/Text.hpp new file mode 100644 index 0000000..0c894ff --- /dev/null +++ b/include/JUI/Text.hpp @@ -0,0 +1,8 @@ +// +// Created by dawsh on 7/10/24. +// + +#ifndef TEXT_HPP +#define TEXT_HPP + +#endif //TEXT_HPP diff --git a/include/JUI/UDim.hpp b/include/JUI/UDim.hpp new file mode 100644 index 0000000..bb51ff3 --- /dev/null +++ b/include/JUI/UDim.hpp @@ -0,0 +1,56 @@ +/// 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 UDim.hpp +/// @desc Universal Dimension Class +/// @edit 2024-07-10 + + +#pragma once + +namespace JUI +{ + + /// A coordinate system data type for user interfaces specifically. + /// Contains a "Pixels" component and a "Scale" (0-1 float) component. + /// @see UDim2.hpp + class UDim { + public: + int Pixels; + float Scale; + public: + UDim() : Pixels(0), Scale(0.f) {} + UDim(int pixels, float scale) : Pixels(pixels), Scale(scale) {} + UDim(const UDim& u) = default; + public: + UDim operator + (const UDim& rhs) const; + + UDim operator - (const UDim& rhs) const; + + UDim operator * (float rhs) const; + + UDim operator / (float rhs) const; + }; + + namespace UDimLiterals { + // special requirements on params for user-defined-literals? + // https://en.cppreference.com/w/cpp/language/user_literal + + UDim operator ""_scale(long double sc); + + UDim operator ""_percent(unsigned long long pc); + + UDim operator ""_pixels(unsigned long long px); + + UDim operator ""_px(unsigned long long px); + } + + + using namespace UDimLiterals; + + +} \ No newline at end of file diff --git a/include/JUI/UDim2.hpp b/include/JUI/UDim2.hpp new file mode 100644 index 0000000..ff7944d --- /dev/null +++ b/include/JUI/UDim2.hpp @@ -0,0 +1,62 @@ +/// 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 UDim2.hpp +/// @desc Universal Dimensions 2D Class +/// @edit 2024-07-10 + + +#pragma once + +#include +#include + +namespace JUI +{ + + using namespace J3ML::LinearAlgebra; + + /// Funky Coordinate system purpose-built for screen positioning + /// Contains an X and Y UDim, each containing an integer "Pixels", and fractional "Scale" (0-1) value. + /// GUI Elements use this type to describe their sizing in relation to their parent. + /// @see UDim.hpp + class UDim2 + { + public: // Properties + UDim X; + UDim Y; + public: // Constructors + UDim2(); + + UDim2(int px, int py, float sx, float sy) { + X = {px, sx}; + Y = {py, sy}; + } + UDim2(Vector2 pixels, Vector2 scale) { + X = {static_cast(pixels.x), scale.x}; + Y = {static_cast(pixels.y), scale.y}; + } + static UDim2 FromPixels(int x, int y) { return {x, y, 0, 0}; } + static UDim2 FromScale(float x, float y) { return {0, 0, x, y}; } + public: // Operators + UDim2 operator +(const UDim2& rhs) const; + UDim2 operator -(const UDim2& rhs) const; + UDim2 operator *(float rhs) const; + UDim2 operator /(float rhs) const; + UDim2 &operator=(const UDim2 &) = default; + public: // Methods + Vector2 GetScale() const { + return {X.Scale, Y.Scale}; + } + Vector2 GetPixels() const { + return {X.Pixels, Y.Pixels}; + } + protected: + private: + }; + +} \ No newline at end of file diff --git a/include/JUI/Widget.hpp b/include/JUI/Widget.hpp new file mode 100644 index 0000000..ff356cc --- /dev/null +++ b/include/JUI/Widget.hpp @@ -0,0 +1,8 @@ +// +// Created by dawsh on 7/10/24. +// + +#ifndef WIDGET_HPP +#define WIDGET_HPP + +#endif //WIDGET_HPP diff --git a/src/JUI/JUI.cpp b/src/JUI/JUI.cpp new file mode 100644 index 0000000..c07245a --- /dev/null +++ b/src/JUI/JUI.cpp @@ -0,0 +1,3 @@ +// +// Created by dawsh on 7/10/24. +// diff --git a/src/JUI/UDim.cpp b/src/JUI/UDim.cpp new file mode 100644 index 0000000..047f308 --- /dev/null +++ b/src/JUI/UDim.cpp @@ -0,0 +1,33 @@ +#include + +JUI::UDim JUI::UDimLiterals::operator ""_scale(long double sc) { + return {0, static_cast(sc)}; +} + +JUI::UDim JUI::UDimLiterals::operator ""_percent(unsigned long long pc) { + return {0, pc/100.f}; +} + +JUI::UDim JUI::UDimLiterals::operator ""_pixels(unsigned long long px) { + return {static_cast(px), 0.f}; +} + +JUI::UDim JUI::UDimLiterals::operator ""_px(unsigned long long px) { + return {static_cast(px), 0.f}; +} + +JUI::UDim JUI::UDim::operator+(const UDim &rhs) const { + return {Pixels + rhs.Pixels, Scale + rhs.Scale}; +} + +JUI::UDim JUI::UDim::operator-(const UDim &rhs) const { + return {Pixels - rhs.Pixels, Scale - rhs.Scale}; +} + +JUI::UDim JUI::UDim::operator*(float rhs) const { + return {static_cast(Pixels * rhs), Scale*rhs}; +} + +JUI::UDim JUI::UDim::operator/(float rhs) const { + return {static_cast(Pixels / rhs), Scale/rhs}; +} diff --git a/src/JUI/UDim2.cpp b/src/JUI/UDim2.cpp new file mode 100644 index 0000000..ce35925 --- /dev/null +++ b/src/JUI/UDim2.cpp @@ -0,0 +1,6 @@ +#include + +JUI::UDim2::UDim2() { + //X = {0, 0.f}; + //Y = {0, 0.f}; +}