#include #include #include #include #include #include //// #include #include #include #include #include #include //// PD::OsCtx* pOs = nullptr; 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; #else return in; #endif } 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"; } 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"; } 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; } class MainMenu : public PD::Ultra::Layout { public: MainMenu(PD::Li::Font& font) { SetFont(font); SetBaseViewport(PD::ivec2(1280, 720)); pBackground.SetSize(800, 450); pBackground.SetColor("#ffffffff"); pBackground.SetAlignment(UltraAlignment_Center); Push(pBackground); pText.SetColor("#ffffff"); pText.SetText("MousePos: "); pText.SetAlignment(UltraAlignment_TopRight); Push(pText); 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); } ~MainMenu() {} void Update() { pText.SetText(std::format("MousePos: {}", PD::Hid::MousePos())); } private: PD::Ultra::Rect pBackground; PD::Ultra::Text pText; PD::Ultra::Button pBtn; }; class App { public: App(PD::Li::Font& font) : main(font) {} ~App() {} void Update(PD::ivec2 vp, PD::Li::Drawlist& list) { main.Update(); main.SetViewport(vp); main.Render(list); } private: MainMenu main; }; 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); } }; int main(int argc, char** argv) { // PD::LogFilter(PD::LogLevel::Warning); #ifdef __APPLE__ Driver drv = Driver::OpenGL2; // default gl2 #else Driver drv = Driver::OpenGL3; #endif 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; } } #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; PD::Image img(ResourcePath("icon.png")); auto pTex = PD::Gfx::LoadTexture(img, img.Width(), img.Height()); PD::Li::Font font; PD::Li::Font debug_font; font.LoadTTF(ResourcePath("default.ttf"), 32, LiFontFlags_SDF); debug_font.LoadTTF(ResourcePath("JetBrainsMono-Medium.ttf"), 32, LiFontFlags_SDF | LiFontFlags_Monospace); pList.SetFont(&font); App app(font); Cursor LeftStick; Cursor RightStick; RightStick.pColor = "#00ffff"; PD::UI7::Context ui7; ui7.GetIO().Font = &font; #ifdef __3DS__ ui7.AddViewPort("Default", PD::ivec4(0, 0, 320, 240)); ui7.GetIO().FontScale = 0.5f; #else ui7.AddViewPort("Default", PD::ivec4(0, 0, 1280, 720)); #endif ui7.UseViewPort("Default"); bool pMetricsWin = true; while (pOs->Mainloop()) { PD::TT::End("OSCTX::MainLoop"); pOs->DrawOnScreen(0); pOs->ClearViewPort(); PD::TT::Scope __st("MainLoop"); PD::TT::Beg("MainRaw"); PD::Hid::Update(); PD::Gfx::NewFrame(); PD::Li::ResetPools(); // app.Update(pOs->GetViewport(), pList); 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; } /*pList.DrawText( PD::fvec2(5, 37), std::format( "Input:\n Driver: {}\n Gamepad: {}\n {}\n {}\n " "{}\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n " "{}\n {}\n {}\n {}\n {}\n {}\n {}\n {}\n " "{}\n {}\n " "{}\n {}\n LS: [{}]\n RS: [{}]\nLSP: {}", 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), 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) .c_str(), "#ffffff");*/ // LeftStick.Render(pList); // RightStick.Render(pList); 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);*/ pList.SetFontscale(std::sin(PD::Os::GetTime() * 0.001f) * 1.85f + 2.15f); pList.DrawText(PD::fvec2(5, 130), "Some text...", "#fff00fff"); #ifdef __3DS__ pList.SetFontscale(0.4); #else pList.SetFontscale(0.6f); #endif pList.SetFont(&debug_font); int __i = 0; for (auto& it : PD::TT::GetTraceMap()) { pList.DrawText( PD::fvec2(2, 2 + (__i++) * 17), std::format("{}: {}", it.second.GetID(), PD::Strings::FormatNanos(it.second.GetLastDiff())) .c_str(), "#ff00ff"); } pList.SetFont(&font); PD::TT::Beg("BuildUI7Menus"); if (auto m = ui7.BeginMenu("Test")) { m->Label("Hello World!"); ui7.EndMenu(); } if (auto m = ui7.BeginMenu("LI DBG INFO")) { m->PushFont(&debug_font); m->Label("Gfx Driver: {}", PD::Gfx::GetDriverName()); m->Separator(); m->Label("LI Draw Comamnds: {}", PD::Gfx::GetNumCommands()); m->Label("GFX Draw Calls: {}", PD::Gfx::GetNumDrawcalls()); m->Label("GFX Vertices: {}", PD::Gfx::GetNumVertices()); m->Label("GFX Triangles: {}", PD::Gfx::GetNumVertices() / 3); m->Label("GFX Indices: {}", PD::Gfx::GetNumIndices()); m->PopFont(); ui7.EndMenu(); } ui7.MetricsMenu(&pMetricsWin); ui7.StyleEditor(); PD::TT::End("BuildUI7Menus"); PD::TT::Beg("UI7::Context::Update"); ui7.Update(); PD::TT::End("UI7::Context::Update"); PD::Gfx::Reset(); PD::TT::Beg("PD::Gfx::Draw"); pOs->DrawOnScreen(1); pOs->ClearViewPort(); PD::Gfx::Draw(ui7.GetDrawData()); pOs->DrawOnScreen(0); PD::Gfx::Draw(pList); PD::TT::End("PD::Gfx::Draw"); pList.Clear(); PD::TT::End("MainRaw"); pOs->SwapBuffers(); PD::TT::Beg("OSCTX::MainLoop"); } font.Delete(); debug_font.Delete(); PD::Gfx::DeleteTexture(pTex); PD::Gfx::Deinit(); pOs->Deinit(); delete pOs; return 0; }