Initial Cross Platform Work

This commit is contained in:
2025-04-24 16:39:24 +02:00
parent dbffb7f316
commit 13c2869ba8
170 changed files with 18611 additions and 10292 deletions

View File

@ -1,231 +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/core/timer.hpp>
#include <pd/core/timetrace.hpp>
#include <pd/lib3ds/drv_hid.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/overlays/message_mgr.hpp>
#include <pd/overlays/overlay_mgr.hpp>
namespace PD {
/**
* Template Class for a User Application on the 3ds
*/
class App {
public:
/**
* alias for AppFlags
*/
using AppFlags = u32;
/**
* App Flags
*
* - Probably only the default Setup should be used
*/
enum AppFlags_ {
AppFlags_None = 0, ///< Do Nothing
AppFLags_UserLoop = 1 << 0, ///< Handle User MainLoop
AppFlags_HandleOverlays = 1 << 1, ///< Process Overlays
AppFlags_HandleMessageMgr = 1 << 2, ///< Process Messages
AppFlags_HandleRendering = 1 << 3, ///< Handle Rendering
/// Default Flags
AppFlags_Default = AppFlags_HandleMessageMgr | AppFlags_HandleOverlays |
AppFlags_HandleRendering | AppFLags_UserLoop,
};
/**
* alias for AppInitFlags
*/
using AppInitFlags = u32;
/**
* App Init Flags
*/
enum AppInitFlags_ {
AppInitFlags_None = 0, ///< Do nothing (probably a useles ability)
AppInitFlags_MountRomfs = 1 << 0, ///< Mount Romfs on PreInit
AppInitFlags_InitGraphics = 1 << 1, ///< Default Init Graphics for GPU use
AppInitFlags_New3dsMode = 1 << 2, ///< Enable New3DS Speedup
AppInitFlags_InitGraphicsNoC3D = 1 << 3, ///< Init GFX for Buf Modification
AppInitFlags_InitLithium = 1 << 4, ///< Init 2D Rendering Engine
/// I dont have a name for this one yet
/// It Inits Internal Directory structure
AppInitFlags_UnnamedOption1 = 1 << 5,
AppInitFlags_InitHwInfo = 1 << 6, ///< Init HwInfo from lib3ds
/// Default App Init Flags
AppInitFlags_Default = AppInitFlags_MountRomfs | AppInitFlags_InitGraphics |
AppInitFlags_New3dsMode | AppInitFlags_InitLithium,
};
/**
* App Constructor that can Optionally set a name for the App
* @param name App Name Defaults to App
*/
App(const std::string& name = "App") {
if (too) {
Error("Only one App can be created at the same time!");
}
this->name = name;
too++;
}
/**
* App Deconstructor
*/
~App() { too--; }
/**
* Templete function where the user can Init his stuff
*/
virtual void Init() {}
/**
* Template function to deinit stuff (most is deinit automatically
* but it is still possible that some things need to be ordered manually)
*/
virtual void Deinit() {}
/**
* Template User MainLoop
* @param delta Delta time
* @param time App Run time
* @return false to exit the App
*/
virtual bool MainLoop(float delta, float time) { return false; }
/**
* Function to actually run the app
*
* Example:
* ```cpp
* int main() {
* UserApp app;
* app.Run();
* return 0;
* }
* ```
*/
void Run();
/**
* Get the Renderer Reference
* @return Renderer Reference
*/
LI::Renderer::Ref Renderer() { return renderer; }
/**
* Get Message Manager Reference
* @return Message Manager Reference
*/
MessageMgr::Ref Messages() { return msg_mgr; }
/**
* Get Overlay Manager Reference
* @return Overlay Manager Reference
*/
OverlayMgr::Ref Overlays() { return overlay_mgr; }
/**
* Get Input Driver Reference
* @return Input Driver Reference
*/
Hid::Ref Input() { return input_mgr; }
/**
* Get Framerate
* @return frames per second
*/
float GetFps() const { return fps; }
/**
* Enable Runtime Feature(s) (AppFlags)
* @param flags Flag(s) to enable
*/
void FeatureEnable(AppFlags flags) { runtimeflags |= flags; }
/**
* Disable Runtime Feature(s) (AppFlags)
* @param flags Flag(s) to disable
*/
void FeatureDisable(AppFlags flags) { runtimeflags &= ~flags; }
/**
* Get Reference Access to runtimeflags
* @return reference to runtimeflags
*/
AppFlags& GetFeatureSet() { return runtimeflags; }
/**
* Get App Datadirectory (if enabled in AppInitFlags)
* @return App Data Directory
*/
std::string GetDataDirectory();
protected:
/**
* Top Screen Reference
*/
Screen::Ref Top;
/**
* Bottom Screen Reference
*/
Screen::Ref Bottom;
/**
* AppInitFlags
*
* - Can only be edited in your App class Constructor
* - Editing them Later will not effect the Deinit Process
* Example:
* ```cpp
* class YourApp : public PD::App {
* public:
* YourApp(): App("YourApp") {
* AppInitFlags |= AppInitFlags_InitLithium;
* }
* }
* ```
*/
AppInitFlags InitFlags = AppInitFlags_Default;
private:
/** Runtime Flags (can be edited) */
AppFlags runtimeflags = AppFlags_Default;
/** Safe Copy to prevent from editing befor Deinit */
AppInitFlags SafeInitFlags = AppInitFlags_Default;
/** PreInit Handler */
void PreInit();
/** Post Deinit Handler */
void PostDeinit();
/** Renderer Reference */
LI::Renderer::Ref renderer;
/** Message Manager */
MessageMgr::Ref msg_mgr;
/** Overlay Manager */
OverlayMgr::Ref overlay_mgr;
/** Input Driver */
Hid::Ref input_mgr;
/** Timer to track the App Runtime */
Timer::Ref app_time;
/** Last Time (for delta time and fps calculation) */
u64 last_time;
/** Framerate */
float fps;
/** App Name */
std::string name;
/** A static variable to make sure only one App instance can exist */
static int too;
};
} // 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/common.hpp>
namespace PD {
/**
* Language System
*
* - Translations are saved into json files
* - path should point to a directory containing the json files
* - example for filenames: `en.json`, `de.json`, `fr.json`
*/
class Lang : public SmartCtor<Lang> {
public:
Lang() = default;
~Lang() = default;
/**
* Function to set the path to search for Language files
* @param path Path to search the files
*/
void SetBasePath(const std::string &path) { langs_path = path; }
/**
* Load a language file by the language key
* @param lang_key Language key for example `de`
*/
void Load(const std::string &lang_key) {
LoadFile(langs_path + "/" + lang_key + ".json");
}
/**
* Directly load a Language file from a specific path
* @param path Path to load the file from
*/
void LoadFile(const std::string &path);
/**
* Get a String by a `Keyword`
* @param k Keyword to search for
* @return Returns the string or if none found it returns the Keyword
*/
const std::string &Get(const std::string &k);
/**
* Get the Language Name
* @return Returns the Language Name
*/
const std::string &GetName() { return lang_name; }
/**
* Get the Language ID / Key
* @return Returns the Language ID
*/
const std::string &GetID() { return lang_id; }
/**
* Get the Language Author(s)
* @return Returns the Author(s) of the Language file
*/
const std::string &GetAuthor() { return lang_author; }
/**
* Get the Language File Search Path
* @return Returns Path where the Files are searched for
*/
const std::string &GetPath() { return langs_path; }
private:
const int ver = 0;
/** Language Files Root path */
std::string langs_path = "romfs:/lang";
/** Language Name */
std::string lang_name;
/** Language ID / Key */
std::string lang_id;
/** Language Author */
std::string lang_author;
/** KEY - STRING Table for faster Key access */
std::map<std::string, std::string> ltable;
};
} // namespace PD

View File

@ -36,12 +36,12 @@ namespace BitUtil {
* @param v 32 bit unsigned int
* @return true if its a single bit number
*/
bool IsSingleBit(u32 v);
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
*/
u32 GetPow2(u32 v);
PD_CORE_API u32 GetPow2(u32 v);
} // namespace BitUtil
} // namespace PD

View File

@ -36,7 +36,7 @@ namespace PD {
* - Supports 32Bit input color
* @note Safetey checks are disabled for maximum performance
*/
class Color {
class PD_CORE_API Color {
public:
/**
* Default Constructor (all variables are set to 0)

View File

@ -38,6 +38,17 @@ SOFTWARE.
#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
@ -90,31 +101,31 @@ namespace LibInfo {
* Get the Compiler Name and Version the lib got Compiled with
* @return Compiler Name / Version
*/
const std::string CompiledWith();
PD_CORE_API const std::string CompiledWith();
/**
* Get the C++ Version used to compile the lib
* @return C++ Version (__cplusplus)
*/
const std::string CxxVersion();
PD_CORE_API const std::string CxxVersion();
/**
* Get the Buildtime of the Library
* @return Build Time
*/
const std::string BuildTime();
PD_CORE_API const std::string BuildTime();
/**
* Get the Library Version
* @return Library Version String
*/
const std::string Version();
PD_CORE_API const std::string Version();
/**
* Get the Git Commit the Lib got compiled in
* @return Git Commit 7digit short hash
*/
const std::string Commit();
PD_CORE_API const std::string Commit();
/**
* Get the Git Branch which was active when compiling the lib
* @return Git Branch
*/
const std::string Branch();
PD_CORE_API const std::string Branch();
} // namespace LibInfo
} // namespace PD

View File

@ -1,40 +1,39 @@
#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 {
/**
* Function to Throw an Error Screen
* @param error Error Message to Display
*/
void Error(const std::string& error);
/**
* Custom Assert Function that Shows an Error Screen if it fails
* @param v The bool var to check `(Throws error if it is false)`
* @param msg The Message that Should be displayed if the Assert fails
*/
void Assert(bool v, const std::string& msg);
} // 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/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>
#include <pd/core/vec.hpp>

View File

@ -28,7 +28,7 @@ SOFTWARE.
namespace PD {
/** Input Driver Template class */
class Hid : public SmartCtor<Hid> {
class PD_CORE_API Hid : public SmartCtor<Hid> {
public:
/** Key [Controller] */
enum Key : u32 {
@ -67,19 +67,19 @@ class Hid : public SmartCtor<Hid> {
Event_Held, ///< Key Held
Event_Up, ///< Key released
};
Hid() = default;
Hid(const std::string& name = "NullBackend") : pName(name) {}
~Hid() = default;
/**
* Get TOuch Position
* @return touch pos
*/
vec2 TouchPos() const { return touch[0]; }
fvec2 TouchPos() const { return touch[0]; }
/**
* Get Last Touch Position (from last frame)
* @return touch pos
*/
vec2 TouchPosLast() const { return touch[1]; }
fvec2 TouchPosLast() const { return touch[1]; }
/**
* Check for a Button Event
@ -157,13 +157,16 @@ class Hid : public SmartCtor<Hid> {
*/
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 */
vec2 touch[2];
fvec2 touch[2];
/** locked state */
bool locked = false;
/** Key event tables */

View File

@ -35,12 +35,12 @@ namespace IO {
* @param path Path to the File
* @return 8Bit FileBuffer
*/
std::vector<u8> LoadFile2Mem(const std::string& path);
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
/**
* Hash a 8Bit Memory Buffer
* @param data 8Bit input Buffer
* @return 32Bit Hash
*/
u32 HashMemory(const std::vector<u8>& data);
PD_CORE_API u32 HashMemory(const std::vector<u8>& data);
} // namespace IO
} // namespace PD

View File

@ -1,103 +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 {
class Markdown {
public:
Markdown() = default;
~Markdown() = default;
void Header(const std::string& hdr, int lvl = 2) {
if (task != 0 || lvl < 1 || lvl > 10) {
return;
}
/// Directly create the string with its amount of #
std::string str(lvl, '#');
str += " ";
str += hdr;
s << str << std::endl << std::endl;
}
void BeginTable(const std::vector<std::string>& head) {
if (task != 0) {
return;
}
ctc = head.size();
for (auto& it : head) {
s << "| " << it << " ";
}
s << "|\n";
for (int i = 0; i < ctc; i++) {
s << "|---";
}
s << "|\n";
task = 1;
}
Markdown& TableAddEntry(const std::string& e) {
if (task != 1) {
return *this;
}
ctci++;
s << "| " << e << " ";
if (ctci == ctc) {
s << "|\n";
ctci = 0;
}
return *this;
}
void EndTable() {
if (task != 1) {
return;
}
s << std::endl;
task = 0;
}
void Write(const std::string& path) {
std::ofstream f(path);
if (!f) {
return;
}
f << s.str();
f.close();
}
private:
/// @brief Tasks
/// 0 = free
/// 1 = table
/// 2 = text
int task = 0;
/// @brief Current Table Columns
int ctc = 0;
/// @brief Current Table Column Index
int ctci = 0;
std::stringstream s;
};
} // namespace PD

View File

@ -1,36 +1,41 @@
#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 <3ds.h>
#include <pd/core/common.hpp>
#include <pd/core/markdown.hpp>
namespace PD {
class ResultDecoder {
public:
ResultDecoder(Result res);
};
#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 {
class PD_CORE_API Mat4 {
public:
Mat4() { Zeros(); }
~Mat4() = default;
void Zeros();
void Ortho(float left, float right, float bottom, float top, float near,
float far);
float m[16];
};
} // namespace PD

View File

@ -1,57 +1,50 @@
#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 {
/**
* static Namespace containing Access to some 3ds Hardware Info
*/
namespace HwInfo {
/**
* Init connecttion to required sys modules
*/
void Init();
/**
* Deinit connection to sys modules
*/
void Deinit();
/**
* Check if the Console is Charging
* @return true if the console is charging
*/
bool IsCharging();
/**
* Get the Current Battery Percentage
* @return Battery Percentage (from 0 to 100)
*/
int GetBatteryPercentage();
/**
* Get Current Wifi Level
* @return wifi level (0 to 4)
*/
int GetWifiLevel();
} // namespace HwInfo
} // 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.
*/
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_CORE_BUILD_SHARED
#define PD_CORE_API __declspec(dllexport)
#else
#define PD_CORE_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_CORE_BUILD_SHARED
#define PD_CORE_API __attribute__((visibility("default")))
#else
#define PD_CORE_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_CORE_BUILD_SHARED
#define PD_CORE_API __attribute__((visibility("default")))
#else
#define PD_CORE_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_CORE_API
#else
#define PD_CORE_API
#endif

View File

@ -1,73 +1,51 @@
#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/drivers/hid.hpp>
namespace PD {
/**
* Simple Table Containing the codepoint references
* for the Controller Icons on the 3ds
*/
namespace GamePadIcons {
/**
* Icon ID
*/
enum ID {
A,
B,
X,
Y,
L,
R,
Dpad,
Start,
Select,
Home,
Steps,
PlayCoin,
AnalogStick,
Power3DS,
DpadUp,
DpadDown,
DpadLeft,
DpadRight,
DpadHorizontal,
DpadVertical,
};
/**
* Get Icon by ID
* @param id ID to Get
* @return codepoint
*/
std::string GetIcon(ID id);
/**
* Get Icon By Input Driver Key
* @param key Key to find
* @return codepoint
*/
std::string GetIcon(Hid::Key key);
} // namespace GamePadIcons
#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 {
/**
* Custom Allocator for Custom Vec and probably other stuff in future
*/
template <typename T>
class Allocator {
public:
Allocator() = default;
~Allocator() = default;
virtual T* Allocate(size_t n) { return new T[n]; }
virtual T* AllocateRaw(size_t n) {
return reinterpret_cast<T*>(::operator new(sizeof(T) * n));
}
virtual void DeallocateRaw(T* ptr) { operator delete(ptr); }
virtual void Deallocate(T* ptr) { delete[] ptr; }
template <typename... Args>
void Construct(T* ptr, Args&&... args) {
new (ptr) T(std::forward<Args>(args)...);
}
void Destroy(T* ptr) { ptr->~T(); }
};
} // namespace PD

View File

@ -0,0 +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];
};
} // namespace PD

210
include/pd/core/sl/list.hpp Normal file
View File

@ -0,0 +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;
};
} // namespace PD

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
@ -21,20 +22,20 @@ 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 to Everything that has to
* do with the 3ds (very empty currently)
*/
namespace Ctr {
/**
* Get the System Language key (for lang system)
* @return language key
*/
std::string GetSystemLanguage();
} // namespace Ctr
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

View File

@ -1,10 +1,9 @@
// THIS FILE WAS GENERATED BY build_shaders.py!!!
#pragma once
/*
MIT License
Copyright (c) 2024 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,9 +22,12 @@ 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 <cstddef>
extern unsigned char li7_shader[];
extern size_t li7_shader_size;
#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>

View File

@ -0,0 +1,70 @@
#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/vector.hpp>
namespace PD {
/**
* Custom Stack class (caus std::stack ofsten lead to memory coruption)
*/
template <typename T, typename Alloc = Allocator<T>>
class Stack {
public:
Stack() = default;
explicit Stack(size_t cap) : pVec(cap) {}
void Push(const T& val) { pVec.Add(val); }
void Pop() {
if (pVec.Size() == 0) {
exit(1);
}
pVec.PopBack();
}
T& Top() {
if (pVec.Size() == 0) {
exit(1);
}
return pVec[pVec.Size() - 1];
}
const T& Top() const {
if (pVec.Size() == 0) {
exit(1);
}
return pVec[pVec.Size() - 1];
}
bool IsEmpty() const { return pVec.Size() == 0; }
size_t Size() const { return pVec.Size(); }
void Clear() { pVec.Clear(); }
private:
Vec<T, Alloc> pVec;
};
} // namespace PD

