3 Commits
Author SHA1 Message Date
tobid7 7b6e611f12 Add cmake presets
- MSVC requires cmake for Windows
- mingw only builds when GLSLANG is excluded due to wrong header generation
2026-03-28 13:53:55 +01:00
tobid7 72deaad28d build 3dsx and nro in ALL stage 2026-03-28 13:52:59 +01:00
tobid7 2e652a3c24 More stuff done at Project Ultra
- Added renderspace
- Revision System (to not always update pRenderspace
- added some test scene
2026-03-28 13:52:36 +01:00
20 changed files with 339 additions and 35 deletions
+2
View File
@@ -54,8 +54,10 @@ set(PD_SOURCES
# Ultra
source/ultra/canvas.cpp
source/ultra/layout.cpp
source/ultra/elems/element.cpp
source/ultra/elems/rect.cpp
source/ultra/elems/text.cpp
source/ultra/elems/image.cpp
)
if(${PD_BUILD_SHARED})
+14
View File
@@ -0,0 +1,14 @@
{
"version": 10,
"cmakeMinimumRequired": {
"major": 3,
"minor": 22,
"patch": 0
},
"include": [
"cmake/presets/3ds.json",
"cmake/presets/switch.json",
"cmake/presets/mingw.json",
"cmake/presets/msvc.json"
]
}
+35
View File
@@ -0,0 +1,35 @@
{
"version": 10,
"configurePresets": [
{
"name": "3ds-debug",
"generator": "Ninja",
"displayName": "Nintendo 3DS",
"binaryDir": "${sourceDir}/build/3ds-debug",
"toolchainFile": "/opt/devkitPro/cmake/3DS.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "3ds-release",
"generator": "Ninja",
"displayName": "Nintendo 3DS",
"binaryDir": "${sourceDir}/build/3ds-release",
"toolchainFile": "/opt/devkitPro/cmake/3DS.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "3ds-release",
"configurePreset": "3ds-release"
},
{
"name": "3ds-debug",
"configurePreset": "3ds-debug"
}
]
}
+35
View File
@@ -0,0 +1,35 @@
{
"version": 10,
"configurePresets": [
{
"name": "mingw-release",
"displayName": "MinGW",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/mingw-release",
"cacheVariables": {
"SPV_EXCLUDE_GLSLANG": "ON",
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "mingw-debug",
"displayName": "MinGW",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/mingw-debug",
"cacheVariables": {
"SPV_EXCLUDE_GLSLANG": "ON",
"CMAKE_BUILD_TYPE": "Debug"
}
}
],
"buildPresets": [
{
"name": "mingw-release",
"configurePreset": "mingw-release"
},
{
"name": "mingw-debug",
"configurePreset": "mingw-debug"
}
]
}
+24
View File
@@ -0,0 +1,24 @@
{
"version": 10,
"configurePresets": [
{
"name": "msvc",
"cmakeExecutable": "C:\\Program Files\\CMake\\bin\\cmake.exe",
"displayName": "MSVC",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/build/msvc-build"
}
],
"buildPresets": [
{
"name": "msvc-release",
"configuration": "Release",
"configurePreset": "msvc"
},
{
"name": "msvc-debug",
"configuration": "Debug",
"configurePreset": "msvc"
}
]
}
+37
View File
@@ -0,0 +1,37 @@
{
"version": 10,
"configurePresets": [
{
"name": "switch-debug",
"generator": "Ninja",
"displayName": "Nintendo Switch",
"binaryDir": "${sourceDir}/build/switch-debug",
"toolchainFile": "/opt/devkitPro/cmake/Switch.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"SPV_EXCLUDE_GLSLANG": "ON"
}
},
{
"name": "switch-release",
"generator": "Ninja",
"displayName": "Nintendo Switch",
"binaryDir": "${sourceDir}/build/switch-release",
"toolchainFile": "/opt/devkitPro/cmake/Switch.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"SPV_EXCLUDE_GLSLANG": "ON"
}
}
],
"buildPresets": [
{
"name": "switch-release",
"configurePreset": "switch-release"
},
{
"name": "switch-debug",
"configurePreset": "switch-debug"
}
]
}
+8 -14
View File
@@ -2,19 +2,7 @@
#include <pd/core/core.hpp>
#include <pd/lithium/lithium.hpp>
using UltraAlignment = PD::u32;
enum UltraAlignment_ {
UltraAlignment_None = 0,
UltraAlignment_Top = 1 << 0,
UltraAlignment_Bot = 1 << 1,
UltraAlignment_Left = 1 << 2,
UltraAlignment_Right = 1 << 3,
UltraAlignment_TopLeft = UltraAlignment_Top | UltraAlignment_Left,
UltraAlignment_TopRight = UltraAlignment_Top | UltraAlignment_Right,
UltraAlignment_BotLeft = UltraAlignment_Bot | UltraAlignment_Left,
UltraAlignment_BotRight = UltraAlignment_Bot | UltraAlignment_Right,
};
#include <pd/ultra/flags.hpp>
namespace PD {
namespace Ultra {
@@ -31,18 +19,24 @@ class PD_API Canvas {
PD::fvec2 VTranslateAlignPos(const PD::fvec2& pos, const PD::fvec2& size,
UltraAlignment align) const;
PD::Li::Rect VTranslateObject(const PD::fvec2& pos, const PD::fvec2& size,
UltraAlignment align, bool size_modified = false) const;
UltraAlignment align,
bool size_modified = false) const;
PD::Li::Rect TranslateObject(const PD::fvec2& pos, const PD::fvec2& size,
UltraAlignment align,
bool size_modified = false) const;
PD::fvec2 TranslatePos(const PD::fvec2& p) const;
PD::fvec2 VTranslateSize(const PD::fvec2& s) const;
PD::fvec2 TranslateSize(const PD::fvec2& s) const;
float VTranslateFontscale(float f) const;
float TranslateFontscale(float f) const;
const PD::u32& GetRevision() const;
private:
PD::fvec2 pViewport;
PD::fvec2 pVirtualViewPort;
float pVfactor = 0.f;
PD::fvec2 pVoff;
PD::u32 pRev; // revision
};
} // namespace Ultra
} // namespace PD
+18 -2
View File
@@ -1,10 +1,12 @@
#pragma once
#include <pd/lithium/lithium.hpp>
#include <pd/ultra/flags.hpp>
namespace PD {
namespace Ultra {
class ElementBase {
class Canvas;
class PD_API ElementBase {
public:
ElementBase() {}
~ElementBase() {}
@@ -14,8 +16,22 @@ class ElementBase {
* Reset Function (for PD::Pool::FastReset)
*/
virtual void Reset() {}
void Update(Canvas& c);
private:
void SetAlignment(UltraAlignment a) { pAlignment = a; }
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
void SetPosition(float x, float y) { pPos = PD::fvec2(x, y); }
void SetSize(const PD::fvec2& size) { pSize = size; }
void SetSize(float w, float h) { pSize = PD::fvec2(w, h); }
protected:
bool RevisionUpdate(PD::u32 req);
PD::u32 pCanvasRev = 0;
PD::Li::Rect pRenderspace;
UltraAlignment pAlignment = 0;
PD::fvec2 pPos;
PD::fvec2 pSize;
ElementBase* pParent = nullptr;
};
} // namespace Ultra
} // namespace PD
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include <pd/core/core.hpp>
#include <pd/ultra/elems/element.hpp>
namespace PD {
namespace Ultra {
class PD_API Image : public ElementBase {
public:
Image() {}
Image(PD::Li::Texture* tex, const PD::fvec2& pos, float rounding = 0.f,
UltraAlignment align = 0)
: pColor(0xffffffff), pRounding(rounding) {
this->pAlignment = align;
this->pPos = pos;
SetTexture(tex);
}
Image(PD::Li::Texture* tex, float x, float y, float rounding = 0.f,
UltraAlignment align = 0)
: pColor(0xffffffff), pRounding(rounding) {
this->pAlignment = align;
this->pPos = PD::fvec2(x, y);
SetTexture(tex);
}
~Image() {}
void Draw(PD::Li::Drawlist& l) override;
void SetColor(const PD::Color& color) { pColor = color; }
void SetRounding(float r) { pRounding = r; }
void SetTexture(PD::Li::Texture* tex) {
pTex = tex;
SetSize(pTex->GetSize());
}
private:
PD::Color pColor = 0xffffffff;
PD::Li::Texture* pTex = nullptr;
float pRounding = 0.f;
};
} // namespace Ultra
} // namespace PD
+14 -6
View File
@@ -8,20 +8,28 @@ namespace Ultra {
class PD_API Rect : public ElementBase {
public:
Rect() {}
Rect(const PD::fvec2& pos, const PD::fvec2& size, const PD::Color& color,
float rounding = 0.f, UltraAlignment align = 0)
: pColor(color), pRounding(rounding) {
this->pAlignment = align;
this->pPos = pos;
this->pSize = size;
}
Rect(float x, float y, float w, float h, const PD::Color& color,
float rounding = 0.f, UltraAlignment align = 0)
: pColor(color), pRounding(rounding) {
this->pAlignment = align;
this->pPos = PD::fvec2(x, y);
this->pSize = PD::fvec2(w, h);
}
~Rect() {}
void Draw(PD::Li::Drawlist& l) override;
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
void SetPosition(float x, float y) { pPos = PD::fvec2(x, y); }
void SetSize(const PD::fvec2& size) { pSize = size; }
void SetSize(float w, float h) { pSize = PD::fvec2(w, h); }
void SetColor(const PD::Color& color) { pColor = color; }
void SetRounding(float r) { pRounding = r; }
private:
PD::fvec2 pPos;
PD::fvec2 pSize;
PD::Color pColor;
float pRounding = 0.f;
};
-3
View File
@@ -12,13 +12,10 @@ class PD_API Text : public ElementBase {
void Draw(PD::Li::Drawlist& l) override;
void SetPosition(const PD::fvec2& pos) { pPos = pos; }
void SetPosition(float x, float y) { pPos = PD::fvec2(x, y); }
void SetColor(const PD::Color& color) { pColor = color; }
void SetText(const std::string& text) { pText = text; }
private:
PD::fvec2 pPos;
PD::Color pColor;
std::string pText;
};
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <pd/common.hpp>
using UltraAlignment = PD::u32;
enum UltraAlignment_ {
UltraAlignment_None = 0,
UltraAlignment_Top = 1 << 0,
UltraAlignment_Bot = 1 << 1,
UltraAlignment_Left = 1 << 2,
UltraAlignment_Right = 1 << 3,
UltraAlignment_CenterVertical = 1 << 4,
UltraAlignment_CenterHorizontal = 1 << 5,
UltraAlignment_TopLeft = UltraAlignment_Top | UltraAlignment_Left,
UltraAlignment_TopRight = UltraAlignment_Top | UltraAlignment_Right,
UltraAlignment_BotLeft = UltraAlignment_Bot | UltraAlignment_Left,
UltraAlignment_BotRight = UltraAlignment_Bot | UltraAlignment_Right,
};
+38 -2
View File
@@ -2,9 +2,9 @@
namespace PD {
namespace Ultra {
PD_API Canvas::Canvas() {}
PD_API Canvas::Canvas() { pRev = 0; }
PD_API Canvas::Canvas(const PD::fvec2& size) : pViewport(size) {}
PD_API Canvas::Canvas(const PD::fvec2& size) : pViewport(size) { pRev = 0; }
PD_API Canvas::~Canvas() {}
@@ -15,9 +15,11 @@ PD_API void Canvas::SetVirtualViewport(const PD::fvec2& size) {
pViewport.y / pVirtualViewPort.y);
pVoff = (pViewport - (pVirtualViewPort * pVfactor)) * 0.5f;
}
pRev++;
}
PD_API void Canvas::SetViewport(const PD::fvec2& size) {
if (pViewport == size) return;
pViewport = size;
SetVirtualViewport(pVirtualViewPort); // recalculate Vfactor
}
@@ -55,6 +57,8 @@ PD_API PD::Li::Rect Canvas::VTranslateObject(const PD::fvec2& pos,
final.x = pos.x * pVfactor;
} else if (align & UltraAlignment_Right) {
final.x = pViewport.x - (pos.x * pVfactor) - nsize.x;
} else if (align & UltraAlignment_CenterHorizontal) {
final.x = pViewport.x * 0.5 - nsize.x * 0.5 + pos.x * pVfactor;
} else {
final.x = pVoff.x + (pos.x * pVfactor) - nsize.x * 0.5;
}
@@ -62,17 +66,49 @@ PD_API PD::Li::Rect Canvas::VTranslateObject(const PD::fvec2& pos,
final.y = pos.y * pVfactor;
} else if (align & UltraAlignment_Bot) {
final.y = pViewport.y - (pos.y * pVfactor) - nsize.y;
} else if (align & UltraAlignment_CenterVertical) {
final.y = pViewport.y * 0.5 - nsize.y * 0.5 + pos.y * pVfactor;
} else {
final.y = pVoff.y + (pos.y * pVfactor) - nsize.y * 0.5;
}
return PD::fvec4(final, final + nsize);
}
PD_API PD::Li::Rect Canvas::TranslateObject(const PD::fvec2& pos,
const PD::fvec2& size,
UltraAlignment align,
bool size_modified) const {
PD::fvec2 nsize = size;
if (!size_modified) nsize *= pViewport;
PD::fvec2 final;
if (align & UltraAlignment_Left) {
final.x = pos.x * pViewport.x;
} else if (align & UltraAlignment_Right) {
final.x = pViewport.x - (pos.x * pViewport.x) - nsize.x;
} else if (align & UltraAlignment_CenterHorizontal) {
final.x = pViewport.x * 0.5 - nsize.x * 0.5 + pos.x * pViewport.x;
} else {
final.x = pVoff.x + (pos.x * pViewport.x) - nsize.x * 0.5;
}
if (align & UltraAlignment_Top) {
final.y = pos.y * pViewport.y;
} else if (align & UltraAlignment_Bot) {
final.y = pViewport.y - (pos.y * pViewport.y) - nsize.y;
} else if (align & UltraAlignment_CenterVertical) {
final.y = pViewport.y * 0.5 - nsize.y * 0.5 + pos.y * pViewport.y;
} else {
final.y = pVoff.y + (pos.y * pViewport.y) - nsize.y * 0.5;
}
return PD::fvec4(final, final + nsize);
}
PD_API PD::fvec2 Canvas::VTranslateAlignPos(const PD::fvec2& pos,
const PD::fvec2& size,
UltraAlignment align) const {
return VTranslateObject(pos, size, align).TopLeft();
}
PD_API const PD::u32& Canvas::GetRevision() const { return pRev; }
} // namespace Ultra
} // namespace PD
+26
View File
@@ -0,0 +1,26 @@
#include <pd/ultra/canvas.hpp>
#include <pd/ultra/elems/element.hpp>
namespace PD {
namespace Ultra {
PD_API bool ElementBase::RevisionUpdate(PD::u32 req) {
if (req != pCanvasRev) {
pCanvasRev = req;
return true;
} else {
return false;
}
}
PD_API void ElementBase::Update(Canvas& c) {
if (RevisionUpdate(c.GetRevision())) {
if (pParent) {
pRenderspace = c.VTranslateObject(
pParent->pRenderspace.TopLeft(),
pRenderspace.BotRight() - pRenderspace.TopLeft(), pAlignment, true);
} else {
pRenderspace = c.VTranslateObject(pPos, pSize, pAlignment);
}
}
}
} // namespace Ultra
} // namespace PD
+11
View File
@@ -0,0 +1,11 @@
#include <pd/ultra/elems/image.hpp>
namespace PD {
namespace Ultra {
PD_API void Image::Draw(PD::Li::Drawlist& l) {
l.BindTexture(*pTex);
l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding);
l.PathFill(pColor);
}
} // namespace Ultra
} // namespace PD
+3 -1
View File
@@ -3,8 +3,10 @@
namespace PD {
namespace Ultra {
PD_API void Rect::Draw(PD::Li::Drawlist& l) {
l.PathRect(pPos, pPos + pSize, pRounding);
l.PathRect(pRenderspace.TopLeft(), pRenderspace.BotRight(), pRounding);
l.PathFill(pColor);
l.DrawText(pRenderspace.BotRight(), std::to_string(pCanvasRev).c_str(),
0xff0000ff);
}
} // namespace Ultra
} // namespace PD
+1 -1
View File
@@ -3,7 +3,7 @@
namespace PD {
namespace Ultra {
PD_API void Text::Draw(PD::Li::Drawlist& l) {
l.DrawText(pPos, pText.c_str(), pColor);
l.DrawText(pRenderspace.TopLeft(), pText.c_str(), pColor);
}
} // namespace Ultra
} // namespace PD
+1
View File
@@ -9,6 +9,7 @@ PD_API void Layout::SetFont(PD::Li::Font& font) { pList.SetFont(&font); }
PD_API void Layout::Render() {
pList.Clear();
for (auto& it : pElements) {
it->Update(pCanvas);
it->Draw(pList);
}
}
+2 -2
View File
@@ -16,7 +16,7 @@ function(make_3ds_target _NAME TITLE AUTHOR _VERSION ICON ROMFS)
DEPENDS ${_NAME}.elf
COMMENT "Creating ${_NAME}.smdh"
)
add_custom_target(${_NAME}.3dsx
add_custom_target(${_NAME}.3dsx ALL
COMMAND ${3DSXTOOL} ${_NAME}.elf ${_NAME}.3dsx --smdh=${_NAME}.smdh
--romfs="${ROMFS}"
DEPENDS ${_NAME}.smdh
@@ -35,7 +35,7 @@ function(make_nx_target _NAME TITLE AUTHOR _VERSION ICON ROMFS)
DEPENDS ${_NAME}.elf
COMMENT "Creating ${_NAME}.nacp"
)
add_custom_target(${_NAME}.nro
add_custom_target(${_NAME}.nro ALL
COMMAND ${ELF2NRO} ${_NAME}.elf ${_NAME}.nro --nacp=${_NAME}.nacp
--romfsdir="${ROMFS}" --icon="${ICON}"
DEPENDS ${_NAME}.nacp
+9 -4
View File
@@ -4,9 +4,11 @@
#include <palladium>
////
#include <pd/ultra/elems/image.hpp>
#include <pd/ultra/elems/rect.hpp>
#include <pd/ultra/elems/text.hpp>
#include <pd/ultra/layout.hpp>
////
PD::OsCtx* pOs = nullptr;
@@ -65,15 +67,18 @@ int main(int argc, char** argv) {
PD::Ultra::Layout lyt;
lyt.GetCanvas().SetVirtualViewport(PD::fvec2(400, 240));
lyt.SetFont(font);
PD::Ultra::Rect rr;
PD::Ultra::Rect rr(
0, 0, 90, 60, PD::Color("#ffff00"), 12.f,
UltraAlignment_CenterHorizontal | UltraAlignment_CenterVertical);
PD::Ultra::Text txt;
rr.SetPosition(12, 20);
rr.SetSize(90, 60);
rr.SetColor(PD::Color("#ff00ff"));
PD::Ultra::Image _img(&pTex, 10, 10, 5.f, UltraAlignment_BotRight);
_img.SetSize(90); // Override size
lyt.Add(rr);
lyt.Add(_img);
txt.SetPosition(0);
txt.SetColor(0xffffffff);
txt.SetText("const std::string &text");
txt.SetAlignment(UltraAlignment_TopLeft);
lyt.Add(txt);
while (pOs->Mainloop()) {
lyt.GetCanvas().SetViewport(pOs->GetViewport());