# Rewrite 5

- Move Libraries Source into pd directory and give them all their own CMakeLists.txt
- Partial rewrite core (color, autogenerated vec), lithium (now uses UNIQUE PTR for Commands), UI7
- Use MenuV2 as new standart in UI7
- Implementz ViewPort Pre alpha to UI7
- Add Line Drawing to DrawList (not Working)
- Implement a Complete new drievrs API (static Drivers)
- NO SUPPORT FOR SHARED LIBRARY BUILDS IN VERSION 5 YET
- Add Tools to Autogenerate Headers and Stuff
This commit is contained in:
2025-06-22 21:05:09 +02:00
parent 963fa72e41
commit 57634cbf4b
184 changed files with 13967 additions and 18453 deletions

92
include/pd/core/bit_util.hpp Normal file → Executable file
View File

@ -1,47 +1,47 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Binary Utillity Functions
*/
namespace BitUtil {
/**
* Check if a 32 Bit number only set a sigle bit to 1
* @param v 32 bit unsigned int
* @return true if its a single bit number
*/
PD_CORE_API bool IsSingleBit(u32 v);
/**
* Get the Next Power of two Number
* @param v Current Number
* @return Next Number thats a Pow of 2
*/
PD_CORE_API u32 GetPow2(u32 v);
} // namespace BitUtil
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Binary Utillity Functions
*/
namespace BitUtil {
/**
* Check if a 32 Bit number only set a sigle bit to 1
* @param v 32 bit unsigned int
* @return true if its a single bit number
*/
PD_CORE_API bool IsSingleBit(u32 v);
/**
* Get the Next Power of two Number
* @param v Current Number
* @return Next Number thats a Pow of 2
*/
PD_CORE_API u32 GetPow2(u32 v);
} // namespace BitUtil
} // namespace PD

151
include/pd/core/color.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -27,42 +26,22 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
/**
* Color class
*
* - Supports hex input starting with a # and 6 or 8 digits
* - Supports rgb(a) 8Bit unsigned number input
* - Supports rgb(a) float input from 0.0 to 1.0
* - Supports 32Bit input color
* @note Safetey checks are disabled for maximum performance
*/
class PD_CORE_API Color {
private:
/** Red Value */
u8 m_r;
/** Green Value */
u8 m_g;
/** Blue Value */
u8 m_b;
/** Alpha Value */
u8 m_a;
public:
/**
* Default Constructor (all variables are set to 0)
*/
// Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
constexpr Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
constexpr Color() : r(0), g(0), b(0), a(0) {}
constexpr ~Color() {}
/**
* Constructor for 32Bit Color Input
* @param color 32Bit Color value
*/
constexpr Color(u32 color) {
m_a = (color >> 24) & 0xff;
m_b = (color >> 16) & 0xff;
m_g = (color >> 8) & 0xff;
m_r = color & 0xff;
constexpr Color(u32 clr) {
a = (clr >> 24) & 0xff;
b = (clr >> 16) & 0xff;
g = (clr >> 8) & 0xff;
r = clr & 0xff;
}
/**
* Constructor for 8Bit Input
@ -71,12 +50,7 @@ class PD_CORE_API Color {
* @param b Blue Value
* @param a Optional Alpha Value (Defaults to 255)
*/
constexpr Color(int r, int g, int b, int a = 255) {
m_r = r;
m_g = g;
m_b = b;
m_a = a;
}
constexpr Color(int r, int g, int b, int a = 255) : r(r), g(g), b(b), a(a) {}
/**
* Constructor for float Input
* @param r Red Value
@ -86,20 +60,16 @@ class PD_CORE_API Color {
* @note There is no Check if the number is between 0.0 and 1.0
*/
constexpr Color(float r, float g, float b, float a = 1.f) {
m_r = static_cast<u8>(255.f * r);
m_g = static_cast<u8>(255.f * g);
m_b = static_cast<u8>(255.f * b);
m_a = static_cast<u8>(255.f * a);
r = static_cast<u8>(255.f * r);
g = static_cast<u8>(255.f * g);
b = static_cast<u8>(255.f * b);
a = static_cast<u8>(255.f * a);
}
/**
* Constructor for Hex Input
* @param hex Hex String in `#ffffff` or `#ffffffff` format
*/
Color(const std::string& hex) { Hex(hex); }
/**
* Unused Deconstructor
*/
// ~Color() {}
/**
* Create Color Object by Hex String
@ -114,63 +84,6 @@ class PD_CORE_API Color {
*/
std::string Hex(bool rgba = false) const;
/**
* Setter for Red
* @param v value
* @return Color class reference
*/
Color& r(u8 v) {
m_r = v;
return *this;
}
/**
* Getter for Red
* @return Red Value
*/
u8 r() const { return m_r; }
/**
* Setter for Green
* @param v value
* @return Color class reference
*/
Color& g(u8 v) {
m_g = v;
return *this;
}
/**
* Getter for Green
* @return Green Value
*/
u8 g() const { return m_g; }
/**
* Setter for Blue
* @param v value
* @return Color class reference
*/
Color& b(u8 v) {
m_b = v;
return *this;
}
/**
* Getter for Blue
* @return Blue Value
*/
u8 b() const { return m_b; }
/**
* Setter for Alpha
* @param v value
* @return Color class reference
*/
Color& a(u8 v) {
m_a = v;
return *this;
}
/**
* Getter for Alpha
* @return Alpha Value
*/
u8 a() const { return m_a; }
/**
* Fade from Current to another Color
* @param color Color to fade to
@ -178,24 +91,25 @@ class PD_CORE_API Color {
* @return Class Reference
*/
Color& Fade(const Color& color, float p) {
m_a = static_cast<u8>((color.a() - m_a) * ((p + 1.f) / 2));
m_b = static_cast<u8>((color.b() - m_b) * ((p + 1.f) / 2));
m_g = static_cast<u8>((color.g() - m_g) * ((p + 1.f) / 2));
m_r = static_cast<u8>((color.r() - m_r) * ((p + 1.f) / 2));
a = static_cast<u8>((color.a - a) * ((p + 1.f) / 2));
b = static_cast<u8>((color.b - b) * ((p + 1.f) / 2));
g = static_cast<u8>((color.g - g) * ((p + 1.f) / 2));
r = static_cast<u8>((color.r - r) * ((p + 1.f) / 2));
return *this;
}
/**
* Get 32Bit Color Value
* @return 32Bit Color Value
* @return 32Bit Color Value (ABGR iirc)
*/
u32 Get() const { return (m_a << 24) | (m_b << 16) | (m_g << 8) | m_r; }
u32 Get() const { return (a << 24) | (b << 16) | (g << 8) | r; }
/**
* Get The Luminance of the Color
* @return luminance (from 0.0 to 1.0)
*/
float Luminance() const {
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
return (0.3 * (m_r / 255.f) + 0.59 * (m_g / 255.f) + 0.11 * (m_b / 255.f));
return (0.3 * (r / 255.f) + 0.59 * (g / 255.f) + 0.11 * (b / 255.f));
}
/**
* Check if the Color is Light or Dark
@ -208,24 +122,11 @@ class PD_CORE_API Color {
* @return 32Bit Color Value
*/
operator u32() const { return Get(); }
/** Public Access Data section */
u8 r;
u8 g;
u8 b;
u8 a;
};
namespace Colors {
constexpr Color White = Color(1.f, 1.f, 1.f, 1.f);
constexpr Color Black = Color(0.f, 0.f, 0.f, 1.f);
constexpr Color Red = Color(1.f, 0.f, 0.f, 1.f);
constexpr Color Green = Color(0.f, 1.f, 0.f, 1.f);
constexpr Color Blue = Color(0.f, 0.f, 1.f, 1.f);
constexpr Color Yellow = Color(1.f, 1.f, 0.f, 1.f);
constexpr Color Cyan = Color(0.f, 1.f, 1.f, 1.f);
constexpr Color Magenta = Color(1.f, 0.f, 1.f, 1.f);
constexpr Color Gray = Color(0.5f, 0.5f, 0.5f, 1.f);
constexpr Color LightGray = Color(0.75f, 0.75f, 0.75f, 1.f);
constexpr Color DarkGray = Color(0.25f, 0.25f, 0.25f, 1.f);
constexpr Color Orange = Color(1.f, 0.65f, 0.f, 1.f);
constexpr Color Pink = Color(1.f, 0.75f, 0.8f, 1.f);
constexpr Color Brown = Color(0.6f, 0.4f, 0.2f, 1.f);
constexpr Color Purple = Color(0.5f, 0.f, 0.5f, 1.f);
constexpr Color Teal = Color(0.f, 0.5f, 0.5f, 1.f);
constexpr Color Transparent = Color(0.f, 0.f, 0.f, 0.f);
} // namespace Colors
} // namespace PD

197
include/pd/core/common.hpp Normal file → Executable file
View File

@ -1,131 +1,68 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <chrono>
#include <cinttypes>
#include <cmath>
#include <filesystem> // Requires C++ 17 or later
#include <format> // Requires C++ 20 or later
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// Platform API
#include <pd/core/pd_p_api.hpp>
// Legacy Smart Pointer
#define PD_SMART_CTOR(x) \
using Ref = std::shared_ptr<x>; \
template <typename... args> \
static Ref New(args&&... cargs) { \
return std::make_shared<x>(std::forward<args>(cargs)...); \
}
namespace PD {
/**
* SmartCtor (std::shared_ptr) Template class for Smart Pointers
*
* - Just add : public PD::SmartCtor<YourClass> to your class
* @tparam T Your Class
*/
template <typename T>
class SmartCtor {
public:
/** Reference alias for std::shared_ptr<Type> */
using Ref = std::shared_ptr<T>;
/**
* static Function to Create a New Reference
* @param args Additional Arguments (Depends on your classes Constructors)
* @return New Reference Object
*/
template <typename... Args>
static Ref New(Args&&... args) {
return std::make_shared<T>(std::forward<Args>(args)...);
}
};
/**
* Wrapper for SmartCtor<Type>::New(Args)
* @tparam T Class Type
* @param args Arguments
* @return Type Reference (SmartPointer)
*/
template <typename T, typename... Args>
SmartCtor<T>::Ref New(Args&&... args) {
return SmartCtor<T>::New(std::forward<Args>(args)...);
}
// Defines
/** alias for 64 Bit unsigned integer */
using u64 = unsigned long long;
/** alias for 32 Bit unsigned integer */
using u32 = unsigned int;
/** alias for 16 Bit unsigned integer */
using u16 = unsigned short;
/** alias for 8 Bit unsigned integer */
using u8 = unsigned char;
/**
* LinInfo Compile Information
*/
namespace LibInfo {
/**
* Get the Compiler Name and Version the lib got Compiled with
* @return Compiler Name / Version
*/
PD_CORE_API const std::string CompiledWith();
/**
* Get the C++ Version used to compile the lib
* @return C++ Version (__cplusplus)
*/
PD_CORE_API const std::string CxxVersion();
/**
* Get the Buildtime of the Library
* @return Build Time
*/
PD_CORE_API const std::string BuildTime();
/**
* Get the Library Version
* @return Library Version String
*/
PD_CORE_API const std::string Version();
/**
* Get the Git Commit the Lib got compiled in
* @return Git Commit 7digit short hash
*/
PD_CORE_API const std::string Commit();
/**
* Get the Git Branch which was active when compiling the lib
* @return Git Branch
*/
PD_CORE_API const std::string Branch();
} // namespace LibInfo
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <chrono>
#include <cinttypes>
#include <cmath>
#include <filesystem> // Requires C++ 17 or later
#include <format> // Requires C++ 20 or later
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/** Dynamic Lib loading */
#include <pd/core/pd_p_api.hpp>
/** Memory Management */
#define PD_SHARED(x) \
using Ref = std::shared_ptr<x>; \
template <typename... Args> \
static Ref New(Args&&... args) { \
return std::make_shared<x>(std::forward<Args>(args)...); \
}
#define PD_UNIQUE(x) \
using Ref = std::unique_ptr<x>; \
template <typename... Args> \
static Ref New(Args&&... args) { \
return std::make_unique<x>(std::forward<Args>(args)...); \
}
#define PD_BIT(x) (1 << x)
namespace PD {
/** Types */
using u8 = unsigned char;
using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;
} // namespace PD

8
include/pd/core/core.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -22,17 +21,14 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
*/
#include <pd/core/bit_util.hpp>
#include <pd/core/color.hpp>
#include <pd/core/common.hpp>
#include <pd/core/hid_driver.hpp>
#include <pd/core/io.hpp>
#include <pd/core/mat.hpp>
#include <pd/core/sl/sl.hpp>
#include <pd/core/strings.hpp>
#include <pd/core/sys.hpp>
#include <pd/core/timer.hpp>
#include <pd/core/timetrace.hpp>
#include <pd/core/tween.hpp>

126
include/pd/core/io.hpp Normal file → Executable file
View File

@ -1,72 +1,56 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Set of File Functions
*/
namespace IO {
enum RleFmt {
Default = 0,
_16 = 1 << 0,
_32 = 1 << 1,
_64 = 1 << 2,
};
/**
* Load a File into an 8Bit Memory Buffer
* @param path Path to the File
* @return 8Bit FileBuffer
*/
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
/**
* Hash a 8Bit Memory Buffer
* @param data 8Bit input Buffer
* @return 32Bit Hash
*/
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
/**
* Function to decrompress RLE buffer
* @param data Data buffer to decompress
*/
PD_CORE_API void DecompressRLE(std::vector<u8>& data);
/**
* Function to decrompress Extended RLE Buffer
* @param data Data buffer to decompress
*/
PD_CORE_API void DecompressRLE_Ex(std::vector<u8>& data);
/**
* Function to compress data with RLE Algorithm
* @param data Data buf
*/
PD_CORE_API void CompressRLE(std::vector<u8>& data);
/**
* Extended RLE Compress function (slower cause searches best format)
* @param data Data buf
*/
PD_CORE_API void CompressRLE_Ex(std::vector<u8>& data);
} // namespace IO
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Set of File Functions
*/
namespace IO {
/**
* Load a File into an 8Bit Memory Buffer
* @param path Path to the File
* @return 8Bit FileBuffer
*/
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
/**
* Hash a 8Bit Memory Buffer
* @param data 8Bit input Buffer
* @return 32Bit Hash
*/
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
/**
* Function to decrompress RLE buffer
* @param data Data buffer to decompress
*/
PD_CORE_API void DecompressRLE(std::vector<u8>& data);
/**
* Function to compress data with RLE Algorithm
* @param data Data buf
*/
PD_CORE_API void CompressRLE(std::vector<u8>& data);
} // namespace IO
} // namespace PD

0
include/pd/core/mat.hpp Normal file → Executable file
View File

9
include/pd/core/pd_p_api.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -22,7 +21,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
*/
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_CORE_BUILD_SHARED
@ -47,4 +48,4 @@ SOFTWARE.
#define PD_CORE_API
#else
#define PD_CORE_API
#endif
#endif

0
include/pd/core/sl/allocator.hpp Normal file → Executable file
View File

140
include/pd/core/sl/hashmap.hpp Normal file → Executable file
View File

@ -1,71 +1,71 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/sl/list.hpp>
#include <pd/core/sl/pair.hpp>
namespace PD {
template <typename K, typename V, size_t bucket_count = 10>
class HashMap {
public:
HashMap() {}
~HashMap() {}
void Insert(const K& k, const V& v) {
size_t idx = Hash(k);
auto& bukket = pBuckets[idx];
for (auto& it : bukket) {
if (it.First == k) {
it.Second = v;
return;
}
}
bukket.PushBack(Pair(k, v));
}
bool Contains(const K& k) const {
size_t idx = Hash(k);
auto& bukket = pBuckets[idx];
for (auto& it : bukket) {
if (it.First == k) {
return true;
}
}
return false;
}
void Clear() {
for (size_t i = 0; i < bucket_count; i++) {
pBuckets[i].Clear();
}
}
size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; }
PD::List<PD::Pair<K, V>> pBuckets[bucket_count];
};
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/sl/list.hpp>
#include <pd/core/sl/pair.hpp>
namespace PD {
template <typename K, typename V, size_t bucket_count = 10>
class HashMap {
public:
HashMap() {}
~HashMap() {}
void Insert(const K& k, const V& v) {
size_t idx = Hash(k);
auto& bukket = pBuckets[idx];
for (auto& it : bukket) {
if (it.First == k) {
it.Second = v;
return;
}
}
bukket.PushBack(Pair(k, v));
}
bool Contains(const K& k) const {
size_t idx = Hash(k);
auto& bukket = pBuckets[idx];
for (auto& it : bukket) {
if (it.First == k) {
return true;
}
}
return false;
}
void Clear() {
for (size_t i = 0; i < bucket_count; i++) {
pBuckets[i].Clear();
}
}
size_t Hash(const K& k) const { return std::hash<K>{}(k) % bucket_count; }
PD::List<PD::Pair<K, V>> pBuckets[bucket_count];
};
} // namespace PD

418
include/pd/core/sl/list.hpp Normal file → Executable file
View File