View File

@ -1,45 +1,43 @@
#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/drivers/hid.hpp>
namespace PD {
/**
* Nintendo 3DS Input Driver
*/
class CtrHid : public Hid {
public:
/**
* Constructor to setup Key binds
*/
CtrHid();
~CtrHid() = default;
/**
* Overrideing the Update Function for Input Checking etc
*/
void Update() override;
};
#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 {
/**
* Function to get Arraysize for any type using modern c++ to
* get the size at compiletime instead of runtime
* @note this function only works for Arrays declared as
* type arr[size] and not for pointer references.
* This function will precalculate the size at compile time
* while keeping the code clean to not hardcode arraysizes
* into functions like std::fill_n
*/
template <typename T, size_t N>
constexpr size_t ArraySize(T (&)[N]) noexcept {
return N;
}
} // namespace PD

View File

@ -0,0 +1,165 @@
#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/sl/allocator.hpp>
namespace PD {
/**
* Open Access Vector class (Alternative to std::vector)
*/
template <typename T, typename Alloc = Allocator<T>>
class Vec {
public:
Vec() {
pData = pAllocator.Allocate(2);
pCap = 2;
Clear();
pPos = 0;
};
Vec(const size_t& Size) {
pData = pAllocator.Allocate(Size + 2);
pCap = Size + 2;
Clear();
pPos = Size;
}
Vec(const size_t& Size, const T& v) {
pData = pAllocator.Allocate(Size + 2);
pCap = Size + 2;
Clear();
pPos = Size;
std::fill_n(pData, Size, v);
}
Vec(const T* s, const T* e) {
pData = pAllocator.Allocate(2);
pCap = 2;
Clear();
pPos = 0;
Resize(e - s);
std::copy_n(s, e - s, pData);
}
Vec(const Vec& v) {
pCap = v.pCap;
pPos = v.pPos;
pData = pAllocator.Allocate(pCap);
for (size_t i = 0; i < pPos; i++) {
pData[i] = v.pData[i];
}
}
~Vec() { pAllocator.Deallocate(pData); }
void Add(const T& v) {
if (pPos >= pCap) {
Reserve(pCap * 2);
}
pData[pPos++] = v;
}
void PopBack() {
if (pPos == 0) return;
pPos--;
}
T Pop() {
if (pPos == 0) {
// Todo: LOG
exit(1);
}
return pData[pPos--];
}
T& At(const size_t& Idx) {
if (Idx >= pPos) {
// Log
exit(1);
}
return pData[Idx];
}
const T& At(const size_t& Idx) const {
if (Idx >= pPos) {
// Log
exit(1);
}
return pData[Idx];
}
T& operator[](const size_t& Idx) { return At(Idx); }
const T& operator[](const size_t& Idx) const { return At(Idx); }
void operator+=(T v) { Add(v); }
T* Begin() { return pData; }
const T* Begin() const { return pData; }
T* End() { return pData + pPos; }
const T* End() const { return pData + pPos; }
// Support: `for(auto& it : Vec)` //
T* begin() { return pData; }
const T* begin() const { return pData; }
T* end() { return pData + pPos; }
const T* end() const { return pData + pPos; }
T* Data() { return pData; }
T* Data() const { return pData; }
size_t Size() const { return pPos; }
size_t Capacity() const { return pCap; }
void Clear() {
// Avoid memset to support std::string for now
// probably revert this decision based if it lacks performance
// or make it a setting
std::fill(pData, pData + pCap, T());
pPos = 0;
}
void Reserve(const size_t& Size) {
if (Size <= pCap) return;
T* tmp = pAllocator.Allocate(Size);
std::fill(tmp, tmp + Size, T());
std::copy(pData, pData + pCap, tmp);
pAllocator.Deallocate(pData);
pData = tmp;
pCap = Size;
}
void Resize(size_t Size) {
if (Size < pPos) {
pPos = Size;
} else if (Size > pCap) {
Reserve(Size);
}
std::fill(pData + pPos, pData + Size, T());
pPos = Size;
}
// Allocator
Alloc pAllocator;
// Data Reference Pointer
T* pData;
// Capacity
size_t pCap;
// Current Position (Size)
size_t pPos;
};
} // namespace PD

View File

