# Changes -> 0.5.1

- 3ds
  - Remove Gfx values that are present in Backend Tamplate
  - Move to default Palladium Namespace
  - Set the Input Flags
- Desktop
  - Move to PD Namespace
  - Comment out old keyboard stuff
  - HidDriver needs a rewrite but is functional enough
- Core
  - Add u128 class (only used in input driver so far
- Drivers (Core)
  - Move Gfx to PD namespace
  - Move Vertex/Index Pos and Projection Mtx to Gfx template
  - Add Keyboard support with u128 to Hid
  - Add a Update func if no hiddriver is specified (to prevent crashes when requestign inputs)
- Image
   - Add RGBA -> BGRA support (used in windows bitmaps iirc)
- Lithium
  - Add Vertex/Index counters to drawlist
  - Add a LoadTTF from Mem func and let the loadfile func use PD::IO::LoadFile2Mem (looks cleaner)
  - Add LoadDefaultFont (which loads one of the integrated fonts if the PD_LI_INCLUDE_FONTS flag was passed on palaldium build) !!! Note that there are no fonts integrated yet due to i dont know how to handle licensing...
- UI7
  - Add MouseLeft support to Input handler
  - Use xy coords of the Viewport to create Menus inside it
  - Get num of Vertices/Indices out of FinalDrawList
  - Add some Palladium Info to metrics Menu
  - Readd Compiler string
- pdfm
  - New tool that creates fonts.cpp/fonts.hpp
This commit is contained in:
2025-08-14 20:37:55 +02:00
parent 87910b57de
commit 310b44caf5
38 changed files with 644 additions and 166 deletions

View File

@ -30,4 +30,5 @@ SOFTWARE.
#include <pd/core/sl/pair.hpp>
#include <pd/core/sl/stack.hpp>
#include <pd/core/sl/tools.hpp>
#include <pd/core/sl/vector.hpp>
#include <pd/core/sl/u128.hpp>
#include <pd/core/sl/vector.hpp>

125
include/pd/core/sl/u128.hpp Normal file
View File

@ -0,0 +1,125 @@
#pragma once
#include <pd/core/common.hpp>
namespace PD {
/**
* 128 Bit support for all platforms probably
* only used for flag checks in Keyboard/Mouse Input driver
*/
class u128 {
public:
u64 pLow = 0;
u64 pHigh = 0;
constexpr u128() : pLow(0), pHigh(0) {}
constexpr u128(u64 l, u64 h = 0) : pLow(l), pHigh(h) {}
/**
* Best way so far to create flags that go over 63
* like `1 << 65` is just `u128::Flag(65)`
*/
constexpr static u128 Flag(u32 i) {
if (i < 64) {
return u128(1ULL << i, 0);
} else if (i < 128) {
return u128(0, 1ULL << (i - 64));
}
return u128();
}
u128 operator+(const u128& v) const {
u128 ret;
ret.pLow = pLow + v.pLow;
ret.pHigh = pHigh + v.pHigh + (ret.pLow < pLow);
return ret;
}
u128 operator&(const u128& v) const {
return u128(pLow & v.pLow, pHigh & v.pHigh);
}
u128 operator<<(u32 s) const {
if (s == 0) {
return *this;
}
if (s >= 128) {
return u128();
}
if (s >= 64) {
return u128(0, pLow << (s - 64));
}
return u128(pLow << s, (pHigh << s) | (pLow >> (64 - s)));
}
u128 operator>>(u32 s) const {
if (s == 0) {
return *this;
}
if (s >= 128) {
return u128();
}
if (s >= 64) {
return u128(pHigh >> (s - 64), 0);
}
return u128((pLow >> s) | (pHigh << (64 - s)), pHigh >> s);
}
u128& operator|=(const u128& v) {
pLow |= v.pLow;
pHigh |= v.pHigh;
return *this;
}
u128 operator|(const u128& v) const {
return u128(pLow | v.pLow, pHigh | v.pHigh);
}
u128& operator&=(const u128& v) {
pLow &= v.pLow;
pHigh &= v.pHigh;
return *this;
}
u128 operator~() const { return u128(~pLow, ~pHigh); }
/**
* Old why to make if checks possible
* Problem was that a operator& is required
* with u128 as result
*/
// bool operator&(const u128& v) const {
// return pLow & v.pLow || pHigh & v.pHigh;
// }
bool operator==(const u128& v) const {
return pLow == v.pLow && pHigh == v.pHigh;
}
/**
* Use explicit here to make sure it is only for checking and not for
* some error leading implicit bool assignments...
*/
explicit operator bool() const { return pLow != 0 || pHigh != 0; }
/** Deprecated way to handle `flag & SomeFlag` */
bool Has(const u128& v) const { return pLow & v.pLow || pHigh & v.pHigh; }
bool operator!=(const u128& v) const { return !(*this == v); }
};
} // namespace PD
namespace std {
/**
* Provide c++ STL support for unordered map to u128
*/
template <>
struct hash<PD::u128> {
size_t operator()(const PD::u128& k) const {
// just combine hashes of the parts usign simple xor op
size_t h0 = std::hash<PD::u64>{}(k.pLow);
size_t h1 = std::hash<PD::u64>{}(k.pHigh);
return h0 ^ (h1 << 1);
}
};
} // namespace std

View File

@ -34,7 +34,6 @@ enum LiBackendFlags_ {
};
namespace PD {
namespace Li {
class GfxDriver {
public:
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};
@ -48,27 +47,29 @@ class GfxDriver {
virtual void Deinit() {}
virtual void NewFrame() {}
virtual void BindTex(TexAddress addr) {}
virtual void BindTex(Li::TexAddress addr) {}
virtual void RenderDrawData(const std::vector<Command::Ref>& Commands) {}
virtual void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {}
void SetViewPort(const ivec2& vp) { ViewPort = vp; }
virtual Texture::Ref LoadTex(
virtual Li::Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
Texture::Type type = Texture::Type::RGBA32,
Texture::Filter filter = Texture::Filter::LINEAR) {
Li::Texture::Type type = Li::Texture::Type::RGBA32,
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
// Texture loading not supported (when this func not get override)
return nullptr;
}
Texture::Ref GetSolidTex() { return pSolid; }
Li::Texture::Ref GetSolidTex() { return pSolid; }
const std::string pName = "NullGfx";
LiBackendFlags Flags = 0;
ivec2 ViewPort;
fvec4 ClearColor;
Texture::Ref pSolid;
Mat4 Projection;
Li::Texture::Ref pSolid;
size_t CurrentVertex = 0;
size_t CurrentIndex = 0;
/** Debug Variables */
@ -91,24 +92,23 @@ class Gfx {
static void Deinit() { pGfx->Deinit(); }
static void NewFrame() { pGfx->NewFrame(); }
static void BindTex(TexAddress addr) { pGfx->BindTex(addr); }
static void BindTex(Li::TexAddress addr) { pGfx->BindTex(addr); }
static void SetViewPort(const ivec2& vp) { pGfx->SetViewPort(vp); }
static void RenderDrawData(const std::vector<Command::Ref>& Commands) {
static void RenderDrawData(const std::vector<Li::Command::Ref>& Commands) {
pGfx->RenderDrawData(Commands);
}
static LiBackendFlags Flags() { return pGfx->Flags; }
static Texture::Ref LoadTex(
static Li::Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
Texture::Type type = Texture::Type::RGBA32,
Texture::Filter filter = Texture::Filter::LINEAR) {
Li::Texture::Type type = Li::Texture::Type::RGBA32,
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
return pGfx->LoadTex(pixels, w, h, type, filter);
}
static Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
static Li::Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
static GfxDriver::Ref pGfx;
};
} // namespace Li
} // namespace PD

View File

@ -26,14 +26,70 @@ SOFTWARE.
#include <pd/core/core.hpp>
namespace PD {
/** Did not found a better solution yet sadly */
namespace HidKb {
// Lets use u128 here
using KbKey = u128;
constexpr static KbKey Kb_No = 0;
constexpr static KbKey Kb_Escape = KbKey::Flag(0);
constexpr static KbKey Kb_Q = KbKey::Flag(1);
constexpr static KbKey Kb_W = KbKey::Flag(2);
constexpr static KbKey Kb_E = KbKey::Flag(3);
constexpr static KbKey Kb_R = KbKey::Flag(4);
constexpr static KbKey Kb_T = KbKey::Flag(5);
constexpr static KbKey Kb_Z = KbKey::Flag(6);
constexpr static KbKey Kb_U = KbKey::Flag(7);
constexpr static KbKey Kb_I = KbKey::Flag(8);
constexpr static KbKey Kb_O = KbKey::Flag(9);
constexpr static KbKey Kb_P = KbKey::Flag(10);
constexpr static KbKey Kb_A = KbKey::Flag(11);
constexpr static KbKey Kb_S = KbKey::Flag(12);
constexpr static KbKey Kb_D = KbKey::Flag(13);
constexpr static KbKey Kb_F = KbKey::Flag(14);
constexpr static KbKey Kb_G = KbKey::Flag(15);
constexpr static KbKey Kb_H = KbKey::Flag(16);
constexpr static KbKey Kb_J = KbKey::Flag(17);
constexpr static KbKey Kb_K = KbKey::Flag(18);
constexpr static KbKey Kb_L = KbKey::Flag(19);
constexpr static KbKey Kb_Y = KbKey::Flag(20);
constexpr static KbKey Kb_X = KbKey::Flag(21);
constexpr static KbKey Kb_C = KbKey::Flag(22);
constexpr static KbKey Kb_V = KbKey::Flag(23);
constexpr static KbKey Kb_B = KbKey::Flag(24);
constexpr static KbKey Kb_N = KbKey::Flag(25);
constexpr static KbKey Kb_M = KbKey::Flag(26);
constexpr static KbKey Kb_1 = KbKey::Flag(27);
constexpr static KbKey Kb_2 = KbKey::Flag(28);
constexpr static KbKey Kb_3 = KbKey::Flag(29);
constexpr static KbKey Kb_4 = KbKey::Flag(30);
constexpr static KbKey Kb_5 = KbKey::Flag(31);
constexpr static KbKey Kb_6 = KbKey::Flag(32);
constexpr static KbKey Kb_7 = KbKey::Flag(33);
constexpr static KbKey Kb_8 = KbKey::Flag(34);
constexpr static KbKey Kb_9 = KbKey::Flag(35);
constexpr static KbKey Kb_0 = KbKey::Flag(36);
constexpr static KbKey Kb_F1 = KbKey::Flag(37);
constexpr static KbKey Kb_F2 = KbKey::Flag(38);
constexpr static KbKey Kb_F3 = KbKey::Flag(39);
constexpr static KbKey Kb_F4 = KbKey::Flag(40);
constexpr static KbKey Kb_F5 = KbKey::Flag(41);
constexpr static KbKey Kb_F6 = KbKey::Flag(42);
constexpr static KbKey Kb_F7 = KbKey::Flag(43);
constexpr static KbKey Kb_F8 = KbKey::Flag(44);
constexpr static KbKey Kb_F9 = KbKey::Flag(45);
constexpr static KbKey Kb_F10 = KbKey::Flag(46);
constexpr static KbKey Kb_F11 = KbKey::Flag(47);
constexpr static KbKey Kb_F12 = KbKey::Flag(48);
constexpr static KbKey Kb_MouseLeft = KbKey::Flag(120);
} // namespace HidKb
class HidDriver {
public:
enum Flags : u32 {
Flags_None,
FLags_HasGamepad,
Flags_HasKeyboard,
Flags_HasTouch,
Flags_HasMouse,
Flags_None = 0,
FLags_HasGamepad = 1 << 0,
Flags_HasKeyboard = 1 << 1,
Flags_HasTouch = 1 << 2,
Flags_HasMouse = 1 << 3,
};
// Todo: Name to GpKey (GamepadKey)
/** Key [Controller] */
@ -68,64 +124,7 @@ class HidDriver {
Right = DRight | CPRight, ///< DPad or CPad Right
};
// Dont want to use some hardcoded bitset
// so lets use just numbers
enum KbKey : u8 {
Kb_No = 0,
Kb_Escape = 1,
Kb_Q = 2,
Kb_W = 3,
Kb_E = 4,
Kb_R = 5,
Kb_T = 6,
// Yes i use QWERTZ Keyboard
Kb_Z = 7,
Kb_U = 8,
Kb_I = 9,
Kb_O = 10,
Kb_P = 11,
Kb_A = 12,
Kb_S = 13,
Kb_D = 14,
Kb_F = 15,
Kb_G = 16,
Kb_H = 17,
Kb_J = 18,
Kb_K = 19,
Kb_L = 20,
Kb_Y = 21,
Kb_X = 22,
Kb_C = 23,
Kb_V = 24,
Kb_B = 25,
Kb_N = 26,
Kb_M = 27,
Kb_LShift = 28,
Kb_F1 = 29,
Kb_F2 = 30,
Kb_F3 = 31,
Kb_F4 = 32,
Kb_F5 = 33,
Kb_F6 = 34,
Kb_F7 = 35,
Kb_F8 = 36,
Kb_F9 = 37,
Kb_F10 = 38,
Kb_F11 = 39,
Kb_F12 = 40,
Kb_1 = 41,
Kb_2 = 42,
Kb_3 = 43,
Kb_4 = 44,
Kb_5 = 45,
Kb_6 = 46,
Kb_7 = 47,
Kb_8 = 48,
Kb_9 = 49,
Kb_0 = 50,
Kb_Backspace = 51,
Kb_Enter = 52,
};
using KbKey = HidKb::KbKey;
/** Event */
enum Event {
@ -228,7 +227,7 @@ class HidDriver {
/**
* Template Update Function for a device specific driver
*/
virtual void Update() {}
virtual void Update();
/**
* Get Text from Keyboard
*/
@ -244,6 +243,7 @@ class HidDriver {
/** Key Binds Map */
std::unordered_map<u32, u32> pBinds;
std::unordered_map<u128, u128> pKbBinds;
/** Swap Tabe Function */
void SwapTab();
/** Using 2 Positions for Current and Last */
@ -253,7 +253,7 @@ class HidDriver {
/** Key Event Table Setup */
std::unordered_map<Event, u32> KeyEvents[2];
/** Keyboard Key Event Table Setup */
std::unordered_map<u32, Event> KbKeyEvents[2];
std::unordered_map<Event, u128> KbKeyEvents[2];
};
/** Static Hid Controller */
@ -264,7 +264,7 @@ class Hid {
/** Referenec to Drivers enums */
using Key = HidDriver::Key;
using KbKey = HidDriver::KbKey;
using KbKey = HidKb::KbKey;
using Event = HidDriver::Event;
static void Init(HidDriver::Ref v = nullptr) {

View File

@ -35,7 +35,8 @@ class PD_IMAGE_API Image {
RGB, // bpp == 3
RGB565, // bpp == 2 (not supported in laoding)
BGR, // bpp == 3
ABGR // bpp == 4
ABGR, // bpp == 4
BGRA, // bpp == 4
};
Image() = default;
Image(const std::string& path) { this->Load(path); }

View File

@ -70,8 +70,8 @@ class PD_LITHIUM_API DrawList {
void Merge(DrawList::Ref list);
Command::Ref PreGenerateCmd();
void AddCommand(Command::Ref v) { pDrawList.push_back(std::move(v)); }
void Clear() { pDrawList.clear(); }
void AddCommand(Command::Ref v);
void Clear();
void SetFont(Font::Ref font) { pCurrentFont = font; }
void SetFontScale(float scale) { pFontScale = scale; }
@ -194,6 +194,8 @@ class PD_LITHIUM_API DrawList {
Texture::Ref CurrentTex;
std::vector<Command::Ref> pDrawList;
PD::Vec<fvec2> pPath;
u32 pNumIndices = 0;
u32 pNumVertices = 0;
};
} // namespace Li
} // namespace PD

View File

@ -67,6 +67,18 @@ class PD_LITHIUM_API Font {
* @param px_height Pixelheight of the codepoints (limit by 64)
*/
void LoadTTF(const std::string& path, int px_height = 32);
/**
* Load a TTF File from Memory
* @param data File data
* @param px_height Pixelheight of the codepoints (limit by 64)
*/
void LoadTTF(const std::vector<u8>& data, int px_height = 32);
/**
* Function that loads a default integrated font...
* This will only work if PD_LI_INCLUDE_FONTS was set
* on lithium build cause otherwise the font data is not included
*/
void LoadDefaultFont(int id = 0, int pixel_height = 32);
/**
* Getter for Codepoint reference
* @return codepoint dataholder reference

View File

@ -0,0 +1,41 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifdef PD_LI_INCLUDE_FONTS
#include <pd/core/common.hpp>
/** Generated with pdfm */
namespace PD {
struct FontFileData {
std::string Name;
u32 StartOff;
u32 Size;
};
extern FontFileData pFontData[];
extern size_t pNumFonts;
extern PD::u8 pFontsDataRaw[];
} // namespace PD
#endif

View File

@ -58,7 +58,9 @@ class InputHandler {
// Get a Short define for touch pos
fvec2 p = Hid::MousePos();
// Check if Drag starts in the area position
if (Hid::IsDown(Hid::Key::Touch) && Li::Renderer::InBox(p, area)) {
if ((Hid::IsDown(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Down, HidKb::Kb_MouseLeft)) &&
Li::Renderer::InBox(p, area)) {
// Set ID and iniatial Positions
DraggedObject = id;
DragSourcePos = p;
@ -69,11 +71,16 @@ class InputHandler {
DragTime->Reset();
DragTime->Rseume();
return false; // To make sure the Object is "Dragged"
} else if (Hid::IsHeld(Hid::Key::Touch) && IsObjectDragged()) {
} else if ((Hid::IsHeld(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Held,
HidKb::Kb_MouseLeft)) &&
IsObjectDragged()) {
// Update DragLast and DragPoisition
DragLastPosition = DragPosition;
DragPosition = p;
} else if (Hid::IsUp(Hid::Key::Touch) && IsObjectDragged()) {
} else if ((Hid::IsUp(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Up, HidKb::Kb_MouseLeft)) &&
IsObjectDragged()) {
// Released... Everything gets reset
DraggedObject = 0;
DragPosition = 0;

View File

@ -43,8 +43,8 @@ class PD_UI7_API IO {
FDL = Li::DrawList::New();
DeltaStats = TimeStats::New(60);
/** Probably not the best solution i guess */
CurrentViewPort.z = PD::Li::Gfx::pGfx->ViewPort.x;
CurrentViewPort.w = PD::Li::Gfx::pGfx->ViewPort.y;
CurrentViewPort.z = PD::Gfx::pGfx->ViewPort.x;
CurrentViewPort.w = PD::Gfx::pGfx->ViewPort.y;
}
~IO() {}

View File

@ -43,8 +43,9 @@ class PD_UI7_API Layout {
Scrolling[0] = false;
Scrolling[1] = false;
CursorInit();
Pos = fvec2(0, 0);
Size = fvec2(io->CurrentViewPort.z, io->CurrentViewPort.w);
Pos = fvec2(io->CurrentViewPort.x, io->CurrentViewPort.y);
Size = fvec2(io->CurrentViewPort.z - io->CurrentViewPort.x,
io->CurrentViewPort.w - io->CurrentViewPort.y);
WorkRect = fvec4(IO->MenuPadding, Size - (fvec2(2) * IO->MenuPadding));
}
~Layout() = default;

View File

@ -37,7 +37,7 @@ SOFTWARE.
* Major Minor Patch Build
* 0x01010000 -> 1.1.0-0
*/
#define UI7_VERSION 0x00050001
#define UI7_VERSION 0x00050100
namespace PD {
namespace UI7 {