@ -1,210 +1,210 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
template <typename T>
class List {
public:
List() {}
~List() {}
struct Node {
Node(const T& v) : Data(v) {}
T Data;
Node* Prev = nullptr;
Node* Next = nullptr;
};
class Iterator {
public:
Iterator(Node* n) : pNode(n) {}
T& operator*() { return pNode->Data; }
Iterator& operator++() {
pNode = pNode->Next;
return *this;
}
bool operator!=(const Iterator& o) const { return pNode != o.pNode; }
Node* pNode = nullptr;
};
void PushFront(const T& val) {
Node* node = new Node(val);
// node->Data = val;
node->Prev = nullptr;
node->Next = pHead;
if (pHead) {
pHead->Prev = node;
}
pHead = node;
if (!pTail) {
pTail = node;
}
pSize++;
}
void PushBack(const T& val) {
Node* node = new Node(val);
// node->Data = val;
node->Prev = pTail;
node->Next = nullptr;
if (pTail) {
pTail->Next = node;
}
pTail = node;
if (!pHead) {
pHead = node;
}
pSize++;
}
void PopFront() {
if (!pHead) {
return;
}
Node* t = pHead;
pHead = pHead->Next;
if (pHead) {
pHead->Prev = nullptr;
} else {
pTail = nullptr;
}
delete t;
pSize--;
}
void PopBack() {
if (!pTail) {
return;
}
Node* t = pTail;
pTail = pTail->Prev;
if (pTail) {
pTail->Next = nullptr;
} else {
pHead = nullptr;
}
delete t;
pSize--;
}
void Clear() {
while (pHead) {
PopFront();
}
}
void Remove(const T& v) {
Node* s = pHead;
while (s) {
if (s->Data == v) {
if (s->Prev) {
s->Prev->Next = s->Next;
} else {
pHead = s->Next;
}
if (s->Next) {
s->Next->Prev = s->Prev;
} else {
pTail = s->Prev;
}
delete s;
pSize--;
return;
}
s = s->Next;
}
}
void Reverse() {
Node* cur = pHead;
while (cur) {
Node* temp = cur->Prev;
cur->Prev = cur->Next;
cur->Next = temp;
cur = cur->Prev;
}
Node* temp = pHead;
pHead = pTail;
pTail = temp;
}
T& Front() {
if (pHead) {
return pHead->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
const T& Front() const {
if (pHead) {
return pHead->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
T& Back() {
if (pTail) {
return pTail->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
const T& Back() const {
if (pTail) {
return pTail->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
size_t Size() const { return pSize; }
Iterator begin() { return Iterator(pHead); }
Iterator end() { return Iterator(nullptr); }
private:
Node* Find(const T& v) const {
Node* t = pHead;
while (t) {
if (t->Data == v) {
return t;
}
t = t->Next;
}
return nullptr;
}
Node* pHead = nullptr;
Node* pTail = nullptr;
size_t pSize = 0;
};
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
template <typename T>
class List {
public:
List() {}
~List() {}
struct Node {
Node(const T& v) : Data(v) {}
T Data;
Node* Prev = nullptr;
Node* Next = nullptr;
};
class Iterator {
public:
Iterator(Node* n) : pNode(n) {}
T& operator*() { return pNode->Data; }
Iterator& operator++() {
pNode = pNode->Next;
return *this;
}
bool operator!=(const Iterator& o) const { return pNode != o.pNode; }
Node* pNode = nullptr;
};
void PushFront(const T& val) {
Node* node = new Node(val);
// node->Data = val;
node->Prev = nullptr;
node->Next = pHead;
if (pHead) {
pHead->Prev = node;
}
pHead = node;
if (!pTail) {
pTail = node;
}
pSize++;
}
void PushBack(const T& val) {
Node* node = new Node(val);
// node->Data = val;
node->Prev = pTail;
node->Next = nullptr;
if (pTail) {
pTail->Next = node;
}
pTail = node;
if (!pHead) {
pHead = node;
}
pSize++;
}
void PopFront() {
if (!pHead) {
return;
}
Node* t = pHead;
pHead = pHead->Next;
if (pHead) {
pHead->Prev = nullptr;
} else {
pTail = nullptr;
}
delete t;
pSize--;
}
void PopBack() {
if (!pTail) {
return;
}
Node* t = pTail;
pTail = pTail->Prev;
if (pTail) {
pTail->Next = nullptr;
} else {
pHead = nullptr;
}
delete t;
pSize--;
}
void Clear() {
while (pHead) {
PopFront();
}
}
void Remove(const T& v) {
Node* s = pHead;
while (s) {
if (s->Data == v) {
if (s->Prev) {
s->Prev->Next = s->Next;
} else {
pHead = s->Next;
}
if (s->Next) {
s->Next->Prev = s->Prev;
} else {
pTail = s->Prev;
}
delete s;
pSize--;
return;
}
s = s->Next;
}
}
void Reverse() {
Node* cur = pHead;
while (cur) {
Node* temp = cur->Prev;
cur->Prev = cur->Next;
cur->Next = temp;
cur = cur->Prev;
}
Node* temp = pHead;
pHead = pTail;
pTail = temp;
}
T& Front() {
if (pHead) {
return pHead->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
const T& Front() const {
if (pHead) {
return pHead->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
T& Back() {
if (pTail) {
return pTail->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
const T& Back() const {
if (pTail) {
return pTail->Data;
}
// Need a List Empty Error Here (exceptions are disabled on 3ds)
exit(1);
}
size_t Size() const { return pSize; }
Iterator begin() { return Iterator(pHead); }
Iterator end() { return Iterator(nullptr); }
private:
Node* Find(const T& v) const {
Node* t = pHead;
while (t) {
if (t->Data == v) {
return t;
}
t = t->Next;
}
return nullptr;
}
Node* pHead = nullptr;
Node* pTail = nullptr;
size_t pSize = 0;
};
} // namespace PD

80
include/pd/core/sl/pair.hpp Normal file → Executable file
View File

@ -1,41 +1,41 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
template <typename T1, typename T2>
class Pair {
public:
Pair() = default;
Pair(const T1& f, const T2& s) : First(f), Second(s) {}
Pair(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {}
~Pair() = default;
T1 First;
T2 Second;
};
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
template <typename T1, typename T2>
class Pair {
public:
Pair() = default;
Pair(const T1& f, const T2& s) : First(f), Second(s) {}
Pair(T1&& f, T2&& s) : First(std::move(f)), Second(std::move(s)) {}
~Pair() = default;
T1 First;
T2 Second;
};
} // namespace PD

64
include/pd/core/sl/sl.hpp Normal file → Executable file
View File

@ -1,33 +1,33 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/sl/allocator.hpp>
#include <pd/core/sl/hashmap.hpp>
#include <pd/core/sl/list.hpp>
#include <pd/core/sl/pair.hpp>
#include <pd/core/sl/stack.hpp>
#include <pd/core/sl/tools.hpp>
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/sl/allocator.hpp>
#include <pd/core/sl/hashmap.hpp>
#include <pd/core/sl/list.hpp>
#include <pd/core/sl/pair.hpp>
#include <pd/core/sl/stack.hpp>
#include <pd/core/sl/tools.hpp>
#include <pd/core/sl/vector.hpp>

0
include/pd/core/sl/stack.hpp Normal file → Executable file
View File

0
include/pd/core/sl/tools.hpp Normal file → Executable file
View File

0
include/pd/core/sl/vector.hpp Normal file → Executable file
View File

244
include/pd/core/strings.hpp Normal file → Executable file
View File

@ -1,123 +1,123 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Set of String Utillity Functions
*/
namespace Strings {
/**
* Check if a String ends with a specific extension
* @param str Input string
* @param exts List of Extensions to check for
* @return true if one of the extensions is found in the String
*/
PD_CORE_API bool StringEndsWith(const std::string& str,
const std::vector<std::string>& exts);
/**
* Function to Create a wstring of a string
* @param s Input String to Convert
* @return Result wstring
* @note Returns Empty if it has an error
*/
PD_CORE_API std::wstring MakeWstring(const std::string& s);
/**
* Generate a Formatted String by an Nanoseconds Input
* @param nanos Nanoseconds Input
* @return Result String
*/
PD_CORE_API const std::string FormatNanos(unsigned long long nanos);
/**
* Generate a Formatted String by an Milliseconds Input
* @param millis Milliseconds Input
* @return Result String
*/
PD_CORE_API const std::string FormatMillis(unsigned long long millis);
/**
* Create a formatted String by an input bytes value
* @param bytes value in bytes
* @result Formatted String for example `2.5MB`
*/
PD_CORE_API const std::string FormatBytes(unsigned long long bytes);
/**
* Extract the Filename out of a Path
* @param path Path to extract from
* @param saperators Path Split Chars
* @return extracted filename
*/
PD_CORE_API const std::string GetFileName(
const std::string& path, const std::string& saperators = "/\\");
/**
* Remove Extension from a Path / Filename
* @param path Input Path
* @return Path without Extension
*/
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
/**
* Function to Convert a Type to a hex value
* @tparam T Type
* @param v value
* @return hex string beginning with 0x
*/
template <typename T>
inline const std::string ToHex(const T& v) {
std::stringstream s;
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
return s.str();
}
/**
* Generate a Hash out of a string
* @param s String to hash
* @return 32Bit Hash
*/
PD_CORE_API u32 FastHash(const std::string& s);
/**
* Function to Generate a Compiler Name and Version String
* Based on their Macros
* @return CompilerName: Version
*/
inline const std::string GetCompilerVersion() {
/// As the function looks like this Project is meant to
/// Be ported to other systems as well
std::stringstream res;
#ifdef __clang__ // Check clang first
res << "Clang: " << __clang_major__ << ".";
res << __clang_minor__ << ".";
res << __clang_patchlevel__;
#elif __GNUC__
res << "GCC: " << __GNUC__;
res << "." << __GNUC_MINOR__ << ".";
res << __GNUC_PATCHLEVEL__;
#elif _MSC_VER
res << "MSVC: " << _MSC_VER;
#else
res << "Unknown Compiler";
#endif
return res.str();
}
} // namespace Strings
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Set of String Utillity Functions
*/
namespace Strings {
/**
* Check if a String ends with a specific extension
* @param str Input string
* @param exts List of Extensions to check for
* @return true if one of the extensions is found in the String
*/
PD_CORE_API bool StringEndsWith(const std::string& str,
const std::vector<std::string>& exts);
/**
* Function to Create a wstring of a string
* @param s Input String to Convert
* @return Result wstring
* @note Returns Empty if it has an error
*/
PD_CORE_API std::wstring MakeWstring(const std::string& s);
/**
* Generate a Formatted String by an Nanoseconds Input
* @param nanos Nanoseconds Input
* @return Result String
*/
PD_CORE_API const std::string FormatNanos(unsigned long long nanos);
/**
* Generate a Formatted String by an Milliseconds Input
* @param millis Milliseconds Input
* @return Result String
*/
PD_CORE_API const std::string FormatMillis(unsigned long long millis);
/**
* Create a formatted String by an input bytes value
* @param bytes value in bytes
* @result Formatted String for example `2.5MB`
*/
PD_CORE_API const std::string FormatBytes(unsigned long long bytes);
/**
* Extract the Filename out of a Path
* @param path Path to extract from
* @param saperators Path Split Chars
* @return extracted filename
*/
PD_CORE_API const std::string GetFileName(
const std::string& path, const std::string& saperators = "/\\");
/**
* Remove Extension from a Path / Filename
* @param path Input Path
* @return Path without Extension
*/
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
/**
* Function to Convert a Type to a hex value
* @tparam T Type
* @param v value
* @return hex string beginning with 0x
*/
template <typename T>
inline const std::string ToHex(const T& v) {
std::stringstream s;
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
return s.str();
}
/**
* Generate a Hash out of a string
* @param s String to hash
* @return 32Bit Hash
*/
PD_CORE_API u32 FastHash(const std::string& s);
/**
* Function to Generate a Compiler Name and Version String
* Based on their Macros
* @return CompilerName: Version
*/
inline const std::string GetCompilerVersion() {
/// As the function looks like this Project is meant to
/// Be ported to other systems as well
std::stringstream res;
#ifdef __clang__ // Check clang first
res << "Clang: " << __clang_major__ << ".";
res << __clang_minor__ << ".";
res << __clang_patchlevel__;
#elif __GNUC__
res << "GCC: " << __GNUC__;
res << "." << __GNUC_MINOR__ << ".";
res << __GNUC_PATCHLEVEL__;
#elif _MSC_VER
res << "MSVC: " << _MSC_VER;
#else
res << "Unknown Compiler";
#endif
return res.str();
}
} // namespace Strings
} // namespace PD

167
include/pd/core/timer.hpp Normal file → Executable file
View File

@ -1,84 +1,85 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/sys.hpp>
namespace PD {
/**
* Timer class
*/
class PD_CORE_API Timer : public SmartCtor<Timer> {
public:
/**
* Constructor
* @param auto_start [default true] sets if timer should start after creation
*/
Timer(bool auto_start = true);
/**
* Unused Deconstructor
*/
~Timer() {}
/**
* Resume Timer if Paused
*/
void Rseume();
/**
* Pause Timer if not Paused
*/
void Pause();
/**
* Update Timer
*/
void Update();
/**
* Reset Timer
*/
void Reset();
/**
* Check if the Timer is Running
* @return true if its running
*/
bool IsRunning() const;
/**
* Get 64 Bit milliseconds value
* @return 64Bit millis
*/
u64 Get();
/**
* Get as Seconds
* @return seconds as floating number
*/
double GetSeconds();
private:
/** Start of the Timer */
u64 start;
/** Current Time */
u64 now;
/** Is Running */
bool is_running = false;
};
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Timer class
*/
class PD_CORE_API Timer {
public:
/**
* Constructor
* @param auto_start [default true] sets if timer should start after creation
*/
Timer(bool auto_start = true);
/**
* Unused Deconstructor
*/
~Timer() {}
PD_SHARED(Timer);
/**
* Resume Timer if Paused
*/
void Rseume();
/**
* Pause Timer if not Paused
*/
void Pause();
/**
* Update Timer
*/
void Update();
/**
* Reset Timer
*/
void Reset();
/**
* Check if the Timer is Running
* @return true if its running
*/
bool IsRunning() const;
/**
* Get 64 Bit milliseconds value
* @return 64Bit millis
*/
u64 Get();
/**
* Get as Seconds
* @return seconds as floating number
*/
double GetSeconds();
/** Start of the Timer */
u64 pStart;
/** Current Time */
u64 pNow;
/** Is Running */
bool pIsRunning = false;
};
} // namespace PD

512
include/pd/core/timetrace.hpp Normal file → Executable file
View File

@ -1,255 +1,259 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Class to calculate Maximum/Minimum and Average Timings
*/
class TimeStats : public SmartCtor<TimeStats> {
public:
/**
* Constructor taking a lengh for the List
* @param l Lengh of the data list
*/
TimeStats(int l) : len(l), val(l, 0) {}
~TimeStats() = default;
/**
* Add a New Value to the list
* @param v value to add
*/
void Add(u64 v) {
val[idx] = v;
idx = next(idx);
num_val = std::min(num_val + 1, len);
}
/**
* Get Avarage Num
* @return Average
*/
u64 GetAverage() {
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res += val[smart_idx(i)];
}
return res / num_val;
}
/**
* Get Minimum Num
* @return Minimum value
*/
u64 GetMin() {
if (!num_val) return 0.f;
u64 res = std::numeric_limits<u64>::max();
for (int i = 0; i < num_val; i++) {
res = std::min(val[smart_idx(i)], res);
}
return res;
}
/**
* Get Maximum Value
* @return Max Value
*/
u64 GetMax() {
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res = std::max(val[smart_idx(i)], res);
}
return res;
}
/**
* Clear the List
*/
void Clear() {
val.assign(len, 0);
idx = 0;
num_val = 0;
}
/**
* Get Data Buffer
* @return data bufer (not edidable)
*/
const std::vector<u64> &GetData() { return val; }
/**
* Access an element in the list [not edidable]
* @return value to access
*/
const u64 &operator[](int i) { return val[smart_idx(i)]; }
/**
* Get List Lengh
* @return Lengh
*/
const size_t GetLen() { return len; }
/**
* Get Number of Values
* @return number of values
*/
const size_t GetNumValues() { return num_val; }
private:
/**
* Get the Next Position to write to
* @param c current position
* @return next position
*/
size_t next(size_t c) const { return (c + 1) % len; }
/**
* Smart Indexing in for loops to make sure to
* not index a value that was not set yet
* @param v pos in for loop
* @return indexing pos
*/
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
/** Lengh of the list */
int len = 0;
/** Value Storage */
std::vector<u64> val;
int idx = 0;
int num_val = 0;
};
/**
* Timatrace Functions
*/
namespace TT {
/**
* Data Structure for a TimeTrace Result
*/
class Res : public SmartCtor<Res> {
public:
/** Constructore that Inits a protocol at size of 60 frames */
Res() { protocol = TimeStats::New(60); }
~Res() = default;
/**
* Setter for the ID (Name)
* @param v ID of the Trace
*/
void SetID(const std::string &v) { id = v; }
/**
* Getter for the traces ID
* @return Trace ID
*/
const std::string GetID() { return id; }
/**
* Setter for the Start Value
* @param v start time
*/
void SetStart(u64 v) { start = v; }
/**
* Getter for the Start time
* @return start time
*/
u64 GetStart() { return start; }
/**
* Setter for the End Time
* @param v end time
*/
void SetEnd(u64 v) {
end = v;
protocol->Add(GetLastDiff());
}
/**
* Getter for the End Time
* @result end time
*/
u64 GetEnd() { return end; }
/**
* Get Last Diffrence between end and start
* @return end - start
*/
u64 GetLastDiff() { return end - start; }
/**
* Get Protcol Reference
* @return Protocol Ref
*/
TimeStats::Ref GetProtocol() { return protocol; }
private:
/** Trace ID */
std::string id;
/** Start time */
u64 start;
/** End Time */
u64 end;
/** Protocol */
TimeStats::Ref protocol;
};
/**
* Begin a Trace
* @param id Name of the Trace
*/
PD_CORE_API void Beg(const std::string &id);
/**
* End a Trace
* @param id Name of the Trace
*/
PD_CORE_API void End(const std::string &id);
/**
* Collect Start end end of the trace by tracking
* when the Scope object goes out of scope
*
* Example:
* ```cpp
* void SomeFunction() {
* // Create a Scoped Trace called "SomeFunc"
* PD::TT::Scope st("SomeFunc");
* // Do your functions stuff
* // End at the end it goes out of
* // scope which collects the end time
* }
* ```
*/
class Scope {
public:
/**
* Constructor requiring a Name for the Trace
* @param id Name of the Trace
*/
Scope(const std::string &id) {
this->id = id;
Beg(id);
}
/**
* Deconstructor getting the end time when going out of scope
*/
~Scope() { End(id); }
private:
/** Trace Name/ID */
std::string id;
};
} // namespace TT
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
/**
* Class to calculate Maximum/Minimum and Average Timings
*/
class TimeStats {
public:
/**
* Constructor taking a lengh for the List
* @param l Lengh of the data list
*/
TimeStats(int l) : len(l), val(l, 0) {}
~TimeStats() = default;
PD_SHARED(TimeStats);
/**
* Add a New Value to the list
* @param v value to add
*/
void Add(u64 v) {
val[idx] = v;
idx = next(idx);
num_val = std::min(num_val + 1, len);
}
/**
* Get Avarage Num
* @return Average
*/
u64 GetAverage() {
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res += val[smart_idx(i)];
}
return res / num_val;
}
/**
* Get Minimum Num
* @return Minimum value
*/
u64 GetMin() {
if (!num_val) return 0.f;
u64 res = std::numeric_limits<u64>::max();
for (int i = 0; i < num_val; i++) {
res = std::min(val[smart_idx(i)], res);
}
return res;
}
/**
* Get Maximum Value
* @return Max Value
*/
u64 GetMax() {
if (!num_val) return 0.f;
u64 res = 0;
for (int i = 0; i < num_val; i++) {
res = std::max(val[smart_idx(i)], res);
}
return res;
}
/**
* Clear the List
*/
void Clear() {
val.assign(len, 0);
idx = 0;
num_val = 0;
}
/**
* Get Data Buffer
* @return data bufer (not edidable)
*/
const std::vector<u64> &GetData() { return val; }
/**
* Access an element in the list [not edidable]
* @return value to access
*/
const u64 &operator[](int i) { return val[smart_idx(i)]; }
/**
* Get List Lengh
* @return Lengh
*/
const size_t GetLen() { return len; }
/**
* Get Number of Values
* @return number of values
*/
const size_t GetNumValues() { return num_val; }
private:
/**
* Get the Next Position to write to
* @param c current position
* @return next position
*/
size_t next(size_t c) const { return (c + 1) % len; }
/**
* Smart Indexing in for loops to make sure to
* not index a value that was not set yet
* @param v pos in for loop
* @return indexing pos
*/
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
/** Lengh of the list */
int len = 0;
/** Value Storage */
std::vector<u64> val;
int idx = 0;
int num_val = 0;
};
/**
* Timatrace Functions
*/
namespace TT {
/**
* Data Structure for a TimeTrace Result
*/
class Res {
public:
/** Constructore that Inits a protocol at size of 60 frames */
Res(): start(0), end(0) { protocol = TimeStats::New(60); }
~Res() = default;
PD_SHARED(Res);
/**
* Setter for the ID (Name)
* @param v ID of the Trace
*/
void SetID(const std::string &v) { id = v; }
/**
* Getter for the traces ID
* @return Trace ID
*/
const std::string GetID() { return id; }
/**
* Setter for the Start Value
* @param v start time
*/
void SetStart(u64 v) { start = v; }
/**
* Getter for the Start time
* @return start time
*/
u64 GetStart() { return start; }
/**
* Setter for the End Time
* @param v end time
*/
void SetEnd(u64 v) {
end = v;
protocol->Add(GetLastDiff());
}
/**
* Getter for the End Time
* @result end time
*/
u64 GetEnd() { return end; }
/**
* Get Last Diffrence between end and start
* @return end - start
*/
u64 GetLastDiff() { return end - start; }
/**
* Get Protcol Reference
* @return Protocol Ref
*/
TimeStats::Ref GetProtocol() { return protocol; }
private:
/** Trace ID */
std::string id;
/** Start time */
u64 start;
/** End Time */
u64 end;
/** Protocol */
TimeStats::Ref protocol;
};
/**
* Begin a Trace
* @param id Name of the Trace
*/
PD_CORE_API void Beg(const std::string &id);
/**
* End a Trace
* @param id Name of the Trace
*/
PD_CORE_API void End(const std::string &id);
/**
* Collect Start end end of the trace by tracking
* when the Scope object goes out of scope
*
* Example:
* ```cpp
* void SomeFunction() {
* // Create a Scoped Trace called "SomeFunc"
* PD::TT::Scope st("SomeFunc");
* // Do your functions stuff
* // End at the end it goes out of
* // scope which collects the end time
* }
* ```
*/
class Scope {
public:
/**
* Constructor requiring a Name for the Trace
* @param id Name of the Trace
*/
Scope(const std::string &id) {
this->ID = id;
Beg(id);
}
/**
* Deconstructor getting the end time when going out of scope
*/
~Scope() { End(ID); }
private:
/** Trace Name/ID */
std::string ID;
};
} // namespace TT
} // namespace PD

454
include/pd/core/tween.hpp Normal file → Executable file
View File

@ -1,228 +1,228 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
namespace PD {
/**
* D7 Tween Engine (or something like that)
* @tparam T Any Numeric value
*/
template <typename T>
class Tween {
public:
/**
* Effects Table
*/
enum Effect {
Linear, ///< Linear Movement [works]
EaseInQuad, ///< EaseInQuad Movement [works]
EaseOutQuad, ///< EaseOutQuad Movement [works]
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
EaseInCubic, ///< EaseInCubic Movement [not tested]
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
EaseInSine, ///< EaseInSine Movement [works]
EaseOutSine, ///< EaseOutSine Movement [works]
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
};
Tween() = default;
~Tween() = default;
/**
* Update Tween
* @param delta deltatime
*/
void Update(float delta) {
time += delta / 1000.f;
if (time > tend) {
finished = true;
time = tend;
}
}
/**
* Check if Tween is finished
* @return true if finished
*/
bool IsFinished() const { return finished; }
/**
* Force finish the animation
* @return Class reference
*/
Tween& Finish() {
time = tend;
finished = true;
return *this;
}
/**
* Set Start Value
* @tparam T datatype of the Tween
* @param start Start Value
* @return class Reference
*/
Tween& From(const T& start) {
Reset();
this->start = start;
return *this;
}
/**
* Set End Value
* @tparam T datatype of the Tween
* @param end End Value
* @return class Reference
*/
Tween& To(const T& end) {
Reset();
this->end = end;
return *this;
}
/**
* Set the Duration (in seconds)
* @param seconds Duration
* @return class Reference
*/
Tween& In(float seconds) {
Reset();
tend = seconds;
return *this;
}
/**
* Set Effect of the Tween
* @param e Effect
* @return class Reference
*/
Tween& As(const Effect& e) {
effect = e;
return *this;
}
/**
* Reset to time 0
* @return class Reference
*/
Tween& Reset() {
finished = false;
time = 0.f;
return *this;
}
/**
* Get the Prograss in percent (0.0 to 1.0) of the tween
* @return progress value
*/
float Progress() const { return time / tend; }
/**
* Swap Start and end Position of the Tween
* @return class reference
*/
Tween& Swap() {
T temp = start;
start = end;
end = temp;
return *this;
}
T Get() const {
float t = 0.f;
switch (effect) {
case EaseInQuad:
t = time / tend;
return (end - start) * t * t + start;
break;
case EaseOutQuad:
t = time / tend;
return -(end - start) * t * (t - 2) + start;
break;
case EaseInOutQuad:
t = time / (tend / 2);
if (t < 1) return (end - start) / 2 * t * t + start;
t--;
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
break;
case EaseInCubic:
t = time / tend;
return (end - start) * t * t * t + start;
break;
case EaseOutCubic:
t = time / tend;
t--;
return (end - start) * (t * t * t + 1) + start;
break;
// case EaseInOutCubic:
// t = time / (tend / 2);
// if (t < 1) return (end - start) / 2 * t * t * t + start;
// t--;
// return (end - start) / 2 * (t * t * t * 2) + start;
// break;
case EaseInSine:
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
start;
break;
case EaseOutSine:
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
break;
case EaseInOutSine:
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
break;
default: // Linear
return (end - start) * (time / tend) + start;
break;
}
}
/**
* Operator that returns the current value calculated
* by time and effect
*/
operator T() const { return Get(); }
private:
/** Animation Effect */
Effect effect;
/** Time */
float time = 0.f;
/**
* End time
* Defaulting to one to prevent div zero
* without a safetey check
* not implementing one cause if the user is
* Writing a In(0.f) its their fault
*/
float tend = 1.f;
/** Start value */
T start;
/** end value */
T end;
/** is finished value */
bool finished = false;
};
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
namespace PD {
/**
* D7 Tween Engine (or something like that)
* @tparam T Any Numeric value
*/
template <typename T>
class Tween {
public:
/**
* Effects Table
*/
enum Effect {
Linear, ///< Linear Movement [works]
EaseInQuad, ///< EaseInQuad Movement [works]
EaseOutQuad, ///< EaseOutQuad Movement [works]
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
EaseInCubic, ///< EaseInCubic Movement [not tested]
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
EaseInSine, ///< EaseInSine Movement [works]
EaseOutSine, ///< EaseOutSine Movement [works]
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
};
Tween() = default;
~Tween() = default;
/**
* Update Tween
* @param delta deltatime
*/
void Update(float delta) {
time += delta / 1000.f;
if (time > tend) {
finished = true;
time = tend;
}
}
/**
* Check if Tween is finished
* @return true if finished
*/
bool IsFinished() const { return finished; }
/**
* Force finish the animation
* @return Class reference
*/
Tween& Finish() {
time = tend;
finished = true;
return *this;
}
/**
* Set Start Value
* @tparam T datatype of the Tween
* @param start Start Value
* @return class Reference
*/
Tween& From(const T& start) {
Reset();
this->start = start;
return *this;
}
/**
* Set End Value
* @tparam T datatype of the Tween
* @param end End Value
* @return class Reference
*/
Tween& To(const T& end) {
Reset();
this->end = end;
return *this;
}
/**
* Set the Duration (in seconds)
* @param seconds Duration
* @return class Reference
*/
Tween& In(float seconds) {
Reset();
tend = seconds;
return *this;
}
/**
* Set Effect of the Tween
* @param e Effect
* @return class Reference
*/
Tween& As(const Effect& e) {
effect = e;
return *this;
}
/**
* Reset to time 0
* @return class Reference
*/
Tween& Reset() {
finished = false;
time = 0.f;
return *this;
}
/**
* Get the Prograss in percent (0.0 to 1.0) of the tween
* @return progress value
*/
float Progress() const { return time / tend; }
/**
* Swap Start and end Position of the Tween
* @return class reference
*/
Tween& Swap() {
T temp = start;
start = end;
end = temp;
return *this;
}
T Get() const {
float t = 0.f;
switch (effect) {
case EaseInQuad:
t = time / tend;
return (end - start) * t * t + start;
break;
case EaseOutQuad:
t = time / tend;
return -(end - start) * t * (t - 2) + start;
break;
case EaseInOutQuad:
t = time / (tend / 2);
if (t < 1) return (end - start) / 2 * t * t + start;
t--;
return -(end - start) / 2 * (t * (t - 2) - 1) + start;
break;
case EaseInCubic:
t = time / tend;
return (end - start) * t * t * t + start;
break;
case EaseOutCubic:
t = time / tend;
t--;
return (end - start) * (t * t * t + 1) + start;
break;
// case EaseInOutCubic:
// t = time / (tend / 2);
// if (t < 1) return (end - start) / 2 * t * t * t + start;
// t--;
// return (end - start) / 2 * (t * t * t * 2) + start;
// break;
case EaseInSine:
return -(end - start) * cos(time / tend * (M_PI / 2)) + (end - start) +
start;
break;
case EaseOutSine:
return (end - start) * sin(time / tend * (M_PI / 2)) + start;
break;
case EaseInOutSine:
return -(end - start) / 2 * (cos(M_PI * time / tend) - 1) + start;
break;
default: // Linear
return (end - start) * (time / tend) + start;
break;
}
}
/**
* Operator that returns the current value calculated
* by time and effect
*/
operator T() const { return Get(); }
private:
/** Animation Effect */
Effect effect;
/** Time */
float time = 0.f;
/**
* End time
* Defaulting to one to prevent div zero
* without a safetey check
* not implementing one cause if the user is
* Writing a In(0.f) its their fault
*/
float tend = 1.f;
/** Start value */
T start;
/** end value */
T end;
/** is finished value */
bool finished = false;
};
} // namespace PD

36
include/pd/core/vec.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -23,6 +24,37 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec2.hpp>
#include <pd/core/vec3.hpp>
#include <pd/core/vec4.hpp>
#include <pd/core/vec4.hpp>
/** Define Formatters for C++ 20 */
/**
* WHY DOES MSVC ALWAYS NEED THESE EXTRA THINGS
*/
template <typename T, typename CharT>
struct std::formatter<PD::vec2<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const PD::vec2<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "({}, {})", v.x, v.y);
}
};
template <typename T, typename CharT>
struct std::formatter<PD::vec3<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const PD::vec3<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "({}, {}, {})", v.x, v.y, v.z);
}
};
template <typename T, typename CharT>
struct std::formatter<PD::vec4<T>, CharT> : std::formatter<T, CharT> {
template <typename FormatContext>
auto format(const PD::vec4<T>& v, FormatContext& ctx) const {
return std::format_to(ctx.out(), "({}, {}, {}, {})", v.x, v.y, v.z, v.w);
}
};

299
include/pd/core/vec2.hpp Normal file → Executable file
View File

@ -1,135 +1,164 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
template <typename T>
class vec2 {
public:
// SECTION: Constructors //
vec2() = default;
vec2(T v) {
x = v;
y = v;
}
vec2(T x, T y) {
this->x = x;
this->y = y;
}
vec2(const vec2<T> &v) {
x = v.x;
y = v.y;
}
// SECTION: Operators //
// ADD //
vec2 &operator+=(T v) {
x += v;
y += v;
return *this;
}
vec2 &operator+=(const vec2 &v) {
x += v.x;
y += v.y;
return *this;
}
vec2 operator+(T v) const { return vec2(x + v, y + v); }
vec2 operator+(vec2 v) const { return vec2(x + v.x, y + v.y); }
// SUB //
vec2 &operator-=(T v) {
x -= v;
y -= v;
return *this;
}
vec2 &operator-=(const vec2 &v) {
x -= v.x;
y -= v.y;
return *this;
}
vec2 operator-(T v) const { return vec2(x - v, y - v); }
vec2 operator-(vec2 v) const { return vec2(x - v.x, y - v.y); }
// MUL //
vec2 &operator*=(T v) {
x *= v;
y *= v;
return *this;
}
vec2 &operator*=(const vec2 &v) {
x *= v.x;
y *= v.y;
return *this;
}
vec2 operator*(T v) const { return vec2(x * v, y * v); }
vec2 operator*(vec2 v) const { return vec2(x * v.x, y * v.y); }
// DIV //
vec2 &operator/=(T v) {
x /= v;
y /= v;
return *this;
}
vec2 &operator/=(const vec2 &v) {
x /= v.x;
y /= v.y;
return *this;
}
vec2 operator/(T v) const { return vec2(x / v, y / v); }
vec2 operator/(vec2 v) const { return vec2(x / v.x, y / v.y); }
// Make Negative //
vec2 operator-() const { return vec2(-x, -y); }
bool operator==(const vec2 &v) const { return x == v.x && y == v.y; }
bool operator!=(const vec2 &v) const { return !(*this == v); }
// SECTION: Additional Functions //
float Len() const { return sqrt(SqLen()); }
float SqLen() const { return x * x + y * y; }
void Swap() {
T t = x;
x = y;
y = t;
}
// SECTION: DATA //
T x = 0;
T y = 0;
};
using dvec2 = vec2<double>;
using fvec2 = vec2<float>;
using ivec2 = vec2<int>;
} // namespace PD
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec
#include <pd/core/common.hpp>
namespace PD {
template <typename T>
class vec2 {
public:
T x;
T y;
vec2() : x(0), y(0) {}
template <typename T1>
vec2(T1 v) {
x = (T)v;
y = (T)v;
}
template <typename T1>
vec2(vec2<T1> v) {
x = (T)v.x;
y = (T)v.y;
}
vec2(T x, T y) : x(x), y(y) {}
template <typename T1>
vec2<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
return *this;
}
template <typename T1>
vec2<T>& operator+=(const vec2<T1>& v) {
x += (T)v.x;
y += (T)v.y;
return *this;
}
template <typename T1>
vec2<T> operator+(T1 v) const {
return vec2<T>(x + (T)v, y + (T)v);
}
template <typename T1>
vec2<T> operator+(const vec2<T1>& v) const {
return vec2<T>(x + (T)v.x, y + (T)v.y);
}
template <typename T1>
vec2<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
return *this;
}
template <typename T1>
vec2<T>& operator-=(const vec2<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
return *this;
}
template <typename T1>
vec2<T> operator-(T1 v) const {
return vec2<T>(x - (T)v, y - (T)v);
}
template <typename T1>
vec2<T> operator-(const vec2<T1>& v) const {
return vec2<T>(x - (T)v.x, y - (T)v.y);
}
template <typename T1>
vec2<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
return *this;
}
template <typename T1>
vec2<T>& operator*=(const vec2<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
return *this;
}
template <typename T1>
vec2<T> operator*(T1 v) const {
return vec2<T>(x * (T)v, y * (T)v);
}
template <typename T1>
vec2<T> operator*(const vec2<T1>& v) const {
return vec2<T>(x * (T)v.x, y * (T)v.y);
}
template <typename T1>
vec2<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
return *this;
}
template <typename T1>
vec2<T>& operator/=(const vec2<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
return *this;
}
template <typename T1>
vec2<T> operator/(T1 v) const {
return vec2<T>(x / (T)v, y / (T)v);
}
template <typename T1>
vec2<T> operator/(const vec2<T1>& v) const {
return vec2<T>(x / (T)v.x, y / (T)v.y);
}
vec2 operator-() const { return vec2(-x, -y); }
bool operator==(const vec2& v) const { return x == v.x && y == v.y; }
bool operator!=(const vec2& v) const { return !(*this == v); }
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y; }
void SwapXY() {
T t = x;
x = y;
y = t;
}
};
using fvec2 = vec2<float>;
using dvec2 = vec2<double>;
using ivec2 = vec2<int>;
} // namespace PD

