# Changes 0.2.4-1

- Add GIT_BRANCH (for development and stable)
- Write  Documentation of
  - pd-core (exept of vec.hpp)
  - pd-app
  - pd-drivers
  - pd-lib3ds
  - pd-image
  - pd-image
  - pd-ui7
This commit is contained in:
tobid7 2025-03-02 21:11:58 +01:00
parent af3d3e0b5b
commit 7d3f619169
56 changed files with 2481 additions and 536 deletions

View File

@ -16,6 +16,7 @@ target_compile_definitions(${TARGET_NAME} PUBLIC
-D_GNU_SOURCE=1
-DPALLADIUM_VERSION="${PROJECT_VERSION}"
-DPALLADIUM_GIT_COMMIT="${GIT_SHORT_HASH}"
-DPALLADIUM_GIT_BRANCH="${GIT_BRANCH}"
-DBUILD_CTR=1)
### For the libs that depend on another
if(ARG_DEPENDS)
@ -34,6 +35,7 @@ if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
endif()
endif()
## Get Current Git Commit Value
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
@ -41,8 +43,16 @@ execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
)
## Get Current Git Branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Set Project
project(palladium LANGUAGES C CXX VERSION 0.2.3)
project(palladium LANGUAGES C CXX VERSION 0.2.4)
option(PD_BUILD_TESTS "Sets if TestApp and TestBench get build" OFF)

View File

@ -27,19 +27,20 @@ make install
| Name | Last Updated | Platform | Depends |
|---|---|---|---|
| pd-core | 0.2.3 | multi | none |
| pd-core | 0.2.4 | multi | none |
| pd-external | 0.1.0 | multi | none |
| pd-image | 0.2.3 | multi | pd-core |
| pd-drivers | 0.2.1 | multi | pd-core |
| pd-lib3ds | 0.2.2 | 3ds | pd-core, pd-drivers |
| pd-net | 0.2.2 | 3ds | pd-core, pd-lib3ds |
| pd-lithium | 0.2.1 | 3ds | pd-core, pd-image pd-lib3ds, citro3d |
| pd-sound | 0.2.2 | 3ds | pd-core, mpg123 |
| pd-overlays | 0.2.1 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium, pd-ui7 |
| pd-ui7 | 0.2.2 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium |
| pd-app | 0.2.2 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium |
| pd-image | 0.2.4 | multi | pd-core |
| pd-drivers | 0.2.4 | multi | pd-core |
| pd-lib3ds | 0.2.4 | 3ds | pd-core, pd-drivers |
| pd-net | 0.2.4 | 3ds | pd-core, pd-lib3ds |
| pd-lithium | 0.2.4 | 3ds | pd-core, pd-image pd-lib3ds, citro3d |
| pd-sound | 0.2.4 | 3ds | pd-core, mpg123 |
| pd-overlays | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium, pd-ui7 |
| pd-ui7 | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium |
| pd-app | 0.2.4 | 3ds | pd-core, pd-image, pd-lib3ds, pd-lithium |
## Credits
| Icon | Username | Description |
|---|---|---|
| <img src="https://github.com/tobid7.png" alt="https://github.com/tobid7" width="48"/> | [tobid7](https://github.com/tobid7) | main dev of RenderD7, Palladium |

View File

@ -0,0 +1,16 @@
window.MathJax = {
tex: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
processEscapes: true,
processEnvironments: true
},
options: {
ignoreHtmlClass: ".*|",
processHtmlClass: "arithmatex"
}
};
document$.subscribe(() => {
MathJax.typesetPromise()
})

View File

@ -0,0 +1,6 @@
document$.subscribe(function() {
var tables = document.querySelectorAll("article table:not([class])")
tables.forEach(function(table) {
new Tablesort(table)
})
})

View File

@ -0,0 +1,22 @@
<div class="md-copyright">
{% if config.copyright %}
<div class="md-copyright__highlight">
{{ config.copyright }}
</div>
{% endif %}
{% if not config.extra.generator == false %}
&copy; 2024 -
<script>document.write(new Date().getFullYear());</script>
<a href="https://github.com/tobid7">
tobid7
</a>
- Kassel, Germany | Made with
<a href="https://doxide.org" target="_blank" rel="noopener">
Doxide
</a>
and
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
{% endif %}
</div>

View File

@ -0,0 +1,58 @@
:root {
--md-admonition-icon--variable: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20.41 3c1.39 2.71 1.94 5.84 1.59 9-.2 3.16-1.3 6.29-3.17 9l-1.53-1c1.61-2.43 2.55-5.2 2.7-8 .34-2.8-.11-5.57-1.3-8l1.71-1M5.17 3 6.7 4C5.09 6.43 4.15 9.2 4 12c-.34 2.8.12 5.57 1.3 8l-1.69 1c-1.4-2.71-1.96-5.83-1.61-9 .2-3.16 1.3-6.29 3.17-9m6.91 7.68 2.32-3.23h2.53l-3.78 5 2.2 4.92h-2.26L11.71 14l-2.43 3.33H6.76l3.9-5.12-2.13-4.76h2.27l1.28 3.23Z"/></svg>');
--md-admonition-icon--function: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.6 5.29c-1.1-.1-2.07.71-2.17 1.82L13.18 10H16v2h-3l-.44 5.07a3.986 3.986 0 0 1-4.33 3.63 4.007 4.007 0 0 1-3.06-1.87l1.5-1.5c.24.74.9 1.31 1.73 1.38 1.1.1 2.07-.71 2.17-1.82L11 12H8v-2h3.17l.27-3.07c.19-2.2 2.13-3.83 4.33-3.63 1.31.11 2.41.84 3.06 1.87l-1.5 1.5c-.24-.74-.9-1.31-1.73-1.38Z"/></svg>');
--md-admonition-icon--typedef: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M 13.43 7.11 L 13.18 10 H 17 V 12 H 13 L 12.56 17.07 A 1 1 0 0 0 15.287 17.261 L 17.028 17.48 A 1 1 0 0 1 10.57 16.89 L 11 12 H 8 V 10 H 11.17 L 11.44 6.93 Z"/></svg>');
--md-admonition-icon--concept: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3.75 3.5a.25.25 0 0 0-.25.25v2.062a.75.75 0 1 1-1.5 0V3.75C2 2.783 2.783 2 3.75 2h2.062a.75.75 0 1 1 0 1.5Zm13.688-.75a.75.75 0 0 1 .75-.75h2.062c.966 0 1.75.783 1.75 1.75v2.062a.75.75 0 1 1-1.5 0V3.75a.25.25 0 0 0-.25-.25h-2.062a.75.75 0 0 1-.75-.75ZM2.75 17.438a.75.75 0 0 1 .75.75v2.062c0 .138.112.25.25.25h2.062a.75.75 0 1 1 0 1.5H3.75A1.75 1.75 0 0 1 2 20.25v-2.062a.75.75 0 0 1 .75-.75Zm18.5 0a.75.75 0 0 1 .75.75v2.062A1.75 1.75 0 0 1 20.25 22h-2.062a.75.75 0 1 1 0-1.5h2.062a.25.25 0 0 0 .25-.25v-2.062a.75.75 0 0 1 .75-.75Zm-18.5-8.25a.75.75 0 0 1 .75.75v4.124a.75.75 0 1 1-1.5 0V9.938a.75.75 0 0 1 .75-.75ZM9.188 2.75a.75.75 0 0 1 .75-.75h4.124a.75.75 0 1 1 0 1.5H9.938a.75.75 0 0 1-.75-.75Zm0 18.5a.75.75 0 0 1 .75-.75h4.124a.75.75 0 1 1 0 1.5H9.938a.75.75 0 0 1-.75-.75ZM21.25 9.188a.75.75 0 0 1 .75.75v4.124a.75.75 0 1 1-1.5 0V9.938a.75.75 0 0 1 .75-.75ZM3.75 8.25a.75.75 0 0 1 .75-.75h2a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1-.75-.75Zm5.5 0A.75.75 0 0 1 10 7.5h2A.75.75 0 0 1 12 9h-2a.75.75 0 0 1-.75-.75Zm-1-4.5A.75.75 0 0 1 9 4.5v2a.75.75 0 0 1-1.5 0v-2a.75.75 0 0 1 .75-.75Zm0 5.5A.75.75 0 0 1 9 10v2a.75.75 0 0 1-1.5 0v-2a.75.75 0 0 1 .75-.75Zm0 4.75a.75.75 0 0 1 .75.75v4a.75.75 0 0 1-1.5 0v-4a.75.75 0 0 1 .75-.75ZM14 8.25a.75.75 0 0 1 .75-.75h4a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1-.75-.75Z"/></svg>');
--md-admonition-icon--macro: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="m5.41 21 .71-4h-4l.35-2h4l1.06-6h-4l.35-2h4l.71-4h2l-.71 4h6l.71-4h2l-.71 4h4l-.35 2h-4l-1.06 6h4l-.35 2h-4l-.71 4h-2l.71-4h-6l-.71 4h-2M9.53 9l-1.06 6h6l1.06-6h-6Z"/></svg>');
}
.md-typeset .admonition.variable, .md-typeset details.variable,
.md-typeset .admonition.function, .md-typeset details.function,
.md-typeset .admonition.typedef, .md-typeset details.typedef,
.md-typeset .admonition.concept, .md-typeset details.concept,
.md-typeset .admonition.macro, .md-typeset details.macro {
border-color: var(--md-default-fg-color--lighter);
}
.md-typeset .variable > .admonition-title, .md-typeset .variable > summary,
.md-typeset .function > .admonition-title, .md-typeset .function > summary,
.md-typeset .typedef > .admonition-title, .md-typeset .typedef > summary,
.md-typeset .concept > .admonition-title, .md-typeset .concept > summary,
.md-typeset .macro > .admonition-title, .md-typeset .macro > summary {
background-color: var(--md-default-bg-color);
}
.md-typeset .variable > .admonition-title::before,
.md-typeset .variable > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--variable);
mask-image: var(--md-admonition-icon--variable);
}
.md-typeset .function > .admonition-title::before,
.md-typeset .function > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--function);
mask-image: var(--md-admonition-icon--function);
}
.md-typeset .typedef > .admonition-title::before,
.md-typeset .typedef > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--typedef);
mask-image: var(--md-admonition-icon--typedef);
}
.md-typeset .concept > .admonition-title::before,
.md-typeset .concept > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--concept);
mask-image: var(--md-admonition-icon--concept);
}
.md-typeset .macro > .admonition-title::before,
.md-typeset .macro > summary::before {
background-color: var(--md-default-fg-color--light);
-webkit-mask-image: var(--md-admonition-icon--macro);
mask-image: var(--md-admonition-icon--macro);
}

