2026-03-21 14:43:16 +01:00
|
|
|
#include <os/desktopos.hpp>
|
|
|
|
|
#include <os/horizon-ctr.hpp>
|
|
|
|
|
#include <os/horizon-nx.hpp>
|
2026-03-16 17:33:46 +01:00
|
|
|
#include <palladium>
|
2026-03-17 16:47:19 +01:00
|
|
|
|
2026-03-26 21:02:10 +01:00
|
|
|
////
|
2026-04-03 15:17:43 +02:00
|
|
|
#include <pd/ultra/elems/button.hpp>
|
|
|
|
|
#include <pd/ultra/elems/element.hpp>
|
2026-03-28 13:52:36 +01:00
|
|
|
#include <pd/ultra/elems/image.hpp>
|
2026-03-26 21:02:10 +01:00
|
|
|
#include <pd/ultra/elems/rect.hpp>
|
|
|
|
|
#include <pd/ultra/elems/text.hpp>
|
|
|
|
|
#include <pd/ultra/layout.hpp>
|
2026-04-03 15:17:43 +02:00
|
|
|
|
2026-03-26 21:02:10 +01:00
|
|
|
////
|
|
|
|
|
|
2026-03-21 14:43:16 +01:00
|
|
|
PD::OsCtx* pOs = nullptr;
|
2026-03-17 16:47:19 +01:00
|
|
|
|
2026-03-21 14:43:16 +01:00
|
|
|
const char* ResourcePath(const char* in) {
|
|
|
|
|
#if defined(__SWITCH__) || defined(__3DS__)
|
|
|
|
|
static char rbuf[512];
|
|
|
|
|
std::snprintf(rbuf, sizeof(rbuf), "romfs:/%s", in);
|
|
|
|
|
return rbuf;
|
2026-03-18 09:31:47 +01:00
|
|
|
#else
|
2026-03-21 14:43:16 +01:00
|
|
|
return in;
|
2026-03-18 09:31:47 +01:00
|
|
|
#endif
|
2026-03-21 14:43:16 +01:00
|
|
|
}
|
2026-03-16 17:33:46 +01:00
|
|
|
|
2026-04-05 00:26:00 +02:00
|
|
|
std::string Key2String(PD::Hid::Gamepad gp) {
|
|
|
|
|
std::string res;
|
|
|
|
|
if (gp & PD::Hid::Gamepad::A) {
|
|
|
|
|
res += "A";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::B) {
|
|
|
|
|
res += "B";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::X) {
|
|
|
|
|
res += "X";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::Y) {
|
|
|
|
|
res += "Y";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::Start) {
|
|
|
|
|
res += "Start";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::Select) {
|
|
|
|
|
res += "Select";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::DDown) {
|
|
|
|
|
res += "DDown";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::DUp) {
|
|
|
|
|
res += "DUp";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::DLeft) {
|
|
|
|
|
res += "DLeft";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::DRight) {
|
|
|
|
|
res += "DRight";
|
|
|
|
|
}
|
2026-04-09 21:51:38 +02:00
|
|
|
if (gp & PD::Hid::Gamepad::CPDown) {
|
|
|
|
|
res += "CPDown";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::CPUp) {
|
|
|
|
|
res += "CPUp";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::CPLeft) {
|
|
|
|
|
res += "CPLeft";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::CPRight) {
|
|
|
|
|
res += "CPRight";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::CSDown) {
|
|
|
|
|
res += "CSDown";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::CSUp) {
|
|
|
|
|
res += "CSUp";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::CSLeft) {
|
|
|
|
|
res += "CSLeft";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::CSRight) {
|
|
|
|
|
res += "CSRight";
|
|
|
|
|
}
|
2026-04-05 00:26:00 +02:00
|
|
|
if (gp & PD::Hid::Gamepad::L) {
|
|
|
|
|
res += "L";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::R) {
|
|
|
|
|
res += "R";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::ZL) {
|
|
|
|
|
res += "ZL";
|
|
|
|
|
}
|
|
|
|
|
if (gp & PD::Hid::Gamepad::ZR) {
|
|
|
|
|
res += "ZR";
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string ComboGpOut(PD::Hid::Gamepad gp) {
|
|
|
|
|
std::string res = Key2String(gp);
|
|
|
|
|
if (PD::Hid::IsEvent(PD::Hid::Event::Down, gp)) {
|
|
|
|
|
res += ": 1";
|
|
|
|
|
} else if (PD::Hid::IsEvent(PD::Hid::Event::Held, gp)) {
|
|
|
|
|
res += ": 2";
|
|
|
|
|
} else if (PD::Hid::IsEvent(PD::Hid::Event::Up, gp)) {
|
|
|
|
|
res += ": 3";
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 12:43:49 +02:00
|
|
|
class MainMenu : public PD::Ultra::Layout {
|
|
|
|
|
public:
|
|
|
|
|
MainMenu(PD::Li::Font& font) {
|
2026-04-03 15:17:43 +02:00
|
|
|
SetFont(font);
|
2026-04-03 12:43:49 +02:00
|
|
|
SetBaseViewport(PD::ivec2(1280, 720));
|
|
|
|
|
pBackground.SetSize(800, 450);
|
2026-04-03 15:17:43 +02:00
|
|
|
pBackground.SetColor("#ffffffff");
|
2026-04-05 00:26:00 +02:00
|
|
|
pBackground.SetAlignment(UltraAlignment_Center);
|
2026-04-03 12:43:49 +02:00
|
|
|
Push(pBackground);
|
2026-04-03 15:17:43 +02:00
|
|
|
pText.SetColor("#ffffff");
|
|
|
|
|
pText.SetText("MousePos: ");
|
|
|
|
|
pText.SetAlignment(UltraAlignment_TopLeft);
|
2026-04-03 12:43:49 +02:00
|
|
|
Push(pText);
|
2026-04-03 15:17:43 +02:00
|
|
|
pBtn.SetText("Test");
|
|
|
|
|
pBtn.SetAlignment(UltraAlignment_Center);
|
|
|
|
|
pBtn.SetColor("#1273fb");
|
|
|
|
|
pBtn.SetFocusedColor("#0011ff");
|
|
|
|
|
pBtn.SetTextColor("#ffffff");
|
|
|
|
|
pBtn.SetRounding(10);
|
|
|
|
|
pBtn.OnPress([]() { PD::Log("Btn Pressed..."); });
|
|
|
|
|
Push(pBtn);
|
2026-04-03 12:43:49 +02:00
|
|
|
}
|
|
|
|
|
~MainMenu() {}
|
|
|
|
|
|
2026-04-03 15:17:43 +02:00
|
|
|
void Update() {
|
|
|
|
|
pText.SetText(std::format("MousePos: {}", PD::Hid::MousePos()));
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-03 12:43:49 +02:00
|
|
|
private:
|
|
|
|
|
PD::Ultra::Rect pBackground;
|
|
|
|
|
PD::Ultra::Text pText;
|
2026-04-03 15:17:43 +02:00
|
|
|
PD::Ultra::Button pBtn;
|
2026-04-03 12:43:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class App {
|
|
|
|
|
public:
|
|
|
|
|
App(PD::Li::Font& font) : main(font) {}
|
|
|
|
|
~App() {}
|
|
|
|
|
|
|
|
|
|
void Update(PD::ivec2 vp, PD::Li::Drawlist& list) {
|
2026-04-03 15:17:43 +02:00
|
|
|
main.Update();
|
2026-04-03 12:43:49 +02:00
|
|
|
main.SetViewport(vp);
|
|
|
|
|
main.Render(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MainMenu main;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-09 21:51:38 +02:00
|
|
|
struct Cursor {
|
|
|
|
|
PD::fvec2 pPos = 0;
|
|
|
|
|
std::string name;
|
|
|
|
|
PD::Color pColor = 0xffff00ff;
|
|
|
|
|
void Render(PD::Li::Drawlist& l) {
|
|
|
|
|
l.DrawCircleFilled(pPos, 32.f, pColor, 15);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-17 16:47:19 +01:00
|
|
|
int main(int argc, char** argv) {
|
2026-03-22 21:50:53 +01:00
|
|
|
// PD::LogFilter(PD::LogLevel::Warning);
|
2026-03-17 16:47:19 +01:00
|
|
|
Driver drv = Driver::OpenGL3;
|
|
|
|
|
if (argc == 2) {
|
|
|
|
|
if (std::string(argv[1]) == "gl2") {
|
|
|
|
|
drv = Driver::OpenGL2;
|
|
|
|
|
} else if (std::string(argv[1]) == "gl3") {
|
|
|
|
|
drv = Driver::OpenGL3;
|
|
|
|
|
} else if (std::string(argv[1]) == "dx9") {
|
|
|
|
|
drv = Driver::DirectX9;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-21 14:43:16 +01:00
|
|
|
#if defined(__SWITCH__)
|
|
|
|
|
pOs = new PD::HorizonNX(drv);
|
|
|
|
|
#elif defined(__3DS__)
|
|
|
|
|
pOs = new PD::HorizonCtr(drv);
|
|
|
|
|
#else
|
|
|
|
|
pOs = new PD::DesktopOS(drv);
|
|
|
|
|
#endif
|
|
|
|
|
pOs->Init();
|
|
|
|
|
PD::Gfx::Init();
|
|
|
|
|
PD::Li::Drawlist pList;
|
2026-03-21 15:52:09 +01:00
|
|
|
PD::Image img(ResourcePath("icon.png"));
|
|
|
|
|
auto pTex = PD::Gfx::LoadTexture(img, img.Width(), img.Height());
|
2026-03-22 21:50:53 +01:00
|
|
|
PD::Li::Font font;
|
2026-03-26 21:02:10 +01:00
|
|
|
font.LoadTTF(ResourcePath("default.ttf"), 64);
|
2026-03-22 21:50:53 +01:00
|
|
|
pList.SetFont(&font);
|
2026-04-03 12:43:49 +02:00
|
|
|
App app(font);
|
2026-04-09 21:51:38 +02:00
|
|
|
Cursor LeftStick;
|
|
|
|
|
Cursor RightStick;
|
|
|
|
|
RightStick.pColor = "#00ffff";
|
2026-03-21 14:43:16 +01:00
|
|
|
while (pOs->Mainloop()) {
|
2026-04-03 14:12:42 +02:00
|
|
|
PD::Hid::Update();
|
2026-03-21 14:43:16 +01:00
|
|
|
pOs->ClearViewPort();
|
2026-04-03 12:43:49 +02:00
|
|
|
PD::Li::ResetPools(); // Move to other place (or refactor this)
|
|
|
|
|
app.Update(pOs->GetViewport(), pList);
|
2026-04-09 21:51:38 +02:00
|
|
|
pList.SetFontscale(0.7);
|
|
|
|
|
if (PD::Hid::IsEvent(PD::Hid::Event::Down, PD::Hid::Gamepad::CPLeft |
|
|
|
|
|
PD::Hid::Gamepad::CPRight)) {
|
|
|
|
|
LeftStick.pPos.x += PD::Hid::GetLeftStick().x * 15;
|
|
|
|
|
}
|
|
|
|
|
if (PD::Hid::IsEvent(PD::Hid::Event::Down,
|
|
|
|
|
PD::Hid::Gamepad::CPUp | PD::Hid::Gamepad::CPDown)) {
|
|
|
|
|
LeftStick.pPos.y += PD::Hid::GetLeftStick().y * 15;
|
|
|
|
|
}
|
|
|
|
|
if (PD::Hid::IsEvent(PD::Hid::Event::Down, PD::Hid::Gamepad::CSLeft |
|
|
|
|
|
PD::Hid::Gamepad::CSRight)) {
|
|
|
|
|
RightStick.pPos.x += PD::Hid::GetRightStick().x * 15;
|
|
|
|
|
}
|
|
|
|
|
if (PD::Hid::IsEvent(PD::Hid::Event::Down,
|
|
|
|
|
PD::Hid::Gamepad::CSUp | PD::Hid::Gamepad::CSDown)) {
|
|
|
|
|
RightStick.pPos.y += PD::Hid::GetRightStick().y * 15;
|
|
|
|
|
}
|
2026-04-05 00:26:00 +02:00
|
|
|
pList.DrawText(
|
|
|
|
|
PD::fvec2(5, 37),
|
|
|
|
|
std::format(
|
|
|
|
|
"Input:\n Driver: {}\n Gamepad: {}\n {}\n {}\n "
|
|
|
|
|
"{}\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n "
|
2026-04-09 21:51:38 +02:00
|
|
|
"{}\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n "
|
2026-04-05 00:26:00 +02:00
|
|
|
"{}\n {}\n "
|
2026-04-09 21:51:38 +02:00
|
|
|
"{}\n {}\n LS: [{}]\n RS: [{}]\nLSP: {}",
|
2026-04-05 00:26:00 +02:00
|
|
|
PD::Hid::GetDriverName(),
|
|
|
|
|
bool(PD::Hid::GetFlags() & PDHidBackendFlags_HasGamepad),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::Start),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::Select),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::A), ComboGpOut(PD::Hid::Gamepad::B),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::X), ComboGpOut(PD::Hid::Gamepad::Y),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::DDown),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::DUp),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::DLeft),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::DRight),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::L), ComboGpOut(PD::Hid::Gamepad::R),
|
2026-04-09 21:51:38 +02:00
|
|
|
ComboGpOut(PD::Hid::Gamepad::ZL), ComboGpOut(PD::Hid::Gamepad::ZR),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::CPLeft),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::CPRight),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::CPUp),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::CPDown),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::CSLeft),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::CSRight),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::CSUp),
|
|
|
|
|
ComboGpOut(PD::Hid::Gamepad::CSDown), PD::Hid::GetLeftStick(),
|
|
|
|
|
PD::Hid::GetRightStick(), LeftStick.pPos)
|
2026-04-05 00:26:00 +02:00
|
|
|
.c_str(),
|
|
|
|
|
"#ffffff");
|
2026-04-09 21:51:38 +02:00
|
|
|
LeftStick.Render(pList);
|
|
|
|
|
RightStick.Render(pList);
|
2026-04-18 14:33:31 +02:00
|
|
|
pList.UnbindTexture();
|
|
|
|
|
pList.PathRect(50, PD::fvec2(450, 240));
|
|
|
|
|
pList.PathFillGradient("#ff0000", "#990000", PD::Radians(135));
|
|
|
|
|
pList.PathAdd(PD::fvec2(100, 120));
|
|
|
|
|
pList.PathAdd(PD::fvec2(250, 260));
|
|
|
|
|
pList.PathAdd(PD::fvec2(420, 180));
|
|
|
|
|
pList.PathAdd(PD::fvec2(600, 320));
|
|
|
|
|
pList.PathAdd(PD::fvec2(820, 220));
|
|
|
|
|
pList.PathAdd(PD::fvec2(1000, 360));
|
|
|
|
|
|
|
|
|
|
pList.PathStroke("#ff00ff", 10, LiDrawFlags_AA);
|
2026-03-21 14:43:16 +01:00
|
|
|
PD::Gfx::Reset();
|
|
|
|
|
PD::Gfx::Draw(pList);
|
|
|
|
|
pList.Clear();
|
|
|
|
|
pOs->SwapBuffers();
|
|
|
|
|
}
|
2026-03-26 21:02:10 +01:00
|
|
|
font.Delete();
|
2026-03-21 15:52:09 +01:00
|
|
|
PD::Gfx::DeleteTexture(pTex);
|
2026-03-21 14:43:16 +01:00
|
|
|
PD::Gfx::Deinit();
|
|
|
|
|
pOs->Deinit();
|
|
|
|
|
delete pOs;
|
2026-03-16 17:33:46 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|