2025-01-09 20:22:49 +01:00
|
|
|
/*
|
|
|
|
MIT License
|
|
|
|
Copyright (c) 2024 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <3ds.h>
|
|
|
|
|
|
|
|
#include <ctime>
|
|
|
|
#include <pd.hpp>
|
2025-01-19 20:16:43 +01:00
|
|
|
#include <pd/maths/tween.hpp>
|
2025-01-09 20:22:49 +01:00
|
|
|
|
|
|
|
class Test : public PD::App {
|
|
|
|
public:
|
|
|
|
Test() = default;
|
|
|
|
~Test() = default;
|
|
|
|
|
|
|
|
void Init() override {
|
2025-01-29 03:14:29 +01:00
|
|
|
ren = Renderer();
|
|
|
|
inp = Input();
|
2025-01-09 20:22:49 +01:00
|
|
|
test = PD::Texture::New("romfs:/icon.png");
|
2025-01-29 03:14:29 +01:00
|
|
|
// Performance Overlay freezes N3DS
|
|
|
|
// Overlays()->Push(PD::New<PD::Performance>(dbg, dbg_screen));
|
2025-01-19 20:16:43 +01:00
|
|
|
font = PD::LI::Font::New();
|
2025-01-29 03:14:29 +01:00
|
|
|
// font->LoadTTF("romfs:/fonts/ComicNeue.ttf", 32);
|
|
|
|
font->LoadTTF("romfs:/fonts/JetBrainsMono-Medium.ttf", 32);
|
|
|
|
ren->Font(font);
|
|
|
|
ui7 = PD::UI7::Context::New(ren, inp);
|
2025-01-09 20:22:49 +01:00
|
|
|
}
|
|
|
|
|
2025-01-19 20:16:43 +01:00
|
|
|
bool MainLoop(float delta, float time) override {
|
2025-01-09 20:22:49 +01:00
|
|
|
DrawFancyBG(time);
|
2025-01-29 03:14:29 +01:00
|
|
|
ren->OnScreen(PD::Screen::Bottom);
|
|
|
|
// ren->DrawRectSolid(0, vec2(320, 240), PD::Color("#222222"));
|
|
|
|
// ren->Layer(ren->Layer() + 1);
|
|
|
|
// ren->DrawImage(ren->GetViewport().zw() * 0.5 - test->GetSize() * 0.5,
|
|
|
|
// test); ren->DrawText(5, 0xffffffff, "Hello World!", LITextFlags_None);
|
|
|
|
if (ui7->BeginMenu("Test",
|
|
|
|
UI7MenuFlags_Scrolling | UI7MenuFlags_CenterTitle)) {
|
|
|
|
auto m = ui7->GetCurrentMenu();
|
|
|
|
m->SeparatorText("Menu Timings");
|
|
|
|
m->DebugLabels();
|
|
|
|
m->SeparatorText("Lithium Settings");
|
|
|
|
FlagBox(m, "LI AST", PD::LI::RenderFlags_AST);
|
|
|
|
FlagBox(m, "LI LRS", PD::LI::RenderFlags_LRS);
|
|
|
|
FlagBox(m, "LI TMS", PD::LI::RenderFlags_TMS);
|
|
|
|
m->SeparatorText("UI7 Tests");
|
|
|
|
m->Label("This seems to be a label");
|
|
|
|
m->Separator();
|
|
|
|
m->Button("Button?");
|
|
|
|
m->SeparatorText("SeparatorText");
|
|
|
|
m->Checkbox("Test", cbtest);
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
m->Label("Label: " + std::to_string(i));
|
|
|
|
}
|
|
|
|
ui7->EndMenu();
|
|
|
|
}
|
|
|
|
ui7->Update(delta);
|
|
|
|
if (inp->IsDown(PD::Hid::Start)) {
|
2025-01-09 20:22:49 +01:00
|
|
|
return false;
|
|
|
|
}
|
2025-01-29 03:14:29 +01:00
|
|
|
if (inp->IsDown(inp->A)) {
|
2025-01-19 20:16:43 +01:00
|
|
|
Overlays()->Push(PD::New<PD::Performance>(dbg, dbg_screen));
|
|
|
|
Messages()->Push("Test", "Oder SO");
|
|
|
|
}
|
2025-01-29 03:14:29 +01:00
|
|
|
if (inp->IsUp(inp->B)) {
|
2025-01-19 20:16:43 +01:00
|
|
|
Overlays()->Push(PD::New<PD::Keyboard>(text, state));
|
|
|
|
}
|
2025-01-09 20:22:49 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Deinit() override {}
|
|
|
|
|
2025-01-29 03:14:29 +01:00
|
|
|
void FlagBox(PD::UI7::Menu::Ref m, const std::string& label,
|
|
|
|
PD::LI::RenderFlags flag) {
|
|
|
|
bool has_flag = ren->GetFlags() & flag;
|
|
|
|
m->Checkbox(label, has_flag);
|
|
|
|
if (has_flag != (ren->GetFlags() & flag)) {
|
|
|
|
if (has_flag) {
|
|
|
|
ren->GetFlags() |= flag;
|
|
|
|
} else {
|
|
|
|
ren->GetFlags() &= ~flag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-09 20:22:49 +01:00
|
|
|
void DrawFancyBG(float time) {
|
2025-01-29 03:14:29 +01:00
|
|
|
ren->DrawRect(vec2(0, 0), vec2(400, 240), 0xff64c9fd);
|
2025-01-09 20:22:49 +01:00
|
|
|
for (int i = 0; i < 44; i++) Append(i, vec2(0, 0), vec2(400, 240), time);
|
|
|
|
}
|
|
|
|
|
|
|
|
float Offset(float x) {
|
|
|
|
float y = cos(x) * 42;
|
|
|
|
return y - floor(y);
|
|
|
|
}
|
|
|
|
void Append(int index, vec2 position, vec2 size, float time) {
|
|
|
|
float offset = Offset(index) * 62;
|
|
|
|
float x_position = position.x() + size.x() / 8 * ((index % 11) - 1) +
|
|
|
|
cos(offset + time) * 10;
|
|
|
|
float y_position = position.y() + size.y() / 8 * (index / 11) + 40 +
|
|
|
|
sin(offset + time) * 10 + 30;
|
|
|
|
float color_effect = 1 - exp(-(index / 11) / 3.0f);
|
|
|
|
|
2025-01-29 03:14:29 +01:00
|
|
|
ren->DrawTriangle(
|
2025-01-09 20:22:49 +01:00
|
|
|
vec2(x_position, y_position), vec2(x_position + 300, y_position + (90)),
|
|
|
|
vec2(x_position - 300, y_position + (90)),
|
|
|
|
PD::Color(.94f - .17f * color_effect, .61f - .25f * color_effect,
|
|
|
|
.36f + .38f * color_effect));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2025-01-29 03:14:29 +01:00
|
|
|
/// Shorter Acess to Renderer / Input
|
|
|
|
PD::LI::Renderer::Ref ren;
|
|
|
|
PD::Hid::Ref inp;
|
|
|
|
/// Other Data
|
2025-01-09 20:22:49 +01:00
|
|
|
PD::Texture::Ref test;
|
2025-01-19 20:16:43 +01:00
|
|
|
bool dbg = false, dbg_screen = false;
|
2025-01-29 03:14:29 +01:00
|
|
|
bool cbtest = true;
|
2025-01-19 20:16:43 +01:00
|
|
|
std::string text;
|
|
|
|
PD::Keyboard::State state;
|
|
|
|
PD::UI7::Context::Ref ui7;
|
|
|
|
PD::LI::Font::Ref font;
|
2025-01-22 09:22:03 +01:00
|
|
|
vec2 text_pos;
|
2025-01-09 20:22:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
2025-01-29 03:14:29 +01:00
|
|
|
Test app;
|
|
|
|
app.Run();
|
2025-01-09 20:22:49 +01:00
|
|
|
return 0;
|
|
|
|
}
|