15
doxide.yaml Normal file
View File

@ -0,0 +1,15 @@
title: Palladium
description:
files:
- "include/*.hpp"
- "include/pd/app/*.hpp"
- "include/pd/core/*.hpp"
- "include/pd/drivers/*.hpp"
- "include/pd/image/*.hpp"
- "include/pd/lib3ds/*.hpp"
- "include/pd/lithium/*.hpp"
- "include/pd/net/*.hpp"
- "include/pd/overlays/*.hpp"
- "include/pd/sound/*.hpp"
- "include/pd/ui7/*.hpp"
- "include/pd/ui7/container/*.hpp"

View File

@ -32,34 +32,56 @@ SOFTWARE.
#include <pd/overlays/overlay_mgr.hpp>
namespace PD {
/// @brief Template Class for User Application
/**
* 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,
AppFLags_UserLoop = 1 << 0,
AppFlags_HandleOverlays = 1 << 1,
AppFlags_HandleMessageMgr = 1 << 2,
AppFlags_HandleRendering = 1 << 3,
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
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
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!");
@ -67,60 +89,143 @@ class App {
this->name = name;
too++;
}
/**
* App Deconstructor
*/
~App() { too--; }
/// @brief Templete function where the user can Init his stuff
/**
* Templete function where the user can Init his stuff
*/
virtual void Init() {}
/// @brief Templeta funciton to deinit stuff
/// (most of that is done automatically)
/**
* 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() {}
/// @brief App Mainloop
/// @param delta Deltatime
/// @param time App RunTime
/// @return false to exit the app
/**
* 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; }
/// @brief Function to run the App
/// (int main() {
/// UserApp app;
/// app.Run();
/// return 0;
/// })
/**
* 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;
/// @brief Safe Copy to prevent from editing befor Deinit
/** 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;
/// The Only One
/** A static variable to make sure only one App instance can exist */
static int too;
};
} // namespace PD

View File

@ -26,6 +26,15 @@ 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

View File

@ -26,32 +26,73 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
/// @brief Lang System
///< Translations are saved into json files
///< Path should point to a directory the fils
///< for example the files ar named [en.json, de.json, fr.json]
/**
* 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

@ -27,8 +27,21 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
/**
* Binary Utillity Functions
*/
namespace BitUtil {
/**
* Check if a 32 Bit number only set a sigle bit to 1
* @param v 32 bit unsigned int
* @return true if its a single bit number
*/
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);
} // namespace BitUtil
} // namespace PD

View File

@ -27,56 +27,144 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
/// @brief Color class (Supports hex, rgb(a)8, u32 input)
/// @note no safeteychecks used here for performance
/**
* Color class
*
* - Supports hex input starting with a # and 6 or 8 digits
* - Supports rgb(a) 8Bit unsigned number input
* - Supports rgb(a) float input from 0.0 to 1.0
* - Supports 32Bit input color
* @note Safetey checks are disabled for maximum performance
*/
class Color {
public:
/**
* Default Constructor (all variables are set to 0)
*/
Color() : m_r(0), m_g(0), m_b(0), m_a(0) {}
/**
* Constructor for 32Bit Color Input
* @param color 32Bit Color value
*/
Color(u32 color) {
m_a = (color >> 24) & 0xff;
m_b = (color >> 16) & 0xff;
m_g = (color >> 8) & 0xff;
m_r = color & 0xff;
}
/**
* Constructor for 8Bit Input
* @param r Red Value
* @param g Green Value
* @param b Blue Value
* @param a Optional Alpha Value (Defaults to 255)
*/
Color(u8 r, u8 g, u8 b, u8 a = 255) {
m_r = r;
m_g = g;
m_b = b;
m_a = a;
}
/**
* Constructor for float Input
* @param r Red Value
* @param g Green Value
* @param b Blue Value
* @param a Optional Alpha Value (Defaults to 1.0f)
* @note There is no Check if the number is between 0.0 and 1.0
*/
Color(float r, float g, float b, float a = 1.f) {
m_r = static_cast<u8>(255.f * r);
m_g = static_cast<u8>(255.f * g);
m_b = static_cast<u8>(255.f * b);
m_a = static_cast<u8>(255.f * a);
}
/**
* Constructor for Hex Input
* @param hex Hex String in `#ffffff` or `#ffffffff` format
*/
Color(const std::string& hex) { Hex(hex); }
/**
* Unused Deconstructor
*/
~Color() {}
/**
* Create Color Object by Hex String
* @param hex Hex String in `#ffffff` or `#ffffffff` format
* @return Color class itself
*/
Color& Hex(const std::string& hex);
/**
* Convert this Color Object to Hex string
* @param rgba [default false] sets if 8 or 6 digit color should be returned
* @return Color Hex String
*/
std::string Hex(bool rgba = false) const;
/**
* Setter for Red
* @param v value
* @return Color class reference
*/
Color& r(u8 v) {
m_r = v;
return *this;
}
/**
* Getter for Red
* @return Red Value
*/
u8 r() const { return m_r; }
/**
* Setter for Green
* @param v value
* @return Color class reference
*/
Color& g(u8 v) {
m_g = v;
return *this;
}
/**
* Getter for Green
* @return Green Value
*/
u8 g() const { return m_r; }
/**
* Setter for Blue
* @param v value
* @return Color class reference
*/
Color& b(u8 v) {
m_b = v;
return *this;
}
/**
* Getter for Blue
* @return Blue Value
*/
u8 b() const { return m_r; }
/**
* Setter for Alpha
* @param v value
* @return Color class reference
*/
Color& a(u8 v) {
m_a = v;
return *this;
}
/**
* Getter for Alpha
* @return Alpha Value
*/
u8 a() const { return m_r; }
/**
* Fade from Current to another Color
* @param color Color to fade to
* @param p Amount (supports -1.0 to 1.0 for use of sine)
* @return Class Reference
*/
Color& Fade(const Color& color, float p) {
m_a = static_cast<u8>((color.a() - m_a) * ((p + 1.f) / 2));
m_b = static_cast<u8>((color.b() - m_b) * ((p + 1.f) / 2));
@ -84,19 +172,39 @@ class Color {
m_r = static_cast<u8>((color.r() - m_r) * ((p + 1.f) / 2));
return *this;
}
/**
* Get 32Bit Color Value
* @return 32Bit Color Value
*/
u32 Get() const { return (m_a << 24) | (m_b << 16) | (m_g << 8) | m_r; }
/**
* Get The Luminance of the Color
* @return luminance (from 0.0 to 1.0)
*/
float Luminance() const {
// For Reference https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
return (0.3 * (m_r / 255.f) + 0.59 * (m_g / 255.f) + 0.11 * (m_b / 255.f));
}
/**
* Check if the Color is Light or Dark
* @return true if light
*/
bool IsLight() const { return (Luminance() >= 0.5); }
/**
* Operator to cast Color to 32Bit Value
* @return 32Bit Color Value
*/
operator u32() const { return Get(); }
private:
/** Red Value */
u8 m_r;
/** Green Value */
u8 m_g;
/** Blue Value */
u8 m_b;
/** Alpha Value */
u8 m_a;
};
} // namespace PD

View File

@ -38,43 +38,82 @@ SOFTWARE.
#include <vector>
namespace PD {
// New Version of Smart CTOR
// Using as Template class
/**
* SmartCtor (std::shared_ptr) Template class for Smart Pointers
*
* - Just add : public PD::SmartCtor<YourClass> to your class
* @tparam T Your Class
*/
template <typename T>
class SmartCtor {
public:
/// @brief Type Reference
/** Reference alias for std::shared_ptr<Type> */
using Ref = std::shared_ptr<T>;
/// @brief Creates a New Shared Pointer
/// @param ...args Arguments to forward
/// @return Shared Pointer (Reference)
/**
* static Function to Create a New Reference
* @param args Additional Arguments (Depends on your classes Constructors)
* @return New Reference Object
*/
template <typename... Args>
static Ref New(Args&&... args) {
return std::make_shared<T>(std::forward<Args>(args)...);
}
};
/// @brief Wrapper for SmartCtor<Type>::New
/// @tparam T class type
/// @param ...args Arguments
/// @return SmartCtor<T>::Ref type reference
/// @note Not sure if this is solving the problem or
/// if I schould switch back to the macro
/**
* Wrapper for SmartCtor<Type>::New(Args)
* @tparam T Class Type
* @param args Arguments
* @return Type Reference (SmartPointer)
*/
template <typename T, typename... Args>
SmartCtor<T>::Ref New(Args&&... args) {
return SmartCtor<T>::New(std::forward<Args>(args)...);
}
// Defines
/** alias for 64 Bit unsigned integer */
using u64 = unsigned long long;
/** alias for 32 Bit unsigned integer */
using u32 = unsigned int;
/** alias for 16 Bit unsigned integer */
using u16 = unsigned short;
/** alias for 8 Bit unsigned integer */
using u8 = unsigned char;
/**
* LinInfo Compile Information
*/
namespace LibInfo {
/**
* Get the Compiler Name and Version the lib got Compiled with
* @return Compiler Name / Version
*/
const std::string CompiledWith();
/**
* Get the C++ Version used to compile the lib
* @return C++ Version (__cplusplus)
*/
const std::string CxxVersion();
/**
* Get the Buildtime of the Library
* @return Build Time
*/
const std::string BuildTime();
/**
* Get the Library Version
* @return Library Version String
*/
const std::string Version();
/**
* Get the Git Commit the Lib got compiled in
* @return Git Commit 7digit short hash
*/
const std::string Commit();
/**
* Get the Git Branch which was active when compiling the lib
* @return Git Branch
*/
const std::string Branch();
} // namespace LibInfo
} // namespace PD

View File

@ -26,8 +26,21 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
/**
* Set of File Functions
*/
namespace IO {
/**
* Load a File into an 8Bit Memory Buffer
* @param path Path to the File
* @return 8Bit FileBuffer
*/
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);
} // namespace IO
} // namespace PD

View File

