Implement files

This commit is contained in:
2024-07-11 00:05:15 -04:00
parent be37e45664
commit 54bd7896c7
12 changed files with 277 additions and 3 deletions

View File

@@ -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)

24
cmake/CPM.cmake Normal file
View File

@@ -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})

8
include/JUI/JUI.hpp Normal file
View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 7/10/24.
//
#ifndef JUI_HPP
#define JUI_HPP
#endif //JUI_HPP

8
include/JUI/Rect.hpp Normal file
View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 7/10/24.
//
#ifndef RECT_HPP
#define RECT_HPP
#endif //RECT_HPP

8
include/JUI/Scene.hpp Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
namespace JUI
{
}

8
include/JUI/Text.hpp Normal file
View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 7/10/24.
//
#ifndef TEXT_HPP
#define TEXT_HPP
#endif //TEXT_HPP

56
include/JUI/UDim.hpp Normal file
View File

@@ -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;
}

62
include/JUI/UDim2.hpp Normal file
View File

@@ -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 <J3ML/LinearAlgebra.h>
#include <JUI/UDim.hpp>
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<int>(pixels.x), scale.x};
Y = {static_cast<int>(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:
};
}

8
include/JUI/Widget.hpp Normal file
View File

@@ -0,0 +1,8 @@
//
// Created by dawsh on 7/10/24.
//
#ifndef WIDGET_HPP
#define WIDGET_HPP
#endif //WIDGET_HPP

3
src/JUI/JUI.cpp Normal file
View File

@@ -0,0 +1,3 @@
//
// Created by dawsh on 7/10/24.
//

33
src/JUI/UDim.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <JUI/UDim.hpp>
JUI::UDim JUI::UDimLiterals::operator ""_scale(long double sc) {
return {0, static_cast<float>(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<int>(px), 0.f};
}
JUI::UDim JUI::UDimLiterals::operator ""_px(unsigned long long px) {
return {static_cast<int>(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<int>(Pixels * rhs), Scale*rhs};
}
JUI::UDim JUI::UDim::operator/(float rhs) const {
return {static_cast<int>(Pixels / rhs), Scale/rhs};
}

6
src/JUI/UDim2.cpp Normal file
View File

@@ -0,0 +1,6 @@
#include <JUI/UDim2.hpp>
JUI::UDim2::UDim2() {
//X = {0, 0.f};
//Y = {0, 0.f};
}