Compare commits
3
Commits
784421fa6c
...
7b6e611f12
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b6e611f12
|
||
|
|
72deaad28d
|
||
|
|
2e652a3c24
|
@@ -54,8 +54,10 @@ set(PD_SOURCES
|
|||||||
# Ultra
|
# Ultra
|
||||||
source/ultra/canvas.cpp
|
source/ultra/canvas.cpp
|
||||||
source/ultra/layout.cpp
|
source/ultra/layout.cpp
|
||||||
|
source/ultra/elems/element.cpp
|
||||||
source/ultra/elems/rect.cpp
|
source/ultra/elems/rect.cpp
|
||||||
source/ultra/elems/text.cpp
|
source/ultra/elems/text.cpp
|
||||||
|
source/ultra/elems/image.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${PD_BUILD_SHARED})
|
if(${PD_BUILD_SHARED})
|
||||||
|
|||||||
@@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -2,19 +2,7 @@
|
|||||||
|
|
||||||
#include <pd/core/core.hpp>
|
#include <pd/core/core.hpp>
|
||||||
#include <pd/lithium/lithium.hpp>
|
#include <pd/lithium/lithium.hpp>
|
||||||
|
#include <pd/ultra/flags.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,
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
@@ -31,18 +19,24 @@ class PD_API Canvas {
|
|||||||
PD::fvec2 VTranslateAlignPos(const PD::fvec2& pos, const PD::fvec2& size,
|
PD::fvec2 VTranslateAlignPos(const PD::fvec2& pos, const PD::fvec2& size,
|
||||||
UltraAlignment align) const;
|
UltraAlignment align) const;
|
||||||
PD::Li::Rect VTranslateObject(const PD::fvec2& pos, const PD::fvec2& size,
|
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 TranslatePos(const PD::fvec2& p) const;
|
||||||
PD::fvec2 VTranslateSize(const PD::fvec2& s) const;
|
PD::fvec2 VTranslateSize(const PD::fvec2& s) const;
|
||||||
PD::fvec2 TranslateSize(const PD::fvec2& s) const;
|
PD::fvec2 TranslateSize(const PD::fvec2& s) const;
|
||||||
float VTranslateFontscale(float f) const;
|
float VTranslateFontscale(float f) const;
|
||||||
float TranslateFontscale(float f) const;
|
float TranslateFontscale(float f) const;
|
||||||
|
const PD::u32& GetRevision() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PD::fvec2 pViewport;
|
PD::fvec2 pViewport;
|
||||||
PD::fvec2 pVirtualViewPort;
|
PD::fvec2 pVirtualViewPort;
|
||||||
float pVfactor = 0.f;
|
float pVfactor = 0.f;
|
||||||
PD::fvec2 pVoff;
|
PD::fvec2 pVoff;
|
||||||
|
PD::u32 pRev; // revision
|
||||||
};
|
};
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <pd/lithium/lithium.hpp>
|
#include <pd/lithium/lithium.hpp>
|
||||||
|
#include <pd/ultra/flags.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
class ElementBase {
|
class Canvas;
|
||||||
|
class PD_API ElementBase {
|
||||||
public:
|
public:
|
||||||
ElementBase() {}
|
ElementBase() {}
|
||||||
~ElementBase() {}
|
~ElementBase() {}
|
||||||
@@ -14,8 +16,22 @@ class ElementBase {
|
|||||||
* Reset Function (for PD::Pool::FastReset)
|
* Reset Function (for PD::Pool::FastReset)
|
||||||
*/
|
*/
|
||||||
virtual void Reset() {}
|
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 Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -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
|
||||||
@@ -8,20 +8,28 @@ namespace Ultra {
|
|||||||
class PD_API Rect : public ElementBase {
|
class PD_API Rect : public ElementBase {
|
||||||
public:
|
public:
|
||||||
Rect() {}
|
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() {}
|
~Rect() {}
|
||||||
|
|
||||||
void Draw(PD::Li::Drawlist& l) override;
|
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 SetColor(const PD::Color& color) { pColor = color; }
|
||||||
void SetRounding(float r) { pRounding = r; }
|
void SetRounding(float r) { pRounding = r; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PD::fvec2 pPos;
|
|
||||||
PD::fvec2 pSize;
|
|
||||||
PD::Color pColor;
|
PD::Color pColor;
|
||||||
float pRounding = 0.f;
|
float pRounding = 0.f;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,13 +12,10 @@ class PD_API Text : public ElementBase {
|
|||||||
|
|
||||||
void Draw(PD::Li::Drawlist& l) override;
|
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 SetColor(const PD::Color& color) { pColor = color; }
|
||||||
void SetText(const std::string& text) { pText = text; }
|
void SetText(const std::string& text) { pText = text; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PD::fvec2 pPos;
|
|
||||||
PD::Color pColor;
|
PD::Color pColor;
|
||||||
std::string pText;
|
std::string pText;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
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() {}
|
PD_API Canvas::~Canvas() {}
|
||||||
|
|
||||||
@@ -15,9 +15,11 @@ PD_API void Canvas::SetVirtualViewport(const PD::fvec2& size) {
|
|||||||
pViewport.y / pVirtualViewPort.y);
|
pViewport.y / pVirtualViewPort.y);
|
||||||
pVoff = (pViewport - (pVirtualViewPort * pVfactor)) * 0.5f;
|
pVoff = (pViewport - (pVirtualViewPort * pVfactor)) * 0.5f;
|
||||||
}
|
}
|
||||||
|
pRev++;
|
||||||
}
|
}
|
||||||
|
|
||||||
PD_API void Canvas::SetViewport(const PD::fvec2& size) {
|
PD_API void Canvas::SetViewport(const PD::fvec2& size) {
|
||||||
|
if (pViewport == size) return;
|
||||||
pViewport = size;
|
pViewport = size;
|
||||||
SetVirtualViewport(pVirtualViewPort); // recalculate Vfactor
|
SetVirtualViewport(pVirtualViewPort); // recalculate Vfactor
|
||||||
}
|
}
|
||||||
@@ -55,6 +57,8 @@ PD_API PD::Li::Rect Canvas::VTranslateObject(const PD::fvec2& pos,
|
|||||||
final.x = pos.x * pVfactor;
|
final.x = pos.x * pVfactor;
|
||||||
} else if (align & UltraAlignment_Right) {
|
} else if (align & UltraAlignment_Right) {
|
||||||
final.x = pViewport.x - (pos.x * pVfactor) - nsize.x;
|
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 {
|
} else {
|
||||||
final.x = pVoff.x + (pos.x * pVfactor) - nsize.x * 0.5;
|
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;
|
final.y = pos.y * pVfactor;
|
||||||
} else if (align & UltraAlignment_Bot) {
|
} else if (align & UltraAlignment_Bot) {
|
||||||
final.y = pViewport.y - (pos.y * pVfactor) - nsize.y;
|
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 {
|
} else {
|
||||||
final.y = pVoff.y + (pos.y * pVfactor) - nsize.y * 0.5;
|
final.y = pVoff.y + (pos.y * pVfactor) - nsize.y * 0.5;
|
||||||
}
|
}
|
||||||
return PD::fvec4(final, final + nsize);
|
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,
|
PD_API PD::fvec2 Canvas::VTranslateAlignPos(const PD::fvec2& pos,
|
||||||
const PD::fvec2& size,
|
const PD::fvec2& size,
|
||||||
UltraAlignment align) const {
|
UltraAlignment align) const {
|
||||||
return VTranslateObject(pos, size, align).TopLeft();
|
return VTranslateObject(pos, size, align).TopLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PD_API const PD::u32& Canvas::GetRevision() const { return pRev; }
|
||||||
|
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -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
|
||||||
@@ -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,8 +3,10 @@
|
|||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
PD_API void Rect::Draw(PD::Li::Drawlist& l) {
|
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.PathFill(pColor);
|
||||||
|
l.DrawText(pRenderspace.BotRight(), std::to_string(pCanvasRev).c_str(),
|
||||||
|
0xff0000ff);
|
||||||
}
|
}
|
||||||
} // namespace Ultra
|
} // namespace Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Ultra {
|
namespace Ultra {
|
||||||
PD_API void Text::Draw(PD::Li::Drawlist& l) {
|
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 Ultra
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -9,6 +9,7 @@ PD_API void Layout::SetFont(PD::Li::Font& font) { pList.SetFont(&font); }
|
|||||||
PD_API void Layout::Render() {
|
PD_API void Layout::Render() {
|
||||||
pList.Clear();
|
pList.Clear();
|
||||||
for (auto& it : pElements) {
|
for (auto& it : pElements) {
|
||||||
|
it->Update(pCanvas);
|
||||||
it->Draw(pList);
|
it->Draw(pList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function(make_3ds_target _NAME TITLE AUTHOR _VERSION ICON ROMFS)
|
|||||||
DEPENDS ${_NAME}.elf
|
DEPENDS ${_NAME}.elf
|
||||||
COMMENT "Creating ${_NAME}.smdh"
|
COMMENT "Creating ${_NAME}.smdh"
|
||||||
)
|
)
|
||||||
add_custom_target(${_NAME}.3dsx
|
add_custom_target(${_NAME}.3dsx ALL
|
||||||
COMMAND ${3DSXTOOL} ${_NAME}.elf ${_NAME}.3dsx --smdh=${_NAME}.smdh
|
COMMAND ${3DSXTOOL} ${_NAME}.elf ${_NAME}.3dsx --smdh=${_NAME}.smdh
|
||||||
--romfs="${ROMFS}"
|
--romfs="${ROMFS}"
|
||||||
DEPENDS ${_NAME}.smdh
|
DEPENDS ${_NAME}.smdh
|
||||||
@@ -35,7 +35,7 @@ function(make_nx_target _NAME TITLE AUTHOR _VERSION ICON ROMFS)
|
|||||||
DEPENDS ${_NAME}.elf
|
DEPENDS ${_NAME}.elf
|
||||||
COMMENT "Creating ${_NAME}.nacp"
|
COMMENT "Creating ${_NAME}.nacp"
|
||||||
)
|
)
|
||||||
add_custom_target(${_NAME}.nro
|
add_custom_target(${_NAME}.nro ALL
|
||||||
COMMAND ${ELF2NRO} ${_NAME}.elf ${_NAME}.nro --nacp=${_NAME}.nacp
|
COMMAND ${ELF2NRO} ${_NAME}.elf ${_NAME}.nro --nacp=${_NAME}.nacp
|
||||||
--romfsdir="${ROMFS}" --icon="${ICON}"
|
--romfsdir="${ROMFS}" --icon="${ICON}"
|
||||||
DEPENDS ${_NAME}.nacp
|
DEPENDS ${_NAME}.nacp
|
||||||
|
|||||||
@@ -4,9 +4,11 @@
|
|||||||
#include <palladium>
|
#include <palladium>
|
||||||
|
|
||||||
////
|
////
|
||||||
|
#include <pd/ultra/elems/image.hpp>
|
||||||
#include <pd/ultra/elems/rect.hpp>
|
#include <pd/ultra/elems/rect.hpp>
|
||||||
#include <pd/ultra/elems/text.hpp>
|
#include <pd/ultra/elems/text.hpp>
|
||||||
#include <pd/ultra/layout.hpp>
|
#include <pd/ultra/layout.hpp>
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
PD::OsCtx* pOs = nullptr;
|
PD::OsCtx* pOs = nullptr;
|
||||||
@@ -65,15 +67,18 @@ int main(int argc, char** argv) {
|
|||||||
PD::Ultra::Layout lyt;
|
PD::Ultra::Layout lyt;
|
||||||
lyt.GetCanvas().SetVirtualViewport(PD::fvec2(400, 240));
|
lyt.GetCanvas().SetVirtualViewport(PD::fvec2(400, 240));
|
||||||
lyt.SetFont(font);
|
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;
|
PD::Ultra::Text txt;
|
||||||
rr.SetPosition(12, 20);
|
PD::Ultra::Image _img(&pTex, 10, 10, 5.f, UltraAlignment_BotRight);
|
||||||
rr.SetSize(90, 60);
|
_img.SetSize(90); // Override size
|
||||||
rr.SetColor(PD::Color("#ff00ff"));
|
|
||||||
lyt.Add(rr);
|
lyt.Add(rr);
|
||||||
|
lyt.Add(_img);
|
||||||
txt.SetPosition(0);
|
txt.SetPosition(0);
|
||||||
txt.SetColor(0xffffffff);
|
txt.SetColor(0xffffffff);
|
||||||
txt.SetText("const std::string &text");
|
txt.SetText("const std::string &text");
|
||||||
|
txt.SetAlignment(UltraAlignment_TopLeft);
|
||||||
lyt.Add(txt);
|
lyt.Add(txt);
|
||||||
while (pOs->Mainloop()) {
|
while (pOs->Mainloop()) {
|
||||||
lyt.GetCanvas().SetViewport(pOs->GetViewport());
|
lyt.GetCanvas().SetViewport(pOs->GetViewport());
|
||||||
|
|||||||
Reference in New Issue
Block a user