347
include/pd/core/vec3.hpp Normal file → Executable file
View File

@ -1,160 +1,187 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec2.hpp>
namespace PD {
template <typename T>
class vec3 {
public:
// SECTION: Constructors //
vec3() = default;
vec3(T v) {
x = v;
y = v;
z = v;
}
vec3(T x, T y, T z) {
this->x = x;
this->y = y;
this->z = z;
}
vec3(const vec3 &v) {
x = v.x;
y = v.y;
z = v.z;
}
// SECTION: Operators //
// ADD //
vec3 &operator+=(T v) {
x += v;
y += v;
z += v;
return *this;
}
vec3 &operator+=(const vec3 &v) {
x += v.x;
y += v.y;
z += v.z;
return *this;
}
vec3 operator+(T v) const { return vec3(x + v, y + v, z + v); }
vec3 operator+(vec3 v) const { return vec3(x + v.x, y + v.y, z + v.z); }
// SUB //
vec3 &operator-=(T v) {
x -= v;
y -= v;
z -= v;
return *this;
}
vec3 &operator-=(const vec3 &v) {
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
vec3 operator-(T v) const { return vec3(x - v, y - v, z - v); }
vec3 operator-(vec3 v) const { return vec3(x - v.x, y - v.y, z - v.z); }
// MUL //
vec3 &operator*=(T v) {
x *= v;
y *= v;
z *= v;
return *this;
}
vec3 &operator*=(const vec3 &v) {
x *= v.x;
y *= v.y;
z *= v.z;
return *this;
}
vec3 operator*(T v) const { return vec3(x * v, y * v, z * v); }
vec3 operator*(vec3 v) const { return vec3(x * v.x, y * v.y, z * v.z); }
// DIV //
vec3 &operator/=(T v) {
x /= v;
y /= v;
z /= v;
return *this;
}
vec3 &operator/=(const vec3 &v) {
x /= v.x;
y /= v.y;
z /= v.z;
return *this;
}
vec3 operator/(T v) const { return vec3(x / v, y / v, z / v); }
vec3 operator/(vec3 v) const { return vec3(x / v.x, y / v.y, z / v.z); }
// Make Negative //
vec3 operator-() const { return vec3(-x, -y, -z); }
bool operator==(const vec3 &v) const {
return x == v.x && y == v.y && z == v.z;
}
bool operator!=(const vec3 &v) const { return !(*this == v); }
// SECTION: Additional Functions //
float Len() const { return sqrt(SqLen()); }
float SqLen() const { return x * x + y * y + z * z; }
void SwapXY() {
T t = x;
x = y;
y = t;
}
void SwapYZ() {
T t = z;
z = y;
y = t;
}
void SwapXZ() {
T t = z;
z = x;
x = t;
}
// SECTION: DATA //
T x = 0;
T y = 0;
T z = 0;
};
using dvec3 = vec3<double>;
using fvec3 = vec3<float>;
using ivec3 = vec3<int>;
} // namespace PD
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec
#include <pd/core/common.hpp>
namespace PD {
template <typename T>
class vec3 {
public:
T x;
T y;
T z;
vec3() : x(0), y(0), z(0) {}
template <typename T1>
explicit vec3(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
}
template <typename T1>
explicit vec3(vec3<T1> v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
}
vec3(T x, T y, T z) : x(x), y(y), z(z) {}
template <typename T1>
vec3<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
z += (T)v;
return *this;
}
template <typename T1>
vec3<T>& operator+=(const vec3<T1>& v) {
x += (T)v.x;
y += (T)v.y;
z += (T)v.z;
return *this;
}
template <typename T1>
vec3<T> operator+(T1 v) const {
return vec3<T>(x + (T)v, y + (T)v, z + (T)v);
}
template <typename T1>
vec3<T> operator+(const vec3<T1>& v) const {
return vec3<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z);
}
template <typename T1>
vec3<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
z -= (T)v;
return *this;
}
template <typename T1>
vec3<T>& operator-=(const vec3<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
z -= (T)v.z;
return *this;
}
template <typename T1>
vec3<T> operator-(T1 v) const {
return vec3<T>(x - (T)v, y - (T)v, z - (T)v);
}
template <typename T1>
vec3<T> operator-(const vec3<T1>& v) const {
return vec3<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z);
}
template <typename T1>
vec3<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
z *= (T)v;
return *this;
}
template <typename T1>
vec3<T>& operator*=(const vec3<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
z *= (T)v.z;
return *this;
}
template <typename T1>
vec3<T> operator*(T1 v) const {
return vec3<T>(x * (T)v, y * (T)v, z * (T)v);
}
template <typename T1>
vec3<T> operator*(const vec3<T1>& v) const {
return vec3<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z);
}
template <typename T1>
vec3<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
z /= (T)v;
return *this;
}
template <typename T1>
vec3<T>& operator/=(const vec3<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
z /= (T)v.z;
return *this;
}
template <typename T1>
vec3<T> operator/(T1 v) const {
return vec3<T>(x / (T)v, y / (T)v, z / (T)v);
}
template <typename T1>
vec3<T> operator/(const vec3<T1>& v) const {
return vec3<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z);
}
vec3 operator-() const { return vec3(-x, -y, -z); }
bool operator==(const vec3& v) const {
return x == v.x && y == v.y && z == v.z;
}
bool operator!=(const vec3& v) const { return !(*this == v); }
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z; }
void SwapXY() {
T t = x;
x = y;
y = t;
}
void SwapXZ() {
T t = x;
x = z;
z = t;
}
void SwapYZ() {
T t = y;
y = z;
z = t;
}
};
using fvec3 = vec3<float>;
using dvec3 = vec3<double>;
using ivec3 = vec3<int>;
} // namespace PD

416
include/pd/core/vec4.hpp Normal file → Executable file
View File

@ -1,193 +1,223 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec3.hpp>
namespace PD {
template <typename T>
class vec4 {
public:
// SECTION: Constructors //
vec4() = default;
vec4(T v) {
x = v;
y = v;
z = v;
w = v;
}
vec4(T x, T y, T z, T w) {
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
vec4(const vec4 &v) {
x = v.x;
y = v.y;
z = v.z;
w = v.w;
}
vec4(const vec2<T> &xy, const vec2<T> &zw) {
x = xy.x;
y = xy.y;
z = zw.x;
w = zw.y;
}
// SECTION: Operators //
// ADD //
vec4 &operator+=(T v) {
x += v;
y += v;
z += v;
w += v;
return *this;
}
vec4 &operator+=(const vec4<T> &v) {
x += v.x;
y += v.y;
z += v.z;
w += v.w;
return *this;
}
vec4 operator+(T v) const { return vec4<T>(x + v, y + v, z + v, w + v); }
vec4 operator+(vec4 v) const {
return vec4(x + v.x, y + v.y, z + v.z, w + v.w);
}
// SUB //
vec4 &operator-=(T v) {
x -= v;
y -= v;
z -= v;
w -= v;
return *this;
}
vec4 &operator-=(const vec4 &v) {
x -= v.x;
y -= v.y;
z -= v.z;
w -= v.w;
return *this;
}
vec4 operator-(T v) const { return vec4(x - v, y - v, z - v, w - v); }
vec4 operator-(vec4 v) const {
return vec4(x - v.x, y - v.y, z - v.z, w - v.w);
}
// MUL //
vec4 &operator*=(T v) {
x *= v;
y *= v;
z *= v;
w *= v;
return *this;
}
vec4 &operator*=(const vec4 &v) {
x *= v.x;
y *= v.y;
z *= v.z;
w *= v.w;
return *this;
}
vec4 operator*(T v) const { return vec4(x * v, y * v, z * v, w * v); }
vec4 operator*(vec4 v) const {
return vec4(x * v.x, y * v.y, z * v.z, w * v.w);
}
// DIV //
vec4 &operator/=(T v) {
x /= v;
y /= v;
z /= v;
w /= v;
return *this;
}
vec4 &operator/=(const vec4 &v) {
x /= v.x;
y /= v.y;
z /= v.z;
w /= v.w;
return *this;
}
vec4 operator/(T v) const { return vec4(x / v, y / v, z / v, w / v); }
vec4 operator/(vec4 v) const {
return vec4(x / v.x, y / v.y, z / v.z, w / v.w);
}
// Make Negative //
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
bool operator==(const vec4 &v) const {
return x == v.x && y == v.y && z == v.z && w == v.w;
}
bool operator!=(const vec4 &v) const { return !(*this == v); }
// SECTION: Additional Functions //
float Len() const { return sqrt(SqLen()); }
float SqLen() const { return x * x + y * y + z * z + w * w; }
void SwapXY() {
T t = x;
x = y;
y = t;
}
void SwapYZ() {
T t = z;
z = y;
y = t;
}
void SwapXZ() {
T t = z;
z = x;
x = t;
}
// Adding ZW (to lazy to add all of those yet)
void SwapZW() {
T t = w;
w = z;
z = t;
}
// SECTION: DATA //
T x = 0;
T y = 0;
T z = 0;
T w = 0;
};
using dvec4 = vec4<double>;
using fvec4 = vec4<float>;
using ivec4 = vec4<int>;
} // namespace PD
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec
#include <pd/core/common.hpp>
#include <pd/core/vec2.hpp> // Extended
namespace PD {
template <typename T>
class vec4 {
public:
T x;
T y;
T z;
T w;
vec4() : x(0), y(0), z(0), w(0) {}
template <typename T1>
explicit vec4(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
w = (T)v;
}
template <typename T1>
explicit vec4(vec4<T1> v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
w = (T)v.w;
}
/** Extended Constructor */
template <typename T1>
explicit vec4(vec2<T1> a, vec2<T1> b) {
x = (T)a.x;
y = (T)a.y;
z = (T)b.x;
w = (T)b.y;
}
vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
template <typename T1>
vec4<T>& operator+=(T1 v) {
x += (T)v;
y += (T)v;
z += (T)v;
w += (T)v;
return *this;
}
template <typename T1>
vec4<T>& operator+=(const vec4<T1>& v) {
x += (T)v.x;
y += (T)v.y;
z += (T)v.z;
w += (T)v.w;
return *this;
}
template <typename T1>
vec4<T> operator+(T1 v) const {
return vec4<T>(x + (T)v, y + (T)v, z + (T)v, w + (T)v);
}
template <typename T1>
vec4<T> operator+(const vec4<T1>& v) const {
return vec4<T>(x + (T)v.x, y + (T)v.y, z + (T)v.z, w + (T)v.w);
}
template <typename T1>
vec4<T>& operator-=(T1 v) {
x -= (T)v;
y -= (T)v;
z -= (T)v;
w -= (T)v;
return *this;
}
template <typename T1>
vec4<T>& operator-=(const vec4<T1>& v) {
x -= (T)v.x;
y -= (T)v.y;
z -= (T)v.z;
w -= (T)v.w;
return *this;
}
template <typename T1>
vec4<T> operator-(T1 v) const {
return vec4<T>(x - (T)v, y - (T)v, z - (T)v, w - (T)v);
}
template <typename T1>
vec4<T> operator-(const vec4<T1>& v) const {
return vec4<T>(x - (T)v.x, y - (T)v.y, z - (T)v.z, w - (T)v.w);
}
template <typename T1>
vec4<T>& operator*=(T1 v) {
x *= (T)v;
y *= (T)v;
z *= (T)v;
w *= (T)v;
return *this;
}
template <typename T1>
vec4<T>& operator*=(const vec4<T1>& v) {
x *= (T)v.x;
y *= (T)v.y;
z *= (T)v.z;
w *= (T)v.w;
return *this;
}
template <typename T1>
vec4<T> operator*(T1 v) const {
return vec4<T>(x * (T)v, y * (T)v, z * (T)v, w * (T)v);
}
template <typename T1>
vec4<T> operator*(const vec4<T1>& v) const {
return vec4<T>(x * (T)v.x, y * (T)v.y, z * (T)v.z, w * (T)v.w);
}
template <typename T1>
vec4<T>& operator/=(T1 v) {
x /= (T)v;
y /= (T)v;
z /= (T)v;
w /= (T)v;
return *this;
}
template <typename T1>
vec4<T>& operator/=(const vec4<T1>& v) {
x /= (T)v.x;
y /= (T)v.y;
z /= (T)v.z;
w /= (T)v.w;
return *this;
}
template <typename T1>
vec4<T> operator/(T1 v) const {
return vec4<T>(x / (T)v, y / (T)v, z / (T)v, w / (T)v);
}
template <typename T1>
vec4<T> operator/(const vec4<T1>& v) const {
return vec4<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z, w / (T)v.w);
}
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
bool operator==(const vec4& v) const {
return x == v.x && y == v.y && z == v.z && w == v.w;
}
bool operator!=(const vec4& v) const { return !(*this == v); }
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z + w * w; }
void SwapXY() {
T t = x;
x = y;
y = t;
}
void SwapXZ() {
T t = x;
x = z;
z = t;
}
void SwapXW() {
T t = x;
x = w;
w = t;
}
void SwapYZ() {
T t = y;
y = z;
z = t;
}
void SwapYW() {
T t = y;
y = w;
w = t;
}
void SwapZW() {
T t = z;
z = w;
w = t;
}
};
using fvec4 = vec4<float>;
using dvec4 = vec4<double>;
using ivec4 = vec4<int>;
} // namespace PD