@ -36,48 +36,47 @@ namespace Strings {
* @param exts List of Extensions to check for
* @return true if one of the extensions is found in the String
*/
bool StringEndsWith(const std::string& str,
const std::vector<std::string>& exts);
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 Currently using std::filesystem::path for this as wstring_convert
* got removed in c++ 20
* @note Returns Empty if it has an error
*/
std::wstring MakeWstring(const std::string& s);
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
*/
const std::string FormatNanos(unsigned long long nanos);
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
*/
const std::string FormatMillis(unsigned long long millis);
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`
*/
const std::string FormatBytes(unsigned long long bytes);
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
*/
const std::string GetFileName(const std::string& path,
const std::string& saperators = "/\\");
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
*/
const std::string PathRemoveExtension(const std::string& path);
PD_CORE_API const std::string PathRemoveExtension(const std::string& path);
/**
* Function to Convert a Type to a hex value
* @tparam T Type
@ -95,7 +94,7 @@ inline const std::string ToHex(const T& v) {
* @param s String to hash
* @return 32Bit Hash
*/
u32 FastHash(const std::string& s);
PD_CORE_API u32 FastHash(const std::string& s);
/**
* Function to Generate a Compiler Name and Version String
* Based on their Macros
@ -105,14 +104,14 @@ 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 __GNUC__
res << "GCC: " << __GNUC__;
res << "." << __GNUC_MINOR__ << ".";
res << __GNUC_PATCHLEVEL__;
#elif __clang__
#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

View File

@ -39,28 +39,28 @@ using TraceMap = std::map<std::string, TT::Res::Ref>;
* Get Current Time in Milliseconds
* @return 64Bit value of millis
*/
u64 GetTime();
PD_CORE_API u64 GetTime();
/**
* Get Current Time in Nanoseconds
* @return 64Bit value of nanos
*/
u64 GetNanoTime();
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
*/
TT::Res::Ref& GetTraceRef(const std::string& id);
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
*/
bool TraceExist(const std::string& id);
PD_CORE_API bool TraceExist(const std::string& id);
/**
* Get TraceMap Reference
* @return edidable Reference to the TraceMap
*/
TraceMap& GetTraceMap();
PD_CORE_API TraceMap& GetTraceMap();
} // namespace Sys
} // namespace PD

View File

@ -30,7 +30,7 @@ namespace PD {
/**
* Timer class
*/
class Timer : public SmartCtor<Timer> {
class PD_CORE_API Timer : public SmartCtor<Timer> {
public:
/**
* Constructor

View File

@ -211,12 +211,12 @@ class Res : public SmartCtor<Res> {
* Begin a Trace
* @param id Name of the Trace
*/
void Beg(const std::string &id);
PD_CORE_API void Beg(const std::string &id);
/**
* End a Trace
* @param id Name of the Trace
*/
void End(const std::string &id);
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

View File

@ -23,7 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/vec.hpp>
#include <pd/core/common.hpp>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
namespace PD {
/**

View File

@ -1,424 +1,28 @@
#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.
*/
// Why Creating this:
// Cause using makes coding much better structured
// and easy to use like in glsl or glm
#include <pd/core/common.hpp>
namespace PD {
struct vec2 {
// Init Funcs
vec2() {
v[0] = 0;
v[1] = 0;
}
vec2(float x, float y) {
v[0] = x;
v[1] = y;
}
vec2(const vec2 &i) {
v[0] = i[0];
v[1] = i[1];
}
vec2(float i) {
v[0] = i;
v[1] = i;
}
// Operations
// Add
vec2 &operator+=(const vec2 &i) {
v[0] += i[0];
v[1] += i[1];
return *this;
}
vec2 &operator+=(const float &i) {
v[0] += i;
v[1] += i;
return *this;
}
vec2 operator+(const vec2 &i) const { return vec2(v[0] + i[0], v[1] + i[1]); }
vec2 operator+(const float &i) const { return vec2(v[0] + i, v[1] + i); }
// Sub
vec2 &operator-=(const vec2 &i) {
v[0] -= i[0];
v[1] -= i[1];
return *this;
}
vec2 &operator-=(const float &i) {
v[0] -= i;
v[1] -= i;
return *this;
}
vec2 operator-(const vec2 &i) const { return vec2(v[0] - i[0], v[1] - i[1]); }
vec2 operator-(const float &i) const { return vec2(v[0] - i, v[1] - i); }
// Mul
vec2 &operator*=(const vec2 &i) {
v[0] *= i[0];
v[1] *= i[1];
return *this;
}
vec2 &operator*=(const float &i) {
v[0] *= i;
v[1] *= i;
return *this;
}
vec2 operator*(const vec2 &i) const { return vec2(v[0] * i[0], v[1] * i[1]); }
vec2 operator*(const float &i) const { return vec2(v[0] * i, v[1] * i); }
// Div
vec2 &operator/=(const vec2 &i) {
v[0] /= i[0];
v[1] /= i[1];
return *this;
}
vec2 &operator/=(const float &i) {
v[0] /= i;
v[1] /= i;
return *this;
}
vec2 operator/(const vec2 &i) const { return vec2(v[0] / i[0], v[1] / i[1]); }
vec2 operator/(const float &i) const { return vec2(v[0] / i, v[1] / i); }
// Compare
bool operator==(const vec2 &in) const {
return v[0] == in[0] && v[1] == in[1];
}
bool operator!=(const vec2 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
vec2 operator-() const { return vec2(-v[0], -v[1]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const { return v[0] * v[0] + v[1] * v[1]; }
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
// Internal Values
float v[2];
};
struct vec3 {
// Init Funcs
vec3() {
v[0] = 0.f;
v[1] = 0.f;
v[2] = 0.f;
}
vec3(float x, float y, float z) {
v[0] = x;
v[1] = y;
v[2] = z;
}
vec3(const vec3 &i) {
v[0] = i[0];
v[1] = i[1];
v[2] = i[2];
}
vec3(float i) {
v[0] = i;
v[1] = i;
v[2] = i;
}
//// PD REWRITE ADDITIONAL CONTENT ////
vec3(const vec2 &xy, float z) {
v[0] = xy[0];
v[1] = xy[1];
v[2] = z;
}
vec3(float x, const vec2 &yz) {
v[0] = x;
v[1] = yz[0];
v[2] = yz[1];
}
// Operations
// Add
vec3 &operator+=(const vec3 &i) {
v[0] += i[0];
v[1] += i[1];
v[2] += i[2];
return *this;
}
vec3 &operator+=(const float &i) {
v[0] += i;
v[1] += i;
v[2] += i;
return *this;
}
vec3 operator+(const vec3 &i) const {
return vec3(v[0] + i[0], v[1] + i[1], v[2] + i[2]);
}
vec3 operator+(const float &i) const {
return vec3(v[0] + i, v[1] + i, v[2] + i);
}
// Sub
vec3 &operator-=(const vec3 &i) {
v[0] -= i[0];
v[1] -= i[1];
v[2] -= i[2];
return *this;
}
vec3 &operator-=(const float &i) {
v[0] -= i;
v[1] -= i;
v[2] -= i;
return *this;
}
vec3 operator-(const vec3 &i) const {
return vec3(v[0] - i[0], v[1] - i[1], v[2] - i[2]);
}
vec3 operator-(const float &i) const {
return vec3(v[0] - i, v[1] - i, v[2] - i);
}
// Mul
vec3 &operator*=(const vec3 &i) {
v[0] *= i[0];
v[1] *= i[1];
v[2] *= i[2];
return *this;
}
vec3 &operator*=(const float &i) {
v[0] *= i;
v[1] *= i;
v[2] *= i;
return *this;
}
vec3 operator*(const vec3 &i) const {
return vec3(v[0] * i[0], v[1] * i[1], v[2] * i[2]);
}
vec3 operator*(const float &i) const {
return vec3(v[0] * i, v[1] * i, v[2] * i);
}
// Div
vec3 &operator/=(const vec3 &i) {
v[0] /= i[0];
v[1] /= i[1];
v[2] /= i[2];
return *this;
}
vec3 &operator/=(const float &i) {
v[0] /= i;
v[1] /= i;
v[2] /= i;
return *this;
}
vec3 operator/(const vec3 &i) const {
return vec3(v[0] / i[0], v[1] / i[1], v[2] / i[2]);
}
vec3 operator/(const float &i) const {
return vec3(v[0] / i, v[1] / i, v[2] / i);
}
// Compare
bool operator==(const vec3 &in) const {
return v[0] == in[0] && v[1] == in[1] && v[2] == v[2];
}
bool operator!=(const vec3 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
// Base
vec3 operator-() const { return vec3(-v[0], -v[1], -v[2]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const { return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; }
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
float z() const { return v[2]; }
float &z() { return v[2]; }
//// PALLADIUM REWRITE ADDITIONAL CONTENT ////
vec2 xy() const { return vec2(v[0], v[1]); }
vec2 yz() const { return vec2(v[1], v[2]); }
float v[3];
};
struct vec4 {
// Init Funcs
vec4() {
v[0] = 0.f;
v[1] = 0.f;
v[2] = 0.f;
v[3] = 0.f;
}
vec4(float x, float y, float z, float w) {
v[0] = x;
v[1] = y;
v[2] = z;
v[3] = w;
}
vec4(const vec4 &i) {
v[0] = i[0];
v[1] = i[1];
v[2] = i[2];
v[3] = i[3];
}
vec4(const vec2 &i0, const vec2 &i1) {
v[0] = i0[0];
v[1] = i0[1];
v[2] = i1[0];
v[3] = i1[1];
}
vec4(float i) {
v[0] = i;
v[1] = i;
v[2] = i;
v[3] = i;
}
vec4(const vec3 &xyz, float w) {
v[0] = xyz[0];
v[1] = xyz[1];
v[2] = xyz[2];
v[3] = w;
}
vec4(float x, const vec3 &yzw) {
v[0] = x;
v[1] = yzw[1];
v[2] = yzw[2];
v[3] = yzw[3];
}
// Operators
// Add
vec4 &operator+=(const vec4 &i) {
v[0] += i[0];
v[1] += i[1];
v[2] += i[2];
v[3] += i[3];
return *this;
}
vec4 operator+(const vec4 &i) const {
return vec4(v[0] + i[0], v[1] + i[1], v[2] + i[2], v[3] + i[3]);
}
// Sub
vec4 &operator-=(const vec4 &i) {
v[0] -= i[0];
v[1] -= i[1];
v[2] -= i[2];
v[3] -= i[3];
return *this;
}
vec4 operator-(const vec4 &i) const {
return vec4(v[0] - i[0], v[1] - i[1], v[2] - i[2], v[3] - i[3]);
}
// Compare
bool operator==(const vec4 &in) const {
return v[0] == in[0] && v[1] == in[1] && v[2] == in[2] && v[3] == in[3];
}
bool operator!=(const vec4 &in) const {
// use the first comparefuncs result
// and swap it lol
return !(*this == in);
}
// Base
vec4 operator-() const { return vec4(-v[0], -v[1], -v[2], -v[3]); }
float operator[](int i) const { return v[i]; }
float &operator[](int i) { return v[i]; }
float len() const { return sqrt(sqlen()); }
float sqlen() const {
return v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3];
}
// Vec Acess
float x() const { return v[0]; }
float &x() { return v[0]; }
float y() const { return v[1]; }
float &y() { return v[1]; }
float z() const { return v[2]; }
float &z() { return v[2]; }
float w() const { return v[3]; }
float &w() { return v[3]; }
vec2 xy() const { return vec2(v[0], v[1]); }
vec2 zw() const { return vec2(v[2], v[3]); }
vec3 xyz() const { return vec3(v[0], v[1], v[2]); }
vec3 yzw() const { return vec3(v[1], v[2], v[3]); }
// Quaternion Acess
float r() const { return v[0]; }
float &r() { return v[0]; }
float k() const { return v[1]; }
float &k() { return v[1]; }
float j() const { return v[2]; }
float &j() { return v[2]; }
float i() const { return v[3]; }
float &i() { return v[3]; }
vec2 rk() const { return vec2(v[0], v[1]); }
vec2 ji() const { return vec2(v[2], v[3]); }
vec3 rkj() const { return vec3(v[0], v[1], v[2]); }
vec3 kji() const { return vec3(v[1], v[2], v[3]); }
// Internal Values
float v[4];
};
} // 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/vec2.hpp>
#include <pd/core/vec3.hpp>
#include <pd/core/vec4.hpp>

135
include/pd/core/vec2.hpp Normal file
View File

@ -0,0 +1,135 @@
#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

160
include/pd/core/vec3.hpp Normal file
View File

@ -0,0 +1,160 @@
#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

193
include/pd/core/vec4.hpp Normal file
View File

@ -0,0 +1,193 @@
#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

View File

@ -24,41 +24,59 @@ 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/core.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
class Image {
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 fmt = 4) {
this->Copy(buf, w, h, fmt);
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 fmt = 4);
void Copy(const std::vector<u8>& buf, int w, int h, int bpp = 4);
std::vector<u8>& GetBuffer() { return buffer; }
std::vector<u8> GetBuffer() const { return buffer; }
std::vector<PD::u8>& GetBuffer() { return pBuffer; }
std::vector<PD::u8> GetBuffer() const { return pBuffer; }
int Width() const { return w; }
int Height() const { return h; }
int Width() const { return pWidth; }
int Height() const { return pHeight; }
Format Fmt() const { return pFmt; }
u8& operator[](int idx) { return buffer[idx]; }
u8 operator[](int idx) const { return buffer[idx]; }
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<u8>&() { return buffer; }
operator std::vector<u8>() const { return buffer; }
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:
std::vector<u8> buffer;
int w = 0;
int h = 0;
/** Leftover variable used for stbi_load */
int fmt = 0;
};
} // namespace PD

View File

@ -24,8 +24,8 @@ 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>
#include <pd/core/core.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
/**
@ -38,7 +38,7 @@ namespace ImgBlur {
* @param si sigma value to use
* @return list of kernel values
*/
std::vector<float> GaussianKernel(int radius, float si);
PD_IMAGE_API std::vector<float> GaussianKernel(int radius, float si);
/**
* Gaussian Blur for basic Image Buffer
* @param buf Image Buffer (unsigned char)
@ -48,7 +48,7 @@ std::vector<float> GaussianKernel(int radius, float si);
* @param si Blur sigma
* @param idxfn Indexing function
*/
void GaussianBlur(
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;
@ -63,7 +63,7 @@ void GaussianBlur(
* @param si Blur sigma
* @param idxfn Indexing function
*/
void GaussianBlur(
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;

View File

@ -24,7 +24,9 @@ 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/core.hpp>
#include <pd/image/image.hpp>
#include <pd/image/pd_p_api.hpp>
namespace PD {
/**
@ -39,7 +41,11 @@ namespace ImgConvert {
* @param w width of the image
* @param h height of the image
*/
void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
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)
@ -47,6 +53,30 @@ void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
* @param w width
* @param h height
*/
void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
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

View File

@ -0,0 +1,52 @@
#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.
*/
#pragma once
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_IMAGE_BUILD_SHARED
#define PD_IMAGE_API __declspec(dllexport)
#else
#define PD_IMAGE_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_IMAGE_BUILD_SHARED
#define PD_IMAGE_API __attribute__((visibility("default")))
#else
#define PD_IMAGE_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_IMAGE_BUILD_SHARED
#define PD_IMAGE_API __attribute__((visibility("default")))
#else
#define PD_IMAGE_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_IMAGE_API
#else
#define PD_IMAGE_API
#endif

View File

@ -1,71 +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 <3ds.h>
#include <pd/app/error.hpp>
#include <pd/core/common.hpp>
namespace PD {
/**
* Custom C++ Allocator for 3DS linear Memory
* Used for Everything that has to do with Rendering or sound
* Dont going into that much detail here
*
* Example:
* ```cpp
* // Index Buffer for Rendering using Linear Allocator
* std::vector<u16, PD::LinearAllocator<u16>> index_buf;
* ```
*/
template <typename T>
class LinearAllocator : public std::allocator<T> {
public:
using size_type = size_t;
using pointer = T*;
using const_pointer = const T*;
template <typename T1>
struct rebind {
using other = LinearAllocator<T1>;
};
pointer allocate(size_type n, const void* hint = nullptr) {
if (n > this->max_size()) {
Error("Linear Alloc failed (no space left)");
return nullptr;
}
return (pointer)linearAlloc(n * sizeof(T));
}
void deallocate(pointer p, size_type) { linearFree((void*)p); }
size_type max_size() { return linearSpaceFree(); }
LinearAllocator() noexcept {}
LinearAllocator(const LinearAllocator<T>& a) noexcept
: std::allocator<T>(a) {}
~LinearAllocator() noexcept {}
};
} // namespace PD

View File

@ -0,0 +1,76 @@
#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

View File

@ -1,215 +1,62 @@
#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/vec.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> {
public:
Command() = default;
~Command() = default;
/**
* Copy Constructor [to Copy the Data of a Command Reference]
*/
Command(Command::Ref v) {
this->index = v->index;
this->index_buf = v->index_buf;
this->layer = v->layer;
this->mode = v->mode;
this->tex = v->tex;
this->vertex_buf = v->vertex_buf;
}
/**
* Setter for the Commands layer
* @param v layer value
* @return command reference
*/
Command& Layer(int v) {
layer = v;
return *this;
}
/**
* Getter for the Layer
* @return layer value
*/
int Layer() const { return layer; }
/**
* Setter for the Commands Index [used in sorting]
* @param v index value
* @return command reference
*/
Command& Index(int v) {
index = v;
return *this;
}
/**
* Getter for the Index
* @return index value
*/
int Index() const { return index; }
/**
* Setter for the Commands Texture
* @param v Texture reference
* @return command reference
*/
Command& Tex(Texture::Ref v) {
tex = v;
return *this;
}
/**
* Getter for the Texture reference
* @return Texture reference
*/
Texture::Ref Tex() const { return tex; }
/**
* Function to Push a Vertex to the vertexbuffer
* @param v Vertex to push
* @return command reference
*/
Command& PushVertex(const Vertex& v) {
vertex_buf.push_back(v);
return *this;
}
/**
* Access to the Index list [used to write index data
* to the real indexbuffer]
* @return const reference to commands idx buffer
*/
const std::vector<u16>& IndexList() const { return index_buf; }
/**
* Access to the Vertex list [used to write vertices
* data to the real vertexbuffer]
* @return const reference to commands vertex buffer
*/
const std::vector<Vertex>& VertexList() const { return vertex_buf; }
// ADVANCED
/**
* Advanced function to access index list
*
* - This function is UNSAFE to use cause it allows to modify index data
* @return reference to index list
*/
std::vector<u16>& IndexList() { return index_buf; }
/**
* Advanced function to access vertex list
*
* - This function is UNSAFE to use cause it allows to modify index data
* - Using this in StaticText to change Position color and stuff after it is
* rendered into commands
* @return reference to vertex list
*/
std::vector<Vertex>& VertexList() { return vertex_buf; }
/**
* Function to Push an index value to indexbuffer
* @param v Index value
* @return command reference
*/
Command& PushIndex(u16 v) {
index_buf.push_back(vertex_buf.size() + v);
return *this;
}
/**
* Setter for the Commands RenderMode
* @param v RenderMode
* @return command reference
*/
Command& Rendermode(const RenderMode& v) {
mode = v;
return *this;
}
/**
* Getter for the Commands RenderMode
* @return RenderMode
*/
RenderMode Rendermode() const { return mode; }
/** Setter for Scissor Mode */
Command& SetScissorMode(ScissorMode mode) {
scissor = mode;
return *this;
}
/** Getter for Scissor Mode */
ScissorMode GetScissorMode() const { return scissor; }
/** Setter for Scissor Area */
Command& ScissorRect(const vec4& v) {
scissor_area = v;
return *this;
}
/** Getter for Scissor Area */
vec4 ScissorRect() const { return scissor_area; }
private:
/**
* Vertex Buffer
*
* - Using default vector here as its data will be copied later
*/
std::vector<Vertex> vertex_buf;
/**
* Index Buffer
*
* - Using default vector here as its data will be copied later
*/
std::vector<u16> index_buf;
/** Layer */
int layer;
/** Texture Reference */
Texture::Ref tex;
/** Index */
int index;
/** RenderMode (Default to RenderMode_RGBA) */
RenderMode mode = RenderMode_RGBA;
/** Scissor Mode (for defined area to render) */
ScissorMode scissor = ScissorMode_None;
/** scissor box (top left and bottom right) */
vec4 scissor_area;
};
} // namespace LI
#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/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> {
public:
Command() = default;
~Command() = default;
Command& AppendIndex(u16 idx) {
IndexBuffer.Add(VertexBuffer.Size() + idx);
return *this;
}
Command& AppendVertex(const Vertex& v) {
VertexBuffer.Add(v);
return *this;
}
Vec<Vertex> VertexBuffer;
Vec<u16> IndexBuffer;
ivec4 ScissorRect;
bool ScissorEnabled = false;
int Layer;
int Index;
Texture::Ref Tex;
};
} // namespace LI
} // namespace PD

View File

@ -0,0 +1,145 @@
#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/font.hpp>
#include <pd/lithium/pd_p_api.hpp>
namespace PD {
namespace LI {
class PD_LITHIUM_API DrawList : public SmartCtor<DrawList> {
public:
DrawList(Texture::Ref solid) {
WhitePixel = solid;
CurrentTex = solid;
}
~DrawList() {}
Command::Ref PreGenerateCmd();
void AddCommand(Command::Ref v) { pDrawList.Add(v); }
void Clear() { pDrawList.Clear(); }
void SetFont(Font::Ref font) { pCurrentFont = font; }
void SetFontScale(float scale) { pFontScale = scale; }
void DrawSolid() { CurrentTex = WhitePixel; }
void DrawTexture(Texture::Ref tex) { CurrentTex = tex; }
// SECTION: Draw API //
void DrawRect(const fvec2& pos, const fvec2& size, u32 color,
int thickness = 1);
void DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color);
void DrawTriangle(const fvec2& a, const fvec2& b, const fvec2& c, u32 color,
int thickness = 1);
void DrawTriangleFilled(const fvec2& a, const fvec2& b, const fvec2& c,
u32 color);
void DrawCircle(const fvec2& center, float rad, u32 color, int num_segments,
int thickness = 1);
void DrawCircleFilled(const fvec2& center, float rad, u32 color,
int num_segments);
void DrawText(const fvec2& p, const std::string& text, u32 color);
/**
* 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 DrawPolyLine(const Vec<fvec2>& points, u32 clr, u32 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 DrawConvexPolyFilled(const Vec<fvec2>& points, u32 clr);
// SECTION: 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) {
pPath.Reserve(pPath.Size() + num_points);
}
/**
* Clear current Path
* @note PathStroke and PathFill will automatically clear
*/
void PathClear() { pPath.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 PathAdd(const fvec2& v) { pPath.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(u32 clr, int thickness = 1, u32 flags = 0) {
DrawPolyLine(pPath, clr, flags, thickness);
pPath.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(u32 clr) {
DrawConvexPolyFilled(pPath, clr);
pPath.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, u32 flags = 0);
int Layer = 0;
float pFontScale = 0.7f;
Font::Ref pCurrentFont = nullptr;
Texture::Ref CurrentTex = nullptr;
Texture::Ref WhitePixel = nullptr;
PD::Vec<Command::Ref> pDrawList;
PD::Vec<fvec2> pPath;
};
} // namespace LI
} // namespace PD

View File

@ -1,71 +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/common.hpp>
/** Alias for Lithium Text Flags */
using LITextFlags = PD::u32;
/** LITextFlags */
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]
LITextFlags_RenderOOS = 1 << 6 ///< Render Out of Screen
};
/** Aliad for Lithium Render Flags */
using LIRenderFlags = PD::u32;
/** LIRenderFlags */
enum LIRenderFlags_ {
LIRenderFlags_None = 0, ///< Nothing
LIRenderFlags_TMS = 1 << 0, ///< Text Map System
LIRenderFlags_LRS = 1 << 1, ///< Layer Render System
LIRenderFlags_AST = 1 << 2, ///< Auto Static Text
/** Default Enables all of them */
LIRenderFlags_Default =
LIRenderFlags_TMS | LIRenderFlags_LRS | LIRenderFlags_AST,
};
namespace PD {
namespace LI {
/** RenderMode [Required to modify TexENV] */
enum RenderMode {
RenderMode_RGBA, ///< RGBA [for textures or solid colors]
RenderMode_Font, ///< A8 [for textures only crated by 1 color channel]
};
/** Scissor Mode (for ClipRect related rendering) */
enum ScissorMode {
ScissorMode_None = 0, ///< No Scissor
ScissorMode_Inverted = 1, ///< Render Pixels outside the box
ScissorMode_Normal = 3, ///< Only render pixels inside the box
};
} // namespace LI
} // namespace PD

View File

@ -1,181 +1,95 @@
#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/vec.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
namespace PD {
namespace LI {
/** Font Loader for Lithium */
class Font : public SmartCtor<Font> {
public:
/** Codepoint Data holder */
class Codepoint {
public:
Codepoint() = default;
~Codepoint() = default;
/**
* Codepoint ID Getter
* @return 32Bit codepoint value
*/
u32 cp() const { return m_cp; }
/**
* Codepoint ID Setter
* @param v codepoint id
* @return DataHolder reference
*/
Codepoint& cp(u32 v) {
m_cp = v;
return *this;
}
/**
* Getter for the UV Coords
* @return uv coords
*/
vec4 uv() const { return m_uv; }
/**
* Setter for the UV Coords
* @param v uv coords
* @return DataHolder Reference
*/
Codepoint& uv(const vec4& v) {
m_uv = v;
return *this;
}
/**
* Getter for the Texture reference
* @return Texture Reference
*/
Texture::Ref tex() const { return m_tex; }
/**
* Setter for the Texture Reference
* @param v Texture Reference
* @return DataHolder Reference
*/
Codepoint& tex(Texture::Ref v) {
m_tex = v;
return *this;
}
/**
* Getter for the size
* @return Size
*/
vec2 size() const { return m_size; }
/**
* Setter for the Size
* @param v size
* @return DataHolder Reference
*/
Codepoint& size(const vec2& v) {
m_size = v;
return *this;
}
/**
* Getter for the Position offset
* @return offset
*/
float off() const { return m_off; }
/**
* Setter for the Render Offset
* @param v offset
* @return DataHolder Reference
*/
Codepoint& off(float v) {
m_off = v;
return *this;
}
/**
* Getter to check if Codepoint is invalid
* @return true if invalid
*/
bool invalid() const { return m_invalid; }
/**
* Setter for invald state
* @param v true or false
* @return DataHolder Reference
*/
Codepoint& invalid(bool v) {
m_invalid = v;
return *this;
}
private:
/** 32Bit Codepoint ID */
u32 m_cp = 0;
/** UvMap */
vec4 m_uv;
/** Texture Reference */
Texture::Ref m_tex = nullptr;
/** Codepoint Size */
vec2 m_size;
/** Render Position Offset */
float m_off = 0;
/** Invalid check (for skip in renderer) */
bool m_invalid = false;
};
Font() = default;
~Font() = default;
/**
* Load a TTF File
* @param path Path to the TTF file
* @param px_height Pixelheight of the codepoints (limit by 64)
*/
void LoadTTF(const std::string& path, int px_height = 32);
/**
* Load 3DS System Font
*/
void LoadSystemFont();
/**
* Getter for PixelHeight
* @return pixelheigt
*/
int PixelHeight() const { return pixel_height; }
/**
* Getter for Codepoint reference
* @return codepoint dataholder reference
*/
Codepoint& GetCodepoint(u32 c);
/**
* Check if Systemfont is used
* @return true if is system font
*/
bool SystemFont() const { return sysfont; }
private:
/** sysfont set to true if LoadSystemFont got called */
bool sysfont;
/** Pixelheight */
int pixel_height;
/** List of textures (codepoints are using) */
std::vector<Texture::Ref> textures;
/** 32Bit Codepoint Dataholder Reference Map */
std::map<u32, Codepoint> cpmap;
};
} // namespace LI
#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/backend.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]
};
namespace PD {
namespace LI {
/** Font Loader for Lithium */
class PD_LITHIUM_API Font : public SmartCtor<Font> {
public:
/** Codepoint Data holder */
struct Codepoint {
u32 pCodepoint = 0;
fvec4 SimpleUV;
Texture::Ref Tex;
fvec2 Size;
float Offset = 0.f;
bool pInvalid = false;
};
Font(Backend::Ref backend) { pBackend = backend; };
~Font() = default;
/**
* Load a TTF File
* @param path Path to the TTF file
* @param px_height Pixelheight of the codepoints (limit by 64)
*/
void LoadTTF(const std::string& path, int px_height = 32);
/**
* Getter for Codepoint reference
* @return codepoint dataholder reference
*/
Codepoint& GetCodepoint(u32 c);
/**
* Get Text Bounding Box
*/
fvec2 GetTextBounds(const std::string& text, float scale);
/**
* 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,
const fvec2& box = 0);
/** Pixelheight */
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;
};
} // namespace LI
} // namespace PD

View File

@ -1,349 +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/common.hpp>
#include <pd/core/vec.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/flags.hpp>
#include <pd/lithium/font.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace LI {
class Renderer;
/**
* Prerendered Object that can be edidet at runtime
* and supports diffrent textures as well
*/
class StaticObject : public SmartCtor<StaticObject> {
public:
StaticObject() = default;
~StaticObject() = default;
/**
* Push a Draw Command to the Static Object
* @param v Command to add
*/
void PushCommand(Command::Ref v) { cmds.push_back(v); }
/**
* Copy the root Object to a copy buffer for modification
*/
void ReCopy() {
cpy.clear();
for (auto it : cmds) {
cpy.push_back(Command::New(it));
}
}
/**
* Modify the Color of a specific Command in the List
* @param idx Index of the Command
* @param col new COlor to replace with
*/
void ReColorQuad(int idx, u32 col) {
if (idx > (int)cpy.size()) {
return;
}
for (auto& it : cpy[idx]->VertexList()) {
it.Color(col);
}
}
/**
* Move the every Command in the Object by a specific offset
* @param off offset position to apply
*/
void MoveIt(vec2 off) {
for (auto& it : cpy) {
for (auto& jt : it->VertexList()) {
jt.pos += off;
}
}
}
/**
* Change Color of all Commands in the List
* @param col new Color to use
*/
void ReColor(u32 col) {
for (auto& it : cpy) {
for (auto& jt : it->VertexList()) {
jt.Color(col);
}
}
}
/**
* Assign a New Layer to all Objects
* @param layer new layer to set to all its commands
*/
void ReLayer(int layer) {
for (auto& it : cpy) {
it->Layer(layer);
}
}
/**
* Change the Commands Index by setting a start index
* @param start Start index position
*/
void ReIndex(int start) {
for (int i = 0; i < (int)cpy.size(); i++) {
cpy[i]->Index(start + i);
}
}
/**
* Set a Custom Scissor Mode for Object Copy List
* @param m New Mode to Set
*/
void ReSetScissorMode(ScissorMode m) {
for (auto& i : cpy) {
i->SetScissorMode(m);
}
}
/**
* Set Custom Scissor Rect to All Objects
* @param v Scissor Rect to set
*/
void ReScissorRect(const vec4& v) {
for (auto& i : cpy) {
i->ScissorRect(v);
}
}
/**
* Get a Reference to the Copy Commands List
* @return command list reference
*/
std::vector<Command::Ref>& List() {
if (cpy.size() != 0) {
return cpy;
}
return cmds;
}
private:
/** Copy Buffer */
std::vector<Command::Ref> cpy;
/** Source Buffer */
std::vector<Command::Ref> cmds;
};
/**
* Text Box container for TMS and AST
*/
class TextBox {
public:
TextBox() = default;
/**
* Baisc Constructor
* @param s Size of the text
* @param time creation time
*/
TextBox(const vec2& s, float time) {
size = s;
time_created = time;
optional = false;
}
~TextBox() = default;
/**
* Setter for Time created
* @param v time
*/
void TimeCreated(float v) { time_created = v; }
/**
* Setter for Size
* @param v size
*/
void Size(const vec2& v) { size = v; }
/**
* Setter for is optional
*
* - optional text contains the result string of wrap/short
* @param v optional
*/
void Optional(bool v) { optional = v; }
/**
* set Result of Short Text or Wrap Text
* @param v text
*/
void Text(const std::string& v) { text = v; }
/**
* Get Size
* @return size
*/
vec2 Size() const { return size; }
/**
* Get Time Created / Updated
* @param time created/updated
*/
float TimeCreated() const { return time_created; }
/**
* Check if Optional or not
* @return is optional
*/
bool Optional() const { return optional; }
/**
* Get Optional Text
* @return text
*/
std::string Text() const { return text; }
private:
/** Text Size */
vec2 size;
/** Time Created / Updated */
float time_created;
/** Is Optional */
bool optional;
/** Text Wrap / Short */
std::string text;
};
/**
* Static Text [abillity to Prerender Texts into a list of Commands]
*/
class StaticText : public SmartCtor<StaticText> {
public:
StaticText() = default;
/**
* Wrap Constructor to Setup
* @param ren Renderer direct pointer reference
* @param pos Position
* @param clr Color
* @param text Text to Render
* @param flags Text Flags
* @param box Additional textbox for specific flags
*/
StaticText(Renderer* ren, const vec2& pos, u32 clr, const std::string& text,
LITextFlags flags = 0, const vec2& box = 0) {
Setup(ren, pos, clr, text, flags, box);
}
~StaticText() = default;
/**
* Function that Sets Up the Rendering
* @param ren Renderer direct pointer reference
* @param pos Position
* @param clr Color
* @param text Text to Render
* @param flags Text Flags
* @param box Additional textbox for specific flags
*/
void Setup(Renderer* ren, const vec2& pos, u32 clr, const std::string& text,
LITextFlags flags = 0, const vec2& box = 0);
/**
* Get Text Size
* @return size
*/
vec2 GetDim() const { return tdim; }
/**
* Get Text Posiotion
* @return position
*/
vec2 GetPos() const { return pos; }
/**
* Setter to Update Color
* @param col color
*/
void SetColor(u32 col);
/**
* Setter to raplace the texts Commands Position
* @param pos new position
*/
void SetPos(const vec2& pos);
/**
* Set Layer of the Text
* @param l layer
*/
void SetLayer(int l);
/**
* Function to unset the used variable
*/
void SetUnused() { used = false; }
/**
* Function to check if the text got rendered
* @return is used
*/
bool Used() const { return used; }
/**
* Function to check if the text got setup
* @return is setup
*/
bool IsSetup() { return text != nullptr; }
/**
* Draw the Text
*/
void Draw();
/** Get the Raw Object for Custom API's */
StaticObject::Ref GetRawObject() { return text; }
/**
* Set Font used by the static Text
* @param fnt Font used
*/
void Font(Font::Ref fnt) { font = fnt; }
/**
* Get Font used by the Text
* @return Font Reference
*/
Font::Ref Font() { return font; }
/**
* Set a Custom Scissor Mode Static Text
* @param m New Mode to Set
*/
void SetScissorMode(ScissorMode m) { text->ReSetScissorMode(m); }
/**
* Set Custom Scissor Rect to Static Text
* @param v Scissor Rect to set
*/
void ScissorRect(const vec4& v) { text->ReScissorRect(v); }
private:
/** Font */
Font::Ref font;
/** Text got Rendered */
bool used;
/** Renderer pointer Reference */
Renderer* ren;
/** Text Size */
vec2 tdim;
/** Text Position */
vec2 pos;
/** Static Text Object */
StaticObject::Ref text;
};
} // namespace LI
} // namespace PD

View File

@ -0,0 +1,52 @@
#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.
*/
#pragma once
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_LITHIUM_BUILD_SHARED
#define PD_LITHIUM_API __declspec(dllexport)
#else
#define PD_LITHIUM_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_LITHIUM_BUILD_SHARED
#define PD_LITHIUM_API __attribute__((visibility("default")))
#else
#define PD_LITHIUM_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_LITHIUM_BUILD_SHARED
#define PD_LITHIUM_API __attribute__((visibility("default")))
#else
#define PD_LITHIUM_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_LITHIUM_API
#else
#define PD_LITHIUM_API
#endif

View File

@ -1,197 +1,192 @@
#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 {
namespace LI {
/**
* Container that holds position of a rectangle's corners.
*/
class Rect {
public:
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 vec4& t, const vec4& b) {
top = t;
bot = b;
}
/**
* Constructor that initializes the rectangle using individual corner
* positions.
* @param tl Top left corner position.
* @param tr Top right corner position.
* @param bl Bottom left corner position.
* @param br Bottom right corner position.
*/
Rect(const vec2& tl, const vec2& tr, const vec2& bl, const vec2& br) {
top = vec4(tl, tr);
bot = vec4(bl, br);
}
/**
* Constructor that initializes the rectangle using a UV mapping vector.
*
* - The old API used vec4 for UV mapping.
* - Spritesheets have rotated images, so this was updated to use Rect for UV.
*
* @param uv Vec4 UV map.
*/
Rect(const vec4& 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.
*/
vec4 Top() const { return top; }
/**
* Get the bottom left and right corner positions.
* @return Bottom positions.
*/
vec4 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 vec4& 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 vec4& v) {
bot = v;
return *this;
}
/**
* Get the top-left corner position.
* @return Top-left position as vec2.
*/
vec2 TopLeft() const { return vec2(top[0], top[1]); }
/**
* Get the top-right corner position.
* @return Top-right position as vec2.
*/
vec2 TopRight() const { return vec2(top[2], top[3]); }
/**
* Get the bottom-left corner position.
* @return Bottom-left position as vec2.
*/
vec2 BotLeft() const { return vec2(bot[0], bot[1]); }
/**
* Get the bottom-right corner position.
* @return Bottom-right position as vec2.
*/
vec2 BotRight() const { return vec2(bot[2], bot[3]); }
/**
* Set the top-left corner position.
* @param v New top-left position.
* @return Reference to the updated Rect.
*/
Rect& TopLeft(const vec2& v) {
top[0] = v[0];
top[1] = v[1];
return *this;
}
/**
* Set the top-right corner position.
* @param v New top-right position.
* @return Reference to the updated Rect.
*/
Rect& TopRight(const vec2& v) {
top[2] = v[0];
top[3] = v[1];
return *this;
}
/**
* Set the bottom-left corner position.
* @param v New bottom-left position.
* @return Reference to the updated Rect.
*/
Rect& BotLeft(const vec2& v) {
bot[0] = v[0];
bot[1] = v[1];
return *this;
}
/**
* Set the bottom-right corner position.
* @param v New bottom-right position.
* @return Reference to the updated Rect.
*/
Rect& BotRight(const vec2& v) {
bot[2] = v[0];
bot[3] = v[1];
return *this;
}
/**
* Swap X and Y coordinates for all corners.
*
* - Used in SpiteSheet for the rotated images.
*/
void SwapVec2XY() {
for (int i = 0; i < 4; i += 2) {
float t = top[i];
top[i] = top[i + 1];
top[i + 1] = t;
t = bot[i];
bot[i] = bot[i + 1];
bot[i + 1] = t;
}
}
private:
vec4 top; ///< Top left and right corner positions.
vec4 bot; ///< Bottom left and right corner positions.
};
} // namespace LI
#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 LI {
/**
* Container that holds position of a rectangle's corners.
*/
class Rect {
public:
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;
}
/**
* Constructor that initializes the rectangle using individual corner
* positions.
* @param tl Top left corner position.
* @param tr Top right corner position.
* @param bl Bottom left corner position.
* @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);
}
/**
* Constructor that initializes the rectangle using a UV mapping vector.
*
* - The old API used vec4 for UV mapping.
* - Spritesheets have rotated images, so this was updated to use Rect for UV.
*
* @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;
}
/**
* Get the top-left corner position.
* @return Top-left position as vec2.
*/
fvec2 TopLeft() const { return vec2(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); }
/**
* Get the bottom-left corner position.
* @return Bottom-left position as vec2.
*/
fvec2 BotLeft() const { return vec2(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); }
/**
* Set the top-left corner position.
* @param v New top-left position.
* @return Reference to the updated Rect.
*/
Rect& TopLeft(const fvec2& v) {
top.x = v.x;
top.y = v.y;
return *this;
}
/**
* Set the top-right corner position.
* @param v New top-right position.
* @return Reference to the updated Rect.
*/
Rect& TopRight(const fvec2& v) {
top.z = v.x;
top.w = v.y;
return *this;
}
/**
* Set the bottom-left corner position.
* @param v New bottom-left position.
* @return Reference to the updated Rect.
*/
Rect& BotLeft(const fvec2& v) {
bot.x = v.x;
bot.y = v.y;
return *this;
}
/**
* Set the bottom-right corner position.
* @param v New bottom-right position.
* @return Reference to the updated Rect.
*/
Rect& BotRight(const fvec2& v) {
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();
}
private:
fvec4 top; ///< Top left and right corner positions.
fvec4 bot; ///< Bottom left and right corner positions.
};
} // namespace LI
} // namespace PD

View File

@ -1,382 +1,79 @@
#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/vec.hpp>
#include <pd/lib3ds/memory.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/flags.hpp>
#include <pd/lithium/font.hpp>
#include <pd/lithium/objects.hpp>
#include <pd/lithium/screen.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
namespace PD {
namespace LI {
/**
* Lithium base renderer Class.
*/
class Renderer : public SmartCtor<Renderer> {
public:
/**
* Constructor setting up the 2d Rendering Engine
* @param flags Flags to use [can be changed at runtime].
*/
Renderer(LIRenderFlags flags = LIRenderFlags_Default);
/**
* Deconstructor that unloads all the renderer data
*/
~Renderer();
/**
* Prepare render stage for rendering.
*/
void PrepareRender();
/**
* Render a screens Command list.
* @param s Screen to Draw its list on.
*/
void Render(Screen::Ref s);
/**
* Finalize rendering stage.
*/
void FinalizeRender();
/**
* Register Screens (For UI7, probably move this).
* @param bottom set if you register bottom ot top screen.
* @param s Screen to register.
*/
void RegisterScreen(bool bottom, Screen::Ref s) { screens[bottom] = s; }
/**
* Set the Screen next commands will be add to
* @param s Screen of choice
*/
void OnScreen(Screen::Ref s) {
if (!s) {
return;
}
this->screen = s;
area_size = screen->GetSize();
}
/**
* Get cobst reference to active screen.
* @return current screen.
*/
Screen::Ref CurrentScreen() const { return screen; }
/**
* Get Screen of screen regestry.
* @param bottom bottom ot top screen.
* @return screen reference
*/
Screen::Ref GetScreen(bool bottom) {
auto res = screens[bottom];
Assert(res.get(), "Screen is not registered!");
return res;
}
void Rotation(float v) { rot = v; }
float Rotation() const { return rot; }
void TextScale(float v) { text_size = v; }
void DefaultTextScale() { text_size = default_text_size; }
float TextScale() const { return text_size; }
void Layer(int v) { current_layer = v; }
int Layer() const { return current_layer; }
LIRenderFlags& GetFlags() { return flags; }
void Font(Font::Ref v) {
font = v;
font_update = true;
}
Font::Ref Font() const { return font; }
/**
* Use a specific Texture for Next Rectangle.
* @param v texture reference to use.
*/
void UseTex(Texture::Ref v = nullptr) {
if (v == nullptr) {
current_tex = white;
return;
}
current_tex = v;
}
/**
* Draws a Rect based on current Texture
* @param pos Position of the Rect
* @param size Size of the Rect
* @param color Color of the Rect [0xffffffff]
* for full visible texture
* @param uv UV Map (if texture needs a custom uv)
* @note This function is part of Simple Draw API.
*/
void DrawRect(const vec2& pos, const vec2& size, u32 color,
const Rect& uv = vec4(0.f, 1.f, 1.f, 0.f));
/**
* Draw a Solid Rect (uses white tex)
* @note
* - acts as a simplified Draw rect Wrapper
* - This function is part of Simple Draw API.
* @param pos Position of the rect
* @param size Size of the rect
* @param color Color of the rect
*/
void DrawRectSolid(const vec2& pos, const vec2& size, u32 color);
/**
* Render a Triangle
* @param a Position A
* @param b Position B
* @param c Position C
* @param color Color of the triangle
* @note
* - Uses Solid color [white tex]
* - This function is part of Simple Draw API.
*/
void DrawTriangle(const vec2& a, const vec2& b, const vec2& c, u32 color);
/**
* Draw a Circle (Supports Textures)
* @param center_pos Center Position
* @param r Radius of the circle
* @param color Color of the circle
* @param segments Segments to use
* @note
* - Textures could look a bit janky due to uv mapping
* - This function is part of Simple Draw API.
*/
void DrawCircle(const vec2& center_pos, float r, u32 color, int segments);
/**
* Draw a Line between to Positions
* @param a Position A
* @param b Position B
* @param color Color of the line
* @param t Thickness
* @note This function is part of Simple Draw API.
*/
void DrawLine(const vec2& a, const vec2& b, u32 color, int t);
/**
* Render a Text
* @param pos Position of the text
* @param color Color of the Text
* @param text Text to Render
* @param flags flags to use
* @param ap optional size for specific flags
* @note This function is part of Simple Draw API.
*/
void DrawText(const vec2& pos, u32 color, const std::string& text,
u32 flags = 0, const vec2& ap = vec2());
/**
* Draw a Texture as 2D Image
* @param pos Position
* @param tex Texture reference
* @param scale Scale (cause maybe wants to be resized)
* @note
* - Acts as a Simplified wrapper to DrawRect
* - This function is part of Simple Draw API.
*/
void DrawImage(const vec2& pos, Texture::Ref tex,
const vec2& scale = vec2(1.f));
// Debug STUFF
/** DEBUG Get the Number of Vertices of last Frame */
u32 Vertices() const { return vertices; }
/** DEBUG Get the Number of Indices of last frame */
u32 Indices() const { return indices; }
/** DEBUG Get the Number of Commands of last frame */
u32 Commands() const { return commands; }
/** DEBUG Get the Number of Drawcalls of last frame */
u32 DrawCalls() const { return drawcalls; }
/** Auto Static Text Number of Texts */
u32 AstUsage() const { return ast.size(); }
/** Text Map System number of texts */
u32 TmsUsage() const { return tms.size(); }
// TOOLS
/** Rotate a rect corner position by sine and cosine value */
static void RotateCorner(vec2& v, float s, float c);
/** Create a Rect by Position, Size and rotation angle */
static Rect CreateRect(const vec2& pos, const vec2& size, float angle);
/** Create a Line Rect by 2 Position and a thickness value */
static Rect CreateLine(const vec2& a, const vec2& b, int t);
/** Check if a pos and size are inside a vec4 rect */
static bool InBox(const vec2& pos, const vec2& size, const vec4& rect);
/** Check if a pos is inside a vec4 rect */
static bool InBox(const vec2& pos, const vec4& rect);
/** Check if one or all of three positions are somehow inside a vec4 rect */
static bool InBox(const vec2& alpha, const vec2& bravo, const vec2& charlie,
const vec4& rect);
/**
* Get The Address of a Screen
* @note **IMPORTANT** THIS IS FOR 32Bit System
*
* Should find a better way to do this for porting this lib
*/
static u32 Screen32(Screen::Ref s) { return (u32)s.get(); }
/** Function to optimize command order for rendering */
static void OptiCommandList(std::vector<Command::Ref>& list);
/** Returns Viewport with xy */
vec4 GetViewport();
/** Push a Self Created command */
void PushCommand(Command::Ref cmd) {
cmd->Index(cmd_idx++); // Indexing
draw_list[Screen32(screen)].push_back(cmd);
}
/** Automatically sets up a command */
void SetupCommand(Command::Ref cmd);
/** Creates a default Quad Render Command */
void QuadCommand(Command::Ref cmd, const Rect& quad, const Rect& uv, u32 col);
/** Create a Default Triangle */
void TriangleCommand(Command::Ref cmd, const vec2& a, const vec2& b,
const vec2& c, u32 col);
/**
* Create List of a Text Commands
* @param cmds Link to a command List
* @param pos Position
* @param color Color
* @param text Text
* @param flags Flags
* @param box (Size for wrapping / Offset for Centered Text)
*/
void TextCommand(std::vector<Command::Ref>& cmds, const vec2& pos, u32 color,
const std::string& text, LITextFlags flags, const vec2& box);
vec2 GetTextDimensions(const std::string& text);
/**
* Function to short a text and replace the rest by ...
* @param text Text to short
* @param maxlen Maximum width
* @param newsize New Textbox size
* @return shorted text
*/
std::string ShortText(const std::string& text, int maxlen, vec2& newsize);
/**
* Function to Wrap Text by specific width
*
* **NOT IMPLEMENTED YET**
* @param text text to wrap
* @param maxlen maximum width per line
* @param newsize new textbox size
* @return wrapped text
*/
std::string WrapText(const std::string& text, int maxlen, vec2& newsize);
private:
// Helper Funcitons
/**
* Update the 3DS citro3d texenv for specific RenderMode
* @param mode RenderMode to use.
*/
void UpdateRenderMode(const RenderMode& mode);
/** Current Screen */
Screen::Ref screen;
/** Screen Regestry */
Screen::Ref screens[2];
// Context Related
/** Renderer flags */
LIRenderFlags flags = LIRenderFlags_Default;
/** Area Size */
vec2 area_size;
/** Current Layer */
int current_layer = 0;
/** Current Texture */
Texture::Ref current_tex = nullptr;
/** Single Color Texture (for solid color objs) */
Texture::Ref white = nullptr;
/** Current Font Reference */
Font::Ref font = nullptr;
/** Font updated */
bool font_update;
/** Current Rendermode */
RenderMode mode = RenderMode_RGBA;
/** Text Map System */
std::map<std::string, TextBox> tms;
/** (Auto) Static Text */
std::unordered_map<u32, StaticText::Ref> ast;
// Text Rendering
/** Default FOnt height */
const float default_font_h = 24.f;
/** Default Text Scale */
const float default_text_size = 0.7f;
/** Current Text Scale */
float text_size = 0.7f;
// Special
/** Current Rotation (RECTS) */
float rot = 0.f;
// Rendering
/** Map of drawlist by 32Bit memory Address of their Screen */
std::unordered_map<u32, std::vector<Command::Ref>> draw_list;
/** Vertex Buffer in linear Ram */
std::vector<Vertex, LinearAllocator<Vertex>> vertex_buf;
/** 16Bit index buffer in linear Ram */
std::vector<u16, LinearAllocator<u16>> index_buf;
/** vertex index (render stage) */
u32 vertex_idx = 0;
/** index buf index (render stage) */
u32 index_idx = 0;
/** command index (used for debug count) */
u32 cmd_idx = 0;
// Debug
/** Num of Vertices */
u32 vertices = 0;
/** Num of indices */
u32 indices = 0;
/** Num of Commands */
u32 commands = 0;
/** Num of Drawcalls */
u32 drawcalls = 0;
// Shader
/** Shader code */
DVLB_s* dvlb = nullptr;
/** Shader program */
shaderProgram_s shader;
/** Shader Attribute info */
C3D_AttrInfo attr;
/** projection matrix location */
int uLoc_projection = 0;
// Matrix
/** Precalculated Projectrion Matrix for top screen */
C3D_Mtx top_proj;
/** Precalculated Projectrion Matrix for bottom screen */
C3D_Mtx bot_proj;
};
} // namespace LI
#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/backend.hpp>
#include <pd/lithium/drawlist.hpp>
#include <pd/lithium/font.hpp>
#include <pd/lithium/pd_p_api.hpp>
namespace PD {
namespace LI {
class PD_LITHIUM_API Renderer : public SmartCtor<Renderer> {
public:
Renderer(Backend::Ref backend);
~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 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,
u32 color);
static void CmdTriangle(Command::Ref 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,
u32 clr, Texture::Ref tex);
// SECTION: InBounds Checks
static bool InBox(const fvec2& pos, const fvec2& size, const fvec4& area);
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 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 <3ds.h>
#include <citro3d.h>
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
namespace PD {
/**
* 3DS Screen (RenderTarget)
*/
class Screen : public SmartCtor<Screen> {
public:
/** Screens */
enum Screen_ {
Top, ///< Top Screen
Bottom, ///< Bottom Screen
TopRight ///< Top Right Screen area
};
/**
* Constructor to create Screen by Screen Type
* @param screen Screen to grab default init values for
*/
Screen(Screen_ screen) : type(screen) {
if (screen == Top) {
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT,
DisplayTransferFlags);
} else if (screen == Bottom) {
target = C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8,
GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(target, GFX_BOTTOM, GFX_LEFT,
DisplayTransferFlags);
} else if (screen == TopRight) {
target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8,
GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_RIGHT,
DisplayTransferFlags);
}
}
~Screen() = default;
/** Clear the Screen */
void Clear() { C3D_RenderTargetClear(target, C3D_CLEAR_ALL, 0x00000000, 0); }
/** Set the Screen active for Rendering */
void Use() { C3D_FrameDrawOn(target); }
/** Get the Screens Size */
vec2 GetSize() const {
return vec2(target->frameBuf.height, target->frameBuf.width);
}
/** Get the Screen Type */
Screen_ ScreenType() const { return type; }
/** Get the Raw Rendertarget object */
C3D_RenderTarget* Get() const { return target; }
/** Operartor to get the raw RenderTarget */
operator C3D_RenderTarget*() const { return target; }
private:
/** Screen Type */
Screen_ type;
/** Default Init Flags */
const u32 DisplayTransferFlags =
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
/** RenderTarget */
C3D_RenderTarget* target;
};
} // namespace PD

View File

@ -1,66 +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 <citro3d.h>
#include <tex3ds.h>
#include <pd/core/common.hpp>
#include <pd/lithium/texture.hpp>
namespace PD {
/**
* Tex 3DS Spritesheet integration to Lithium
*/
class SpriteSheet : public SmartCtor<SpriteSheet> {
public:
SpriteSheet() = default;
/**
* Constructor to directly load a spritesheet
* @param path Path to spritesheet
*/
SpriteSheet(const std::string& path) { this->LoadFile(path); }
/**
* Deconstructor to unload the Spritesheet
*/
~SpriteSheet();
/**
* Function to load a Spritesheet
* @param path Path to the file
*/
void LoadFile(const std::string& path);
/** Get a Textures Reference */
Texture::Ref Get(int idx);
/** Get Number of Textures in spritesheet */
int NumTextures() const;
/** Operator to get Texture reference */
Texture::Ref operator[](int idx) { return Get(idx); }
private:
/** Storage of the Spritesheets textures */
std::vector<Texture::Ref> textures;
};
} // namespace PD

View File

@ -1,153 +1,76 @@
#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 <citro3d.h>
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
#include <pd/lithium/rect.hpp>
namespace PD {
/**
* Lithium Texture Loader / DataHolder
*/
class Texture : public SmartCtor<Texture> {
public:
/** Texture Type */
enum Type {
RGBA32, ///< RGBA 32
RGB24, ///< RGB24
A8, ///< A8
};
/** Texture Filters */
enum Filter {
NEAREST, ///< Nearest
LINEAR, ///< Linear
};
/** Default constructor */
Texture() : uv(0.f, 1.f, 1.f, 0.f) {}
/**
* Load file Constructor
* @param path path to file
* @param t3x set true if file is a t3x file
*/
Texture(const std::string& path, bool t3x = false) : uv(0.f, 1.f, 1.f, 0.f) {
if (t3x) {
this->LoadT3X(path);
} else {
this->LoadFile(path);
}
}
/**
* Load Memory constructor
* @param data File Data reference
*/
Texture(const std::vector<u8>& data) : uv(0.f, 1.f, 1.f, 0.f) {
this->LoadMemory(data);
}
/**
* Load Pixels constructor
* @param data Pixel Buffer reference
* @param w width
* @param h height
* @param type Buffer Type [Default RGBA32]
* @param filter Filter [DEFAULT NEAREST]
*/
Texture(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
Filter filter = NEAREST)
: uv(0.f, 1.f, 1.f, 0.f) {
this->LoadPixels(data, w, h, type, filter);
}
/** Deconstructor (aka auto delete) */
~Texture() {
if (autounload) {
Delete();
}
}
/// @brief Deletes image (if not already unloaded)
void Delete();
/// @brief Load a png/jpg/bmp from fs into a gpu tex
/// @param path path to image file
void LoadFile(const std::string& path);
/// @brief Load a png/jpg/bmp from memory
/// @param data reference to data buffer of the file
void LoadMemory(const std::vector<u8>& data);
/// @brief Create Texture out of Pixel Data
/// @param data Data reference
/// @param w width
/// @param h heigt
/// @param type Type of the databuffer
/// @param filter Filter (NEAREST OR LINEAR)
void LoadPixels(const std::vector<u8>& data, int w, int h, Type type = RGBA32,
Filter filter = NEAREST);
/// @brief Load a texture of a T3X File
/// @note This is used for single texture T3X
/// Not for SpriteSheets
/// @param path path to .t3x file
void LoadT3X(const std::string& path);
/// @brief Input a Texture that you had set up on your own
/// @param tex Texture reference (deletes itself)
/// @param rszs The size of the source image
/// @param uvs Your uv Setup
void LoadExternal(C3D_Tex* tex, vec2 rszs, LI::Rect uvs) {
this->Delete();
this->tex = tex;
this->size = rszs;
this->uv = uvs;
}
vec2 GetRealSize() {
if (!tex) {
return vec2();
}
return vec2(tex->width, tex->height);
}
vec2 GetSize() const { return size; }
C3D_Tex* GetTex() const { return tex; }
LI::Rect GetUV() const { return uv; }
bool IsValid() const { return tex != 0; }
bool AutoUnLoad() const { return autounload; }
void AutoUnLoad(bool v) { autounload = v; }
operator C3D_Tex*() const { return tex; }
operator vec2() const { return size; }
operator LI::Rect() const { return uv; }
operator bool() const { return tex != 0; }
private:
void MakeTex(std::vector<u8>& buf, int w, int h, Type type = RGBA32,
Filter filter = NEAREST);
vec2 size;
LI::Rect uv;
C3D_Tex* tex = nullptr;
bool autounload = true;
};
#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/rect.hpp>
namespace PD {
namespace LI {
using TexAddress = uintptr_t;
/**
* Lithium Texture Data Holder
* Memory management is handled by backend
*/
class Texture : public SmartCtor<Texture> {
public:
/** Texture Type */
enum Type {
RGBA32, ///< RGBA 32
RGB24, ///< RGB24
A8, ///< A8
};
/** Texture Filters */
enum Filter {
NEAREST, ///< Nearest
LINEAR, ///< Linear
};
/** Default constructor */
Texture() : UV(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)) {
Address = addr;
Size = size;
UV = uv;
}
void CopyOther(Texture::Ref tex) {
Address = tex->Address;
Size = tex->Size;
UV = tex->UV;
}
ivec2 GetSize() const { return Size; }
LI::Rect GetUV() const { return UV; }
operator ivec2() const { return Size; }
operator LI::Rect() const { return UV; }
TexAddress Address;
ivec2 Size;
LI::Rect UV;
};
} // namespace LI
} // namespace PD

View File

@ -1,62 +1,48 @@
#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/vec.hpp>
namespace PD {
namespace LI {
class Vertex {
public:
Vertex() {}
Vertex(const vec2& p, const vec2& u, u32 c) {
pos[0] = p[0];
pos[1] = p[1];
uv = u;
color = c;
}
~Vertex() {}
Vertex& Pos(const vec2& v) {
pos = v;
return *this;
}
Vertex& Uv(const vec2& v) {
uv = v;
return *this;
}
Vertex& Color(u32 v) {
color = v;
return *this;
}
// private:
vec2 pos;
vec2 uv;
u32 color;
};
} // namespace LI
#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>
namespace PD {
namespace LI {
class Vertex {
public:
Vertex() {}
Vertex(const fvec2& p, const fvec2& u, u32 c) {
Pos.x = p.x;
Pos.y = p.y;
UV = u;
Color = c;
}
~Vertex() {}
// private:
fvec2 Pos;
fvec2 UV;
u32 Color;
};
} // namespace LI
} // namespace PD

View File

@ -0,0 +1,52 @@
#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 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 +1,115 @@
#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
};
#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

@ -0,0 +1,52 @@
#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.
*/
#pragma once
#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

60
include/pd/net/socket.hpp Normal file
View File

@ -0,0 +1,60 @@
#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 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

@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/tween.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/core/core.hpp>
#include <pd/overlays/overlay.hpp>
namespace PD {
@ -153,11 +152,11 @@ class Keyboard : public Overlay {
static int too;
// Tween for selector Movement
Tween<vec2> selector;
Tween<fvec2> selector;
// Tween for Selector Size
Tween<vec2> sel_szs;
Tween<fvec2> sel_szs;
// Current Cell size
vec2 cselszs;
fvec2 cselszs;
// selector index
int raw_sel;
@ -169,9 +168,9 @@ class Keyboard : public Overlay {
// Remove Animation
bool rem = false;
/// Probably a float would've done the job as well ;)
Tween<vec2> flymgr;
Tween<fvec2> flymgr;
// Secode Flymanager
Tween<vec2> chflymgr;
Tween<fvec2> chflymgr;
// Show Help
bool show_help = true;
};

View File

@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/color.hpp>
#include <pd/core/tween.hpp>
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
namespace PD {
@ -68,10 +67,10 @@ class MessageMgr : public PD::SmartCtor<MessageMgr> {
PD::Color col_bg; // Background Color
PD::Color col_text; // Text Color
float lifetime = 0.f; // LifeTime
PD::Tween<vec2> pos; // Position effect
PD::Tween<fvec2> pos; // Position effect
std::string title; // Title
std::string msg; // Message
vec2 size; // Size of the Background
fvec2 size; // Size of the Background
bool tbr = false; // To be Removed ?
bool kill = false; // Instant Kill
int s = 0; // Slot

View File

@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
namespace PD {

View File

@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/drivers/hid.hpp>
#include <pd/core/core.hpp>
#include <pd/lithium/renderer.hpp>
#include <pd/overlays/overlay.hpp>

View File

@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/drivers/hid.hpp>
#include <pd/core/core.hpp>
#include <pd/overlays/overlay.hpp>
namespace PD {
@ -74,7 +74,7 @@ class Performance : public Overlay {
* @param text Text to Show
* @param ren Renderer Reference
*/
void Line(vec2& pos, const std::string& text, LI::Renderer::Ref ren);
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

View File

@ -23,8 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/tween.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/core/core.hpp>
#include <pd/overlays/overlay.hpp>
#include <pd/ui7/ui7.hpp>
@ -68,7 +67,7 @@ class SettingsMenu : public Overlay {
// Some Animation
bool rem = false;
Tween<vec2> flymgr;
Tween<fvec2> flymgr;
// Custom UI7 Context
UI7::Context::Ref ctx;

View File

@ -1,54 +1,54 @@
#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
#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 +1,79 @@
#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
#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 +1,62 @@
#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
#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

View File

@ -1,55 +1,55 @@
#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/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
#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/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

View File

@ -1,75 +1,75 @@
#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>
#include <pd/ui7/io.hpp>
namespace PD {
namespace UI7 {
/**
* Button Object
* @note Button Press is delayed by 1 frame
* (but the visual reaction is done in the same frame)
* This only means that InPressed is responding the info in
* the next frame
*/
class Button : public Container {
public:
/**
* Button Object constructor
* @param label Label of the Button
* @param pos Base Position
* @param lr Reference to the Renderer
*/
Button(const std::string& label, UI7::IO::Ref io) {
this->label = label;
this->tdim = io->Ren->GetTextDimensions(label);
}
~Button() = default;
/** Return true if butten is pressed*/
bool IsPressed() { return pressed; }
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Function to Update Size if framepadding changes */
void Update() override;
private:
vec2 tdim; ///< Text size
UI7Color color = UI7Color_Button; ///< current button color
std::string label; ///< Label of the Button
bool pressed = false; ///< ispressed value
};
} // 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>
#include <pd/ui7/io.hpp>
namespace PD {
namespace UI7 {
/**
* Button Object
* @note Button Press is delayed by 1 frame
* (but the visual reaction is done in the same frame)
* This only means that InPressed is responding the info in
* the next frame
*/
class PD_UI7_API Button : public Container {
public:
/**
* Button Object constructor
* @param label Label of the Button
* @param pos Base Position
* @param lr Reference to the Renderer
*/
Button(const std::string& label, UI7::IO::Ref io) {
this->label = label;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Button() = default;
/** Return true if butten is pressed*/
bool IsPressed() { return pressed; }
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Function to Update Size if framepadding changes */
void Update() override;
private:
fvec2 tdim; ///< Text size
UI7Color color = UI7Color_Button; ///< current button color
std::string label; ///< Label of the Button
bool pressed = false; ///< ispressed value
};
} // namespace UI7
} // namespace PD

View File

@ -1,72 +1,72 @@
#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 {
/**
* Checkbox Object
* @note The Updated input is available after
* Context::Update while the visual update is done
* during the Update
*/
class Checkbox : public Container {
public:
/**
* Constructor for Checkbox Object
* @param label Label of the Checkbox
* @param usr_ref Reference to the bool value to update
* @param io IO Reference
*/
Checkbox(const std::string& label, bool& usr_ref, UI7::IO::Ref io)
: usr_ref(usr_ref) {
this->label = label;
this->tdim = io->Ren->GetTextDimensions(label);
}
~Checkbox() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Update Size if framepadding changed */
void Update() override;
private:
vec2 tdim; ///< Text Size
vec2 cbs = vec2(18); ///< Checkbox size
UI7Color color = UI7Color_FrameBackground; ///< Checkbox background Color
std::string label; ///< Checkbox Label
bool& usr_ref; ///< User bool reference
};
} // 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 {
/**
* Checkbox Object
* @note The Updated input is available after
* Context::Update while the visual update is done
* during the Update
*/
class PD_UI7_API Checkbox : public Container {
public:
/**
* Constructor for Checkbox Object
* @param label Label of the Checkbox
* @param usr_ref Reference to the bool value to update
* @param io IO Reference
*/
Checkbox(const std::string& label, bool& usr_ref, UI7::IO::Ref io)
: usr_ref(usr_ref) {
this->label = label;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~Checkbox() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Update Size if framepadding changed */
void Update() override;
private:
fvec2 tdim; ///< Text Size
fvec2 cbs = fvec2(18); ///< Checkbox size
UI7Color color = UI7Color_FrameBackground; ///< Checkbox background Color
std::string label; ///< Checkbox Label
bool& usr_ref; ///< User bool reference
};
} // namespace UI7
} // namespace PD

View File

@ -1,75 +1,75 @@
#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>
#include <pd/ui7/io.hpp>
#include <pd/ui7/layout.hpp>
namespace PD {
namespace UI7 {
/**
* Color Editor (Creating a PopUP when clicking)
*/
class ColorEdit : public Container {
public:
/**
* Constructor
* @param label Label of the Button
* @param pos Base Position
* @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!");
this->label = label;
this->color_ref = color;
this->initial_color = *color;
this->tdim = io->Ren->GetTextDimensions(label);
}
~ColorEdit() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Function to Update Size if framepadding changes */
void Update() override;
private:
vec2 tdim; ///< Text size
u32* color_ref = nullptr; ///< Color Reference
u32 initial_color; ///< Initial Color
std::string label; ///< Label of the Button
Layout::Ref layout; ///< Layout to open
bool is_shown = false; ///< AHow Layout Editor
};
} // 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>
#include <pd/ui7/io.hpp>
#include <pd/ui7/layout.hpp>
namespace PD {
namespace UI7 {
/**
* Color Editor (Creating a PopUP when clicking)
*/
class PD_UI7_API ColorEdit : public Container {
public:
/**
* Constructor
* @param label Label of the Button
* @param pos Base Position
* @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!");
this->label = label;
this->color_ref = color;
this->initial_color = *color;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~ColorEdit() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Function to Update Size if framepadding changes */
void Update() override;
private:
fvec2 tdim; ///< Text size
u32* color_ref = nullptr; ///< Color Reference
u32 initial_color; ///< Initial Color
std::string label; ///< Label of the Button
Layout::Ref layout; ///< Layout to open
bool is_shown = false; ///< AHow Layout Editor
};
} // namespace UI7
} // namespace PD

View File

@ -1,153 +1,166 @@
#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/strings.hpp>
#include <pd/core/vec.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/io.hpp>
namespace PD {
namespace UI7 {
/**
* Container base class all Objects are based on
* @note this class can be used to create custom Objects as well
*/
class Container : public SmartCtor<Container> {
public:
Container() = default;
/**
* Constructor with pos and Size
* @param pos Container Position
* @param size Container Size
*/
Container(const vec2& pos, const vec2& size) : pos(pos), size(size) {}
/**
* Constructor by a vec4 box
* @param box Box containing top left and bottom right coords
*/
Container(const vec4& box) : pos(box.xy()), size(box.zw() - box.xy()) {}
~Container() = default;
/**
* 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) {
list = l;
this->io = io;
this->screen = io->Ren->CurrentScreen();
}
/** Setter for Position */
void SetPos(const vec2& pos) { this->pos = pos; }
/** Setter for Size */
void SetSize(const vec2& size) { this->size = size; }
/** Getter for Position */
vec2 GetPos() { return pos; }
/** Getter for Size */
vec2 GetSize() { return size; }
/**
* Get the Containers Final Position
* for Rendering and Input (if it has a parent Object)
*/
vec2 FinalPos() {
vec2 res = pos;
if (parent) {
/// Probably should use parant->FinalPos here
res += parent->GetPos();
}
return res;
}
/** Setter for Parent Container */
void SetParent(Container::Ref v) { parent = v; }
/** Getter for Parent Container */
Container::Ref GetParent() { return parent; }
/** Check if Rendering can be skipped */
bool Skippable() const { return skippable; }
/** Check if the Object got a timeout (ID OBJ Relevant) */
bool Removable() const { return rem; }
/**
* Handles Scrolling by scrolling pos as well as
* Time for Remove for ID Objects
* @param scrolling Scrolling Position
* @param viewport Viewport to check if the Object is skippable
*/
void HandleScrolling(vec2 scrolling, vec4 viewport);
/** Template function for Input Handling */
virtual void HandleInput() {}
/** Tamplate function for Object rendering */
virtual void Draw() {}
/** Template function to update internal data (if needed) */
virtual void Update() {}
/**
* Function to unlock Input after Rendering is done in
* Menu::Update
* @note This is used if the Object got Input Handled directly after creation
* to not check for Inputs twice
*/
void UnlockInput() { inp_done = false; }
/** Get the Objects ID (if it is an ID object)*/
u32 GetID() const { return id; }
/**
* Set ID for ID Objects
* @param id Object ID (hashed prefix+objname+prefixed_counter)
*/
void SetID(u32 id) { this->id = id; }
protected:
/** used to skip Input/Render preocessing ot not*/
bool skippable = false;
/** value to check if an ID Object goes out of lifetime*/
bool rem = false;
/** Time of the last use (set by HandleScrolling)*/
u64 last_use = 0;
/** Input done or not for current frame*/
bool inp_done = false;
/** Reference to the Screen to draw the Object on*/
Screen::Ref screen;
/** Container Position*/
vec2 pos;
/** Container Size*/
vec2 size;
/** Reference to the Drawlist to Draw to*/
UI7::DrawList::Ref list;
/** IO Reference for Renderer and Theme */
UI7::IO::Ref io;
/** Reference to the parent container*/
Container::Ref parent;
/** Object ID (0 if unused)*/
u32 id = 0;
};
} // namespace UI7
} // 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/core.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/pd_p_api.hpp>
namespace PD {
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> {
public:
Container() = default;
/**
* Constructor with pos and Size
* @param pos Container Position
* @param size Container Size
*/
Container(const fvec2& pos, const fvec2& size) : pos(pos), size(size) {}
/**
* Constructor by a vec4 box
* @param box Box containing top left and bottom right coords
*/
Container(const fvec4& box)
: pos(fvec2(box.x, box.y)), size(fvec2(box.z - box.x, box.w - box.y)) {}
~Container() = default;
/**
* 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) {
list = l;
this->io = io;
// this->screen = io->Ren->CurrentScreen();
}
/** Setter for Position */
void SetPos(const fvec2& pos) { this->pos = pos; }
/** Setter for Size */
void SetSize(const fvec2& size) { this->size = size; }
/** Getter for Position */
fvec2 GetPos() { return pos; }
/** Getter for Size */
fvec2 GetSize() { return size; }
/**
* Get the Containers Final Position
* for Rendering and Input (if it has a parent Object)
*/
fvec2 FinalPos() {
vec2 res = pos;
if (parent) {
/// Probably should use parant->FinalPos here
res += parent->GetPos();
}
return res;
}
/** Setter for Parent Container */
void SetParent(Container::Ref v) { parent = v; }
/** Getter for Parent Container */
Container::Ref GetParent() { return parent; }
/** Check if Rendering can be skipped */
bool Skippable() const { return skippable; }
/** Check if the Object got a timeout (ID OBJ Relevant) */
bool Removable() const { return rem; }
/**
* Handles Scrolling by scrolling pos as well as
* Time for Remove for ID Objects
* @param scrolling Scrolling Position
* @param viewport Viewport to check if the Object is skippable
*/
void HandleScrolling(fvec2 scrolling, fvec4 viewport);
/** Template function for Input Handling */
virtual void HandleInput() {}
/** Tamplate function for Object rendering */
virtual void Draw() {}
/** Template function to update internal data (if needed) */
virtual void Update() {}
/** Internal Input Handler */
void HandleInternalInput();
/**
* Function to unlock Input after Rendering is done in
* Menu::Update
* @note This is used if the Object got Input Handled directly after creation
* to not check for Inputs twice
*/
void UnlockInput() { inp_done = false; }
/** Get the Objects ID (if it is an ID object)*/
u32 GetID() const { return id; }
/**
* Set ID for ID Objects
* @param id Object ID (hashed prefix+objname+prefixed_counter)
*/
void SetID(u32 id) { this->id = id; }
/** Get a reference to IO */
UI7::IO::Ref GetIO() { return io; }
protected:
/** used to skip Input/Render preocessing ot not*/
bool skippable = false;
/** value to check if an ID Object goes out of lifetime*/
bool rem = false;
/** Time of the last use (set by HandleScrolling)*/
u64 last_use = 0;
/** Input done or not for current frame*/
bool inp_done = false;
/** Reference to the Screen to draw the Object on*/
// Screen::Ref screen;
/** Container Position*/
fvec2 pos;
/** Container Size*/
fvec2 size;
/** Reference to the Drawlist to Draw to*/
UI7::DrawList::Ref list;
/** IO Reference for Renderer and Theme */
UI7::IO::Ref io;
/** Reference to the parent container*/
Container::Ref parent;
/** Object ID (0 if unused)*/
u32 id = 0;
/** Internal Flags */
u32 pFlags = 0;
/** Is Selected? */
bool pSelected = false;
/** Was Pressed */
bool pPressed = false;
/** Was Pressed Twice */
bool pPressedTwice = false;
};
} // namespace UI7
} // namespace PD

View File

@ -1,90 +1,90 @@
#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>
#include <pd/ui7/io.hpp>
namespace PD {
namespace UI7 {
/**
* DragData Object can take a datatype or a list
* and modifys these by moving left or right when dragging
*/
template <typename T>
class DragData : public Container {
public:
/**
* Constructor
* @param label Label of the Button
* @param data Data reference (Supported types can be seen in dragdata.cpp)
* @param num_elms Number of Array elements (for exaple with use ofvec4)
* @param io IO Reference
* @param min minimum number using Minimum limit
* @param max Maximum number set by max limit by default
* @param step To set the modifier for drag movement
* @param precision for float and double to set precision
*/
DragData(const std::string& label, T* data, size_t num_elms, UI7::IO::Ref io,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), T step = 1,
int precision = 1) {
PD::Assert(data != nullptr, "Input Data Address is null!");
this->label = label;
this->data = data;
this->elm_count = num_elms;
this->min = min;
this->max = max;
this->step = step;
this->precision = precision;
this->tdim = io->Ren->GetTextDimensions(label);
}
~DragData() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Function to Update Size if framepadding changes */
void Update() override;
private:
vec2 tdim; ///< Text size
std::string label; ///< Label of the Button
T* data;
size_t elm_count = 0;
T min;
T max;
T step;
int precision = 1;
};
} // 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>
#include <pd/ui7/io.hpp>
namespace PD {
namespace UI7 {
/**
* DragData Object can take a datatype or a list
* and modifys these by moving left or right when dragging
*/
template <typename T>
class PD_UI7_API DragData : public Container {
public:
/**
* Constructor
* @param label Label of the Button
* @param data Data reference (Supported types can be seen in dragdata.cpp)
* @param num_elms Number of Array elements (for exaple with use ofvec4)
* @param io IO Reference
* @param min minimum number using Minimum limit
* @param max Maximum number set by max limit by default
* @param step To set the modifier for drag movement
* @param precision for float and double to set precision
*/
DragData(const std::string& label, T* data, size_t num_elms, UI7::IO::Ref io,
T min = std::numeric_limits<T>::min(),
T max = std::numeric_limits<T>::max(), T step = 1,
int precision = 1) {
// PD::Assert(data != nullptr, "Input Data Address is null!");
this->label = label;
this->data = data;
this->elm_count = num_elms;
this->min = min;
this->max = max;
this->step = step;
this->precision = precision;
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
}
~DragData() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Function to Update Size if framepadding changes */
void Update() override;
private:
fvec2 tdim; ///< Text size
std::string label; ///< Label of the Button
T* data;
size_t elm_count = 0;
T min;
T max;
T step;
int precision = 1;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,75 @@
#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/container/container.hpp>
#include <pd/ui7/io.hpp>
namespace PD {
namespace UI7 {
/**
* Button Object
* @note Button Press is delayed by 1 frame
* (but the visual reaction is done in the same frame)
* This only means that InPressed is responding the info in
* the next frame
*/
class PD_UI7_API DynObj : public Container {
public:
/**
* Button Object constructor
* @param label Label of the Button
* @param pos Base Position
* @param lr Reference to the Renderer
*/
DynObj(std::function<void(UI7::IO::Ref, UI7::DrawList::Ref, Container*)>
RenderFunc) {
pRenFun = RenderFunc;
}
~DynObj() = default;
/** Return true if butten is pressed*/
bool IsPressed() { return pressed; }
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
*/
void HandleInput() override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
/** Function to Update Size if framepadding changes */
void Update() override;
private:
UI7Color color = UI7Color_Button; ///< current button color
bool pressed = false; ///< ispressed value
std::function<void(UI7::IO::Ref, UI7::DrawList::Ref, Container*)> pRenFun;
};
} // namespace UI7
} // namespace PD

View File

@ -30,21 +30,21 @@ namespace UI7 {
/**
* Image Object
*/
class Image : public Container {
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(Texture::Ref img, vec2 size = 0.f, LI::Rect uv = vec4(0.f)) {
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) {
if (size.x != 0 || size.y != 0) {
this->SetSize(size);
} else {
this->SetSize(img->GetSize());
this->SetSize(fvec2(img->GetSize().x, img->GetSize().y));
}
}
~Image() = default;
@ -56,9 +56,9 @@ class Image : public Container {
void Draw() override;
private:
Texture::Ref img; ///< Texture reference to the Image
vec2 newsize = 0.f; ///< New Size
LI::Rect cuv; ///< Custom UV
LI::Texture::Ref img; ///< Texture reference to the Image
fvec2 newsize = 0.f; ///< New Size
LI::Rect cuv; ///< Custom UV
};
} // namespace UI7
} // namespace PD

View File

@ -30,16 +30,16 @@ namespace UI7 {
/**
* Label [Text] Object
*/
class Label : public Container {
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, LI::Renderer::Ref lr) {
Label(const std::string& label, IO::Ref io) {
this->label = label;
this->tdim = lr->GetTextDimensions(label);
this->tdim = io->Font->GetTextBounds(label, io->FontScale);
this->SetSize(tdim);
}
~Label() = default;
@ -51,7 +51,7 @@ class Label : public Container {
void Draw() override;
private:
vec2 tdim; ///< Text Size
fvec2 tdim; ///< Text Size
UI7Color color = UI7Color_Text; ///< Color
std::string label; ///< Text to Render
};

View File

@ -1,31 +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/ui7/container/button.hpp>
#include <pd/ui7/container/checkbox.hpp>
#include <pd/ui7/container/coloredit.hpp>
#include <pd/ui7/container/dragdata.hpp>
#include <pd/ui7/container/image.hpp>
#include <pd/ui7/container/label.hpp>
#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/button.hpp>
#include <pd/ui7/container/checkbox.hpp>
#include <pd/ui7/container/coloredit.hpp>
#include <pd/ui7/container/dragdata.hpp>
#include <pd/ui7/container/dynobj.hpp>
#include <pd/ui7/container/image.hpp>
#include <pd/ui7/container/label.hpp>

View File

@ -1,238 +1,236 @@
#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/lithium/renderer.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/theme.hpp>
namespace PD {
namespace UI7 {
/** DrawList class */
class DrawList : public SmartCtor<DrawList> {
public:
/**
* Constructor for a new Drawlist
* @param r Renderer reference
*/
DrawList(LI::Renderer::Ref r) { ren = r; }
~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 vec2& pos, const vec2& size, const UI7Color& clr,
int thickness = 1);
/**
* Render a Rectangle
* @param pos Position
* @param szs Size
* @param clr Color
*/
void AddRectangle(vec2 pos, vec2 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 vec2& a, const vec2& b, const vec2& 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 vec2& a, const vec2& b, const vec2& 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 vec2& 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 vec2& 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(vec2 pos, const std::string& text, const UI7Color& clr,
LITextFlags flags = 0, vec2 box = vec2());
/**
* 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(vec2 pos, Texture::Ref img, vec2 size = 0.f,
LI::Rect uv = vec4(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 vec2& a, const vec2& 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 std::vector<vec2>& 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 std::vector<vec2>& points,
const UI7Color& clr);
/** Clear the Drawlist */
void Clear();
/** Process [Render] the Drawlist */
void Process();
/** Push a Clip Rect */
void PushClipRect(const vec4& v) { clip_rects.push(v); }
/** Revert Last Clip Rect */
void PopClipRect() { clip_rects.pop(); }
/** Getter for the Layer */
int Layer() const { return layer; }
/** Setter fot the Layer */
void Layer(int v) { layer = v; }
/** 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 vec2& v) { Path.push_back(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 vec2& 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(vec2 a, vec2 b, float rounding = 0.f, UI7DrawFlags flags = 0);
private:
/** Base Layer offset (Internal Used) */
int BaseLayer() const { return base; }
/** Base Layer offset (Internal Used) */
void BaseLayer(int v) { base = v; }
// Set friendclass here to not expose private functions as public
friend class Menu;
friend class Context;
int layer; ///< Current Layer
int base; ///< Base Layer
LI::Renderer::Ref ren; ///< Renderer Reference
std::stack<vec4> clip_rects; ///< Stack containing Scissor Areas
u32 num_vertices; ///< Number of Vertices
u32 num_indices; ///< Number of Indices
std::vector<vec2> Path;
// Map for Auto Static Text
std::unordered_map<u32, LI::StaticText::Ref> static_text;
// List of Drawcommands generated
std::vector<std::pair<bool, LI::Command::Ref>> commands;
};
} // 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>
#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

View File

@ -1,84 +1,99 @@
#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.
*/
/** 32Bit Value to Stpre Menu Flags */
using UI7MenuFlags = unsigned int;
/** 32Bit Value to store Alignment Flags */
using UI7Align = unsigned int;
/** 32Bit Value to store Context (IO) flags */
using UI7IOFlags = unsigned int;
/** 32Bit Value for Layout Flags */
using UI7LayoutFlags = unsigned int;
/** 32Bit value for DrawFlags */
using UI7DrawFlags = unsigned int;
/** Menu Flags */
enum UI7MenuFlags_ {
UI7MenuFlags_None = 0, ///< No Flags (Default)
UI7MenuFlags_NoTitlebar = 1 << 0, ///< Dont Show Titlebar
UI7MenuFlags_CenterTitle = 1 << 1, ///< Center the Menu Title in Titlebar
UI7MenuFlags_HzScrolling = 1 << 2, ///< Enable Horizontal Scrolling
UI7MenuFlags_VtScrolling = 1 << 3, ///< Enable Vertical Scrolling
UI7MenuFlags_NoBackground = 1 << 4, ///< Dont Render Menu Background
UI7MenuFlags_NoClipRect = 1 << 5, ///< Disable clip render area of the Menu
UI7MenuFlags_NoCollapse = 1 << 6, ///< Disable Menu Collapse
UI7MenuFlags_NoMove = 1 << 7, ///< Disable Menu Movement
UI7MenuFlags_NoResize = 1 << 8, ///< Disable Menu Resize
UI7MenuFlags_NoClose = 1 << 9, ///< Disable Close Button
UI7MenuFlags_NoScrollbar = 1 << 10, ///< Hide the Scrollbar
// Enable Horizontal and Vertical Scrolling
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
};
/** UI7 Layout Flags */
enum UI7LayoutFlags_ {
UI7LayoutFlags_None = 0, ///< No Flags used
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
};
enum UI7DrawFlags_ {
UI7DrawFlags_None = 0,
UI7DrawFlags_Close = 1 << 0, ///< Close a PolyLine
UI7DrawFlags_AALines = 1 << 1, ///< Anti aliased Lines
};
/** UI7 Context Flags */
enum UI7IOFlags_ {
UI7IOFlags_None = 0, ///< No Additional Config available
UI7IOFlags_HasTouch = 1 << 0, ///< Enable touch support [future]
UI7IOFlags_HasMouseCursor = 1 << 1, ///< Enable Mouse support [future]
};
/** Probably need to update this */
enum UI7Align_ {
UI7Align_Left = 1 << 0, ///< [Hz Op] Align Left (Default)
UI7Align_Center = 1 << 1, ///< [Hz Op] Align Center
UI7Align_Right = 1 << 2, ///< [Hz Op] Align Right
UI7Align_Top = 1 << 3, ///< [Vt Op] Align Top (Default)
UI7Align_Mid = 1 << 4, ///< [Vt Op] Align Mid
UI7Align_Bottom = 1 << 5, ///< [Vt Op] Align Bottom
// Default Horizontal and Vertical Alignment
UI7Align_Default = UI7Align_Left | UI7Align_Top,
#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.
*/
/** 32Bit Value to Stpre Menu Flags */
using UI7MenuFlags = unsigned int;
/** 32Bit Value to store Alignment Flags */
using UI7Align = unsigned int;
/** 32Bit Value to store Context (IO) flags */
using UI7IOFlags = unsigned int;
/** 32Bit Value for Layout Flags */
using UI7LayoutFlags = unsigned int;
/** 32Bit value for DrawFlags */
using UI7DrawFlags = unsigned int;
/** Menu Flags */
enum UI7MenuFlags_ {
UI7MenuFlags_None = 0, ///< No Flags (Default)
UI7MenuFlags_NoTitlebar = 1 << 0, ///< Dont Show Titlebar
UI7MenuFlags_CenterTitle = 1 << 1, ///< Center the Menu Title in Titlebar
UI7MenuFlags_HzScrolling = 1 << 2, ///< Enable Horizontal Scrolling
UI7MenuFlags_VtScrolling = 1 << 3, ///< Enable Vertical Scrolling
UI7MenuFlags_NoBackground = 1 << 4, ///< Dont Render Menu Background
UI7MenuFlags_NoClipRect = 1 << 5, ///< Disable clip render area of the Menu
UI7MenuFlags_NoCollapse = 1 << 6, ///< Disable Menu Collapse
UI7MenuFlags_NoMove = 1 << 7, ///< Disable Menu Movement
UI7MenuFlags_NoResize = 1 << 8, ///< Disable Menu Resize
UI7MenuFlags_NoClose = 1 << 9, ///< Disable Close Button
UI7MenuFlags_NoScrollbar = 1 << 10, ///< Hide the Scrollbar
// Enable Horizontal and Vertical Scrolling
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
};
/** UI7 Layout Flags */
enum UI7LayoutFlags_ {
UI7LayoutFlags_None = 0, ///< No Flags used
UI7LayoutFlags_UseClipRect = 1 << 0, ///< Enable ClipRect
};
enum UI7DrawFlags_ {
UI7DrawFlags_None = 0,
UI7DrawFlags_Close = 1 << 0, ///< Close a PolyLine
UI7DrawFlags_AALines = 1 << 1, ///< Anti aliased Lines
};
/** UI7 Context Flags */
enum UI7IOFlags_ {
UI7IOFlags_None = 0, ///< No Additional Config available
UI7IOFlags_HasTouch = 1 << 0, ///< Enable touch support [future]
UI7IOFlags_HasMouseCursor = 1 << 1, ///< Enable Mouse support [future]
};
/** Probably need to update this */
enum UI7Align_ {
UI7Align_Left = 1 << 0, ///< [Hz Op] Align Left (Default)
UI7Align_Center = 1 << 1, ///< [Hz Op] Align Center
UI7Align_Right = 1 << 2, ///< [Hz Op] Align Right
UI7Align_Top = 1 << 3, ///< [Vt Op] Align Top (Default)
UI7Align_Mid = 1 << 4, ///< [Vt Op] Align Mid
UI7Align_Bottom = 1 << 5, ///< [Vt Op] Align Bottom
// Default Horizontal and Vertical Alignment
UI7Align_Default = UI7Align_Left | UI7Align_Top,
};
/** Special flags for Layout::AddObjectEx */
enum UI7LytAdd_ {
UI7LytAdd_None = 0, ///< Also known as default or ->AddObject
UI7LytAdd_NoCursorUpdate = 1 << 0, ///< Add without cursor alignment
UI7LytAdd_NoScrollHandle = 1 << 1, ///< Skip HandleScrolling
UI7LytAdd_Front = 1 << 2, ///< Add in front of the list
};
enum UI7ContainerFlags_ {
UI7ContainerFlags_None = 0,
UI7ContainerFlags_EnableInternalInput = 1 << 0,
UI7ContainerFlags_Selectable = 1 << 1,
UI7ContainerFlags_OutlineSelected = 1 << 2,
};

View File

@ -23,8 +23,7 @@ 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/strings.hpp>
#include <pd/core/core.hpp>
namespace PD {
namespace UI7 {

View File

@ -0,0 +1,130 @@
#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/id.hpp>
namespace PD {
namespace UI7 {
class InputHandler : public SmartCtor<InputHandler> {
public:
InputHandler(Hid::Ref inp_drv) {
DragTime = Timer::New(false);
Inp = inp_drv;
}
~InputHandler() = default;
/**
* Function to Check if current Object is dragged
* or set it dragged
* @param id ID to identify this specific Object
* @param area Area where to start dragging
* @return if inputs to this objects are alowed or not
*/
bool DragObject(const UI7::ID& id, fvec4 area) {
if (CurrentMenu != FocusedMenu) {
return false;
}
if (IsObjectDragged()) {
// Only block if the Dragged Object has a difrent id
if (DraggedObject != id) {
return false;
}
}
// Get a Short define for touch pos
vec2 p = Inp->TouchPos();
// Check if Drag starts in the area position
if (Inp->IsDown(Inp->Touch) && LI::Renderer::InBox(p, area)) {
// Set ID and iniatial Positions
DraggedObject = id;
DragSourcePos = p;
DragPosition = p;
DragLastPosition = p;
DragDestination = area;
// Reset and Start DragTimer
DragTime->Reset();
DragTime->Rseume();
return false; // To make sure the Object is "Dragged"
} else if (Inp->IsHeld(Inp->Touch) && IsObjectDragged()) {
// Update DragLast and DragPoisition
DragLastPosition = DragPosition;
DragPosition = p;
} else if (Inp->IsUp(Inp->Touch) && IsObjectDragged()) {
// Released... Everything gets reset
DraggedObject = 0;
DragPosition = 0;
DragSourcePos = 0;
DragLastPosition = 0;
DragDestination = 0;
// Set Drag released to true (only one frame)
// and Only if still in Box
DragReleased = LI::Renderer::InBox(Inp->TouchPosLast(), area);
DragReleasedAW = true; // Advanced
u64 d_rel = Sys::GetTime();
if (d_rel - DragLastReleased < DoubleClickTime) {
DragDoubleRelease = true;
DragLastReleased = 0; // Set 0 to prevent double exec
} else {
DragLastReleased = d_rel;
}
// Ensure timer is paused
DragTime->Pause();
DragTime->Reset();
// Still return The Object is Dragged to ensure
// the DragReleased var can be used
return true;
}
return IsObjectDragged();
}
void Update() {
DragTime->Update();
DragReleased = false;
DragReleasedAW = false;
DragDoubleRelease = false;
}
u64 DoubleClickTime = 500; // Milliseconds
u32 FocusedMenu = 0;
fvec4 FocusedMenuRect;
u32 CurrentMenu = 0;
u32 DraggedObject = 0;
fvec2 DragSourcePos = 0;
fvec2 DragPosition = 0;
fvec2 DragLastPosition = 0;
fvec4 DragDestination = 0;
Timer::Ref DragTime;
u64 DragLastReleased = 0;
bool DragReleased = false; ///< Drag Releaded in Box
bool DragReleasedAW = false; ///< Drag Released Anywhere
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

View File

@ -1,169 +1,102 @@
#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/timer.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
#include <pd/ui7/theme.hpp>
namespace PD {
namespace UI7 {
/**
* Shared Configuration and Runtime Data for a UI7 Context
*/
class IO : public SmartCtor<IO> {
public:
/**
* IO Constructor setting UP References
*/
IO(Hid::Ref input_driver, LI::Renderer::Ref ren) {
Time = Timer::New();
DragTime = Timer::New(false);
Theme = UI7::Theme::New();
Inp = input_driver;
Ren = ren;
Back = UI7::DrawList::New(Ren);
Front = UI7::DrawList::New(Ren);
RegisterDrawList("CtxBackList", Back);
DeltaStats = TimeStats::New(60);
};
~IO() = default;
/**
* IO Update Internal Variables
*/
void Update();
float Framerate = 0.f;
float Delta = 0.f;
u64 LastTime = 0;
TimeStats::Ref DeltaStats;
Timer::Ref Time;
Hid::Ref Inp;
LI::Renderer::Ref Ren;
UI7::Theme::Ref Theme;
vec2 MenuPadding = 5.f;
vec2 FramePadding = 5.f;
vec2 ItemSpace = vec2(5.f, 2.f);
vec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)
bool ShowMenuBorder = true;
bool ShowFrameBorder = false; // not implemented yet
float OverScrollMod = 0.15f;
u64 DoubleClickTime = 500; // Milliseconds
std::vector<std::pair<UI7::ID, DrawList::Ref>> DrawListRegestry;
DrawList::Ref Back;
DrawList::Ref Front;
u32 NumVertices = 0; ///< Debug Vertices Num
u32 NumIndices = 0; ///< Debug Indices Num
// DrawListApi
void RegisterDrawList(const UI7::ID& id, DrawList::Ref v) {
DrawListRegestry.push_back(std::make_pair(id, v));
}
// Input API
u32 FocusedMenu = 0;
vec4 FocusedMenuRect;
u32 CurrentMenu = 0;
u32 DraggedObject = 0;
vec2 DragSourcePos = 0;
vec2 DragPosition = 0;
vec2 DragLastPosition = 0;
vec4 DragDestination = 0;
Timer::Ref DragTime;
u64 DragLastReleased = 0;
bool DragReleased = false; ///< Drag Releaded in Box
bool DragReleasedAW = false; ///< Drag Released Anywhere
bool DragDoubleRelease = false; ///< Double Click
/** Check if an object is Dragged already */
bool IsObjectDragged() const { return DraggedObject != 0; }
/**
* Function to Check if current Object is dragged
* or set it dragged
* @param id ID to identify this specific Object
* @param area Area where to start dragging
* @return if inputs to this objects are alowed or not
*/
bool DragObject(const UI7::ID& id, vec4 area) {
if (CurrentMenu != FocusedMenu) {
return false;
}
if (IsObjectDragged()) {
// Only block if the Dragged Object has a difrent id
if (DraggedObject != id) {
return false;
}
}
// Get a Short define for touch pos
vec2 p = Inp->TouchPos();
// Check if Drag starts in the area position
if (Inp->IsDown(Inp->Touch) && Ren->InBox(p, area)) {
// Set ID and iniatial Positions
DraggedObject = id;
DragSourcePos = p;
DragPosition = p;
DragLastPosition = p;
DragDestination = area;
// Reset and Start DragTimer
DragTime->Reset();
DragTime->Rseume();
return false; // To make sure the Object is "Dragged"
} else if (Inp->IsHeld(Inp->Touch) && IsObjectDragged()) {
// Update DragLast and DragPoisition
DragLastPosition = DragPosition;
DragPosition = p;
} else if (Inp->IsUp(Inp->Touch) && IsObjectDragged()) {
// Released... Everything gets reset
DraggedObject = 0;
DragPosition = 0;
DragSourcePos = 0;
DragLastPosition = 0;
DragDestination = 0;
// Set Drag released to true (only one frame)
// and Only if still in Box
DragReleased = Ren->InBox(Inp->TouchPosLast(), area);
DragReleasedAW = true; // Advanced
u64 d_rel = Sys::GetTime();
if (d_rel - DragLastReleased < DoubleClickTime) {
DragDoubleRelease = true;
DragLastReleased = 0; // Set 0 to prevent double exec
} else {
DragLastReleased = d_rel;
}
// Ensure timer is paused
DragTime->Pause();
DragTime->Reset();
// Still return The Object is Dragged to ensure
// the DragReleased var can be used
return true;
}
return IsObjectDragged();
}
};
} // 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>
#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>
namespace PD {
namespace UI7 {
/**
* Shared Configuration and Runtime Data for a UI7 Context
*/
class PD_UI7_API IO : public SmartCtor<IO> {
public:
/**
* IO Constructor setting UP References
*/
IO(Hid::Ref input_driver, LI::Renderer::Ref ren) {
Time = Timer::New();
InputHandler = UI7::InputHandler::New(input_driver);
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);
DeltaStats = TimeStats::New(60);
};
~IO() = default;
/**
* IO Update Internal Variables
*/
void Update();
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;
float FontScale = 0.7f;
UI7::Theme::Ref Theme;
fvec2 MenuPadding = 5.f;
fvec2 FramePadding = 5.f;
fvec2 ItemSpace = vec2(5.f, 2.f);
fvec2 MinSliderDragSize = 10.f; // Min height (Vt) and Min Width (Hz)
bool ShowMenuBorder = true;
bool ShowFrameBorder = false; // not implemented yet
float OverScrollMod = 0.15f;
u64 DoubleClickTime = 500; // Milliseconds
PD::List<Pair<UI7::ID, 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;
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) {
DrawListRegestry.PushBack(Pair(id, v));
}
UI7::InputHandler::Ref InputHandler;
};
} // namespace UI7
} // namespace PD

View File

@ -1,120 +1,134 @@
#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/ui7/container/container.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/io.hpp>
namespace PD {
namespace UI7 {
class Layout : public PD::SmartCtor<Layout> {
public:
Layout(const ID& id, IO::Ref io) : ID(id) {
this->IO = io;
DrawList = UI7::DrawList::New(io->Ren);
Scrolling[0] = false;
Scrolling[1] = false;
CursorInit();
Pos = vec2(0, 0);
Size = vec2(320, 240);
WorkRect = vec4(IO->MenuPadding, Size - (vec2(2) * IO->MenuPadding));
}
~Layout() = default;
const std::string& GetName() const { return ID.GetName(); }
const UI7::ID& GetID() const { return this->ID; }
const vec2& GetPosition() const { return Pos; }
void SetPosition(const vec2& v) { Pos = v; }
const vec2& GetSize() const { return Size; }
void SetSize(const vec2& v) { Size = v; }
UI7::DrawList::Ref GetDrawList() { return DrawList; }
void CursorInit();
void SameLine();
void CursorMove(const vec2& size);
bool ObjectWorkPos(vec2& movpos);
void AddObject(Container::Ref obj);
Container::Ref FindObject(u32 id);
void ClearIDObjects() { IDObjects.clear(); }
vec2 AlignPosition(vec2 pos, vec2 size, vec4 area, UI7Align alignment);
/** Get the Alignment for Current State */
UI7Align GetAlignment() {
/// if temp alignment is used then return it and
/// reset tmpalign
if (TempAlign) {
auto t = TempAlign;
TempAlign = 0;
return t;
}
return Alignment;
}
void SetAlign(UI7Align a) { Alignment = a; }
void NextAlign(UI7Align a) { TempAlign = a; }
void Update();
private:
friend class Menu;
friend class Context;
// Base Components
UI7::ID ID;
UI7::IO::Ref IO;
UI7::DrawList::Ref DrawList;
// Positioning
vec2 Pos;
vec2 Size;
UI7Align Alignment = UI7Align_Default;
UI7Align TempAlign;
// Cursor
vec2 Cursor;
vec2 InitialCursorOffset;
vec2 BackupCursor;
vec2 SamelineCursor;
vec2 BeforeSameLine;
vec2 LastObjSize;
vec2 MaxPosition;
vec4 WorkRect;
// Scrolling
vec2 ScrollOffset;
bool Scrolling[2];
// Objects
std::vector<Container::Ref> Objects;
std::vector<Container::Ref> IDObjects;
};
} // 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>
#include <pd/ui7/container/container.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/io.hpp>
#include <pd/ui7/pd_p_api.hpp>
namespace PD {
namespace UI7 {
class PD_UI7_API Layout : public PD::SmartCtor<Layout> {
public:
Layout(const ID& id, IO::Ref io) : ID(id) {
this->IO = io;
DrawList = UI7::DrawList::New(io.get());
Scrolling[0] = false;
Scrolling[1] = false;
CursorInit();
Pos = fvec2(0, 0);
Size = fvec2(320, 240);
WorkRect = fvec4(IO->MenuPadding, Size - (fvec2(2) * IO->MenuPadding));
}
~Layout() = default;
const std::string& GetName() const { return ID.GetName(); }
const UI7::ID& GetID() const { return this->ID; }
const fvec2& GetPosition() const { return Pos; }
void SetPosition(const fvec2& v) { Pos = v; }
const fvec2& GetSize() const { return Size; }
void SetSize(const fvec2& v) { Size = v; }
UI7::DrawList::Ref GetDrawList() { return DrawList; }
void CursorInit();
void SameLine();
void CursorMove(const fvec2& size);
bool ObjectWorkPos(fvec2& movpos);
/**
* Extended Object Add Func to Add Object in Front or disable
* Position by cursor as well as cursor update...
* Should only be used in special cases as the
* AddObject function is faster
* Using Flags for its features cause dont want to have too much args
*/
void AddObjectEx(Container::Ref obj, u32 Flags);
/**
* Fast Function to Add Object in Layout SPace like
* button Label images etc
*/
void AddObject(Container::Ref obj);
Container::Ref FindObject(u32 id);
void ClearIDObjects() { IDObjects.clear(); }
fvec2 AlignPosition(fvec2 pos, fvec2 size, fvec4 area, UI7Align alignment);
/** Get the Alignment for Current State */
UI7Align GetAlignment() {
/// if temp alignment is used then return it and
/// reset tmpalign
if (TempAlign) {
auto t = TempAlign;
TempAlign = 0;
return t;
}
return Alignment;
}
void SetAlign(UI7Align a) { Alignment = a; }
void NextAlign(UI7Align a) { TempAlign = a; }
void Update();
private:
friend class Menu;
friend class Context;
friend class ReMenu;
// Base Components
UI7::ID ID;
UI7::IO::Ref IO;
UI7::DrawList::Ref DrawList;
// Positioning
fvec2 Pos;
fvec2 Size;
UI7Align Alignment = UI7Align_Default;
UI7Align TempAlign;
// Cursor
fvec2 Cursor;
fvec2 InitialCursorOffset;
fvec2 BackupCursor;
fvec2 SamelineCursor;
fvec2 BeforeSameLine;
fvec2 LastObjSize;
fvec2 MaxPosition;
fvec4 WorkRect;
// Scrolling
fvec2 ScrollOffset;
bool Scrolling[2];
// Objects
PD::List<Container::Ref> Objects;
std::vector<Container::Ref> IDObjects;
};
} // namespace UI7
} // namespace PD

View File

@ -1,298 +1,300 @@
#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/tween.hpp>
#include <pd/drivers/hid.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>
namespace PD {
namespace UI7 {
/** Menu Class for UI7 */
class 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;
// Objects
/**
* 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(Texture::Ref img, vec2 size = 0.f, LI::Rect uv = vec4(0));
/**
* Color Edit Object that opens a popup editor if clicked
* @param label Name of the Edit field
* @param color Color reference to edit
*/
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,
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((u32)data));
Container::Ref r = Layout->FindObject(id);
if (!r) {
r = PD::New<UI7::DragData<T>>(label, data, num_elms, io, min, max, step,
precision);
r->SetID(id);
}
Layout->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 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); }
/**
* Get IO Reference
* @return io Reference
*/
UI7::IO::Ref GetIO() { return io; }
// API for Custom Objects
/** 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; }
/**
* Animated Scroll to Position
* @param pos Destination Position
*/
void ScrollTo(vec2 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(); }
// 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();
// 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<vec2> 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;
};
} // 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>
#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>
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;
// Objects
/**
* 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));
/**
* Color Edit Object that opens a popup editor if clicked
* @param label Name of the Edit field
* @param color Color reference to edit
*/
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,
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);
if (!r) {
r = PD::New<UI7::DragData<T>>(label, data, num_elms, io, min, max, step,
precision);
r->SetID(id);
}
Layout->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 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); }
/**
* Get IO Reference
* @return io Reference
*/
UI7::IO::Ref GetIO() { return io; }
// API for Custom Objects
/** 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; }
/**
* 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(); }
// 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;
};
} // namespace UI7
} // namespace PD

View File

@ -0,0 +1,52 @@
#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.
*/
#pragma once
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef PD_UI7_BUILD_SHARED
#define PD_UI7_API __declspec(dllexport)
#else
#define PD_UI7_API __declspec(dllimport)
#endif
#elif defined(__APPLE__) // macOS (untested yet)
#ifdef PD_UI7_BUILD_SHARED
#define PD_UI7_API __attribute__((visibility("default")))
#else
#define PD_UI7_API
#endif
#elif defined(__linux__) // Linux (untested yet)
#ifdef PD_UI7_BUILD_SHARED
#define PD_UI7_API __attribute__((visibility("default")))
#else
#define PD_UI7_API
#endif
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define PD_UI7_API
#else
#define PD_UI7_API
#endif

107
include/pd/ui7/remenu.hpp Normal file
View File

@ -0,0 +1,107 @@
#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

View File

@ -1,160 +1,161 @@
#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>
/**
* Using this to support 32bit color values as well as
* values from UI7Color_
*/
using UI7Color = PD::u32;
/** Theme Color */
enum UI7Color_ {
UI7Color_Background, ///< UI7 Menu Background
UI7Color_Border, ///< Menu/Frame Border Color
UI7Color_Button, ///< UI7 Button Idle Color
UI7Color_ButtonDead, ///< UI7 Disabled Button Color
UI7Color_ButtonActive, ///< UI7 Pressed Button Color
UI7Color_ButtonHovered, ///< UI7 Hovered Button Color
UI7Color_Text, ///< UI7 Text Color
UI7Color_TextDead, ///< UI7 Dead Text Color
UI7Color_Header, ///< UI7 Menu Header Color
UI7Color_HeaderDead, ///< Inactive Header
UI7Color_Selector, ///< UI7 Selector Color
UI7Color_Checkmark, ///< UI7 Checkmark Color
UI7Color_FrameBackground, ///< UI7 Frame Background
UI7Color_FrameBackgroundHovered, ///< UI7 Hovered Frame Background
UI7Color_Progressbar, ///< UI7 Progressbar Background
UI7Color_ListEven, ///< UI7 List (Even Entry) Background Color
UI7Color_ListOdd, ///< UI7 List (Odd Entry) Background Color
};
namespace PD {
namespace UI7 {
/** Theme Class */
class Theme : public SmartCtor<Theme> {
public:
/**
* Default Constructor Setting up the Default theme
* @note if using SmartCtor Reference you probably need to do
* Theme::Default(*theme.get());
*/
Theme() { Default(*this); }
~Theme() = default;
/**
* Simple static Loader for the Default Theme
* @param theme Theme Reference
*/
static void Default(Theme& theme);
/**
* White Mode Theme
* @param Theme theme reference
*/
static void Flashbang(Theme& theme);
/** Revert the last Color Change */
Theme& Pop() {
theme[changes[changes.size() - 1].first] =
changes[changes.size() - 1].second;
changes.pop_back();
return *this;
}
/**
* Revert the last color Change done for a specific color
* @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);
break;
}
}
return *this;
}
/**
* Change a Color
* @param tc Color Identifier
* @param color Color to change to
*/
Theme& Change(UI7Color tc, u32 color) {
if (theme.find(tc) == theme.end()) {
return *this;
}
changes.push_back(std::make_pair(tc, theme[tc]));
theme[tc] = color;
return *this;
}
/**
* Get the Color of a Color ReferenceID
* @param c ReferenceID
*/
u32 Get(UI7Color c) const {
auto e = theme.find(c);
if (e == theme.end()) {
return 0x00000000;
}
return e->second;
}
/**
* [UNSAFE] to use
* Get the Color Ref of a Color ReferenceID
* @param c ReferenceID
*/
u32& GetRef(UI7Color c) {
auto e = theme.find(c);
if (e == theme.end()) {
static u32 noclr = 0x00000000;
return noclr;
}
return e->second;
}
/**
* Operator wrapper for get
* @param c Color ReferenceID
*/
u32 operator[](UI7Color c) const { return Get(c); }
/**
* Change but just sets [can implement completly new ids]
* @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; }
private:
std::unordered_map<u32, u32> theme; ///< Theme Data
std::vector<std::pair<UI7Color, u32>> changes; ///< List of Changes
};
} // 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>
#include <pd/ui7/pd_p_api.hpp>
/**
* Using this to support 32bit color values as well as
* values from UI7Color_
*/
using UI7Color = PD::u32;
/** Theme Color */
enum UI7Color_ {
UI7Color_Background, ///< UI7 Menu Background
UI7Color_Border, ///< Menu/Frame Border Color
UI7Color_Button, ///< UI7 Button Idle Color
UI7Color_ButtonDead, ///< UI7 Disabled Button Color
UI7Color_ButtonActive, ///< UI7 Pressed Button Color
UI7Color_ButtonHovered, ///< UI7 Hovered Button Color
UI7Color_Text, ///< UI7 Text Color
UI7Color_TextDead, ///< UI7 Dead Text Color
UI7Color_Header, ///< UI7 Menu Header Color
UI7Color_HeaderDead, ///< Inactive Header
UI7Color_Selector, ///< UI7 Selector Color
UI7Color_Checkmark, ///< UI7 Checkmark Color
UI7Color_FrameBackground, ///< UI7 Frame Background
UI7Color_FrameBackgroundHovered, ///< UI7 Hovered Frame Background
UI7Color_Progressbar, ///< UI7 Progressbar Background
UI7Color_ListEven, ///< UI7 List (Even Entry) Background Color
UI7Color_ListOdd, ///< UI7 List (Odd Entry) Background Color
};
namespace PD {
namespace UI7 {
/** Theme Class */
class PD_UI7_API Theme : public SmartCtor<Theme> {
public:
/**
* Default Constructor Setting up the Default theme
* @note if using SmartCtor Reference you probably need to do
* Theme::Default(*theme.get());
*/
Theme() { Default(*this); }
~Theme() = default;
/**
* Simple static Loader for the Default Theme
* @param theme Theme Reference
*/
static void Default(Theme& theme);
/**
* White Mode Theme
* @param Theme theme reference
*/
static void Flashbang(Theme& theme);
/** Revert the last Color Change */
Theme& Pop() {
theme[changes[changes.size() - 1].first] =
changes[changes.size() - 1].second;
changes.pop_back();
return *this;
}
/**
* Revert the last color Change done for a specific color
* @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);
break;
}
}
return *this;
}
/**
* Change a Color
* @param tc Color Identifier
* @param color Color to change to
*/
Theme& Change(UI7Color tc, u32 color) {
if (theme.find(tc) == theme.end()) {
return *this;
}
changes.push_back(std::make_pair(tc, theme[tc]));
theme[tc] = color;
return *this;
}
/**
* Get the Color of a Color ReferenceID
* @param c ReferenceID
*/
u32 Get(UI7Color c) const {
auto e = theme.find(c);
if (e == theme.end()) {
return 0x00000000;
}
return e->second;
}
/**
* [UNSAFE] to use
* Get the Color Ref of a Color ReferenceID
* @param c ReferenceID
*/
u32& GetRef(UI7Color c) {
auto e = theme.find(c);
if (e == theme.end()) {
static u32 noclr = 0x00000000;
return noclr;
}
return e->second;
}
/**
* Operator wrapper for get
* @param c Color ReferenceID
*/
u32 operator[](UI7Color c) const { return Get(c); }
/**
* Change but just sets [can implement completly new ids]
* @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; }
private:
std::unordered_map<u32, u32> theme; ///< Theme Data
std::vector<std::pair<UI7Color, u32>> changes; ///< List of Changes
};
} // namespace UI7
} // namespace PD

View File

@ -1,148 +1,152 @@
#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/timetrace.hpp>
#include <pd/drivers/hid.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/theme.hpp>
/**
* Declare UI7 Version
* Format: 00 00 00 00
* Major Minor Patch Build
* 0x01010000 -> 1.1.0-0
*/
#define UI7_VERSION 0x00030200
namespace PD {
namespace UI7 {
/**
* Get UI7 Version String
* @param show_build Ahow build num (mostly unused)
* @return Version String (1.0.0-1 for example)
*/
std::string GetVersion(bool show_build = false);
/** Base Context for UI7 */
class 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);
}
~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);
/**
* 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)
*/
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); }
/**
* 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
Menu::Ref current; ///< Current Menu
// IO
IO::Ref io;
};
} // 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>
#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>
/**
* Declare UI7 Version
* Format: 00 00 00 00
* Major Minor Patch Build
* 0x01010000 -> 1.1.0-0
*/
#define UI7_VERSION 0x00040000
namespace PD {
namespace UI7 {
/**
* Get UI7 Version String
* @param show_build Ahow 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);
}
~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)
*/
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); }
/**
* 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;
};
} // namespace UI7
} // namespace PD