@ -26,23 +26,81 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
/**
* Set of String Utillity Functions
*/
namespace Strings {
/**
* Check if a String ends with a specific extension
* @param str Input string
* @param exts List of Extensions to check for
* @return true if one of the extensions is found in the String
*/
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
*/
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);
/**
* Generate a Formatted String by an Milliseconds Input
* @param millis Milliseconds Input
* @return Result String
*/
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);
/**
* 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 = "/\\");
/**
* Remove Extension from a Path / Filename
* @param path Input Path
* @return Path without Extension
*/
const std::string PathRemoveExtension(const std::string& path);
/**
* Function to Convert a Type to a hex value
* @tparam T Type
* @param v value
* @return hex string beginning with 0x
*/
template <typename T>
inline const std::string ToHex(const T& v) {
std::stringstream s;
s << "0x" << std::setfill('0') << std::setw(sizeof(v) * 2) << std::hex << v;
return s.str();
}
/**
* Generate a Hash out of a string
* @param s String to hash
* @return 32Bit Hash
*/
u32 FastHash(const std::string& s);
/**
* Function to Generate a Compiler Name and Version String
* Based on their Macros
* @return CompilerName: Version
*/
inline const std::string GetCompilerVersion() {
/// As the function looks like this Project is meant to
/// Be ported to other systems as well

View File

@ -27,12 +27,40 @@ SOFTWARE.
#include <pd/core/timetrace.hpp>
namespace PD {
/**
* Namespace containing functions for get Millis and Get Nanos
*/
namespace Sys {
/**
* alias for the TimeTrace Traces Map
*/
using TraceMap = std::map<std::string, TT::Res::Ref>;
/**
* Get Current Time in Milliseconds
* @return 64Bit value of millis
*/
u64 GetTime();
/**
* Get Current Time in Nanoseconds
* @return 64Bit value of nanos
*/
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);
/**
* Check if a Trace with the name exists
* @param id tracename to search
* @return true if exist
*/
bool TraceExist(const std::string& id);
/**
* Get TraceMap Reference
* @return edidable Reference to the TraceMap
*/
TraceMap& GetTraceMap();
} // namespace Sys
} // namespace PD

View File

@ -27,21 +27,58 @@ SOFTWARE.
#include <pd/core/sys.hpp>
namespace PD {
/**
* Timer class
*/
class Timer : public SmartCtor<Timer> {
public:
/**
* Constructor
* @param auto_start [default true] sets if timer should start after creation
*/
Timer(bool auto_start = true);
/**
* Unused Deconstructor
*/
~Timer() {}
/**
* Resume Timer if Paused
*/
void Rseume();
/**
* Pause Timer if not Paused
*/
void Pause();
/**
* Update Timer
*/
void Update();
/**
* Reset Timer
*/
void Reset();
/**
* Check if the Timer is Running
* @return true if its running
*/
bool IsRunning() const;
/**
* Get 64 Bit milliseconds value
* @return 64Bit millis
*/
u64 Get();
/**
* Get as Seconds
* @return seconds as floating number
*/
double GetSeconds();
private:
/** Start of the Timer */
u64 start;
/** Current Time */
u64 now;
/** Is Running */
bool is_running = false;
};
} // namespace PD

View File