View File

@ -23,33 +23,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/lib3ds/memory.hpp>
#include <pd/sound/decoder.hpp>
#include <pd/sound/metadata.hpp>
namespace PD {
namespace Music {
/**
* Music Player
*/
class Player : public SmartCtor<Player> {
public:
Player() {}
~Player() {}
private:
MetaData meta;
size_t samples_total = 0;
size_t samples_played = 0;
size_t samples_per_sec = 0;
std::string file;
std::vector<signed short, LinearAllocator<signed short>> buffers[2];
ndspWaveBuf wave_buf[2] = {0};
bool last_buf = false;
int ret = -1;
bool done = false;
bool playing = false;
bool stop = false;
};
} // namespace Music
} // namespace PD
#include <pd/drivers/gfx.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/drivers/os.hpp>

111
include/pd/drivers/gfx.hpp Executable file
View File

@ -0,0 +1,111 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/texture.hpp>
using LiBackendFlags = PD::u32;
enum LiBackendFlags_ {
LiBackendFlags_None = 0,
LiBackendFlags_FlipUV_Y = PD_BIT(0), // Essential for font loading
};
namespace PD {
namespace Li {
class GfxDriver {
public:
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};
~GfxDriver() = default;
PD_SHARED(GfxDriver);
void PostInit();
virtual void Init() {}
virtual void Deinit() {}
virtual void NewFrame() {}
virtual void BindTex(TexAddress addr) {}
virtual void RenderDrawData(const std::vector<Command::Ref>& Commands) {}
virtual Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
Texture::Type type = Texture::Type::RGBA32,
Texture::Filter filter = Texture::Filter::LINEAR) {
// Texture loading not supported (when this func not get override)
return nullptr;
}
Texture::Ref GetSolidTex() { return pSolid; }
const std::string pName = "NullGfx";
LiBackendFlags Flags = 0;
ivec2 ViewPort;
fvec4 ClearColor;
Texture::Ref pSolid;
/** Debug Variables */
// Optional Index counter
u32 IndexCounter;
// Optional Vertex counter
u32 VertexCounter;
// Optional Frame Counter
u64 FrameCounter;
};
/** Static Gfx Controller */
class Gfx {
public:
Gfx() = default;
~Gfx() = default;
static void Init(GfxDriver::Ref d);
static void Deinit() { pGfx->Deinit(); }
static void NewFrame() { pGfx->NewFrame(); }
static void BindTex(TexAddress addr) { pGfx->BindTex(addr); }
static void RenderDrawData(const std::vector<Command::Ref>& Commands) {
pGfx->RenderDrawData(Commands);
}
static LiBackendFlags Flags() { return pGfx->Flags; }
static Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
Texture::Type type = Texture::Type::RGBA32,
Texture::Filter filter = Texture::Filter::LINEAR) {
return pGfx->LoadTex(pixels, w, h, type, filter);
}
static Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
static GfxDriver::Ref pGfx;
};
} // namespace Li
} // namespace PD

View File

@ -1,175 +1,214 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
namespace PD {
/** Input Driver Template class */
class PD_CORE_API Hid : public SmartCtor<Hid> {
public:
/** Key [Controller] */
enum Key : u32 {
No = 0, ///< No Key
A = 1 << 0, ///< A
B = 1 << 1, ///< B
X = 1 << 2, ///< X
Y = 1 << 3, ///< Y
Start = 1 << 4, ///< Start
Select = 1 << 5, ///< Select
L = 1 << 6, ///< L
R = 1 << 7, ///< R
DUp = 1 << 8, ///< Dpad Up
DDown = 1 << 9, ///< Dpad down
DLeft = 1 << 10, ///< Dpad left
DRight = 1 << 11, ///< Dpad right
CPUp = 1 << 12, ///< Cpad up
CPDown = 1 << 13, ///< cpad down
CPLeft = 1 << 14, ///< cpad left
CPRight = 1 << 15, ///< Cpad right
CSUp = 1 << 16, ///< Cstick up
CSDown = 1 << 17, ///< cstick down
CSLeft = 1 << 18, ///< cstick left
CSRight = 1 << 19, ///< cstick right
ZL = 1 << 20, ///< ZL
ZR = 1 << 21, ///< ZR
Touch = 1 << 22, ///< Touch
Up = DUp | CPUp, ///< DPad or CPad Up
Down = DDown | CPDown, ///< DPad or CPad Down
Left = DLeft | CPLeft, ///< DPad or CPad Left
Right = DRight | CPRight, ///< DPad or CPad Right
};
/** Event */
enum Event {
Event_Down, ///< Key Pressed
Event_Held, ///< Key Held
Event_Up, ///< Key released
};
Hid(const std::string& name = "NullBackend") : pName(name) {}
~Hid() = default;
/**
* Get TOuch Position
* @return touch pos
*/
fvec2 TouchPos() const { return touch[0]; }
/**
* Get Last Touch Position (from last frame)
* @return touch pos
*/
fvec2 TouchPosLast() const { return touch[1]; }
/**
* Check for a Button Event
* @param e Event Type
* @param keys Keys to check for
* @return if key(s) doing the requiested event
*/
bool IsEvent(Event e, Key keys);
/**
* Check for Key Press Event
* @param keys set of keys
* @return true if key is pressed
*/
bool IsDown(Key keys) const { return key_events[0].at(Event_Down) & keys; }
/**
* Check for Key Held Event
* @param keys set of keys
* @return true if key is held
*/
bool IsHeld(Key keys) const { return key_events[0].at(Event_Held) & keys; }
/**
* Check for Key Release Event
* @param keys set of keys
* @return true if key is released
*/
bool IsUp(Key keys) const { return key_events[0].at(Event_Up) & keys; }
/**
* Sett all keyevents to 0
*/
void Clear() {
for (int i = 0; i < 2; i++) {
key_events[i][Event_Down] = 0;
key_events[i][Event_Up] = 0;
key_events[i][Event_Held] = 0;
}
}
/**
* Lock input driver
* @param v lock or not lock
*/
void Lock(bool v) {
if (v != locked) {
SwappyTable();
}
locked = v;
}
/**
* Check if Driver is locked
* @return true if locked
*/
bool Locked() const { return locked; }
/**
* Lock Input Driver
*/
void Lock() {
if (!locked) {
SwappyTable();
}
locked = true;
}
/**
* Unlock Input Driver
*/
void Unlock() {
if (locked) {
SwappyTable();
}
locked = false;
}
/**
* Template Update Function for a device specific driver
*/
virtual void Update() {}
/** Backend Identification Name */
const std::string pName;
protected:
/** Key binds map */
std::unordered_map<u32, u32> binds;
/** Function to swap around the Table */
void SwappyTable();
/** Using 2 Touch positions for current and last frame */
fvec2 touch[2];
/** locked state */
bool locked = false;
/** Key event tables */
std::unordered_map<Event, u32> key_events[2];
};
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPHidE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
namespace PD {
class HidDriver {
public:
/** Key [Controller] */
enum Key : u32 {
No = 0, ///< No Key
A = 1 << 0, ///< A
B = 1 << 1, ///< B
X = 1 << 2, ///< X
Y = 1 << 3, ///< Y
Start = 1 << 4, ///< Start
Select = 1 << 5, ///< Select
L = 1 << 6, ///< L
R = 1 << 7, ///< R
DUp = 1 << 8, ///< Dpad Up
DDown = 1 << 9, ///< Dpad down
DLeft = 1 << 10, ///< Dpad left
DRight = 1 << 11, ///< Dpad right
CPUp = 1 << 12, ///< Cpad up
CPDown = 1 << 13, ///< cpad down
CPLeft = 1 << 14, ///< cpad left
CPRight = 1 << 15, ///< Cpad right
CSUp = 1 << 16, ///< Cstick up
CSDown = 1 << 17, ///< cstick down
CSLeft = 1 << 18, ///< cstick left
CSRight = 1 << 19, ///< cstick right
ZL = 1 << 20, ///< ZL
ZR = 1 << 21, ///< ZR
Touch = 1 << 22, ///< Touch
Up = DUp | CPUp, ///< DPad or CPad Up
Down = DDown | CPDown, ///< DPad or CPad Down
Left = DLeft | CPLeft, ///< DPad or CPad Left
Right = DRight | CPRight, ///< DPad or CPad Right
};
/** Event */
enum Event {
Event_Down, ///< Key Pressed
Event_Held, ///< Key Held
Event_Up, ///< Key released
};
HidDriver(const std::string& name = "NullHid") : pName(name) {};
virtual ~HidDriver() = default;
PD_SHARED(HidDriver);
/**
* Get Mouse Position
* @return Mouse pos
*/
fvec2 MousePos() const {
return pMouse[0];
} /**
* Get Last Mouse Position (from last frame)
* @return Mouse pos
*/
fvec2 MousePosLast() const { return pMouse[1]; }
/**
* Check for a Button Event
* @param e Event Type
* @param keys Keys to check for
* @return if key(s) doing the requiested event
*/
bool IsEvent(Event e, Key keys);
/**
* Check for Key Press Event
* @param keys set of keys
* @return true if key is pressed
*/
bool IsDown(Key keys) const { return KeyEvents[0].at(Event_Down) & keys; }
/**
* Check for Key Held Event
* @param keys set of keys
* @return true if key is held
*/
bool IsHeld(Key keys) const { return KeyEvents[0].at(Event_Held) & keys; }
/**
* Check for Key Release Event
* @param keys set of keys
* @return true if key is released
*/
bool IsUp(Key keys) const { return KeyEvents[0].at(Event_Up) & keys; }
/**
* Sett all keyevents to 0
*/
void Clear() {
for (int i = 0; i < 2; i++) {
KeyEvents[i][Event_Down] = 0;
KeyEvents[i][Event_Up] = 0;
KeyEvents[i][Event_Held] = 0;
}
}
/**
* Lock input driver
* @param v lock or not lock
*/
void Lock(bool v) {
if (v != pLocked) {
SwapTab();
}
pLocked = v;
}
/**
* Check if Driver is locked
* @return true if locked
*/
bool Locked() const { return pLocked; }
/**
* Lock Input Driver
*/
void Lock() {
if (!pLocked) {
SwapTab();
}
pLocked = true;
}
/**
* Unlock Input Driver
*/
void Unlock() {
if (pLocked) {
SwapTab();
}
pLocked = false;
}
/**
* Template Update Function for a device specific driver
*/
virtual void Update() {}
/** Data Section */
/** Backend Identification Name */
const std::string pName;
/** Key Binds Map */
std::unordered_map<u32, u32> pBinds;
/** Swap Tabe Function */
void SwapTab();
/** Using 2 Positions for Current and Last */
fvec2 pMouse[2];
/** Lock State */
bool pLocked = false;
/** Key Event Table Setup */
std::unordered_map<Event, u32> KeyEvents[2];
};
/** Static Hid Controller */
class Hid {
public:
Hid() = default;
~Hid() = default;
/** Referenec to Drivers enums */
using Key = HidDriver::Key;
using Event = HidDriver::Event;
static void Init(HidDriver::Ref v = nullptr) {
if (v) {
pHid = v;
} else {
pHid = HidDriver::New();
}
}
static bool IsEvent(Event e, Key keys) { return pHid->IsEvent(e, keys); }
static bool IsDown(Key keys) { return pHid->IsDown(keys); }
static bool IsUp(Key keys) { return pHid->IsUp(keys); }
static bool IsHeld(Key keys) { return pHid->IsHeld(keys); }
static fvec2 MousePos() { return pHid->MousePos(); }
static fvec2 MousePosLast() { return pHid->MousePosLast(); }
static void Clear() { pHid->Clear(); }
static void Lock() { pHid->Lock(); }
static void Lock(bool v) { pHid->Lock(v); }
static void Unlock() { pHid->Unlock(); }
static bool Locked() { return pHid->Locked(); }
static void Update() { pHid->Update(); }
static HidDriver::Ref pHid;
};
} // namespace PD

137
include/pd/core/sys.hpp → include/pd/drivers/os.hpp Normal file → Executable file
View File

@ -1,66 +1,71 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/timetrace.hpp>
namespace PD {
/**
* Namespace containing functions for get Millis and Get Nanos
*/
namespace Sys {
/**
* alias for the TimeTrace Traces Map
*/
using TraceMap = std::map<std::string, TT::Res::Ref>;
/**
* Get Current Time in Milliseconds
* @return 64Bit value of millis
*/
PD_CORE_API u64 GetTime();
/**
* Get Current Time in Nanoseconds
* @return 64Bit value of nanos
*/
PD_CORE_API u64 GetNanoTime();
/**
* Get a TimeTrace Reference by its string ID
* @param id trace name
* @return Trace reference or nullptr if not found
*/
PD_CORE_API TT::Res::Ref& GetTraceRef(const std::string& id);
/**
* Check if a Trace with the name exists
* @param id tracename to search
* @return true if exist
*/
PD_CORE_API bool TraceExist(const std::string& id);
/**
* Get TraceMap Reference
* @return edidable Reference to the TraceMap
*/
PD_CORE_API TraceMap& GetTraceMap();
} // namespace Sys
} // namespace PD
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/timetrace.hpp>
namespace PD {
using TraceMap = std::map<std::string, TT::Res::Ref>;
class OsDriver {
public:
OsDriver() = default;
virtual ~OsDriver() = default;
PD_SHARED(OsDriver);
virtual u64 GetTime();
virtual u64 GetNanoTime();
TraceMap& GetTraceMap();
TT::Res::Ref& GetTraceRef(const std::string& id);
bool TraceExist(const std::string& id);
TraceMap pTraces;
};
/** Static Os Controller */
class OS {
public:
OS() = default;
~OS() = default;
static void Init(OsDriver::Ref v = nullptr) {
if (v) {
pOs = v;
} else {
pOs = OsDriver::New();
}
}
static u64 GetTime() { return pOs->GetTime(); }
static u64 GetNanoTime() { return pOs->GetNanoTime(); }
static TraceMap& GetTraceMap() { return pOs->GetTraceMap(); }
static TT::Res::Ref& GetTraceRef(const std::string& id) {
return pOs->GetTraceRef(id);
}
static bool TraceExist(const std::string& id) { return pOs->TraceExist(id); }
static OsDriver::Ref pOs;
};
} // namespace PD

View File

@ -1,56 +1,26 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
namespace PD {
/**
* Overlay Template class
*/
class Overlay : public SmartCtor<Overlay> {
public:
Overlay() = default;
virtual ~Overlay() = default;
/**
* Update Function for Overlay input and rendering
* @param delta Deltatime
* @param ren Renderer reference
* @param inp Input Driver
*/
virtual void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) = 0;
/** Check if killed to remove from Overlay Manager */
bool IsKilled() const { return kill; }
protected:
/** Internall Kill function to call from your Overlay */
void Kill() { kill = true; }
private:
bool kill = false; ///< Should be killed or not
};
} // namespace PD
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#define PD_DEF_EXP(x, y) x y = nullptr

0
include/pd/external/json.hpp vendored Normal file → Executable file
View File

0
include/pd/external/stb_image.h vendored Normal file → Executable file
View File

0
include/pd/external/stb_truetype.h vendored Normal file → Executable file
View File

164
include/pd/image/image.hpp Normal file → Executable file
View File

@ -1,82 +1,84 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
class PD_IMAGE_API Image : public SmartCtor<Image> {
public:
enum Format {
RGBA, // bpp == 4
RGB, // bpp == 3
RGB565, // bpp == 2 (not supported in laoding)
BGR, // bpp == 3
ABGR // bpp == 4
};
Image() = default;
Image(const std::string& path) { this->Load(path); }
Image(const std::vector<u8>& buf) { this->Load(buf); }
Image(const std::vector<u8>& buf, int w, int h, int bpp = 4) {
this->Copy(buf, w, h, bpp);
}
~Image() = default;
void Load(const std::string& path);
void Load(const std::vector<u8>& buf);
void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4);
std::vector<PD::u8>& GetBuffer() { return pBuffer; }
std::vector<PD::u8> GetBuffer() const { return pBuffer; }
int Width() const { return pWidth; }
int Height() const { return pHeight; }
Format Fmt() const { return pFmt; }
u8& operator[](int idx) { return pBuffer[idx]; }
u8 operator[](int idx) const { return pBuffer[idx]; }
// Probably these make th eabove ones useless
operator std::vector<PD::u8>&() { return pBuffer; }
operator std::vector<PD::u8>() const { return pBuffer; }
static void Convert(Image::Ref img, Image::Format dst);
static void ReTile(Image::Ref img,
std::function<u32(int x, int y, int w)> src,
std::function<u32(int x, int y, int w)> dst);
static int Fmt2Bpp(Format fmt);
std::vector<PD::u8> pBuffer;
int pWidth;
int pHeight;
Format pFmt = Format::RGBA;
private:
/** Leftover variable used for stbi_load */
int fmt = 0;
};
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
class PD_IMAGE_API Image {
public:
enum Format {
RGBA, // bpp == 4
RGB, // bpp == 3
RGB565, // bpp == 2 (not supported in laoding)
BGR, // bpp == 3
ABGR // bpp == 4
};
Image() = default;
Image(const std::string& path) { this->Load(path); }
Image(const std::vector<u8>& buf) { this->Load(buf); }
Image(const std::vector<u8>& buf, int w, int h, int bpp = 4) {
this->Copy(buf, w, h, bpp);
}
~Image() = default;
PD_SHARED(Image)
void Load(const std::string& path);
void Load(const std::vector<u8>& buf);
void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4);
std::vector<PD::u8>& GetBuffer() { return pBuffer; }
std::vector<PD::u8> GetBuffer() const { return pBuffer; }
int Width() const { return pWidth; }
int Height() const { return pHeight; }
Format Fmt() const { return pFmt; }
u8& operator[](int idx) { return pBuffer[idx]; }
u8 operator[](int idx) const { return pBuffer[idx]; }
// Probably these make th eabove ones useless
operator std::vector<PD::u8>&() { return pBuffer; }
operator std::vector<PD::u8>() const { return pBuffer; }
static void Convert(Image::Ref img, Image::Format dst);
static void ReTile(Image::Ref img,
std::function<u32(int x, int y, int w)> src,
std::function<u32(int x, int y, int w)> dst);
static int Fmt2Bpp(Format fmt);
std::vector<PD::u8> pBuffer;
int pWidth;
int pHeight;
Format pFmt = Format::RGBA;
private:
/** Leftover variable used for stbi_load */
int fmt = 0;
};
} // namespace PD

142
include/pd/image/img_blur.hpp Normal file → Executable file
View File

@ -1,72 +1,72 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
/**
* Namepace containing functions to blur images
*/
namespace ImgBlur {
/**
* Function to create Gaussian Kernel List
* @param radius Rasius to use
* @param si sigma value to use
* @return list of kernel values
*/
PD_IMAGE_API std::vector<float> GaussianKernel(int radius, float si);
/**
* Gaussian Blur for basic Image Buffer
* @param buf Image Buffer (unsigned char)
* @param w width of the image
* @param h width of the image
* @param radius Blur radius
* @param si Blur sigma
* @param idxfn Indexing function
*/
PD_IMAGE_API void GaussianBlur(
std::vector<u8> &buf, int w, int h, float radius, float si,
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
return y * w + x;
});
/**
* Advanced func to access memory directly
* @param buf Referenvce to the buffer
* @param w width of the image
* @param h width of the image
* @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
* @param radius Blur radius
* @param si Blur sigma
* @param idxfn Indexing function
*/
PD_IMAGE_API void GaussianBlur(
void *buf, int w, int h, int bpp, float radius, float si,
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
return y * w + x;
});
} // namespace ImgBlur
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
/**
* Namepace containing functions to blur images
*/
namespace ImgBlur {
/**
* Function to create Gaussian Kernel List
* @param radius Rasius to use
* @param si sigma value to use
* @return list of kernel values
*/
PD_IMAGE_API std::vector<float> GaussianKernel(int radius, float si);
/**
* Gaussian Blur for basic Image Buffer
* @param buf Image Buffer (unsigned char)
* @param w width of the image
* @param h width of the image
* @param radius Blur radius
* @param si Blur sigma
* @param idxfn Indexing function
*/
PD_IMAGE_API void GaussianBlur(
std::vector<u8> &buf, int w, int h, float radius, float si,
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
return y * w + x;
});
/**
* Advanced func to access memory directly
* @param buf Referenvce to the buffer
* @param w width of the image
* @param h width of the image
* @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
* @param radius Blur radius
* @param si Blur sigma
* @param idxfn Indexing function
*/
PD_IMAGE_API void GaussianBlur(
void *buf, int w, int h, int bpp, float radius, float si,
std::function<int(int, int, int)> idxfn = [](int x, int y, int w) -> int {
return y * w + x;
});
} // namespace ImgBlur
} // namespace PD

162
include/pd/image/img_convert.hpp Normal file → Executable file
View File

@ -1,82 +1,82 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/image/image.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
/**
* Namespace containing function to convert images
*/
namespace ImgConvert {
/**
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
* to every pixel
* @param out Result List
* @param in Input Buffer List (rgb24)
* @param w width of the image
* @param h height of the image
*/
PD_IMAGE_API
void RGB24toRGBA32(std::vector<PD::u8> &out, const std::vector<u8> &in,
const int &w, const int &h);
PD_IMAGE_API
void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in,
const int &w, const int &h);
/**
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
* @param buf Buffer to convert
* @param w width
* @param h height
*/
PD_IMAGE_API void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
PD_IMAGE_API void ReverseBuf(std::vector<u8> &buf, size_t bpp, int w, int h);
/**
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
* to every pixel
* @param out Result List
* @param in Input Buffer List (rgb24)
* @param w width of the image
* @param h height of the image
*/
PD_IMAGE_API
void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
const int &h);
PD_IMAGE_API
void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
const int &h);
/**
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
* @param buf Buffer to convert
* @param w width
* @param h height
*/
PD_IMAGE_API void Reverse32(PD::Vec<u8> &buf, const int &w, const int &h);
PD_IMAGE_API void ReverseBuf(PD::Vec<u8> &buf, size_t bpp, int w, int h);
} // namespace ImgConvert
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/image/image.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
/**
* Namespace containing function to convert images
*/
namespace ImgConvert {
/**
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
* to every pixel
* @param out Result List
* @param in Input Buffer List (rgb24)
* @param w width of the image
* @param h height of the image
*/
PD_IMAGE_API
void RGB24toRGBA32(std::vector<PD::u8> &out, const std::vector<u8> &in,
const int &w, const int &h);
PD_IMAGE_API
void RGB32toRGBA24(std::vector<u8> &out, const std::vector<u8> &in,
const int &w, const int &h);
/**
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
* @param buf Buffer to convert
* @param w width
* @param h height
*/
PD_IMAGE_API void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
PD_IMAGE_API void ReverseBuf(std::vector<u8> &buf, size_t bpp, int w, int h);
/**
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
* to every pixel
* @param out Result List
* @param in Input Buffer List (rgb24)
* @param w width of the image
* @param h height of the image
*/
PD_IMAGE_API
void RGB24toRGBA32(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
const int &h);
PD_IMAGE_API
void RGB32toRGBA24(PD::Vec<u8> &out, const PD::Vec<u8> &in, const int &w,
const int &h);
/**
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
* @param buf Buffer to convert
* @param w width
* @param h height
*/
PD_IMAGE_API void Reverse32(PD::Vec<u8> &buf, const int &w, const int &h);
PD_IMAGE_API void ReverseBuf(PD::Vec<u8> &buf, size_t bpp, int w, int h);
} // namespace ImgConvert
} // namespace PD

9
include/pd/image/pd_p_api.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -22,9 +21,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
*/
#pragma once
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_IMAGE_BUILD_SHARED
@ -49,4 +48,4 @@ SOFTWARE.
#define PD_IMAGE_API
#else
#define PD_IMAGE_API
#endif
#endif

View File

@ -1,76 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
using LIBackendFlags = PD::u32;
enum LIBackendFlags_ {
LIBackendFlags_None = 0,
LIBackendFlags_FlipUV_Y = 1 << 0, // Essential for Font Loading
};
namespace PD {
namespace LI {
class Backend {
public:
Backend(const std::string& name = "NullBackend") : pName(name) {}
~Backend() = default;
// Using Legacy SmartCTOR API here
PD_SMART_CTOR(Backend)
virtual void Init() {}
virtual void Deinit() {}
virtual void NewFrame() {}
virtual void BindTexture(TexAddress addr) {}
virtual void RenderDrawData(const Vec<Command::Ref>& Commands) {}
virtual Texture::Ref LoadTexture(
const std::vector<PD::u8>& pixels, int w, int h,
Texture::Type type = Texture::Type::RGBA32,
Texture::Filter filter = Texture::Filter::LINEAR) {
// Texture loading not supported (when this func not get override)
return nullptr;
}
/** Backend identification name */
const std::string pName = "NullBackend";
LIBackendFlags Flags = 0;
ivec2 ViewPort;
fvec4 ClearColor;
// Optional Index Counter
int IndexCounter = 0;
// Optional Vertex Counter
int VertexCounter = 0;
// Optional Frame Counter
int FrameCounter = 0;
};
} // namespace LI
} // namespace PD

28
include/pd/lithium/command.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -25,38 +24,35 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
// #include <pd/lithium/flags.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace LI {
/**
* Lithium Draw Command (containing a list of vertex and index data
* only for this specific command itself)
*/
class Command : public SmartCtor<Command> {
namespace Li {
class Command {
public:
Command() = default;
~Command() = default;
Command& AppendIndex(u16 idx) {
PD_UNIQUE(Command);
Command& AddIdx(const u16& idx) {
IndexBuffer.Add(VertexBuffer.Size() + idx);
return *this;
}
Command& AppendVertex(const Vertex& v) {
VertexBuffer.Add(v);
Command& AddVtx(const Vertex& v) {
VertexBuffer.Add(std::move(v));
return *this;
}
Vec<Vertex> VertexBuffer;
Vec<u16> IndexBuffer;
PD::Vec<Vertex> VertexBuffer;
PD::Vec<u16> IndexBuffer;
ivec4 ScissorRect;
bool ScissorEnabled = false;
bool ScissorOn = false;
int Layer;
int Index;
Texture::Ref Tex;
};
} // namespace LI
} // namespace Li
} // namespace PD

84
include/pd/lithium/drawlist.hpp Normal file → Executable file
View File

@ -28,24 +28,47 @@ SOFTWARE.
#include <pd/lithium/font.hpp>
#include <pd/lithium/pd_p_api.hpp>
/** Path Rect Flags */
using LiPathRectFlags = PD::u32;
/** Setup for everything (oder so) */
enum LiPathRectFlags_ : PD::u32 {
LiPathRectFlags_None = 0,
LiPathRectFlags_KeepTopLeft = PD_BIT(0),
LiPathRectFlags_KeepTopRight = PD_BIT(1),
LiPathRectFlags_KeepBotRight = PD_BIT(2),
LiPathRectFlags_KeepBotLeft = PD_BIT(3),
LiPathRectFlags_KeepTop = PD_BIT(0) | PD_BIT(1),
LiPathRectFlags_KeepBot = PD_BIT(2) | PD_BIT(3),
LiPathRectFlags_KeepLeft = PD_BIT(0) | PD_BIT(3),
LiPathRectFlags_KeepRight = PD_BIT(1) | PD_BIT(2),
};
namespace PD {
namespace LI {
class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
namespace Li {
class PD_LITHIUM_API DrawList {
public:
DrawList(Texture::Ref solid) {
WhitePixel = solid;
CurrentTex = solid;
}
~DrawList() {}
DrawList() { DrawSolid(); }
~DrawList() { pDrawList.clear(); }
/** Require Copy and Move Constructors */
DrawList(const DrawList&) = delete;
DrawList& operator=(const DrawList&) = delete;
DrawList(DrawList&&) noexcept = default;
DrawList& operator=(DrawList&&) noexcept = default;
PD_SHARED(DrawList);
Command::Ref PreGenerateCmd();
void AddCommand(Command::Ref v) { pDrawList.Add(v); }
void Clear() { pDrawList.Clear(); }
void AddCommand(Command::Ref v) { pDrawList.push_back(std::move(v)); }
void Clear() { pDrawList.clear(); }
void SetFont(Font::Ref font) { pCurrentFont = font; }
void SetFontScale(float scale) { pFontScale = scale; }
void DrawSolid() { CurrentTex = WhitePixel; }
void DrawSolid();
void DrawTexture(Texture::Ref tex) { CurrentTex = tex; }
// SECTION: Draw API //
@ -62,7 +85,12 @@ class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
int num_segments);
void DrawText(const fvec2& p, const std::string& text, u32 color);
/**
* Extended Draw Text Function
*/
void DrawTextEx(const fvec2& p, const std::string& text, u32 color,
LiTextFlags flags, fvec2 box = fvec2(0.f));
void DrawLine(const fvec2& a, const fvec2& b, u32 color, int t = 1);
/**
* Take list of points and display it as a line on screen
* @param points List of Positions
@ -126,20 +154,38 @@ class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
}
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
int segments);
void PathFastArcToN(const fvec2& c, float r, float amin, float amax, int s);
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
/// @param a Top Left Position
/// @param b Bottom Right Position
/// @param rounding rounding
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f);
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
/// @param a Top Left Position
/// @param b Bottom Right Position
/// @param rounding rounding
/// @param flags DrawFlags (for special rounding rules)
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
void PathRectEx(fvec2 a, fvec2 b, float rounding = 0.f, u32 flags = 0);
int Layer = 0;
void PushClipRect(const fvec4& cr) { pClipRects.Push(cr); }
void PopClipRect() {
if (pClipRects.IsEmpty()) {
return;
}
pClipRects.Pop();
}
/** One linear Clip rect Setup */
void pClipCmd(Command* cmd);
/** Data Section */
Stack<fvec4> pClipRects;
int Layer;
float pFontScale = 0.7f;
Font::Ref pCurrentFont = nullptr;
Texture::Ref CurrentTex = nullptr;
Texture::Ref WhitePixel = nullptr;
PD::Vec<Command::Ref> pDrawList;
Font::Ref pCurrentFont;
Texture::Ref CurrentTex;
std::vector<Command::Ref> pDrawList;
PD::Vec<fvec2> pPath;
};
} // namespace LI
} // namespace PD
} // namespace Li
} // namespace PD

51
include/pd/lithium/font.hpp Normal file → Executable file
View File