@ -26,17 +26,32 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
/**
* Class to calculate Maximum/Minimum and Average Timings
*/
class TimeStats : public SmartCtor<TimeStats> {
public:
/**
* Constructor taking a lengh for the List
* @param l Lengh of the data list
*/
TimeStats(int l) : len(l), val(l, 0) {}
~TimeStats() = default;
/**
* Add a New Value to the list
* @param v value to add
*/
void Add(u64 v) {
val[idx] = v;
idx = next(idx);
num_val = std::min(num_val + 1, len);
}
/**
* Get Avarage Num
* @return Average
*/
u64 GetAverage() {
if (!num_val) return 0.f;
u64 res = 0;
@ -46,6 +61,10 @@ class TimeStats : public SmartCtor<TimeStats> {
return res / num_val;
}
/**
* Get Minimum Num
* @return Minimum value
*/
u64 GetMin() {
if (!num_val) return 0.f;
u64 res = std::numeric_limits<u64>::max();
@ -55,6 +74,10 @@ class TimeStats : public SmartCtor<TimeStats> {
return res;
}
/**
* Get Maximum Value
* @return Max Value
*/
u64 GetMax() {
if (!num_val) return 0.f;
u64 res = 0;
@ -64,62 +87,168 @@ class TimeStats : public SmartCtor<TimeStats> {
return res;
}
/**
* Clear the List
*/
void Clear() {
val.assign(len, 0);
idx = 0;
num_val = 0;
}
/**
* Get Data Buffer
* @return data bufer (not edidable)
*/
const std::vector<u64> &GetData() { return val; }
/**
* Access an element in the list [not edidable]
* @return value to access
*/
const u64 &operator[](int i) { return val[smart_idx(i)]; }
/**
* Get List Lengh
* @return Lengh
*/
const size_t GetLen() { return len; }
/**
* Get Number of Values
* @return number of values
*/
const size_t GetNumValues() { return num_val; }
private:
/**
* Get the Next Position to write to
* @param c current position
* @return next position
*/
size_t next(size_t c) const { return (c + 1) % len; }
/**
* Smart Indexing in for loops to make sure to
* not index a value that was not set yet
* @param v pos in for loop
* @return indexing pos
*/
size_t smart_idx(size_t v) const { return (idx + len - num_val + v) % len; }
/** Lengh of the list */
int len = 0;
/** Value Storage */
std::vector<u64> val;
int idx = 0;
int num_val = 0;
};
/**
* Timatrace Functions
*/
namespace TT {
/**
* Data Structure for a TimeTrace Result
*/
class Res : public SmartCtor<Res> {
public:
/** Constructore that Inits a protocol at size of 60 frames */
Res() { protocol = TimeStats::New(60); }
~Res() = default;
/**
* Setter for the ID (Name)
* @param v ID of the Trace
*/
void SetID(const std::string &v) { id = v; }
/**
* Getter for the traces ID
* @return Trace ID
*/
const std::string GetID() { return id; }
/**
* Setter for the Start Value
* @param v start time
*/
void SetStart(u64 v) { start = v; }
/**
* Getter for the Start time
* @return start time
*/
u64 GetStart() { return start; }
/**
* Setter for the End Time
* @param v end time
*/
void SetEnd(u64 v) {
end = v;
protocol->Add(GetLastDiff());
}
/**
* Getter for the End Time
* @result end time
*/
u64 GetEnd() { return end; }
/**
* Get Last Diffrence between end and start
* @return end - start
*/
u64 GetLastDiff() { return end - start; }
/**
* Get Protcol Reference
* @return Protocol Ref
*/
TimeStats::Ref GetProtocol() { return protocol; }
private:
/** Trace ID */
std::string id;
/** Start time */
u64 start;
/** End Time */
u64 end;
/** Protocol */
TimeStats::Ref protocol;
};
/**
* Begin a Trace
* @param id Name of the Trace
*/
void Beg(const std::string &id);
/**
* End a Trace
* @param id Name of the Trace
*/
void End(const std::string &id);
/**
* Collect Start end end of the trace by tracking
* when the Scope object goes out of scope
*
* Example:
* ```cpp
* void SomeFunction() {
* // Create a Scoped Trace called "SomeFunc"
* PD::TT::Scope st("SomeFunc");
* // Do your functions stuff
* // End at the end it goes out of
* // scope which collects the end time
* }
* ```
*/
class Scope {
public:
/**
* Constructor requiring a Name for the Trace
* @param id Name of the Trace
*/
Scope(const std::string &id) {
this->id = id;
Beg(id);
}
/**
* Deconstructor getting the end time when going out of scope
*/
~Scope() { End(id); }
private:
/** Trace Name/ID */
std::string id;
};
} // namespace TT

View File

@ -26,24 +26,35 @@ SOFTWARE.
#include <pd/core/vec.hpp>
namespace PD {
/**
* D7 Tween Engine (or something like that)
* @tparam T Any Numeric value
*/
template <typename T>
class Tween {
public:
/**
* Effects Table
*/
enum Effect {
Linear,
EaseInQuad,
EaseOutQuad,
EaseInOutQuad,
EaseInCubic,
EaseOutCubic,
EaseInOutCubic,
EaseInSine,
EaseOutSine,
EaseInOutSine,
Linear, ///< Linear Movement [works]
EaseInQuad, ///< EaseInQuad Movement [works]
EaseOutQuad, ///< EaseOutQuad Movement [works]
EaseInOutQuad, ///< EaseInOutQuad Movement [works]
EaseInCubic, ///< EaseInCubic Movement [not tested]
EaseOutCubic, ///< EaseOutCubic Movement [not tested]
EaseInOutCubic, ///< EaseInOutCubic Movement [disabled]
EaseInSine, ///< EaseInSine Movement [works]
EaseOutSine, ///< EaseOutSine Movement [works]
EaseInOutSine, ///< EaseInOutSine Movement [not tested]
};
Tween() {}
~Tween() {}
Tween() = default;
~Tween() = default;
/**
* Update Tween
* @param delta deltatime
*/
void Update(float delta) {
time += delta / 1000.f;
if (time > tend) {
@ -52,44 +63,82 @@ class Tween {
}
}
/**
* Check if Tween is finished
* @return true if finished
*/
bool IsFinished() const { return finished; }
/**
* Force finish the animation
* @return Class reference
*/
Tween& Finish() {
time = tend;
finished = true;
return *this;
}
/**
* Set Start Value
* @tparam T datatype of the Tween
* @param start Start Value
* @return class Reference
*/
Tween& From(const T& start) {
Reset();
this->start = start;
return *this;
}
/**
* Set End Value
* @tparam T datatype of the Tween
* @param end End Value
* @return class Reference
*/
Tween& To(const T& end) {
Reset();
this->end = end;
return *this;
}
/**
* Set the Duration (in seconds)
* @param seconds Duration
* @return class Reference
*/
Tween& In(float seconds) {
Reset();
tend = seconds;
return *this;
}
/**
* Set Effect of the Tween
* @param e Effect
* @return class Reference
*/
Tween& As(const Effect& e) {
effect = e;
return *this;
}
/**
* Reset to time 0
* @return class Reference
*/
Tween& Reset() {
finished = false;
time = 0.f;
return *this;
}
/// @brief Probably usefull for fading colors by animation
/// Used to create this caus dont wanted to create a
/// fade effect fpr keyboard without having to Tween functions
/// @return
/**
* Get the Prograss in percent (0.0 to 1.0) of the tween
* @return progress value
*/
float Progress() const { return time / tend; }
/**
* Swap Start and end Position of the Tween
* @return class reference
*/
Tween& Swap() {
T temp = start;
start = end;
@ -97,6 +146,10 @@ class Tween {
return *this;
}
/**
* Operator that returns the current value calculated
* by time and effect
*/
operator T() {
float t = 0.f;
switch (effect) {
@ -147,15 +200,23 @@ class Tween {
}
private:
/** Animation Effect */
Effect effect;
/** Time */
float time = 0.f;
// Defaulting to one to prevent div zero
// without a safetey check
// not implementing one cause if the user is
// Writing a In(0.f) its their fault
/**
* End time
* Defaulting to one to prevent div zero
* without a safetey check
* not implementing one cause if the user is
* Writing a In(0.f) its their fault
*/
float tend = 1.f;
/** Start value */
T start;
/** end value */
T end;
/** is finished value */
bool finished = false;
};
} // namespace PD

View File

@ -23,11 +23,9 @@ 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
*/
// Why Creating this:
// Cause using makes coding much better structured
// and easy to use like in glsl or glm
#include <pd/core/common.hpp>

View File

@ -27,54 +27,89 @@ SOFTWARE.
#include <pd/core/vec.hpp>
namespace PD {
/** Input Driver Template class */
class Hid : public SmartCtor<Hid> {
public:
/** Key [Controller] */
enum Key : u32 {
No = 0,
A = 1 << 0,
B = 1 << 1,
X = 1 << 2,
Y = 1 << 3,
Start = 1 << 4,
Select = 1 << 5,
L = 1 << 6,
R = 1 << 7,
DUp = 1 << 8,
DDown = 1 << 9,
DLeft = 1 << 10,
DRight = 1 << 11,
CPUp = 1 << 12,
CPDown = 1 << 13,
CPLeft = 1 << 14,
CPRight = 1 << 15,
CSUp = 1 << 16,
CSDown = 1 << 17,
CSLeft = 1 << 18,
CSRight = 1 << 19,
ZL = 1 << 20,
ZR = 1 << 21,
Touch = 1 << 22,
Up = DUp | CPUp,
Down = DDown | CPDown,
Left = DLeft | CPLeft,
Right = DRight | CPRight,
No = 0, ///< No Key
A = 1 << 0, ///< A
B = 1 << 1, ///< B
X = 1 << 2, ///< X
Y = 1 << 3, ///< Y
Start = 1 << 4, ///< Start
Select = 1 << 5, ///< Select
L = 1 << 6, ///< L
R = 1 << 7, ///< R
DUp = 1 << 8, ///< Dpad Up
DDown = 1 << 9, ///< Dpad down
DLeft = 1 << 10, ///< Dpad left
DRight = 1 << 11, ///< Dpad right
CPUp = 1 << 12, ///< Cpad up
CPDown = 1 << 13, ///< cpad down
CPLeft = 1 << 14, ///< cpad left
CPRight = 1 << 15, ///< Cpad right
CSUp = 1 << 16, ///< Cstick up
CSDown = 1 << 17, ///< cstick down
CSLeft = 1 << 18, ///< cstick left
CSRight = 1 << 19, ///< cstick right
ZL = 1 << 20, ///< ZL
ZR = 1 << 21, ///< ZR
Touch = 1 << 22, ///< Touch
Up = DUp | CPUp, ///< DPad or CPad Up
Down = DDown | CPDown, ///< DPad or CPad Down
Left = DLeft | CPLeft, ///< DPad or CPad Left
Right = DRight | CPRight, ///< DPad or CPad Right
};
/** Event */
enum Event {
Event_Down,
Event_Held,
Event_Up,
Event_Down, ///< Key Pressed
Event_Held, ///< Key Held
Event_Up, ///< Key released
};
Hid() {}
~Hid() {}
Hid() = default;
~Hid() = default;
/**
* Get TOuch Position
* @return touch pos
*/
vec2 TouchPos() const { return touch[0]; }
/**
* Get Last Touch Position (from last frame)
* @return touch pos
*/
vec2 TouchPosLast() const { return touch[1]; }
/**
* Check for a Button Event
* @param e Event Type
* @param keys Keys to check for
* @return if key(s) doing the requiested event
*/
bool IsEvent(Event e, Key keys);
/**
* Check for Key Press Event
* @param keys set of keys
* @return true if key is pressed
*/
bool IsDown(Key keys) const { return key_events[0].at(Event_Down) & keys; }
/**
* Check for Key Held Event
* @param keys set of keys
* @return true if key is held
*/
bool IsHeld(Key keys) const { return key_events[0].at(Event_Held) & keys; }
/**
* Check for Key Release Event
* @param keys set of keys
* @return true if key is released
*/
bool IsUp(Key keys) const { return key_events[0].at(Event_Up) & keys; }
/**
* Sett all keyevents to 0
*/
void Clear() {
for (int i = 0; i < 2; i++) {
key_events[i][Event_Down] = 0;
@ -83,19 +118,33 @@ class Hid : public SmartCtor<Hid> {
}
}
/**
* Lock input driver
* @param v lock or not lock
*/
void Lock(bool v) {
if (v != locked) {
SwappyTable();
}
locked = v;
}
/**
* Check if Driver is locked
* @return true if locked
*/
bool Locked() const { return locked; }
/**
* Lock Input Driver
*/
void Lock() {
if (!locked) {
SwappyTable();
}
locked = true;
}
/**
* Unlock Input Driver
*/
void Unlock() {
if (locked) {
SwappyTable();
@ -103,16 +152,21 @@ class Hid : public SmartCtor<Hid> {
locked = false;
}
/// @brief Get the New Keystates etc
/// @note WOW not using the deltatime
/**
* Template Update Function for a device specific driver
*/
virtual void Update() {}
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
/** Using 2 Touch positions for current and last frame */
vec2 touch[2];
/** locked state */
bool locked = false;
/** Key event tables */
std::unordered_map<Event, u32> key_events[2];
};
} // namespace PD

View File

@ -28,28 +28,41 @@ SOFTWARE.
#include <pd/core/vec.hpp>
namespace PD {
/**
* Namepace containing functions to blur images
*/
namespace ImgBlur {
/**
* Function to create Gaussian Kernel List
* @param radius Rasius to use
* @param si sigma value to use
* @return list of kernel values
*/
std::vector<float> GaussianKernel(int radius, float si);
/// @brief Gaussian Blur for basic Image Buffer
/// @param buf Image Buffer (unsigned char)
/// @param w // width of the image
/// @param h // width of the image
/// @param radius // Blur radius
/// @param si // Blur sigma
/// @param idxfn // Indexing function (if buffer is 3ds tiled)
/**
* Gaussian Blur for basic Image Buffer
* @param buf Image Buffer (unsigned char)
* @param w width of the image
* @param h width of the image
* @param radius Blur radius
* @param si Blur sigma
* @param idxfn Indexing function
*/
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;
});
/// @brief Advanced func to access memory directly
/// @param buf Referenvce to the buffer
/// @param w // width of the image
/// @param h // width of the image
/// @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
/// @param radius // Blur radius
/// @param si // Blur sigma
/// @param idxfn // Indexing function (if buffer is 3ds tiled)
/**
* Advanced func to access memory directly
* @param buf Referenvce to the buffer
* @param w width of the image
* @param h width of the image
* @param bpp Bytes per Pixels (RGB[A], RGB565, etc)
* @param radius Blur radius
* @param si Blur sigma
* @param idxfn Indexing function
*/
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 {

View File

@ -27,13 +27,26 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
/**
* Namespace containing function to convert images
*/
namespace ImgConvert {
/**
* Convert RGB24 to RGBA32 by adding a 4th alpha value set to 255
* to every pixel
* @param out Result List
* @param in Input Buffer List (rgb24)
* @param w width of the image
* @param h height of the image
*/
void RGB24toRGBA32(std::vector<u8> &out, const std::vector<u8> &in,
const int &w, const int &h);
/// @brief Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
/// @param buf Buffer to convert
/// @param w width
/// @param h height
/**
* Reverse 32 (RGBA -> ABGR || ABGR -> RGBA)
* @param buf Buffer to convert
* @param w width
* @param h height
*/
void Reverse32(std::vector<u8> &buf, const int &w, const int &h);
} // namespace ImgConvert
} // namespace PD

View File

@ -26,11 +26,20 @@ SOFTWARE.
#include <pd/drivers/hid.hpp>
namespace PD {
/**
* Nintendo 3DS Input Driver
*/
class CtrHid : public Hid {
public:
/**
* Constructor to setup Key binds
*/
CtrHid();
~CtrHid() {}
~CtrHid() = default;
/**
* Overrideing the Update Function for Input Checking etc
*/
void Update() override;
};
} // namespace PD

View File

@ -27,7 +27,14 @@ SOFTWARE.
#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,
@ -50,7 +57,17 @@ enum ID {
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
} // namespace PD

View File

@ -26,11 +26,32 @@ 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

View File

@ -26,10 +26,21 @@ SOFTWARE.
#include <3ds.h>
#include <pd/core/common.hpp>
#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:

View File

@ -26,7 +26,15 @@ 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
} // namespace PD

View File

@ -25,19 +25,25 @@ 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>
#include <pd/core/vec.hpp>
namespace PD {
namespace LI {
/// @brief Reform the Drawcommand by generating the Vertexbuffer into it
/**
* Lithium Draw Command (containing a list of vertex and index data
* only for this specific command itself)
*/
class Command : public SmartCtor<Command> {
public:
Command() {}
~Command() {}
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;
@ -47,58 +53,140 @@ class Command : public SmartCtor<Command> {
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
/**
* 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; }
private:
/// Using Default std::vector here
/**
* 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;
};
} // namespace LI

View File

@ -26,35 +26,40 @@ SOFTWARE.
#include <pd/core/common.hpp>
/** Alias for Lithium Text Flags */
using LITextFlags = PD::u32;
/** LITextFlags */
enum LITextFlags_ {
LITextFlags_None = 0,
LITextFlags_AlignRight = 1 << 0,
LITextFlags_AlignMid = 1 << 1,
LITextFlags_Shaddow = 1 << 2, // Draws the text twice
LITextFlags_Wrap = 1 << 3, // May be runs better with TMS
LITextFlags_Short = 1 << 4, // May be runs better with TMS
LITextFlags_Scroll = 1 << 5, // Not implemented
LITextFlags_RenderOOS = 1 << 6 // Render Out of Screen
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,
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 {
/// @brief Required to Set the TexENV
/** RenderMode [Required to modify TexENV] */
enum RenderMode {
RenderMode_RGBA,
RenderMode_Font,
RenderMode_RGBA, ///< RGBA [for textures or solid colors]
RenderMode_Font, ///< A8 [for textures only crated by 1 color channel]
};
} // namespace LI
} // namespace PD

View File

@ -25,70 +25,156 @@ SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec.hpp>
#include <pd/lithium/rect.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/core/vec.hpp>
namespace PD {
namespace LI {
/** Font Loader for Lithium */
class Font : public SmartCtor<Font> {
public:
/** Codepoint Data holder */
class Codepoint {
public:
Codepoint() {}
~Codepoint() {}
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() {}
~Font() {}
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

View File

@ -25,23 +25,34 @@ 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>
#include <pd/core/vec.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() {}
~StaticObject() {}
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) {
@ -49,6 +60,11 @@ class StaticObject : public SmartCtor<StaticObject> {
}
}
/**
* 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;
@ -58,6 +74,10 @@ class StaticObject : public SmartCtor<StaticObject> {
}
}
/**
* 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()) {
@ -66,6 +86,10 @@ class StaticObject : public SmartCtor<StaticObject> {
}
}
/**
* 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()) {
@ -74,18 +98,30 @@ class StaticObject : public SmartCtor<StaticObject> {
}
}
/**
* Add the Layer by a specific number
* @param base_layer baselayer or number to add on top of the commands layer
*/
void ReLayer(int base_layer) {
for (auto& it : cpy) {
it->Layer(it->Layer() + base_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);
}
}
/**
* Get a Reference to the Copy Commands List
* @return command list reference
*/
std::vector<Command::Ref>& List() {
if (cpy.size() != 0) {
return cpy;
@ -94,72 +130,184 @@ class StaticObject : public SmartCtor<StaticObject> {
}
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() {}
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() {}
~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;
std::string text; // TextWrap
/** Text Wrap / Short */
std::string text;
};
/**
* Static Text [abillity to Prerender Texts into a list of Commands]
*/
class StaticText : public SmartCtor<StaticText> {
public:
StaticText() {}
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() {}
~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();
/**
* 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; }
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

View File

@ -28,64 +28,156 @@ SOFTWARE.
namespace PD {
namespace LI {
/// @brief Container that holds top and bottom corners of a quad
/**
* 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);
}
/// This Constructor Fixes the issue of rewriting some Stuff in the Text
/// Renderer
/**
* 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];
@ -98,8 +190,8 @@ class Rect {
}
private:
vec4 top;
vec4 bot;
vec4 top; ///< Top left and right corner positions.
vec4 bot; ///< Bottom left and right corner positions.
};
} // namespace LI
} // namespace PD

View File

@ -25,6 +25,7 @@ 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>
@ -33,20 +34,48 @@ SOFTWARE.
#include <pd/lithium/screen.hpp>
#include <pd/lithium/texture.hpp>
#include <pd/lithium/vertex.hpp>
#include <pd/core/vec.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;
@ -55,7 +84,16 @@ class Renderer : public SmartCtor<Renderer> {
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!");
@ -76,6 +114,10 @@ class Renderer : public SmartCtor<Renderer> {
}
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;
@ -84,149 +126,256 @@ class Renderer : public SmartCtor<Renderer> {
current_tex = v;
}
/// @brief Draws a Rect based on current Texture
/// @param pos Pos
/// @param size Size
/// @param color Color
/// @param uv UV Map
/**
* 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));
/// @brief Draw a Solid Rect (uses white tex)
/// @note acts as a simplified Draw rect Wrapper
/// @param pos Position
/// @param size Size
/// @param color Color
/**
* 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);
/// @brief Render a Triangle
/// @param a Position Alpha
/// @param b Position Bravo
/// @param c Position Delta
/// @param color Color
/// @note Defaults to Solif 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);
/// @brief Draw a Circle (Supports Textures)
/// @param center_pos Center Position
/// @param r Radius
/// @param color Color
/// @param segments Segments to use
/// @note Textures could look a bit janky due to uv mapping
/**
* 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);
/// @brief Draw a Line between to Positions
/// @param a Position Alpha
/// @param b Position Bravo
/// @param color Color
/// @param t Thickness
/**
* 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());
/// @brief 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
/**
* 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 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 ///
// 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);
/// @brief 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
/**
* 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);
/// @brief Returns Viewport with xy
/** Returns Viewport with xy */
vec4 GetViewport();
/// @brief Push a Self Created command
/** Push a Self Created command */
void PushCommand(Command::Ref cmd) {
cmd->Index(cmd_idx++); // Indexing
draw_list[Screen32(screen)].push_back(cmd);
}
/// @brief Automatically sets up a command
/** Automatically sets up a command */
void SetupCommand(Command::Ref cmd);
/// @brief Creates a default Quad Render Command
/** Creates a default Quad Render Command */
void QuadCommand(Command::Ref cmd, const Rect& quad, const Rect& uv, u32 col);
/// @brief Create a Default Triangle
/** Create a Default Triangle */
void TriangleCommand(Command::Ref cmd, const vec2& a, const vec2& b,
const vec2& c, u32 col);
/// @brief 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)
/// @note Funktion macht noch faxxen (Text nicht sichtbar)
/**
* 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 ///
// Helper Funcitons
/**
* Update the 3DS citro3d texenv for specific RenderMode
* @param mode RenderMode to use.
*/
void UpdateRenderMode(const RenderMode& mode);
/// One Screen Only... ///
/** Current Screen */
Screen::Ref screen;
/// Reference Screens ///
/** Screen Regestry */
Screen::Ref screens[2];
/// Context Related ///
// 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;
Texture::Ref white = nullptr; // Single color
/** 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
/** Text Map System */
std::map<std::string, TextBox> tms;
// (Auto) Static Text
/** (Auto) Static Text */
std::unordered_map<u32, StaticText::Ref> ast;
/// Text Rendering ///
// 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 ///
// Special
/** Current Rotation (RECTS) */
float rot = 0.f;
/// Rendering ///
// Use dual drawlist
// 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 ///
// 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
/** 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
// Matrix
/** Precalculated Projectrion Matrix for top screen */
C3D_Mtx top_proj;
/** Precalculated Projectrion Matrix for bottom screen */
C3D_Mtx bot_proj;
};
} // namespace LI

View File

@ -30,9 +30,21 @@ SOFTWARE.
#include <pd/core/vec.hpp>
namespace PD {
/**
* 3DS Screen (RenderTarget)
*/
class Screen : public SmartCtor<Screen> {
public:
enum Screen_ { Top, Bottom, TopRight };
/** 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,
@ -51,27 +63,36 @@ class Screen : public SmartCtor<Screen> {
DisplayTransferFlags);
}
}
~Screen() {}
~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

@ -30,19 +30,37 @@ SOFTWARE.
#include <pd/lithium/texture.hpp>
namespace PD {
/**
* Tex 3DS Spritesheet integration to Lithium
*/
class SpriteSheet : public SmartCtor<SpriteSheet> {
public:
SpriteSheet() {}
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

@ -27,26 +27,33 @@ SOFTWARE.
#include <citro3d.h>
#include <pd/core/common.hpp>
#include <pd/lithium/rect.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,
RGB24,
A8,
RGBA32, ///< RGBA 32
RGB24, ///< RGB24
A8, ///< A8
};
/** Texture Filters */
enum Filter {
NEAREST,
LINEAR,
NEAREST, ///< Nearest
LINEAR, ///< Linear
};
/// @brief Default constructor
/** Default constructor */
Texture() : uv(0.f, 1.f, 1.f, 0.f) {}
/// @brief Load file Constructor
/// @param path path to file
/**
* 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);
@ -54,23 +61,27 @@ class Texture : public SmartCtor<Texture> {
this->LoadFile(path);
}
}
/// @brief Load Memory constructor
/// @param data File Data reference
/**
* 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);
}
/// @brief Load Pixels constructor
/// @param data Pixel Buffer reference
/// @param w width
/// @param h height
/// @param type Buffer Type
/// @param filter Filter
/**
* 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);
}
/// @brief Deconstructor (aka auto delete)
/** Deconstructor (aka auto delete) */
~Texture() {
if (autounload) {
Delete();
@ -119,7 +130,7 @@ class Texture : public SmartCtor<Texture> {
return vec2(tex->width, tex->height);
}
vec2 GetSize() const { return size; }
C3D_Tex* GetTex() const { return tex; };
C3D_Tex* GetTex() const { return tex; }
LI::Rect GetUV() const { return uv; }
bool IsValid() const { return tex != 0; }

View File

@ -31,16 +31,16 @@ class DownloadManager : public SmartCtor<DownloadManager> {
public:
using Error = u64;
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
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() {}
~DownloadManager() {}

View File

@ -27,8 +27,21 @@ SOFTWARE.
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, vec2 pos, LI::Renderer::Ref lr) {
this->screen = lr->CurrentScreen();
this->label = label;
@ -37,17 +50,27 @@ class Button : public Container {
color = UI7Color_Button;
this->SetSize(tdim + vec2(8, 4));
}
~Button() {}
~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
* @param inp Reference to the Input Handler
*/
void HandleInput(Hid::Ref inp) override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
vec2 tdim;
UI7Color color;
std::string label;
bool pressed = false;
vec2 tdim; ///< Text size
UI7Color color; ///< current button color
std::string label; ///< Label of the Button
bool pressed = false; ///< ispressed value
};
} // namespace UI7
} // namespace PD

View File

@ -27,8 +27,21 @@ SOFTWARE.
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 pos Base Position
* @param usr_ref Reference to the bool value to update
* @param lr Reference to the renderer (for text size calculation)
*/
Checkbox(const std::string& label, vec2 pos, bool& usr_ref,
LI::Renderer::Ref lr)
: usr_ref(usr_ref) {
@ -39,17 +52,25 @@ class Checkbox : public Container {
color = UI7Color_FrameBackground;
this->SetSize(cbs + vec2(tdim.x() + 5, 0));
}
~Checkbox() {}
~Checkbox() = default;
/**
* Override for the Input Handler
* @note This function is usally called by Menu::Update
* @param inp Reference to the Input Handler
*/
void HandleInput(Hid::Ref inp) override;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
vec2 tdim;
vec2 cbs = vec2(18);
UI7Color color;
std::string label;
bool& usr_ref;
vec2 tdim; ///< Text Size
vec2 cbs = vec2(18); ///< Checkbox size
UI7Color color; ///< Checkbox background Color
std::string label; ///< Checkbox Label
bool& usr_ref; ///< User bool reference
};
} // namespace UI7
} // namespace PD

View File

@ -25,59 +25,128 @@ SOFTWARE.
#include <pd/core/common.hpp>
#include <pd/core/strings.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/core/vec.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/ui7/drawlist.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() {}
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) {}
Container(const vec4& box) : pos(box.xy()), size(box.zw()) {}
~Container() {}
/**
* 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 r Renderer Reference
* @param l DrawList Reference
* @param lt Theme Reference
*/
void Init(LI::Renderer::Ref r, UI7::DrawList::Ref l, UI7::Theme::Ref lt) {
list = l;
theme = lt;
ren = r;
}
/** 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(Hid::Ref inp) {}
/** Tamplate function for Object rendering */
virtual void Draw() {}
/**
* 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
/** 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;
/** Reference to the theme to use*/
UI7::Theme::Ref theme;
/** Reference to the Renderer*/
LI::Renderer::Ref ren;
/** Reference to the parent container*/
Container::Ref parent;
/** Object ID (0 if unused)*/
u32 id = 0;
};
} // namespace UI7

View File

@ -27,8 +27,18 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/**
* Image Object
*/
class Image : public Container {
public:
/**
* Constructor for the Image Object
* @param img Image Texture Reference
* @param pos Base Position
* @param lr Renderer Reference [to determinate screen]
* @param size Custom Size of the Image
*/
Image(Texture::Ref img, vec2 pos, LI::Renderer::Ref lr, vec2 size = 0.f) {
this->screen = lr->CurrentScreen();
this->img = img;
@ -39,12 +49,16 @@ class Image : public Container {
this->SetSize(img->GetSize());
}
}
~Image() {}
~Image() = default;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
Texture::Ref img;
Texture::Ref img; ///< Texture reference to the Image
};
} // namespace UI7
} // namespace PD

View File

@ -27,8 +27,17 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/**
* Label [Text] Object
*/
class Label : public Container {
public:
/**
* Constructor for Label Object
* @param label Label [Text] to Draw
* @param pos Base Position
* @param lr Renderer Reference
*/
Label(const std::string& label, vec2 pos, LI::Renderer::Ref lr) {
this->screen = lr->CurrentScreen();
this->label = label;
@ -37,14 +46,18 @@ class Label : public Container {
color = UI7Color_Text;
this->SetSize(tdim);
}
~Label() {}
~Label() = default;
/**
* Override for the Rendering Handler
* @note This function is usally called by Menu::Update
* */
void Draw() override;
private:
vec2 tdim;
UI7Color color;
std::string label;
vec2 tdim; ///< Text Size
UI7Color color; ///< Color
std::string label; ///< Text to Render
};
} // namespace UI7
} // namespace PD

View File

@ -29,39 +29,75 @@ SOFTWARE.
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;
/**
* 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 pos0 Position a
* @param pos1 Position b
* @param pos2 Position c
* @param clr Color
*/
void AddTriangle(vec2 pos0, vec2 pos1, vec2 pos2, const UI7Color& clr);
/**
* 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
*/
void AddImage(vec2 pos, Texture::Ref img, vec2 size = 0.f);
/** Clear the Drawlist */
void Clear();
/** Process [Render] the Drawlist */
void Process();
/** Getter for the Layer */
int Layer() const { return layer; }
/** Setter fot the Layer */
void Layer(int v) { layer = v; }
private:
/// @brief Base Layer offset (Internal Used)
/** Base Layer offset (Internal Used) */
int BaseLayer() const { return base; }
/// @brief Base Layer offset (Internal Used)
/** Base Layer offset (Internal Used) */
void BaseLayer(int v) { base = v; }
/// @brief Exopose Renderer here for Menus [DONT KNOW IF THIUS GETS REMOVED]
LI::Renderer::Ref GetRenderer() { return ren; }
// Set friendclass here to not expose private functions as public
friend class Menu;
friend class Context;
int layer;
int base;
LI::Renderer::Ref ren;
int layer; ///< Current Layer
int base; ///< Base Layer
LI::Renderer::Ref ren; ///< Renderer Reference
// 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

View File

@ -23,26 +23,31 @@ 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;
/** Menu Flags */
enum UI7MenuFlags_ {
UI7MenuFlags_None = 0,
UI7MenuFlags_NoTitlebar = 1 << 0,
UI7MenuFlags_CenterTitle = 1 << 1,
UI7MenuFlags_HzScrolling = 1 << 2,
UI7MenuFlags_VtScrolling = 1 << 3,
UI7MenuFlags_NoBackground = 1 << 4,
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
// Enable Horizontal and Vertical Scrolling
UI7MenuFlags_Scrolling = UI7MenuFlags_HzScrolling | UI7MenuFlags_VtScrolling,
};
/// @brief Probably need to update this
/** Probably need to update this */
enum UI7Align_ {
UI7Align_Left = 1 << 0,
UI7Align_Center = 1 << 1,
UI7Align_Right = 1 << 2,
UI7Align_Top = 1 << 3,
UI7Align_Mid = 1 << 4,
UI7Align_Bottom = 1 << 5,
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,
};

View File

@ -28,25 +28,39 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/**
* ID Class (Generating an ID by String)
*/
class ID {
public:
/**
* Constructor to Generate ID by input string
* @param text Input String
*/
ID(const std::string& text) {
id = PD::Strings::FastHash(text);
name = text;
}
/**
* Constructor used for const char* which is automatically
* used when directly placing a string istead of using ID("")
* @param text Input String
*/
ID(const char* text) {
id = PD::Strings::FastHash(text);
name = text;
}
~ID() {}
~ID() = default;
/** Get The ID Initial Name */
std::string GetName() const { return name; }
/** Return the ID when casting to u32 */
operator u32() const { return id; }
private:
u32 id;
std::string name;
u32 id; ///< Hash of the name
std::string name; ///< Name
};
} // namespace UI7
} // namespace PD

View File

@ -23,8 +23,8 @@ 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/tween.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/ui7/containers.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
@ -32,200 +32,292 @@ SOFTWARE.
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 tl Theme Reference
* @param h Input Driver Reference
*/
Menu(ID id, Theme::Ref tl, Hid::Ref h) {
/// Setup the Input Data
theme = tl;
this->inp = h;
this->id = id;
this->name = id.GetName();
/// Set Default Values here
scrolling[0] = false;
scrolling[1] = false;
scrollbar[0] = false;
scrollbar[1] = false;
scroll_allowed[0] = false;
scroll_allowed[1] = false;
};
~Menu() {}
}
~Menu() = default;
/// Objects ///
// Objects
/// @brief Render a Simple Label
/// @param label The text to draw
/**
* Render a Simple Label
* @param label The text to draw
*/
void Label(const std::string& label);
/// @brief Render a Button
/// @param label The buttons text
/// @return if the button was pressed
/**
* Render a Button
* @param label The buttons text
* @return if the button was pressed
*/
bool Button(const std::string& label);
/// @brief Render a Checkbox
/// @param label Label of the Checkbox
/// @param v A value to update
/**
* Render a Checkbox
* @param label Label of the Checkbox
* @param v A value to update
*/
void Checkbox(const std::string& label, bool& v);
/// @brief Render an Image
/// @param img Texture reference of the image
/// @param size a Custom Size if needed
/**
* 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);
/// Basic API ///
// Basic API
/// @brief Add the Next object to the same line
/** Add the Next Objext to the same line */
void SameLine();
/// @brief Add a Separator Line
/** Add a Separator Line */
void Separator();
/// @brief Render a Separator Line with a Text
/// @todo determinate text position by current alignment
/// @param label The Text to show
/**
* 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);
/// @brief Put the last Added Object into the Joinlist
/** Put the last Added Object into the Joinlist */
void Join();
/// @brief Add the Last element to the join list
/// and perform an alignment operation
/// @param a Alignment Oeration(s)
/**
* Add the Last element to the join list
* and perform an alignment operation
* @param a Alignment Oeration(s)
*/
void JoinAlign(UI7Align a);
/// @brief Align the Last Object
/// @param a Alignment Operation
/**
* Align the Last Object
* @param a Alignment Operation
*/
void AfterAlign(UI7Align a);
/// @brief Set a Temp alignment op for the next Object
/// @param a Alignment Operation
/**
* Set a Temp alignment op for the next Object
* @param a Alignment Operation
*/
void NextAlign(UI7Align a) { tmpalign = a; }
/// @brief Align Every Single Object by this operationset
/// @param a Alignment
/**
* Align Every Single Object by this operationset
* @param a Alignment
*/
void PushAlignment(UI7Align a) { alignment = a; }
/// @brief Use default alignment
/** Use default alignment */
void PopAlignment() { alignment = UI7Align_Default; }
/// @brief Get a New Position depending on the Alignment
/// @param pos Current Position
/// @param size Object size
/// @param view Viewport [position and size]
/// @param a Alignment Operations
/// @return new position based on the alignment
/**
* Get a New Position depending on the Alignment
* @param pos Current Position
* @param size Object size
* @param view Viewport [position and size]
* @param a Alignment Operations
* @return new position based on the alignment
*/
static vec2 AlignPos(vec2 pos, vec2 size, vec4 view, UI7Align a);
/// @brief Returns a Reference to the theme
/// @return Reference to the base Theme of the context
/**
* Returns a Reference to the theme
* @return Reference to the base Theme of the context
*/
Theme::Ref GetTheme() { return theme; }
/// @brief Directly return a Color by using the
/// m->ThemeColor(UI7Color_Text) for example
/// @param clr The Input UI7 Color
/// @return The 32bit color value
/**
* 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 theme->Get(clr); }
/// API for Custom Objects
// API for Custom Objects
/// @brief Handles the Position of Objects in Scrolling Menu
/// @note As Containers have their own FUnc to handle this, this
/// function is only useful to Render Live Objects whicch cannot be aligned
/// by the internal Alignment Api
/// @param pos position reference to write the new position to
/// @param size size of the Object
/// @return if the object can be skipped in rendering
/**
* Handles the Position of Objects in Scrolling Menu
* @note As Containers have their own FUnc to handle this, this
* function is only useful to Render Live Objects whicch cannot be aligned
* by the internal Alignment Api
* @param pos position reference to write the new position to
* @param size size of the Object
* @return if the object can be skipped in rendering
*/
bool HandleScrolling(vec2& pos, const vec2& size);
/// @brief Get the Cursor Position
/// @return Cursor Pos
/**
* Get the Cursor Position
* @return Cursor Pos
*/
vec2 Cursor() const { return cursor; }
/// @brief Set the Cursor position
/// @note The old Position can be restored with RestoreCursor
/// @param v New Position
/**
* Set the Cursor position
* @note The old Position can be restored with RestoreCursor
* @param v New Position
*/
void Cursor(const vec2& v) {
bcursor = cursor;
cursor = v;
}
/// @brief Restore to the last cursor Position
/** Restore to the last cursor Position */
void RestoreCursor() {
cursor = bcursor;
bcursor = vec2();
}
/// @brief Return if a Vertical Scrollbar exists
/** Return if a Vertical Scrollbar exists */
bool HasVerticalScrollbar() { return scrollbar[1]; }
/// @brief Return if a Horizontal Scrollbar exists
/** Return if a Horizontal Scrollbar exists */
bool HasHorizontalScrollbar() { return scrollbar[0]; }
/// @brief Get the Titlebar height
/** Get the Titlebar height */
float TitleBarHeight() { return tbh; }
/// @brief Set a Custom Titlebar heigt
/// @note Could destroy some basic functionality
/**
* Set a Custom Titlebar heigt
* @note Could destroy some basic functionality
*/
void TitleBarHeight(float v) { tbh = v; }
/// @brief Init the Cursor
/// @note Useful when using with a Custom TitlebarHeight
/**
* Init the Cursor
* @note Useful when using with a Custom TitlebarHeight
*/
void CursorInit() { Cursor(vec2(5, tbh + 5)); }
/// @brief Move the Cursor for new Object
/// @param szs Size of the current Object
/**
* Move the Cursor for new Object
* @param szs Size of the current Object
*/
void CursorMove(const vec2& szs);
/// @brief Get the ViewArea of the Menu
/** Get the ViewArea of the Menu */
vec4 ViewArea() const { return view_area; }
/// @brief Get the Main Area of the Menu
/// (only relevant for input)
/**
* Get the Main Area of the Menu
* (only relevant for input)
*/
vec4 MainArea() const { return main_area; }
/// @brief Set a MainArea for input
/// @param v Area where Objects can receive inputs
/**
* Set a MainArea for input
* @param v Area where Objects can receive inputs
*/
void MainArea(const vec4& v) { main_area = v; }
/// @brief Get The Scrolling offset
/** Get The Scrolling offset */
vec2 ScrollOffset() const { return scrolling_off; }
/// @brief Set a Scrolling offset
/// @param v Custom Scrolling offset
/**
* Set a Scrolling offset
* @param v Custom Scrolling offset
*/
void ScrollOffset(const vec2& v) { scrolling_off = v; }
/// @brief Get the Current Scrollmodification value
/** Get the Current Scrollmodification value */
vec2 ScrollMod() const { return scroll_mod; }
/// @brief Animated Scroll to Position
/// @param pos Destination Position
/**
* Animated Scroll to Position
* @param pos Destination Position
*/
void ScrollTo(vec2 pos) {
scroll_anim.From(scrolling_off)
.To(pos)
.In(1.f)
.As(scroll_anim.EaseInOutSine);
}
/// @brief Check if Still in ScrollAnimation
/** Check if Still in ScrollAnimation */
bool IsAnimatedScroll() { return !scroll_anim.IsFinished(); }
/// Objects API ///
// Objects API
/// @brief Push an object to the current ListHandler
/// @param obj Object reference to use
/// @return Reference to the Object (from a time
/// where ObjectPush(Container::New()) was used)
/**
* Push an object to the current ListHandler
* @param obj Object reference to use
* @return Reference to the Object (from a time
* where ObjectPush(Container::New()) was used)
*/
Container::Ref ObjectPush(Container::Ref obj);
/// @brief Search for an Object by an id
/// @param id 32 Bit hash/id
/// @return the found Object or nullptr
/**
* Search for an Object by an id
* @param id 32 Bit hash/id
* @return the found Object or nullptr
*/
Container::Ref FindIDObj(u32 id);
/**
* 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 Lists ///
// Draw Lists
/// @brief Background Layer Drawlist
/** Background Layer Drawlist */
DrawList::Ref BackList() { return back; }
/// @brief Setter for Background Layer Drawlist
/** Setter for Background Layer Drawlist */
void BackList(DrawList::Ref v) { back = v; }
/// @brief Main Layer Drawlist
/** Main Layer Drawlist */
DrawList::Ref MainList() { return main; }
/// @brief Setter for Main Layer Drawlist
/** Setter for Main Layer Drawlist */
void MainList(DrawList::Ref v) { main = v; }
/// @brief Foreground Layer Drawlist
/** Foreground Layer Drawlist */
DrawList::Ref FrontList() { return front; }
/// @brief Setter for Foreground Layer Drawlist
/** Setter for Foreground Layer Drawlist */
void FrontList(DrawList::Ref v) { front = v; }
/// Advanced ///
// Advanced
/// @brief Display Debug Labels of the Menu
/** Display Debug Labels of the Menu */
void DebugLabels();
/// Uneditable Stuff ///
// Uneditable Stuff
/// @brief Menu Name
/** Menu Name */
std::string GetName() const { return name; }
/// @brief Menu ID [Hash of the Name]
/** Menu ID [Hash of the Name] */
u32 GetID() const { return id; }
private:
/// Advanced Handlers
// Advanced Handlers
/**
* Setup for the Menu
* @param flags Menu Flags
*/
void PreHandler(UI7MenuFlags flags);
/** Handle things like scrolling */
void PostHandler();
/// Basic Settings
// Basic Settings
/**
* Set Backup Cursor
* @param v Position
*/
void BackupCursor(const vec2& v) { bcursor = v; }
/** Get Sameline Cursor */
vec2 SameLineCursor() const { return slcursor; }
/**
* Set Sameline Cursor
* @param v Position
*/
void SameLineCursor(const vec2& v) { slcursor = v; }
/**
* Set View Area
* @param v vec4 containing pos and size
*/
void ViewArea(const vec4& v) { view_area = v; }
/**
* Set Scroll Modification
* @param v Mod
*/
void ScrollMod(const vec2& v) { scroll_mod = v; }
/** Get the Alignment for Current State */
UI7Align GetAlignment() {
/// if temp alignment is used then return it and
/// reset tmpalign
if (tmpalign) {
auto t = tmpalign;
tmpalign = 0;
@ -234,49 +326,53 @@ class Menu : public SmartCtor<Menu> {
return alignment;
}
/// Internal Processing
/** Internal Processing */
void Update(float delta);
/// This ability is crazy useful
// This ability is crazy useful
friend class Context;
/// Data
// Data
// Default Alignment for all Objects
UI7Align alignment = UI7Align_Default;
UI7Align tmpalign = 0;
UI7MenuFlags flags = 0;
u32 id;
std::string name;
vec2 cursor;
vec2 bcursor;
vec2 slcursor;
vec4 view_area;
vec4 main_area;
vec2 scrolling_off;
bool scrolling[2];
vec2 scroll_mod;
float tbh;
bool scrollbar[2];
bool scroll_allowed[2];
bool has_touch;
UI7Align tmpalign = 0; ///< Temp Alignment [only used once]
UI7MenuFlags flags = 0; ///< Menu Flags
u32 id; ///< Menu ID
std::string name; ///< Menu Name
vec2 cursor; ///< Current Cursor Position
vec2 bcursor; ///< Backup Cursor
vec2 slcursor; ///< Sameline Cursor
vec4 view_area; ///< view Area
vec4 main_area; ///< Main Area [Input related]
vec2 scrolling_off; ///< Scrolling Position
bool scrolling[2]; ///< Is Hz or Vt Scrolling Enabled
vec2 scroll_mod; ///< Scroll Modificator
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)
Container::Ref tmp_parent;
Container::Ref tmp_parent; ///< Parent Container (for better alignment etc)
/// Objects API
std::vector<Container::Ref> objects;
std::vector<Container::Ref> idobjs;
std::vector<Container*> join;
int count_btn = 0;
int count_cbx = 0;
// Objects API
std::vector<Container::Ref> objects; ///< Current frame Objects
std::vector<Container::Ref> idobjs; ///< Objects using an ID
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
// DrawLists
DrawList::Ref back;
DrawList::Ref main;
DrawList::Ref front;
vec2 max;
vec2 mouse;
vec2 bslpos;
vec2 last_size;
DrawList::Ref back; ///< Background Drawlist
DrawList::Ref main; ///< Main Drawlist
DrawList::Ref front; ///< Foreground Drawlist
vec2 max; ///< Max Position
vec2 mouse; ///< Mouse/Touch Position
vec2 bslpos; ///< Before Sameline Position
vec2 last_size; ///< Last Object Size
// Theme
Theme::Ref theme;
@ -285,7 +381,8 @@ class Menu : public SmartCtor<Menu> {
Hid::Ref inp;
// Animations System
Tween<vec2> scroll_anim;
Tween<vec2> scroll_anim; ///< for Scroll to Animation
};
} // namespace UI7
} // namespace PD

View File

@ -25,40 +25,51 @@ 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,
UI7Color_Button,
UI7Color_ButtonDead,
UI7Color_ButtonActive,
UI7Color_ButtonHovered,
UI7Color_Text,
UI7Color_TextDead,
UI7Color_Header,
UI7Color_Selector,
UI7Color_Checkmark,
UI7Color_FrameBackground,
UI7Color_FrameBackgroundHovered,
UI7Color_Progressbar,
UI7Color_ListEven,
UI7Color_ListOdd,
UI7Color_Background, ///< UI7 Menu Background
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_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 {
/// @brief Theme Class
/** Theme Class */
class Theme : public SmartCtor<Theme> {
public:
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() {}
~Theme() = default;
/// @brief Simple static Loader for the Default Theme
/// @param theme Theme Reference
/**
* Simple static Loader for the Default Theme
* @param theme Theme Reference
*/
static void Default(Theme& theme);
/// @brief Revert the last Color Change
/** Revert the last Color Change */
Theme& Pop() {
theme[changes[changes.size() - 1].first] =
changes[changes.size() - 1].second;
@ -66,8 +77,10 @@ class Theme : public SmartCtor<Theme> {
return *this;
}
/// @brief Revert the last color Change done for a specific color
/// @param c Color to revert change from
/**
* 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) {
@ -79,9 +92,11 @@ class Theme : public SmartCtor<Theme> {
return *this;
}
/// @brief Change a Color
/// @param tc Color Identifier
/// @param color Color to change to
/**
* 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;
@ -91,8 +106,10 @@ class Theme : public SmartCtor<Theme> {
return *this;
}
/// @brief Get the Color of a Color ReferenceID
/// @param c ReferenceID
/**
* Get the Color of a Color ReferenceID
* @param c ReferenceID
*/
u32 Get(UI7Color c) const {
auto e = theme.find(c);
if (e == theme.end()) {
@ -101,18 +118,22 @@ class Theme : public SmartCtor<Theme> {
return e->second;
}
/// @brief Operator wrapper for get
/// @param c Color ReferenceID
/**
* Operator wrapper for get
* @param c Color ReferenceID
*/
u32 operator[](UI7Color c) const { return Get(c); }
/// @brief 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
/**
* 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;
std::vector<std::pair<UI7Color, u32>> changes;
std::unordered_map<u32, u32> theme; ///< Theme Data
std::vector<std::pair<UI7Color, u32>> changes; ///< List of Changes
};
} // namespace UI7
} // 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> //// WOW A NON UI/ Header
#include <pd/drivers/hid.hpp>
#include <pd/ui7/drawlist.hpp>
#include <pd/ui7/flags.hpp>
#include <pd/ui7/id.hpp>
@ -32,67 +32,113 @@ SOFTWARE.
namespace PD {
namespace UI7 {
/** 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
this->ren = ren;
this->inp = hid;
/// Init Theme and Front / Back Drawlists
theme = Theme::New();
back = DrawList::New(ren);
front = DrawList::New(ren);
}
~Context() {}
~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);
/**
* 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();
/// @brief Get Theme reference
/// @return Reference to the base Theme of the context
/**
* Get Theme reference
* @return Reference to the base Theme of the context
*/
Theme::Ref GetTheme() { return theme; }
/// @brief Directly return a Color by using the
/// ctx->ThemeColor(UI7Color_Text) for example
/// @param clr The Input UI7 Color
/// @return The 32bit color value
/**
*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 theme->Get(clr); }
/// @brief Update Context (Render menus)
/// @param delta deltatime
/**
* Update Context (Render menus)
* @param delta deltatime
*/
void Update(float delta);
/// Expose DrawLists
// Expose DrawLists
/** Background DrawList Reference */
DrawList::Ref BackList() { return back; }
/** Foreground DrawList Reference */
DrawList::Ref FrontList() { return 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; }
private:
// Used in Overlays
int root_layer = 0;
// Linked Renderer / Hid
// Linked Renderer
LI::Renderer::Ref ren;
// Input Driver Reference
Hid::Ref inp;
// Timing
// Delta time
float delta;
// Context Run Time
float time;
/// @brief Last Time [unused ?]
float last;
// Context
// In Menu [unused ?]
bool in_menu;
// Debug
// Is Debugging [unused ?]
bool debugging;
// Menu Handlers
// Map of The Menus by ID
std::unordered_map<u32, Menu::Ref> menus;
std::vector<u32> amenus; // Active ones
Menu::Ref current;
// Context DrawList
std::vector<u32> amenus; ///< Active ones
Menu::Ref current; ///< Current Menu
// Debug Drawlist
DrawList::Ref debug;
// Foreground Drawlist
DrawList::Ref front;
// Background Drawlist
DrawList::Ref back;
// Theme
// Active Theme
Theme::Ref theme;
// Promt Handler
};
} // namespace UI7
} // namespace PD

45
mkdocs.yaml Normal file
View File

@ -0,0 +1,45 @@
site_name: Palladium
site_description:
theme:
name: material
custom_dir: docs/overrides
features:
- navigation.indexes
palette:
# Palette toggle for light mode
- scheme: default
primary: blue
accent: blue
toggle:
icon: material/brightness-7
name: Switch to dark mode
# Palette toggle for dark mode
- scheme: slate
primary: blue
accent: blue
toggle:
icon: material/brightness-4
name: Switch to light mode
markdown_extensions:
- def_list
- attr_list
- admonition
- pymdownx.details
- pymdownx.superfences
- pymdownx.arithmatex:
generic: true
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
plugins:
- search
extra_css:
- stylesheets/doxide.css
extra_javascript:
- javascripts/mathjax.js
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
- https://cdn.jsdelivr.net/npm/tablesort@5.3.0/src/tablesort.min.js
- https://cdn.jsdelivr.net/npm/tablesort@5.3.0/src/sorts/tablesort.number.js
- javascripts/tablesort.js

View File

@ -31,6 +31,9 @@ SOFTWARE.
#ifndef PALLADIUM_GIT_COMMIT
#define PALLADIUM_GIT_COMMIT "unknown"
#endif
#ifndef PALLADIUM_GIT_BRANCH
#define PALLADIUM_GIT_BRANCH "unknown"
#endif
const std::string PD::LibInfo::CompiledWith() {
return Strings::GetCompilerVersion();
@ -40,4 +43,5 @@ const std::string PD::LibInfo::CxxVersion() {
}
const std::string PD::LibInfo::BuildTime() { return __DATE__ " - " __TIME__; }
const std::string PD::LibInfo::Version() { return PALLADIUM_VERSION; }
const std::string PD::LibInfo::Commit() { return PALLADIUM_GIT_COMMIT; }
const std::string PD::LibInfo::Commit() { return PALLADIUM_GIT_COMMIT; }
const std::string PD::LibInfo::Branch() { return PALLADIUM_GIT_BRANCH; }

View File

@ -36,11 +36,11 @@ void Button::HandleInput(Hid::Ref inp) {
Assert(screen.get(), "Screen is not set up!");
if (screen->ScreenType() == Screen::Bottom) {
if (inp->IsHeld(inp->Touch) &&
LI::Renderer::InBox(inp->TouchPos(), vec4(pos, size))) {
LI::Renderer::InBox(inp->TouchPos(), vec4(FinalPos(), size))) {
color = UI7Color_ButtonHovered;
}
if (inp->IsUp(inp->Touch) &&
LI::Renderer::InBox(inp->TouchPosLast(), vec4(pos, size))) {
LI::Renderer::InBox(inp->TouchPosLast(), vec4(FinalPos(), size))) {
color = UI7Color_ButtonActive;
pressed = true;
}
@ -51,8 +51,8 @@ void Button::Draw() {
Assert(ren.get() && list.get() && theme,
"Did you run Container::Init correctly?");
ren->OnScreen(screen);
list->AddRectangle(pos, size, theme->Get(color));
list->AddText(pos + size * 0.5 - tdim * 0.5, label,
list->AddRectangle(FinalPos(), size, theme->Get(color));
list->AddText(FinalPos() + size * 0.5 - tdim * 0.5, label,
theme->Get(UI7Color_Text));
}
} // namespace UI7

View File

@ -35,11 +35,11 @@ void Checkbox::HandleInput(Hid::Ref inp) {
Assert(screen.get(), "Screen is not set up!");
if (screen->ScreenType() == Screen::Bottom) {
if (inp->IsHeld(inp->Touch) &&
LI::Renderer::InBox(inp->TouchPos(), vec4(pos, size))) {
LI::Renderer::InBox(inp->TouchPos(), vec4(FinalPos(), size))) {
color = UI7Color_FrameBackgroundHovered;
}
if (inp->IsUp(inp->Touch) &&
LI::Renderer::InBox(inp->TouchPosLast(), vec4(pos, size))) {
LI::Renderer::InBox(inp->TouchPosLast(), vec4(FinalPos(), size))) {
color = UI7Color_FrameBackgroundHovered;
usr_ref = !usr_ref;
}
@ -50,12 +50,12 @@ void Checkbox::Draw() {
Assert(ren.get() && list.get() && theme,
"Did you run Container::Init correctly?");
ren->OnScreen(screen);
list->AddRectangle(pos, cbs, theme->Get(color));
list->AddRectangle(FinalPos(), cbs, theme->Get(color));
if (usr_ref) {
list->AddRectangle(pos + 2, cbs - 4, theme->Get(UI7Color_Checkmark));
list->AddRectangle(FinalPos() + 2, cbs - 4, theme->Get(UI7Color_Checkmark));
}
list->AddText(pos + vec2(cbs.x() + 5, cbs.y() * 0.5 - tdim.y() * 0.5), label,
theme->Get(UI7Color_Text));
list->AddText(FinalPos() + vec2(cbs.x() + 5, cbs.y() * 0.5 - tdim.y() * 0.5),
label, theme->Get(UI7Color_Text));
}
} // namespace UI7
} // namespace PD

View File

@ -29,7 +29,7 @@ void Image::Draw() {
Assert(ren.get() && list.get(), "Did you run Container::Init correctly?");
Assert(img.get(), "Image is nullptr!");
ren->OnScreen(screen);
list->AddImage(pos, img);
list->AddImage(FinalPos(), img);
}
} // namespace UI7
} // namespace PD

View File

@ -29,7 +29,7 @@ void Label::Draw() {
Assert(ren.get() && list.get() && theme,
"Did you run Container::Init correctly?");
ren->OnScreen(screen);
list->AddText(pos, label, theme->Get(UI7Color_Text));
list->AddText(FinalPos(), label, theme->Get(UI7Color_Text));
}
} // namespace UI7
} // namespace PD

View File

@ -160,13 +160,12 @@ void UI7::Menu::PreHandler(UI7MenuFlags flags) {
this->flags = flags;
this->scrolling[0] = flags & UI7MenuFlags_HzScrolling;
this->scrolling[1] = flags & UI7MenuFlags_VtScrolling;
has_touch =
main->GetRenderer()->CurrentScreen()->ScreenType() == Screen::Bottom;
has_touch = main->ren->CurrentScreen()->ScreenType() == Screen::Bottom;
if (!(flags & UI7MenuFlags_NoBackground)) {
back->AddRectangle(0, view_area.zw(), theme->Get(UI7Color_Background));
}
if (!(flags & UI7MenuFlags_NoTitlebar)) {
tbh = front->GetRenderer()->TextScale() * 30.f;
tbh = front->ren->TextScale() * 30.f;
front->AddRectangle(0, vec2(view_area.z(), tbh),
theme->Get(UI7Color_Header));
vec2 tpos(5, tbh * 0.5 - front->ren->GetTextDimensions(name).y() * 0.5);
@ -314,7 +313,7 @@ void UI7::Menu::Separator() {
void UI7::Menu::SeparatorText(const std::string& label) {
vec2 size = vec2(view_area.z() - (scrollbar[1] ? 24 : 10), 1);
vec2 tdim = this->back->GetRenderer()->GetTextDimensions(label);
vec2 tdim = this->back->ren->GetTextDimensions(label);
vec2 pos = Cursor();
CursorMove(vec2(size.x(), tdim.y() - 4)); // Fix to make gap not to large
@ -412,5 +411,12 @@ void UI7::Menu::AfterAlign(UI7Align a) {
}
ref->SetPos(np);
}
void UI7::Menu::CreateParent() {
Assert(!tmp_parent, "There is already an existing Parent container!");
tmp_parent = Container::New();
tmp_parent->SetPos(0);
tmp_parent->SetSize(0);
}
} // namespace UI7
} // namespace PD