@ -25,26 +25,25 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/backend.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/pd_p_api.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
using LITextFlags = PD::u32;
enum LITextFlags_ {
LITextFlags_None = 0, ///< Do nothing
LITextFlags_AlignRight = 1 << 0, ///< Align Right of position
LITextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
LITextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
LITextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
LITextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
LITextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
using LiTextFlags = PD::u32;
enum LiTextFlags_ {
LiTextFlags_None = 0, ///< Do nothing
LiTextFlags_AlignRight = 1 << 0, ///< Align Right of position
LiTextFlags_AlignMid = 1 << 1, ///< Align in the middle of pos and box
LiTextFlags_Shaddow = 1 << 2, ///< Draws the text twice to create shaddow
LiTextFlags_Wrap = 1 << 3, ///< Wrap Text: May be runs better with TMS
LiTextFlags_Short = 1 << 4, ///< Short Text: May be runs better with TMS
LiTextFlags_Scroll = 1 << 5, ///< Not implemented [scoll text if to long]
};
namespace PD {
namespace LI {
/** Font Loader for Lithium */
class PD_LITHIUM_API Font : public SmartCtor<Font> {
namespace Li {
class PD_LITHIUM_API Font {
public:
/** Codepoint Data holder */
struct Codepoint {
@ -55,8 +54,13 @@ class PD_LITHIUM_API Font : public SmartCtor<Font> {
float Offset = 0.f;
bool pInvalid = false;
};
Font(Backend::Ref backend) { pBackend = backend; };
/** Constructore doesnt need Backand anymore */
Font() = default;
~Font() = default;
PD_SHARED(Font);
/**
* Load a TTF File
* @param path Path to the TTF file
@ -76,20 +80,19 @@ class PD_LITHIUM_API Font : public SmartCtor<Font> {
/**
* Extended Draw Text Function that vreates a Command List
*/
void CmdTextEx(Vec<Command::Ref>& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text, LITextFlags flags = 0,
void CmdTextEx(std::vector<Command::Ref>& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text, LiTextFlags flags = 0,
const fvec2& box = 0);
/** Pixelheight */
/** Data Section */
int PixelHeight;
int DefaultPixelHeight = 24;
private:
/** List of textures (codepoints are using) */
std::vector<Texture::Ref> Textures;
/** 32Bit Codepoint Dataholder Reference Map */
std::map<u32, Codepoint> CodeMap;
Backend::Ref pBackend = nullptr;
/**
* 32Bit Codepoint Dataholder reference map
* **Now using unordered map**
*/
std::unordered_map<u32, Codepoint> CodeMap;
};
} // namespace LI
} // namespace Li
} // namespace PD

View File

@ -1,64 +1,32 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/overlays/overlay.hpp>
namespace PD {
/**
* Overlay Manager Class
*/
class OverlayMgr : public SmartCtor<OverlayMgr> {
public:
/**
* Constructor
* @param ren Renderer
* @param inp Input Driver reference
*/
OverlayMgr(LI::Renderer::Ref ren, Hid::Ref inp) {
this->ren = ren;
this->inp = inp;
}
/** Deconstructor */
~OverlayMgr() { overlays.clear(); }
/**
* Append a New Overlay
* @param overlay Overlay reference to push
*/
void Push(Overlay::Ref overlay);
/**
* Update Overlays
* @paran delta Deltatime
*/
void Update(float delta);
private:
std::vector<Overlay::Ref> overlays; ///< Overlay List
LI::Renderer::Ref ren; ///< Renderer reference
Hid::Ref inp; ///< Input Driver reference
};
} // namespace PD
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/lithium/command.hpp>
#include <pd/lithium/drawlist.hpp>
#include <pd/lithium/font.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/lithium/texture.hpp>

9
include/pd/lithium/pd_p_api.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -22,9 +21,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
*/
#pragma once
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_LITHIUM_BUILD_SHARED
@ -49,4 +48,4 @@ SOFTWARE.
#define PD_LITHIUM_API
#else
#define PD_LITHIUM_API
#endif
#endif

105
include/pd/lithium/rect.hpp Normal file → Executable file
View File

@ -26,24 +26,20 @@ SOFTWARE.
#include <pd/core/core.hpp>
namespace PD {
namespace LI {
/**
* Container that holds position of a rectangle's corners.
*/
namespace Li {
class Rect {
public:
Rect() = default;
Rect() : Top(0), Bot(0) {}
~Rect() = default;
/**
* Constructor that initializes the rectangle using top and bottom positions.
* @param t Top left and right corner positions.
* @param b Bottom left and right corner positions.
*/
Rect(const fvec4& t, const fvec4& b) {
top = t;
bot = b;
Top = t;
Bot = b;
}
/**
* Constructor that initializes the rectangle using individual corner
* positions.
@ -53,8 +49,8 @@ class Rect {
* @param br Bottom right corner position.
*/
Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) {
top = fvec4(tl, tr);
bot = fvec4(bl, br);
Top = fvec4(tl, tr);
Bot = fvec4(bl, br);
}
/**
@ -66,67 +62,30 @@ class Rect {
* @param uv Vec4 UV map.
*/
Rect(const fvec4& uv) {
top = vec4(uv.x, uv.y, uv.z, uv.y);
bot = vec4(uv.x, uv.w, uv.z, uv.w);
}
~Rect() = default;
/**
* Get the top left and right corner positions.
* @return Top positions.
*/
fvec4 Top() const { return top; }
/**
* Get the bottom left and right corner positions.
* @return Bottom positions.
*/
fvec4 Bot() const { return bot; }
/**
* Set the top left and right corner positions.
* @param v New top positions.
* @return Reference to the updated Rect.
*/
Rect& Top(const fvec4& v) {
top = v;
return *this;
}
/**
* Set the bottom left and right corner positions.
* @param v New bottom positions.
* @return Reference to the updated Rect.
*/
Rect& Bot(const fvec4& v) {
bot = v;
return *this;
Top = vec4(uv.x, uv.y, uv.z, uv.y);
Bot = vec4(uv.x, uv.w, uv.z, uv.w);
}
/**
* Get the top-left corner position.
* @return Top-left position as vec2.
*/
fvec2 TopLeft() const { return vec2(top.x, top.y); }
fvec2 TopLeft() const { return fvec2(Top.x, Top.y); }
/**
* Get the top-right corner position.
* @return Top-right position as vec2.
*/
fvec2 TopRight() const { return vec2(top.z, top.w); }
fvec2 TopRight() const { return fvec2(Top.z, Top.w); }
/**
* Get the bottom-left corner position.
* @return Bottom-left position as vec2.
*/
fvec2 BotLeft() const { return vec2(bot.x, bot.y); }
fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); }
/**
* Get the bottom-right corner position.
* @return Bottom-right position as vec2.
*/
fvec2 BotRight() const { return vec2(bot.z, bot.w); }
fvec2 BotRight() const { return fvec2(Bot.z, Bot.y); }
/**
* Set the top-left corner position.
@ -134,8 +93,8 @@ class Rect {
* @return Reference to the updated Rect.
*/
Rect& TopLeft(const fvec2& v) {
top.x = v.x;
top.y = v.y;
Top.x = v.x;
Top.y = v.y;
return *this;
}
@ -145,8 +104,8 @@ class Rect {
* @return Reference to the updated Rect.
*/
Rect& TopRight(const fvec2& v) {
top.z = v.x;
top.w = v.y;
Top.z = v.x;
Top.w = v.y;
return *this;
}
@ -156,8 +115,8 @@ class Rect {
* @return Reference to the updated Rect.
*/
Rect& BotLeft(const fvec2& v) {
bot.x = v.x;
bot.y = v.y;
Bot.x = v.x;
Bot.y = v.y;
return *this;
}
@ -167,26 +126,22 @@ class Rect {
* @return Reference to the updated Rect.
*/
Rect& BotRight(const fvec2& v) {
bot.z = v.x;
bot.w = v.y;
Bot.z = v.x;
Bot.w = v.y;
return *this;
}
/**
* Swap X and Y coordinates for all corners.
*
* - Used in SpiteSheet for the rotated images.
*/
void SwapVec2XY() {
top.SwapXY();
top.SwapZW();
bot.SwapXY();
bot.SwapZW();
Top.SwapXY();
Top.SwapZW();
Bot.SwapXY();
Bot.SwapZW();
}
private:
fvec4 top; ///< Top left and right corner positions.
fvec4 bot; ///< Bottom left and right corner positions.
/** Data Section */
fvec4 Top;
fvec4 Bot;
};
} // namespace LI
} // namespace Li
} // namespace PD

43
include/pd/lithium/renderer.hpp Normal file → Executable file
View File

@ -24,37 +24,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/lithium/backend.hpp>
#include <pd/lithium/drawlist.hpp>
#include <pd/lithium/font.hpp>
#include <pd/drivers/drivers.hpp>
#include <pd/lithium/pd_p_api.hpp>
#include <pd/lithium/rect.hpp>
namespace PD {
namespace LI {
class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> {
namespace Li {
/**
* Static Class Render Setup Functions
*/
class PD_LITHIUM_API Renderer {
public:
Renderer(Backend::Ref backend);
Renderer() = default;
~Renderer() = default;
void Render();
// SECTION: ADVANCED API
void AddCommand(Command::Ref v) { DrawList.Add(v); }
void RegisterDrawList(DrawList::Ref list) { pDrawLists.Add(list); }
Command::Ref PreGenerateCmd();
// SECTION: Open Command and Object creation API
static void RotateCorner(fvec2& pos, float sinus, float cosinus);
static void RotateCorner(fvec2& pos, float s, float c);
static Rect PrimRect(const fvec2& pos, const fvec2& size, float angle = 0.f);
static Rect PrimLine(const fvec2& a, const fvec2& b, int thickness = 1);
static void CmdQuad(Command::Ref cmd, const Rect& quad, const Rect& uv,
static void CmdQuad(Command* cmd, const Rect& quad, const Rect& uv,
u32 color);
static void CmdTriangle(Command::Ref cmd, const fvec2 a, const fvec2 b,
static void CmdTriangle(Command* cmd, const fvec2 a, const fvec2 b,
const fvec2 c, u32 clr);
static void CmdPolyLine(const Vec<fvec2>& points, u32 clr, u32 flags = 0,
int thickness = 1);
static void CmdConvexPolyFilled(Command::Ref cmd, const Vec<fvec2>& points,
static void CmdConvexPolyFilled(Command* cmd, const Vec<fvec2>& points,
u32 clr, Texture::Ref tex);
// SECTION: InBounds Checks
@ -63,17 +57,6 @@ class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> {
static bool InBox(const fvec2& pos, const fvec4& area);
static bool InBox(const fvec2& a, const fvec2& b, const fvec2& c,
const fvec4& area);
// SECTION: Data //
Texture::Ref WhitePixel = nullptr;
Backend::Ref pBackend = nullptr;
Texture::Ref CurrentTex = nullptr;
int Layer = 0;
private:
PD::Vec<Command::Ref> DrawList;
PD::Vec<DrawList::Ref> pDrawLists;
};
} // namespace LI
} // namespace Li
} // namespace PD

39
include/pd/lithium/texture.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -28,49 +27,49 @@ SOFTWARE.
#include <pd/lithium/rect.hpp>
namespace PD {
namespace LI {
namespace Li {
/** Use so address type for TexAddress */
using TexAddress = uintptr_t;
/**
* Lithium Texture Data Holder
* Memory management is handled by backend
*/
class Texture : public SmartCtor<Texture> {
class Texture {
public:
/** Texture Type */
/** Texture Types */
enum Type {
RGBA32, ///< RGBA 32
RGB24, ///< RGB24
A8, ///< A8
RGBA32, ///< Rgba 32Bit
RGB24, ///< Rgb 24 Bit
A8, ///< A8 8Bit alpha
};
/** Texture Filters */
enum Filter {
NEAREST, ///< Nearest
LINEAR, ///< Linear
};
/** Default constructor */
Texture() : UV(0.f, 0.f, 1.f, 1.f) {}
/** Constructor */
Texture() : Address(0), Size(0), UV(fvec4(0.f, 0.f, 1.f, 1.f)) {}
Texture(TexAddress addr, ivec2 size,
LI::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
Li::Rect uv = fvec4(0.f, 0.f, 1.f, 1.f)) {
Address = addr;
Size = size;
UV = uv;
}
void CopyOther(Texture::Ref tex) {
PD_SHARED(Texture);
void CopyFrom(Texture::Ref tex) {
Address = tex->Address;
Size = tex->Size;
UV = tex->UV;
}
/** Left in Code getter (should be remoevd) */
ivec2 GetSize() const { return Size; }
LI::Rect GetUV() const { return UV; }
Li::Rect GetUV() const { return UV; }
operator ivec2() const { return Size; }
operator LI::Rect() const { return UV; }
operator Li::Rect() const { return UV; }
TexAddress Address;
ivec2 Size;
LI::Rect UV;
Li::Rect UV;
};
} // namespace LI
} // namespace Li
} // namespace PD

10
include/pd/lithium/vertex.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -27,7 +26,7 @@ SOFTWARE.
#include <pd/core/core.hpp>
namespace PD {
namespace LI {
namespace Li {
class Vertex {
public:
Vertex() {}
@ -40,9 +39,12 @@ class Vertex {
~Vertex() {}
// private:
/** Open Access Data Section */
fvec2 Pos;
fvec2 UV;
u32 Color;
};
} // namespace LI
} // namespace Li
} // namespace PD

View File

@ -1,53 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/net/socket.hpp>
namespace PD {
namespace Net {
class Backend {
public:
Backend(const std::string& name = "NullBackend") : pName(name) {}
~Backend() = default;
PD_SMART_CTOR(Backend)
virtual bool Init() = 0;
virtual void Deinit() = 0;
virtual int NewSocket() = 0;
virtual void Close(int sock_id) = 0;
virtual int GetInvalidRef() const = 0;
virtual bool Bind(int sock_id, u16 port) = 0;
virtual bool Listen(int sock_id, int backlog = 5) = 0;
virtual bool WaitForRead(int sock_id, int timeout_ms) = 0;
virtual bool Accept(int sock_id, Socket::Ref client) = 0;
virtual bool Connect(int sock_id, const std::string& ip, u16 port) = 0;
virtual int Send(int sock_id, const std::string& data) = 0;
virtual int Receive(int sock_id, std::string& data, int size = 1024) = 0;
/** Backend identification name */
const std::string pName;
};
} // namespace Net
} // namespace PD

View File

@ -1,115 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/external/json.hpp>
namespace PD {
/**
* Download manager class
*/
class DownloadManager : public SmartCtor<DownloadManager> {
public:
/** Alias to contain Error Cdoe and for some Errors a Status Code */
using Error = u64;
/** Error Codes of DL Manager */
enum Error_ {
Error_None, ///< Function Executed Successfully
Error_Memory, ///< Memory Allocation Error
Error_Write, ///< Unable to Write File
Error_StatusCode, ///< Error with Status Code
Error_Git, ///< Git Error
Error_CtrStatus, ///< 3ds Result Code
Error_Curl, ///< Curl Error
Error_Busy, ///< Another Download Taskl is already running
Error_Invalid, ///< Invalid Json struct
Error_NoWifi, ///< Console not connected to wifi
};
DownloadManager() = default;
~DownloadManager() = default;
/**
* Extract the DL Manager Error code of a Error
* @param err Error
* @return Downloadmanager Error code
*/
static Error_ GetErrorCode(Error err) {
return (Error_)u32(err & 0xffffffff);
}
/**
* Extract the DL Manager Status code of a Error
* @param err Error
* @return Status code
*/
static int GetStatusCode(Error err) {
Error_ c = GetErrorCode(err);
if (c != Error_StatusCode && c != Error_CtrStatus && c != Error_Curl) {
return 0;
}
return u32(err >> 32);
}
/**
* Download from URL inro a String Buffer
* @param url URL to download from
* @param res result buffer
* @return Error Code
*/
Error Get(const std::string& url, std::string& res);
/**
* Download from URL into a File
* @param url URL to download from
* @param res_path Path to write file to
* @return Error Code
*/
Error GetFile(const std::string& url, const std::string& res_path);
/**
* Download a File from a Git Release
* @param url URL of the repo
* @param asset Asset to download
* @param path Path to write file into
* @param pre download from Prerelease
* @return Error Code
*/
Error GetGitRelease(const std::string& url, const std::string& asset,
const std::string& path, bool pre);
/**
* Get a json API request as nlohmann json object
* @param url URL to request
* @param res result json object
* @return Error Code
*/
Error GetAsJson(const std::string& url, nlohmann::json& res);
/** Get Current Progress in Bytes */
u64 ProgressCurrent() const { return current; }
/** Get Total number in bytes */
u64 ProgressTotal() const { return total; }
private:
u64 current; ///< Current Progress
u64 total; ///< Total Bytes tp Download
};
} // namespace PD

View File

@ -1,61 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/net/pd_p_api.hpp>
namespace PD {
namespace Net {
class Backend;
/**
* Wrapper class around the functionality of Net::Backend
*/
class PD_NET_API Socket {
public:
Socket(PD::SmartCtor<Backend>::Ref bknd) { backend = bknd; };
Socket(PD::SmartCtor<Backend>::Ref bknd, u16 port) {
backend = bknd;
this->Create();
this->Bind(port);
}
~Socket() { Close(); };
PD_SMART_CTOR(Socket);
bool Create();
bool Bind(u16 port);
bool Listen(int backlog = 5);
bool WaitForRead(int timeout_ms);
bool Accept(Socket::Ref client);
bool Connect(const std::string& ip, u16 port);
int Send(const std::string& data);
int Receive(std::string& data, int size = 1024);
void Close();
bool IsValid() const;
int pSocket;
PD::SmartCtor<Net::Backend>::Ref backend;
};
} // namespace Net
} // namespace PD

View File

@ -1,177 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/overlays/overlay.hpp>
namespace PD {
/**
* Development Function to dump Keyboard Layout into a Json File
* @param path Path to write into
*/
void DumpLayout(const std::string& path);
/**
* Keyboard class
*
* - needs to be pushed with text and State reference as Overlay
* to communicate with it
* @note Hardcoded Rendering to get maximum Rendering Performance
*/
class Keyboard : public Overlay {
public:
/** Key Operations */
enum KeyOperation {
AppendSelf = 0, ///< Append Keyname to res string
Shift = 1, ///< Shift
Backspace = 2, ///< Backspace
Enter = 3, ///< Enter
OpCancel = 4, ///< Cancel
OpConfirm = 5, ///< Confirm
Tab = 6, ///< Tab
Caps = 7, ///< Caps
Space = 8, ///< Space
Op1 = 9, ///< Unnset Op 1
Op2 = 10, ///< Unset Op 2
};
/** Keyboard Type */
enum Type {
Default, ///< Default Keyboard
Numpad, ///< Numpad
Password, ///< Password Input
};
/** State */
enum State {
None, ///< Doing nothing
Cancel, ///< Cancelled
Confirm, ///< Confirmed
};
/** Alias for Keyboard Flags */
using Flags = u32;
/** Flags */
enum Flags_ {
Flags_None = 0, ///< Nothing
Flags_BlendTop = 1 << 0, ///< Blend Top Screen
Flags_BlendBottom = 1 << 1, ///< Blend Bottom
Flags_LockControls = 1 << 2, ///< Lock Contols (Input Driver)
Flags_Transparency = 1 << 3, ///< Transparant Keyboard Colors
// Default Flags
Flags_Default = Flags_BlendBottom | Flags_BlendTop | Flags_LockControls,
};
/**
* Keyboard Constructor
* @param text Result Text
* @param state Result State
* @param hint Hint to display if result is empty
* @param type Keyboard type
* @param flags Keyboard flags to use
*/
Keyboard(std::string& text, State& state, const std::string& hint = "",
Type type = Default, Flags flags = Flags_Default) {
too++;
if (too > 1) {
Kill();
return;
}
this->text = &text;
this->copy = text;
this->state = &state;
this->hint = hint;
this->type = type;
this->flags = flags;
this->raw_sel = -1;
flymgr.From(vec2(0, 240)).To(vec2(0, 115)).In(0.3f).As(flymgr.EaseInQuad);
chflymgr.From(vec2(-320, 0)).To(vec2(-320, 0)).In(0.1f).As(chflymgr.Linear);
}
/** Deconstructor */
~Keyboard() { too--; }
/**
* Rendering and Input Handler
* @param delta Deltatime for Animations
* @param ren Renderer Reference
* @param inp Input Driver reference
*/
void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override;
/** Remove Keyboard */
void Rem() {
rem = true;
flymgr.From(vec2(0, 115)).To(vec2(0, 240)).In(0.2f).As(flymgr.EaseOutQuad);
}
private:
/** Prerender Keys */
void LoadTheKeys(LI::Renderer::Ref ren);
/** Controller Movement */
void Movement(Hid::Ref inp);
/** Trigger Move from to Animation */
void MoveSelector();
/** Execute a Key operation */
void DoOperation(KeyOperation op, const std::string& kname);
/** Recolor all Keys with the same operation */
void RecolorBy(KeyOperation op, u32 color, int cm);
/** Bind an operation */
void InputOpBind(Hid::Key k, KeyOperation op, Hid::Ref inp, int cm);
// Result Text reference
std::string* text;
// Copy of the Text
std::string copy;
// Hint
std::string hint;
// Result State reference
State* state;
// Keyboard Type
Type type;
// Keyboard flags
Flags flags;
// def, caps, shift
int mode = 0;
// Stands for The Only One
static int too;
// Tween for selector Movement
Tween<fvec2> selector;
// Tween for Selector Size
Tween<fvec2> sel_szs;
// Current Cell size
fvec2 cselszs;
// selector index
int raw_sel;
// Prerendered Keytables
LI::StaticObject::Ref keys[3];
// Value to check if table is loadet
bool keys_loadet = false;
// Remove Animation
bool rem = false;
/// Probably a float would've done the job as well ;)
Tween<fvec2> flymgr;
// Secode Flymanager
Tween<fvec2> chflymgr;
// Show Help
bool show_help = true;
};
} // namespace PD

View File

@ -1,98 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
namespace PD {
/**
* Message Manager
*/
class MessageMgr : public PD::SmartCtor<MessageMgr> {
public:
/**
* Message Container
*/
class Container : public PD::SmartCtor<Container> {
public:
/**
* Message Constructor
* @param title Title
* @param msg Message
*/
Container(const std::string& title, const std::string& msg);
~Container() = default;
/** Render the Container */
void Render(PD::LI::Renderer::Ref ren);
/**
* Update Animations by slot and delta
* @param slot Slot
* @param delta Deltatime
*/
void Update(int slot, float delta);
/** Trigger Fly in Animation */
void FlyIn();
/** Trigger Change Position Animation */
void ToBeMoved(int slot);
/** Trigger Removed Animation */
void ToBeRemoved();
/** Check if Message can be removed from list */
bool ShouldBeRemoved() const { return (tbr && pos.IsFinished()) || kill; }
private:
PD::Color col_bg; // Background Color
PD::Color col_text; // Text Color
float lifetime = 0.f; // LifeTime
PD::Tween<fvec2> pos; // Position effect
std::string title; // Title
std::string msg; // Message
fvec2 size; // Size of the Background
bool tbr = false; // To be Removed ?
bool kill = false; // Instant Kill
int s = 0; // Slot
};
/** Constructor to Link a Renderer reference */
MessageMgr(PD::LI::Renderer::Ref r) { ren = r; }
~MessageMgr() = default;
/**
* Add a New Message
* @param title Message Title
* @param text Message Text
*/
void Push(const std::string& title, const std::string& text);
/**
* Update Messages
* @param delta Deltatime
*/
void Update(float delta);
private:
std::vector<Container::Ref> msgs; // List of Messages
PD::LI::Renderer::Ref ren; // Renderer Reference
};
} // namespace PD

View File

@ -1,84 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/overlays/overlay.hpp>
namespace PD {
/**
* Performance Overlay
*
* - Framerate / Frametime
* - Renderer Avarage Time
* - Overlays Avarage Time
* - UserApp Average Time
* - **V**ertices and **I**ndices
* - **D**Draw Commands and Draw **C**alls
* - Text Map System Texts
* - Auto static Text Texts
*/
class Performance : public Overlay {
public:
/**
* Constructor
* @param skill (if set to true the Overlay self kills)
* @param screen Bottom or Top Screen
*/
Performance(bool& skill, bool& screen) {
too++;
if (too > 1) {
Kill();
return;
}
this->skill = &skill;
*this->skill = false; // Make sure its false
this->screen = &screen;
}
/** Deconstructor */
~Performance() { too--; }
/**
* Rendering Function
* @param delta Deltatime
* @param ren Renderer Reference
* @param inp Input Driver Reference
*/
void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override;
private:
/**
* Render an Info line
* @param pos Position reference (gets updated for next line)
* @param text Text to Show
* @param ren Renderer Reference
*/
void Line(fvec2& pos, const std::string& text, LI::Renderer::Ref ren);
// Trace String Average
std::string TSA(const std::string& id);
// Described in Keyboard
static int too;
bool *skill, *screen;
};
} // namespace PD

View File

@ -1,75 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/overlays/overlay.hpp>
#include <pd/ui7/ui7.hpp>
namespace PD {
/**
* Settings Menu Overlay
*/
class SettingsMenu : public Overlay {
public:
/**
* Constructor to setup Overlay
*/
SettingsMenu() {
too++;
if (too > 1) {
Kill();
return;
}
flymgr.From(vec2(0, 240)).To(vec2(0, 115)).In(0.3f).As(flymgr.EaseInQuad);
}
/** Deconstructor */
~SettingsMenu() { too--; }
/** Rendering and Input Handler */
void Update(float delta, LI::Renderer::Ref ren, Hid::Ref inp) override;
/**
* Function to Trigger remove animation
*/
void Rem() {
rem = true;
flymgr.From(vec2(0, 115)).To(vec2(0, 240)).In(0.2f).As(flymgr.EaseOutQuad);
}
private:
/// Section is used to determinate what
/// should be displayed on the top screen
int section = 0;
// Stands for The Only One
static int too;
// Some Animation
bool rem = false;
Tween<fvec2> flymgr;
// Custom UI7 Context
UI7::Context::Ref ctx;
};
} // namespace PD

View File

@ -1,54 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
namespace Music {
/**
* Decoder Template class
*/
class Decoder : public SmartCtor<Decoder> {
public:
Decoder() = default;
virtual ~Decoder() = default;
/** Template Init function */
virtual int Init(const std::string& path) = 0;
/** Template deinit function */
virtual void Deinit() = 0;
/** Template function to get sample rate */
virtual u32 GetSampleRate() = 0;
/** template function to get number of channels */
virtual u8 GetChannels() = 0;
/** template function to get buffer size */
virtual size_t GetBufSize() = 0;
/** template decode function */
virtual u64 Decode(u16* buf_address) = 0;
/** template function to get file sanples if exist */
virtual size_t GetFileSamples() = 0;
};
} // namespace Music
} // namespace PD

View File

@ -1,79 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
namespace PD {
namespace Music {
/**
* Music Metadata Data Holder
*/
class MetaData {
public:
MetaData() = default;
~MetaData() = default;
/** Getter for name */
std::string Name() const { return name; }
/** Getter for album */
std::string Album() const { return album; }
/** Getter for year */
std::string Year() const { return year; }
/** Getter for Title */
std::string Title() const { return title; }
/** Getter for Artist */
std::string Artist() const { return artist; }
/** Getter for [what is this] */
std::string Mdt() const { return mdt; }
/** Gettr for file path */
std::string Path() const { return path; }
/** Setter for Name */
void Name(const std::string &v) { name = v; }
/** Setter for Album */
void Album(const std::string &v) { album = v; }
/** Settr for Year */
void Year(const std::string &v) { year = v; }
/** Settr for Title */
void Title(const std::string &v) { title = v; }
/** Settr for Artist */
void Artist(const std::string &v) { artist = v; }
/** Settr for [what is this] */
void Mdt(const std::string &v) { mdt = v; }
/** Settr for Path */
void Path(const std::string &v) { path = v; }
private:
const std::string unk = "Unknown";
std::string title = unk;
std::string album = unk;
std::string year = unk;
std::string name = unk;
std::string path = unk;
std::string artist = unk;
std::string mdt = unk;
};
} // namespace Music
} // namespace PD

View File

@ -1,62 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <mpg123.h>
#include <pd/sound/decoder.hpp>
namespace PD {
namespace Music {
/**
* MP3 Decoder
*/
class Mp3Decoder : public Decoder {
public:
Mp3Decoder() = default;
~Mp3Decoder() = default;
/** Init Funciton to load file and Init decoder */
int Init(const std::string& path) override;
/** Unload Decoder */
void Deinit() override;
/** Get Sample Rate */
u32 GetSampleRate() override;
/** Get Channels */
u8 GetChannels() override;
/** Get Buffer Size */
size_t GetBufSize() override;
/** Decode next data */
u64 Decode(u16* buf_address) override;
/** Get File Samples if exist */
size_t GetFileSamples() override;
private:
mpg123_handle* handle = nullptr;
size_t buf_size = 0;
u32 rate = 0;
u8 channels = 0;
};
} // namespace Music
} // namespace PD

1
include/pd/ui7/container/button.hpp Normal file → Executable file
View File

@ -48,6 +48,7 @@ class PD_UI7_API Button : public Container {
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Button() = default;
PD_SHARED(Button);
/** Return true if butten is pressed*/
bool IsPressed() { return pressed; }

1
include/pd/ui7/container/checkbox.hpp Normal file → Executable file
View File

@ -47,6 +47,7 @@ class PD_UI7_API Checkbox : public Container {
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Checkbox() = default;
PD_SHARED(Checkbox);
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update

5
include/pd/ui7/container/coloredit.hpp Normal file → Executable file
View File

@ -41,13 +41,14 @@ class PD_UI7_API ColorEdit : public Container {
* @param lr Reference to the Renderer
*/
ColorEdit(const std::string& label, u32* color, UI7::IO::Ref io) {
// PD::Assert(color != nullptr, "Input Color Address is null!");
// PD::Assert(color != nullptr, "Input Color Address is null!");
this->label = label;
this->color_ref = color;
this->initial_color = *color;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~ColorEdit() = default;
PD_SHARED(ColorEdit);
/**
* Override for the Input Handler
@ -64,7 +65,7 @@ class PD_UI7_API ColorEdit : public Container {
void Update() override;
private:
fvec2 tdim; ///< Text size
fvec2 tdim; ///< Text size
u32* color_ref = nullptr; ///< Color Reference
u32 initial_color; ///< Initial Color
std::string label; ///< Label of the Button

8
include/pd/ui7/container/container.hpp Normal file → Executable file
View File

@ -24,7 +24,6 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/pd_p_api.hpp>
@ -34,7 +33,7 @@ namespace UI7 {
* Container base class all Objects are based on
* @note this class can be used to create custom Objects as well
*/
class PD_UI7_API Container : public SmartCtor<Container> {
class PD_UI7_API Container {
public:
Container() = default;
/**
@ -51,13 +50,14 @@ class PD_UI7_API Container : public SmartCtor<Container> {
: pos(fvec2(box.x, box.y)), size(fvec2(box.z - box.x, box.w - box.y)) {}
~Container() = default;
PD_SHARED(Container);
/**
* Init Function Required by every Object that uses
* Render or Input functions
* @param io IO Reference
* @param l DrawList Reference
*/
void Init(UI7::IO::Ref io, UI7::DrawList::Ref l) {
void Init(UI7::IO::Ref io, Li::DrawList::Ref l) {
list = l;
this->io = io;
// this->screen = io->Ren->CurrentScreen();
@ -146,7 +146,7 @@ class PD_UI7_API Container : public SmartCtor<Container> {
/** Container Size*/
fvec2 size;
/** Reference to the Drawlist to Draw to*/
UI7::DrawList::Ref list;
Li::DrawList::Ref list;
/** IO Reference for Renderer and Theme */
UI7::IO::Ref io;
/** Reference to the parent container*/

2
include/pd/ui7/container/dragdata.hpp Normal file → Executable file
View File

@ -62,6 +62,8 @@ class PD_UI7_API DragData : public Container {
}
~DragData() = default;
/** Als ob das funktioniert... */
PD_SHARED(DragData<T>);
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update

6
include/pd/ui7/container/dynobj.hpp Normal file → Executable file
View File

@ -44,12 +44,14 @@ class PD_UI7_API DynObj : public Container {
* @param pos Base Position
* @param lr Reference to the Renderer
*/
DynObj(std::function<void(UI7::IO::Ref, UI7::DrawList::Ref, Container*)>
DynObj(std::function<void(UI7::IO::Ref, Li::DrawList::Ref, Container*)>
RenderFunc) {
pRenFun = RenderFunc;
}
~DynObj() = default;
PD_SHARED(DynObj);
/** Return true if butten is pressed*/
bool IsPressed() { return pressed; }
/**
@ -69,7 +71,7 @@ class PD_UI7_API DynObj : public Container {
private:
UI7Color color = UI7Color_Button; ///< current button color
bool pressed = false; ///< ispressed value
std::function<void(UI7::IO::Ref, UI7::DrawList::Ref, Container*)> pRenFun;
std::function<void(UI7::IO::Ref, Li::DrawList::Ref, Container*)> pRenFun;
};
} // namespace UI7
} // namespace PD

128
include/pd/ui7/container/image.hpp Normal file → Executable file
View File

@ -1,64 +1,66 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Image Object
*/
class PD_UI7_API Image : public Container {
public:
/**
* Constructor for the Image Object
* @param img Image Texture Reference
* @param size Custom Size of the Image
*/
Image(LI::Texture::Ref img, fvec2 size = 0.f, LI::Rect uv = vec4(0.f)) {
this->img = img;
this->newsize = size;
this->cuv = uv;
if (size.x != 0 || size.y != 0) {
this->SetSize(size);
} else {
this->SetSize(fvec2(img->GetSize().x, img->GetSize().y));
}
}
~Image() = default;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
LI::Texture::Ref img; ///< Texture reference to the Image
fvec2 newsize = 0.f; ///< New Size
LI::Rect cuv; ///< Custom UV
};
} // namespace UI7
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Image Object
*/
class PD_UI7_API Image : public Container {
public:
/**
* Constructor for the Image Object
* @param img Image Texture Reference
* @param size Custom Size of the Image
*/
Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0.f)) {
this->img = img;
this->newsize = size;
this->cuv = uv;
if (size.x != 0 || size.y != 0) {
this->SetSize(size);
} else {
this->SetSize(fvec2(img->GetSize().x, img->GetSize().y));
}
}
~Image() = default;
PD_SHARED(Image);
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
Li::Texture::Ref img; ///< Texture reference to the Image
fvec2 newsize = 0.f; ///< New Size
Li::Rect cuv; ///< Custom UV
};
} // namespace UI7
} // namespace PD

118
include/pd/ui7/container/label.hpp Normal file → Executable file
View File

@ -1,59 +1,61 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Label [Text] Object
*/
class PD_UI7_API Label : public Container {
public:
/**
* Constructor for Label Object
* @param label Label [Text] to Draw
* @param lr Renderer Reference
*/
Label(const std::string& label, IO::Ref io) {
this->label = label;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
this->SetSize(tdim);
}
~Label() = default;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
fvec2 tdim; ///< Text Size
UI7Color color = UI7Color_Text; ///< Color
std::string label; ///< Text to Render
};
} // namespace UI7
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/container/container.hpp>
namespace PD {
namespace UI7 {
/**
* Label [Text] Object
*/
class PD_UI7_API Label : public Container {
public:
/**
* Constructor for Label Object
* @param label Label [Text] to Draw
* @param lr Renderer Reference
*/
Label(const std::string& label, IO::Ref io) {
this->label = label;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
this->SetSize(tdim);
}
~Label() = default;
PD_SHARED(Label);
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
fvec2 tdim; ///< Text Size
UI7Color color = UI7Color_Text; ///< Color
std::string label; ///< Text to Render
};
} // namespace UI7
} // namespace PD

0
include/pd/ui7/containers.hpp Normal file → Executable file
View File

View File

@ -1,236 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/ui7/theme.hpp>
namespace PD {
namespace UI7 {
class IO;
/** DrawList class */
class PD_UI7_API DrawList : public SmartCtor<DrawList> {
public:
/**
* Constructor for a new Drawlist
* @param r Renderer reference
*/
DrawList(UI7::IO* io_ref) { pIO = io_ref; }
~DrawList() = default;
/**
* Draw a Rectangle (LINED)
* @param pos position of the rect
* @param size Size of the rect
* @param clr Color of the rect
* @param thickness Thickness of the lines
*/
void AddRect(const fvec2& pos, const fvec2& size, const UI7Color& clr,
int thickness = 1);
/**
* Render a Rectangle
* @param pos Position
* @param szs Size
* @param clr Color
*/
void AddRectangle(fvec2 pos, fvec2 szs, const UI7Color& clr);
/**
* Render a Triangle
* @param a Position a
* @param b Position b
* @param c Position c
* @param clr Color
* @param thickness Thickness of the lines
*/
void AddTriangle(const fvec2& a, const fvec2& b, const fvec2& c,
const UI7Color& clr, int thickness = 1);
/**
* Render a Filled Triangle
* @param a Position a
* @param b Position b
* @param c Position c
* @param clr Color
*/
void AddTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
const UI7Color& clr);
/**
* Add a Lined Circle
* @param pos Center position
* @param rad radius of the circle
* @param col Color of the Circle
* @param num_segments Number of Segments (0 = auto)
* @param thickness thickness of the line
*/
void AddCircle(const fvec2& pos, float rad, UI7Color col,
int num_segments = 0, int thickness = 1);
/**
* Add a Circle
* @param pos Center position
* @param rad radius of the circle
* @param col Color of the Circle
* @param num_segments Number of Segments (0 = auto)
*/
void AddCircleFilled(const fvec2& pos, float rad, UI7Color col,
int num_segments = 0);
/**
* Render a Text
* @param pos Position
* @param text Text
* @param clr Color
* @param flags Flags
* @param box Aditional Text Box limit (for specific flags)
*/
void AddText(fvec2 pos, const std::string& text, const UI7Color& clr,
u32 flags = 0, fvec2 box = fvec2());
/**
* Render an Image
* @param pos Position
* @param img Image Texture Reference
* @param size Optional Size of the Image
* @param uv Custom UV coords
*/
void AddImage(fvec2 pos, LI::Texture::Ref img, fvec2 size = 0.f,
LI::Rect uv = fvec4(0.f));
/**
* Render a Line from Position A to Position B
* @param a Pos a
* @param b Pos b
* @param clr Color
* @param t Thcikness
*/
void AddLine(const fvec2& a, const fvec2& b, const UI7Color& clr, int t = 1);
/**
* Take list of points and display it as a line on screen
* @param points List of Positions
* @param clr Color of the Line
* @param flags Additional Flags (Close for go back to starting point)
* @param thickness Thickness of the Line
*/
void AddPolyLine(const Vec<fvec2>& points, const UI7Color& clr,
UI7DrawFlags flags = 0, int thickness = 1);
/**
* Take a List ofpoints and display it as Filled Shape
* @note Keep in mind to setup the list of points clockwise
* @param points List of Points
* @param clr Color of the shape
*/
void AddConvexPolyFilled(const Vec<fvec2>& points, const UI7Color& clr);
/** Clear the Drawlist */
void Clear();
/** Process [Render] the Drawlist */
void Process(LI::DrawList::Ref d);
/** Push a Clip Rect */
void PushClipRect(const fvec4& v) { pClipRects.Push(v); }
/** Revert Last Clip Rect */
void PopClipRect() { pClipRects.Pop(); }
/** Path API */
/**
* Function to reserve Memory to prevent overhead on
* pusing a lot of points with PathNext
* @param num_points Number of Positions you want to add
*/
void PathReserve(size_t num_points) {
Path.Reserve(Path.Size() + num_points);
}
/**
* Clear current Path
* @note PathStroke and PathFill will automatically clear
*/
void PathClear() { Path.Clear(); }
/**
* Add a Point to the Path
* @note Keep in mind that this function is used for
* setting the starting point
* @param v Position to add
*/
void PathNext(const fvec2& v) { Path.Add(v); }
/**
* Path Stroke Create Line from point to point
* @note For Primitives like Rect or Triangle mak sure to use
* UI7DrawFlags_Close to add a line back to the starting point
* @param clr Color od the line
* @param thickness Thickness of the line
* @param flags Additional Drawflags
*/
void PathStroke(const UI7Color& clr, int thickness = 1,
UI7DrawFlags flags = 0) {
AddPolyLine(Path, clr, flags, thickness);
Path.Clear();
}
/**
* Fill a Path with a Color
* @note **IMPORTANT: ** Paths need to be setup clockwise
* to be rendered correctly
* @param clr Fill Color
*/
void PathFill(const UI7Color& clr) {
AddConvexPolyFilled(Path, clr);
Path.Clear();
}
void PathArcToN(const fvec2& c, float radius, float a_min, float a_max,
int segments);
/// @brief Create a Path Rect (uses to Positions instead of Pos/Size)
/// @param a Top Left Position
/// @param b Bottom Right Position
/// @param rounding rounding
/// @param flags DrawFlags (for special rounding rules)
void PathRect(fvec2 a, fvec2 b, float rounding = 0.f, UI7DrawFlags flags = 0);
int Layer; ///< Layer
int Base; ///< Base Layer
Stack<fvec4> pClipRects; ///< ClipRects
u32 NumVertices; ///< Num vertices
u32 NumIndices; ///< Num Indices
UI7::IO* pIO; ///< IO Reference
LI::Texture::Ref CurrentTex; ///< Current Texture
private:
/**
* One liner to setup command cliprect
*/
void ClipCmd(LI::Command::Ref cmd);
// Set friendclass here to not expose private functions as public
friend class Menu;
friend class Context;
Vec<fvec2> Path;
// Map for Auto Static Text
// std::unordered_map<u32, LI::StaticText::Ref> static_text;
// List of Drawcommands generated
Vec<LI::Command::Ref> Commands;
};
} // namespace UI7
} // namespace PD

0
include/pd/ui7/flags.hpp Normal file → Executable file
View File

141
include/pd/ui7/id.hpp Normal file → Executable file
View File

@ -1,72 +1,71 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
namespace PD {
namespace UI7 {
/**
* ID Class (Generating an ID by String)
*/
class ID {
public:
/**
* Constructor to Generate ID by input string
* @param text Input String
*/
ID(const std::string& text) {
id = PD::Strings::FastHash(text);
name = text;
}
/**
* Constructor used for const char* which is automatically
* used when directly placing a string istead of using ID("")
* @param text Input String
*/
ID(const char* text) {
id = PD::Strings::FastHash(text);
name = text;
}
/**
* Use an ID as Input
*/
ID(u32 id) { this->id = id; }
~ID() = default;
/** Get The ID Initial Name */
const std::string& GetName() const { return name; }
/** Getter for the raw 32bit int id */
const u32& RawID() const { return id; }
/** Return the ID when casting to u32 */
operator u32() const { return id; }
private:
u32 id; ///< Hash of the name
std::string name; ///< Name
};
} // namespace UI7
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
namespace PD {
namespace UI7 {
/**
* ID Class (Generating an ID by String)
*/
class ID {
public:
/**
* Constructor to Generate ID by input string
* @param text Input String
*/
ID(const std::string& text) {
pID = PD::Strings::FastHash(text);
pName = text;
}
/**
* Constructor used for const char* which is automatically
* used when directly placing a string istead of using ID("")
* @param text Input String
*/
ID(const char* text) {
pID = PD::Strings::FastHash(text);
pName = text;
}
/**
* Use an ID as Input
*/
ID(u32 id) { pID = id; }
~ID() = default;
/** Get The ID Initial Name */
const std::string& GetName() const { return pName; }
/** Getter for the raw 32bit int id */
const u32& RawID() const { return pID; }
/** Return the ID when casting to u32 */
operator u32() const { return pID; }
u32 pID; ///< Hash of the name
std::string pName; ///< Name
};
} // namespace UI7
} // namespace PD

34
include/pd/ui7/input_api.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -24,19 +25,19 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/lithium/lithium.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/pd_p_api.hpp>
namespace PD {
namespace UI7 {
class InputHandler : public SmartCtor<InputHandler> {
class InputHandler {
public:
InputHandler(Hid::Ref inp_drv) {
DragTime = Timer::New(false);
Inp = inp_drv;
}
InputHandler() { DragTime = Timer::New(false); }
~InputHandler() = default;
PD_SHARED(InputHandler);
/**
* Function to Check if current Object is dragged
* or set it dragged
@ -55,9 +56,9 @@ class InputHandler : public SmartCtor<InputHandler> {
}
}
// Get a Short define for touch pos
vec2 p = Inp->TouchPos();
fvec2 p = Hid::MousePos();
// Check if Drag starts in the area position
if (Inp->IsDown(Inp->Touch) && LI::Renderer::InBox(p, area)) {
if (Hid::IsDown(Hid::Key::Touch) && Li::Renderer::InBox(p, area)) {
// Set ID and iniatial Positions
DraggedObject = id;
DragSourcePos = p;
@ -68,22 +69,22 @@ class InputHandler : public SmartCtor<InputHandler> {
DragTime->Reset();
DragTime->Rseume();
return false; // To make sure the Object is "Dragged"
} else if (Inp->IsHeld(Inp->Touch) && IsObjectDragged()) {
} else if (Hid::IsHeld(Hid::Key::Touch) && IsObjectDragged()) {
// Update DragLast and DragPoisition
DragLastPosition = DragPosition;
DragPosition = p;
} else if (Inp->IsUp(Inp->Touch) && IsObjectDragged()) {
} else if (Hid::IsUp(Hid::Key::Touch) && IsObjectDragged()) {
// Released... Everything gets reset
DraggedObject = 0;
DragPosition = 0;
DragSourcePos = 0;
DragLastPosition = 0;
DragDestination = 0;
DragDestination = fvec4(0);
// Set Drag released to true (only one frame)
// and Only if still in Box
DragReleased = LI::Renderer::InBox(Inp->TouchPosLast(), area);
DragReleased = Li::Renderer::InBox(Hid::MousePosLast(), area);
DragReleasedAW = true; // Advanced
u64 d_rel = Sys::GetTime();
u64 d_rel = PD::OS::GetTime();
if (d_rel - DragLastReleased < DoubleClickTime) {
DragDoubleRelease = true;
DragLastReleased = 0; // Set 0 to prevent double exec
@ -115,7 +116,8 @@ class InputHandler : public SmartCtor<InputHandler> {
fvec2 DragSourcePos = 0;
fvec2 DragPosition = 0;
fvec2 DragLastPosition = 0;
fvec4 DragDestination = 0;
/** Fvec4 has an constructor problem currently */
fvec4 DragDestination = fvec4(0);
Timer::Ref DragTime;
u64 DragLastReleased = 0;
bool DragReleased = false; ///< Drag Releaded in Box
@ -123,8 +125,6 @@ class InputHandler : public SmartCtor<InputHandler> {
bool DragDoubleRelease = false; ///< Double Click
/** Check if an object is Dragged already */
bool IsObjectDragged() const { return DraggedObject != 0; }
Hid::Ref Inp;
};
} // namespace UI7
} // namespace PD

64
include/pd/ui7/io.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -24,53 +25,43 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/input_api.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/ui7/theme.hpp>
#include <pd/ui7/viewport.hpp>
namespace PD {
namespace UI7 {
/**
* Shared Configuration and Runtime Data for a UI7 Context
*/
class PD_UI7_API IO : public SmartCtor<IO> {
class PD_UI7_API IO {
public:
/**
* IO Constructor setting UP References
*/
IO(Hid::Ref input_driver, LI::Renderer::Ref ren) {
IO() {
Time = Timer::New();
InputHandler = UI7::InputHandler::New(input_driver);
InputHandler = InputHandler::New();
Theme = UI7::Theme::New();
Inp = input_driver;
Ren = ren;
Back = UI7::DrawList::New(this);
Front = UI7::DrawList::New(this);
pRDL = LI::DrawList::New(Ren->WhitePixel);
DrawListRegestry.PushFront(
Pair<UI7::ID, DrawList::Ref>("CtxBackList", Back));
// RegisterDrawList("CtxBackList", Back);
Back = Li::DrawList::New();
Front = Li::DrawList::New();
DeltaStats = TimeStats::New(60);
};
~IO() = default;
/** Probably not the best solution i guess */
CurrentViewPort.z = PD::Li::Gfx::pGfx->ViewPort.x;
CurrentViewPort.w = PD::Li::Gfx::pGfx->ViewPort.y;
}
~IO() {}
PD_SHARED(IO);
/**
* IO Update Internal Variables
*/
void Update();
ivec4 CurrentViewPort = ivec4(0, 0, 0, 0);
std::unordered_map<u32, ViewPort::Ref> ViewPorts;
float Framerate = 0.f;
float Delta = 0.f;
u64 LastTime = 0;
TimeStats::Ref DeltaStats;
Timer::Ref Time;
Hid::Ref Inp;
LI::Renderer::Ref Ren;
LI::DrawList::Ref pRDL;
LI::Font::Ref Font;
Li::Font::Ref Font;
float FontScale = 0.7f;
UI7::Theme::Ref Theme;
fvec2 MenuPadding = 5.f;
@ -81,21 +72,28 @@ class PD_UI7_API IO : public SmartCtor<IO> {
bool ShowFrameBorder = false; // not implemented yet
float OverScrollMod = 0.15f;
u64 DoubleClickTime = 500; // Milliseconds
PD::List<Pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
PD::List<Pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
// Short define for DrawKistRegestryLast
PD::List<Pair<UI7::ID, DrawList::Ref>> pDLRL;
// std::vector<std::pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
DrawList::Ref Back;
DrawList::Ref Front;
PD::List<Pair<UI7::ID, Li::DrawList::Ref>> pDLRL;
// std::vector<std::pair<UI7::ID, Li::DrawList::Ref>> DrawListRegestry;
Li::DrawList::Ref Back;
Li::DrawList::Ref Front;
u32 NumVertices = 0; ///< Debug Vertices Num
u32 NumIndices = 0; ///< Debug Indices Num
Vec<u32> MenuOrder;
// DrawListApi
void RegisterDrawList(const UI7::ID& id, DrawList::Ref v) {
void RegisterDrawList(const UI7::ID& id, Li::DrawList::Ref v) {
DrawListRegestry.PushBack(Pair(id, v));
}
void AddViewPort(const ID& id, const ivec4& size) {
if (ViewPorts.count(id)) {
return;
}
ViewPorts[id] = ViewPort::New(id, size);
}
UI7::InputHandler::Ref InputHandler;
};
} // namespace UI7

20
include/pd/ui7/layout.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -25,27 +26,30 @@ SOFTWARE.
#include <pd/core/core.hpp>
#include <pd/ui7/container/container.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/input_api.hpp>
#include <pd/ui7/pd_p_api.hpp>
#include <pd/ui7/theme.hpp>
namespace PD {
namespace UI7 {
class PD_UI7_API Layout : public PD::SmartCtor<Layout> {
class PD_UI7_API Layout {
public:
Layout(const ID& id, IO::Ref io) : ID(id) {
this->IO = io;
DrawList = UI7::DrawList::New(io.get());
DrawList = Li::DrawList::New();
DrawList->SetFont(IO->Font);
Scrolling[0] = false;
Scrolling[1] = false;
CursorInit();
Pos = fvec2(0, 0);
Size = fvec2(320, 240);
Size = fvec2(io->CurrentViewPort.z, io->CurrentViewPort.w);
WorkRect = fvec4(IO->MenuPadding, Size - (fvec2(2) * IO->MenuPadding));
}
~Layout() = default;
PD_SHARED(Layout);
const std::string& GetName() const { return ID.GetName(); }
const UI7::ID& GetID() const { return this->ID; }
@ -54,7 +58,7 @@ class PD_UI7_API Layout : public PD::SmartCtor<Layout> {
const fvec2& GetSize() const { return Size; }
void SetSize(const fvec2& v) { Size = v; }
UI7::DrawList::Ref GetDrawList() { return DrawList; }
Li::DrawList::Ref GetDrawList() { return DrawList; }
void CursorInit();
void SameLine();
@ -104,7 +108,7 @@ class PD_UI7_API Layout : public PD::SmartCtor<Layout> {
// Base Components
UI7::ID ID;
UI7::IO::Ref IO;
UI7::DrawList::Ref DrawList;
Li::DrawList::Ref DrawList;
// Positioning
fvec2 Pos;

275
include/pd/ui7/menu.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -23,278 +24,90 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "pd/ui7/container/dragdata.hpp"
#include <pd/core/core.hpp>
#include <pd/ui7/containers.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/layout.hpp>
#include <pd/ui7/pd_p_api.hpp>
namespace PD {
namespace UI7 {
/** Menu Class for UI7 */
class PD_UI7_API Menu : public SmartCtor<Menu> {
public:
/**
* Menu COnstructor (Unly used by UI7::Context)
* @param id ID of the Menu
* @param io IO Config Reference
*/
Menu(ID id, UI7::IO::Ref io) {
/// Setup the Input Data
this->io = io;
this->id = id;
this->name = id.GetName();
/// Set Default Values here
scrollbar[0] = false;
scrollbar[1] = false;
scroll_allowed[0] = false;
scroll_allowed[1] = false;
Layout = UI7::Layout::New(id, io);
}
~Menu() = default;
class PD_UI7_API Menu {
public:
Menu(const UI7::ID &id, UI7::IO::Ref pIO);
~Menu() {}
// Objects
PD_SHARED(Menu);
/**
* Render a Simple Label
* @param label The text to draw
*/
void Label(const std::string& label);
void Label(const std::string &label);
/**
* Render a Button
* @param label The buttons text
* @return if the button was pressed
*/
bool Button(const std::string& label);
bool Button(const std::string &label);
/**
* Render a Checkbox
* @param label Label of the Checkbox
* @param v A value to update
*/
void Checkbox(const std::string& label, bool& v);
void Checkbox(const std::string &label, bool &v);
/**
* Render an Image
* @param img Texture reference of the image
* @param size a Custom Size if needed
*/
void Image(LI::Texture::Ref img, fvec2 size = 0.f, LI::Rect uv = fvec4(0));
void Image(Li::Texture::Ref img, fvec2 size = 0.f, Li::Rect uv = fvec4(0));
/**
* Color Edit Object that opens a popup editor if clicked
* @param label Name of the Edit field
* @param color Color reference to edit
* Render a Drag Object witth any supported type:
* [`int`, `float`, `double`, `u8`, `u16`, `u32`]
* @param label Name of the Drag
* @param data Reference to Data Object (can be multiple as well)
* @param num_elements Defien the number of Elements in the Data addr
* @param precission Difine the Format string len for float/double
*/
void ColorEdit(const std::string& label, u32* color);
void DragFloat(const std::string& label, float* data, size_t num_elms);
template <typename T>
void DragData(const std::string& label, T* data, size_t num_elms = 1,
void DragData(const std::string &label, T *data, size_t num_elms = 1,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), T step = 1,
int precision = 1) {
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
Container::Ref r = Layout->FindObject(id);
Container::Ref r = pLayout->FindObject(id);
if (!r) {
r = PD::New<UI7::DragData<T>>(label, data, num_elms, io, min, max, step,
precision);
r = UI7::DragData<T>::New(label, data, num_elms, pIO, min, max, step,
precision);
// Isnt This exactly the same line???
// r = UI7::DragData<T>::New(label, data, num_elms, pIO, min, max, step,
// precision);
r->SetID(id);
}
Layout->AddObject(r);
pLayout->AddObject(r);
}
// Basic API
/**
* Create a Tree Node
* @param id String ID of the Node
* @return node open or not
*/
bool BeginTreeNode(const UI7::ID& id);
/**
* End a Tree Node
*/
void EndTreeNode();
/** Add the Next Objext to the same line */
void SameLine() { Layout->SameLine(); }
/** Add a Separator Line */
void Sameline() { pLayout->SameLine(); }
void Separator();
/**
* Render a Separator Line with a Text
* @todo determinate text position by current alignment
* @param label The Text to show
*/
void SeparatorText(const std::string& label);
/** Put the last Added Object into the Joinlist */
void Join();
/**
* Add the Last element to the join list
* and perform an alignment operation
* @param a Alignment Oeration(s)
*/
void JoinAlign(UI7Align a);
/**
* Align the Last Object
* @param a Alignment Operation
*/
void AfterAlign(UI7Align a);
/**
* Set a Temp alignment op for the next Object
* @param a Alignment Operation
*/
void NextAlign(UI7Align a) { Layout->NextAlign(a); }
/**
* Align Every Single Object by this operationset
* @param a Alignment
*/
void PushAlignment(UI7Align a) { Layout->SetAlign(a); }
/** Use default alignment */
void PopAlignment() { Layout->Alignment = UI7Align_Default; }
/**
* Returns a Reference to the theme
* @return Reference to the base Theme of the context
*/
Theme::Ref GetTheme() { return io->Theme; }
/**
* Directly return a Color by using the
* m->ThemeColor(UI7Color_Text) for example
* @param clr The Input UI7 Color
* @return The 32bit color value
*/
u32 ThemeColor(UI7Color clr) const { return io->Theme->Get(clr); }
void SeparatorText(const std::string &label);
/**
* Get IO Reference
* @return io Reference
*/
UI7::IO::Ref GetIO() { return io; }
void HandleFocus();
void HandleScrolling();
void HandleTitlebarActions();
void DrawBaseLayout();
// API for Custom Objects
void Update();
/** Return if a Vertical Scrollbar exists */
bool HasVerticalScrollbar() { return scrollbar[1]; }
/** Return if a Horizontal Scrollbar exists */
bool HasHorizontalScrollbar() { return scrollbar[0]; }
/** Get the Titlebar height */
float TitleBarHeight() { return tbh; }
/**
* Set a Custom Titlebar heigt
* @note Could destroy some basic functionality
*/
void TitleBarHeight(float v) { tbh = v; }
/** Data Section */
/**
* Animated Scroll to Position
* @param pos Destination Position
*/
void ScrollTo(fvec2 pos) {
scroll_anim.From(Layout->ScrollOffset)
.To(pos)
.In(1.f)
.As(scroll_anim.EaseInOutSine);
}
/** Check if Still in ScrollAnimation */
bool IsAnimatedScroll() { return !scroll_anim.IsFinished(); }
UI7MenuFlags Flags = 0;
Layout::Ref pLayout;
IO::Ref pIO;
ID pID;
bool *pIsShown = nullptr;
bool pIsOpen = true;
// Objects API
/**
* Create a Parent Container to move and edit all sub
* instances at once
*/
void CreateParent();
/** Destory the parent container (if one active) */
void DestroyParent() { tmp_parent = nullptr; }
// Draw List
/** Get DrawList */
DrawList::Ref GetDrawList() { return Layout->DrawList; }
UI7::Layout::Ref GetLayout() { return Layout; }
// Advanced
/**
* Display Debug Labels of a Menu
* @param m Menu to display Data from
* @param t Target to Write the Labels into
*/
static void DebugLabels(Menu::Ref m, Menu::Ref t = nullptr);
// Uneditable Stuff
/** Menu Name */
std::string GetName() const { return name; }
/** Menu ID [Hash of the Name] */
u32 GetID() const { return id; }
private:
// Advanced Handlers
/**
* Setup for the Menu
* @param flags Menu Flags
*/
void PreHandler(UI7MenuFlags flags);
/** Handle things like scrolling */
void PostHandler();
/** Internal Processing */
void Update(float delta);
// Put some Buttons and functionality into its own functions
/** Handler of the Close Button (if exists) */
void CloseButtonHandler();
/** Handler of the Resize Dragging (lower right corner) */
void ResizeHandler();
/** Logic of the Titlebar Movement */
void MoveHandler();
/** Menu Collapse Button Handler */
void CollapseHandler();
/** Scroll Handler (Includes Slider Drag) */
void PostScrollHandler();
/** Handler to Set menu focused or not */
void MenuFocusHandler();
// This ability is crazy useful
friend class Context;
// Data
UI7MenuFlags flags = 0; ///< Menu Flags
u32 id; ///< Menu ID
std::string name; ///< Menu Name
float tbh; ///< Titlebar height
bool scrollbar[2]; ///< Is Hz or Vt Scrollbar rendered
bool scroll_allowed[2]; ///< Is Hz or Vt Scrolling Alowed
bool has_touch; ///< Menu has touch (depends on screen)
bool is_open = true; ///< For Collapse Event
bool* is_shown = nullptr; ///< For Close Button
Container::Ref tmp_parent; ///< Parent Container (for better alignment etc)
// Objects API
std::vector<Container*> join; ///< List of Combined Objects
int count_btn = 0; ///< Count for Button ID Prefix
int count_cbx = 0; ///< Cound for Checkbox ID Prefix
UI7::IO::Ref io; ///< IO Reference
std::map<u32, bool> tree_nodes; ///< Map of Tree nodes
// Animations System
Tween<fvec2> scroll_anim; ///< for Scroll to Animation
// Layout API
PD::UI7::Layout::Ref Layout;
UI7Color clr_close_btn = UI7Color_FrameBackground;
UI7Color clr_collapse_tri = UI7Color_FrameBackground;
UI7Color header = UI7Color_HeaderDead;
float TitleBarHeight = 0.f;
};
} // namespace UI7
} // namespace PD
} // namespace UI7
} // namespace PD

9
include/pd/ui7/pd_p_api.hpp Normal file → Executable file
View File

@ -2,8 +2,7 @@
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -22,9 +21,9 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
*/
#pragma once
/** Generated with ppam */
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_UI7_BUILD_SHARED
@ -49,4 +48,4 @@ SOFTWARE.
#define PD_UI7_API
#else
#define PD_UI7_API
#endif
#endif

View File

@ -1,107 +0,0 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/ui7/layout.hpp>
namespace PD {
namespace UI7 {
/**
* ReMenu (Should get something like MenuBase or so)
* to define basic functionality and extend it by using this as a
* template class
*/
class PD_UI7_API ReMenu {
public:
ReMenu(const UI7::ID& id, UI7::IO::Ref io) : pID(id) {
pLayout = UI7::Layout::New(id, io);
pIO = io;
TitleBarHeight = io->FontScale * 30.f;
pLayout->WorkRect.y += TitleBarHeight;
pLayout->CursorInit();
}
~ReMenu() = default;
/** Using the Legacy version here */
PD_SMART_CTOR(ReMenu)
/**
* Render a Simple Label
* @param label The text to draw
*/
void Label(const std::string& label);
/**
* Render a Button
* @param label The buttons text
* @return if the button was pressed
*/
bool Button(const std::string& label);
/**
* Render a Checkbox
* @param label Label of the Checkbox
* @param v A value to update
*/
void Checkbox(const std::string& label, bool& v);
/**
* Render an Image
* @param img Texture reference of the image
* @param size a Custom Size if needed
*/
void Image(LI::Texture::Ref img, fvec2 size = 0.f, LI::Rect uv = fvec4(0));
template <typename T>
void DragData(const std::string& label, T* data, size_t num_elms = 1,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), T step = 1,
int precision = 1) {
u32 id = Strings::FastHash("drd" + label + std::to_string((uintptr_t)data));
Container::Ref r = pLayout->FindObject(id);
if (!r) {
r = PD::New<UI7::DragData<T>>(label, data, num_elms, pIO, min, max, step,
precision);
r->SetID(id);
}
pLayout->AddObject(r);
}
void Sameline() { pLayout->SameLine(); }
void Separator();
void SeparatorText(const std::string& label);
void HandleFocus();
void HandleScrolling();
void HandleTitlebarActions();
void DrawBaseLayout();
void Update();
UI7MenuFlags Flags = 0;
UI7::Layout::Ref pLayout;
UI7::IO::Ref pIO;
UI7::ID pID;
bool* pIsShown = nullptr;
bool pIsOpen = true;
float TitleBarHeight = 0.f;
};
} // namespace UI7
} // namespace PD

43
include/pd/ui7/theme.hpp Normal file → Executable file
View File

@ -55,16 +55,16 @@ enum UI7Color_ {
namespace PD {
namespace UI7 {
/** Theme Class */
class PD_UI7_API Theme : public SmartCtor<Theme> {
class PD_UI7_API Theme {
public:
/**
* Default Constructor Setting up the Default theme
* @note if using SmartCtor Reference you probably need to do
* @note if using Shared Reference you probably need to do
* Theme::Default(*theme.get());
*/
Theme() { Default(*this); }
~Theme() = default;
~Theme() {}
PD_SHARED(Theme);
/**
* Simple static Loader for the Default Theme
@ -79,9 +79,9 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
/** Revert the last Color Change */
Theme& Pop() {
theme[changes[changes.size() - 1].first] =
changes[changes.size() - 1].second;
changes.pop_back();
pTheme[pChanges[pChanges.size() - 1].first] =
pChanges[pChanges.size() - 1].second;
pChanges.pop_back();
return *this;
}
@ -90,10 +90,10 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param c Color to revert change from
*/
Theme& Pop(UI7Color c) {
for (size_t i = changes.size() - 1; i > 0; i--) {
if (changes[i].first == c) {
theme[c] = changes[i].second;
changes.erase(changes.begin() + i);
for (size_t i = pChanges.size() - 1; i > 0; i--) {
if (pChanges[i].first == c) {
pTheme[c] = pChanges[i].second;
pChanges.erase(pChanges.begin() + i);
break;
}
}
@ -106,11 +106,11 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param color Color to change to
*/
Theme& Change(UI7Color tc, u32 color) {
if (theme.find(tc) == theme.end()) {
if (pTheme.find(tc) == pTheme.end()) {
return *this;
}
changes.push_back(std::make_pair(tc, theme[tc]));
theme[tc] = color;
pChanges.push_back(std::make_pair(tc, pTheme[tc]));
pTheme[tc] = color;
return *this;
}
@ -119,8 +119,8 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param c ReferenceID
*/
u32 Get(UI7Color c) const {
auto e = theme.find(c);
if (e == theme.end()) {
auto e = pTheme.find(c);
if (e == pTheme.end()) {
return 0x00000000;
}
return e->second;
@ -132,8 +132,8 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param c ReferenceID
*/
u32& GetRef(UI7Color c) {
auto e = theme.find(c);
if (e == theme.end()) {
auto e = pTheme.find(c);
if (e == pTheme.end()) {
static u32 noclr = 0x00000000;
return noclr;
}
@ -151,11 +151,10 @@ class PD_UI7_API Theme : public SmartCtor<Theme> {
* @param tc Color ID (Can be self creeated ones as well)
* @param clr Color it should be set to
*/
void Set(UI7Color tc, u32 clr) { theme[tc] = clr; }
void Set(UI7Color tc, u32 clr) { pTheme[tc] = clr; }
private:
std::unordered_map<u32, u32> theme; ///< Theme Data
std::vector<std::pair<UI7Color, u32>> changes; ///< List of Changes
std::unordered_map<u32, u32> pTheme; ///< Theme Data
std::vector<std::pair<UI7Color, u32>> pChanges; ///< List of Changes
};
} // namespace UI7
} // namespace PD

135
include/pd/ui7/ui7.hpp Normal file → Executable file
View File

@ -2,7 +2,8 @@
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Copyright (c) 2024 - 2025 tobid7
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -23,130 +24,56 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "pd/ui7/flags.hpp"
#include <pd/core/core.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/menu.hpp>
#include <pd/ui7/remenu.hpp>
#include <pd/ui7/theme.hpp>
#include <pd/ui7/pd_p_api.hpp>
/**
* Declare UI7 Version
* Format: 00 00 00 00
* Major Minor Patch Build
* 0x01010000 -> 1.1.0-0
*/
#define UI7_VERSION 0x00040000
#define UI7_VERSION 0x00050000
namespace PD {
namespace UI7 {
/**
* Get UI7 Version String
* @param show_build Ahow build num (mostly unused)
* @param show_build Show build num (mostly unused)
* @return Version String (1.0.0-1 for example)
*/
PD_UI7_API std::string GetVersion(bool show_build = false);
/** Base Context for UI7 */
class PD_UI7_API Context : public SmartCtor<Context> {
public:
/**
* Constructor for UI7 Context
* @param ren Renderer Reference
* @param hid Input Driver Reference
*/
Context(LI::Renderer::Ref ren, Hid::Ref hid) {
/// Set the Internal References
io = IO::New(hid, ren);
}
class PD_UI7_API Context {
public:
Context() { pIO = IO::New(); }
~Context() = default;
/**
* Begin a New Menu
* @param id Menu ID / Name shown in Titlebar
* @param flags Optional flags to change stuff
* @return If the Menu was Created
* (useless as false results in an error screen)
*/
bool BeginMenu(const ID& id, UI7MenuFlags flags = 0, bool* show = nullptr);
bool DoMenuEx(const ID& id, UI7MenuFlags flags,
std::function<void(ReMenu::Ref m)> f);
/**
* Get the Current Menu
* for example for auto m = ctx->GetCurrentMenu
*/
Menu::Ref GetCurrentMenu();
/**
* Find a Menu by its ID to edit things outside of
* the place between Begin and EndMenu
* @param id ID (Menu Name) to search for
*/
Menu::Ref FindMenu(const ID& id);
/**
* Ends the Current Menu
* (to be able to create another one)
*/
PD_SHARED(Context);
void AddViewPort(const ID &id, const ivec4 &vp);
void UseViewPort(const ID &id);
void Update();
bool BeginMenu(const ID &id, UI7MenuFlags flags, bool *pShow = nullptr);
void EndMenu();
/**
* Get Theme reference
* @return Reference to the base Theme of the context
*/
Theme::Ref GetTheme() { return io->Theme; }
/**
*Directly return a Color by using the
* ctx->ThemeColor(UI7Color_Text) for example
* @param clr The Input UI7 Color
* @return The 32bit color value
*/
u32 ThemeColor(UI7Color clr) const { return io->Theme->Get(clr); }
Menu::Ref pGetOrCreateMenu(const ID &id) {
auto menu = pMenus.find(id);
if (menu == pMenus.end()) {
pMenus[id] = Menu::New(id, pIO);
menu = pMenus.find(id);
}
return menu->second;
}
/**
* Update Context (Render menus)
* @param delta deltatime
*/
void Update(float delta);
// Expose DrawLists
/** Background DrawList Reference */
DrawList::Ref BackList() { return io->Back; }
/** Foreground DrawList Reference */
DrawList::Ref FrontList() { return io->Front; }
/**
* Set the Root Layer of the Menu
* @param l Layer
*/
void RootLayer(int l) { root_layer = l; }
/** Get the Root Layer of the Menu */
int RootLayer() const { return root_layer; }
/** Get IO Reference */
IO::Ref GetIO() { return io; }
// Debugging / Demo / About
/** About Menu */
void AboutMenu(bool* show = nullptr);
/** Metrics */
void MetricsMenu(bool* show = nullptr);
/** Style Editor Menu (Includes Theme Editor) */
void StyleEditor(bool* show = nullptr);
private:
// Used in Overlays
int root_layer = 0;
// Map of The Menus by ID
std::unordered_map<u32, Menu::Ref> menus;
std::vector<u32> amenus; ///< Active ones
std::vector<u32> aml; ///< Copy of Active Menus
Menu::Ref current; ///< Current Menu
ReMenu::Ref Current;
// IO
IO::Ref io;
IO::Ref pIO;
/** Current Menu */
Menu::Ref pCurrent = nullptr;
std::vector<u32> pCurrentMenus;
std::unordered_map<u32, Menu::Ref> pMenus;
};
} // namespace UI7
} // namespace PD
} // namespace UI7
} // namespace PD

View File

@ -22,31 +22,25 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
*/
#pragma once
#include <pd/core/core.hpp>
#include <pd/ui7/id.hpp>
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_NET_BUILD_SHARED
#define PD_NET_API __declspec(dllexport)
#else
#define PD_NET_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_NET_BUILD_SHARED
#define PD_NET_API __attribute__((visibility("default")))
#else
#define PD_NET_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_NET_BUILD_SHARED
#define PD_NET_API __attribute__((visibility("default")))
#else
#define PD_NET_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_NET_API
#else
#define PD_NET_API
#endif
namespace PD {
namespace UI7 {
class ViewPort {
public:
ViewPort(const ID& id, const ivec4& size) : pID(id), pSize(size) {}
~ViewPort() {}
PD_SHARED(ViewPort);
ID GetID() const { return pID; }
ivec4& GetSize() { return pSize; }
ID pID;
ivec4 pSize;
};
} // namespace UI7
} // namespace PD