Initial Cross Platform Work

This commit is contained in:
2025-04-24 16:39:24 +02:00
parent dbffb7f316
commit 13c2869ba8
170 changed files with 18611 additions and 10292 deletions

30
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.22)
project(test)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED true)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_INSTALL_BINDIR ".")
add_subdirectory(.. palladium)
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
add_subdirectory(../backends/desktop backend-desktop)
else()
add_subdirectory(../backends/3ds backend-3ds)
endif()
add_executable(test source/main.cpp
${BKND_SRC})
target_include_directories(test PUBLIC ../backends)
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
target_link_libraries(test PUBLIC pd-backend-desktop glad glfw)
install(TARGETS test RUNTIME DESTINATION ".")
set(RC_FILES
testassets/ComicNeue.ttf
testassets/logo.png
testassets/test.png)
install(FILES ${RC_FILES} DESTINATION ".")
else()
target_link_libraries(test PUBLIC pd-backend-3ds ctru citro3d)
endif()

View File

@ -1,151 +0,0 @@
/*
MIT License
Copyright (c) 2024 - 2025 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>
class Test : public PD::App {
public:
Test() {
/*
Here can be things modified befor Init anything
cause This place gets called befor Internal Init
*/
}
~Test() = default;
void Init() override {
ren = Renderer();
inp = Input();
test = PD::Texture::New("romfs:/icon.png");
// Performance Overlay freezes N3DS
// Overlays()->Push(PD::New<PD::Performance>(dbg, dbg_screen));
font = PD::LI::Font::New();
// 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);
}
bool MainLoop(float delta, float time) override {
ren->OnScreen(Top);
DrawFancyBG(time);
ren->OnScreen(Bottom);
if (ui7->BeginMenu("Test",
UI7MenuFlags_Scrolling | UI7MenuFlags_CenterTitle)) {
auto m = ui7->GetCurrentMenu();
m->SeparatorText("Menu Timings");
PD::UI7::Menu::DebugLabels(m);
m->SeparatorText("Palladium Info");
m->PushAlignment(UI7Align_Center);
m->Label("Version: " + PD::LibInfo::Version() + " [" +
PD::LibInfo::Commit() + "]");
m->Label("CompileInfo: " + PD::LibInfo::CompiledWith() + " - " +
PD::LibInfo::CxxVersion());
m->Label("Build at " + PD::LibInfo::BuildTime());
m->SeparatorText("Basic Info");
m->Label("sizeof(size_t): " + std::to_string(sizeof(size_t)) + " -> " +
std::to_string(sizeof(size_t) * 8) + "Bit");
m->Label("__cplusplus=" + std::to_string(__cplusplus));
m->Label(PD::Strings::GetCompilerVersion());
m->Label("sizeof(LI::Vertex): " + std::to_string(sizeof(PD::LI::Vertex)));
m->Label("sizeof(PD::u16): " + std::to_string(sizeof(PD::u16)));
m->PopAlignment();
m->SeparatorText("UI7 Tests");
m->Label("This seems to be a label");
m->Image(test);
m->Separator();
if (m->Button("Button?")) {
Messages()->Push("Button", "Pressed...");
}
m->SameLine();
if (m->Button("Palladium")) {
// sthis->FeatureDisable(AppFLags_UserLoop);
Overlays()->Push(PD::New<PD::SettingsMenu>());
}
m->SeparatorText("SeparatorText");
m->Checkbox("Test", cbtest);
ui7->EndMenu();
}
ui7->Update(delta);
if (inp->IsDown(PD::Hid::Start)) {
return false;
}
if (inp->IsDown(inp->A)) {
Overlays()->Push(PD::New<PD::Performance>(dbg, dbg_screen));
Messages()->Push("Test", "Oder SO");
}
if (inp->IsUp(inp->B)) {
Overlays()->Push(PD::New<PD::Keyboard>(text, state));
}
return true;
}
void Deinit() override {}
void DrawFancyBG(float time) {
ren->DrawRect(vec2(0, 0), vec2(400, 240), 0xff64c9fd);
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);
ren->DrawTriangle(
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:
/// Shorter Acess to Renderer / Input
PD::LI::Renderer::Ref ren;
PD::Hid::Ref inp;
/// Other Data
PD::Texture::Ref test;
bool dbg = false, dbg_screen = false;
bool cbtest = true;
std::string text;
PD::Keyboard::State state;
PD::UI7::Context::Ref ui7;
PD::LI::Font::Ref font;
vec2 text_pos;
};
int main() {
Test app;
app.Run();
return 0;
}

View File

@ -1,205 +0,0 @@
/*
MIT License
Copyright (c) 2024 - 2025 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 <pd.hpp>
struct StatsRes {
std::string name;
std::string average;
std::string min;
std::string max;
};
class TestBench : public PD::App {
public:
TestBench() = default;
~TestBench() = default;
void Init() override {
/// Test in OLD3DS Mode
osSetSpeedupEnable(false);
PD::TT::Beg("BaseInit");
inp = Input();
ren = Renderer();
font = PD::LI::Font::New();
font->LoadTTF("romfs:/fonts/JetBrainsMono-Medium.ttf", 32);
ren->Font(font);
ui7 = PD::UI7::Context::New(ren, inp);
/// Maximum frames for 5 seconds
li_stats = PD::TimeStats::New(300);
PD::TT::End("BaseInit");
}
bool MainLoop(float delta, float time) {
if (stime == 0.f) {
stime = time;
}
switch (test) {
case 0:
Test1(time);
break;
case 1:
Test2(delta, time);
break;
default:
Result(delta);
}
if (time - stime > 5.f && test < 2) {
if (test == 0) {
results.push_back(std::make_pair<std::string, std::vector<StatsRes>>(
std::to_string(test + 1),
{MakeRes("LI", li_stats),
MakeRes("Scene1", PD::Sys::GetTraceRef("Test1")->GetProtocol())}));
} else if (test == 1) {
results.push_back(std::make_pair<std::string, std::vector<StatsRes>>(
std::to_string(test + 1),
{MakeRes("LI", li_stats),
MakeRes("Scene2", PD::Sys::GetTraceRef("Test2")->GetProtocol())}));
} else {
results.push_back(std::make_pair<std::string, std::vector<StatsRes>>(
std::to_string(test + 1), {MakeRes("LI", li_stats)}));
}
test++;
stime = time;
frame = 0;
li_stats->Clear();
}
frame++;
return true;
}
StatsRes MakeRes(const std::string& name, PD::TimeStats::Ref s) {
StatsRes res;
res.name = name;
res.average = PD::Strings::FormatNanos(s->GetAverage());
res.min = PD::Strings::FormatNanos(s->GetMin());
res.max = PD::Strings::FormatNanos(s->GetMax());
return res;
}
void Result(float delta) {
UpdateLiTimes();
ren->OnScreen(Top);
if (ui7->BeginMenu("TestBench")) {
auto m = ui7->GetCurrentMenu();
m->Label("Base Init: " + TTime("BaseInit"));
m->Label("Render All: " +
PD::Strings::FormatNanos(li_stats->GetAverage()));
ui7->EndMenu();
}
ren->OnScreen(Bottom);
if (ui7->BeginMenu("Test Results", UI7MenuFlags_Scrolling)) {
auto m = ui7->GetCurrentMenu();
for (auto& it : results) {
m->SeparatorText("Test " + it.first);
for (int i = 0; i < (int)it.second.size(); i++) {
m->Label(it.second[i].name + ":");
m->Label("AVG: " + it.second[i].average);
m->Label("MIN: " + it.second[i].min);
m->Label("MAX: " + it.second[i].max);
if (i != (int)it.second.size() - 1) {
m->Separator();
}
}
}
ui7->EndMenu();
}
ui7->Update(delta);
}
void Test1(float time) {
PD::TT::Scope st("Test1");
UpdateLiTimes();
DrawFancyBG(time);
}
void Test2(float delta, float time) {
PD::TT::Scope st("Test2");
UpdateLiTimes();
DrawFancyBG(time);
if (ui7->BeginMenu("Test2")) {
auto m = ui7->GetCurrentMenu();
m->Label("Text1");
m->Label("Text2");
m->Button("Test");
m->SameLine();
m->Button("Test2");
m->Separator();
m->Label("Line1");
m->Label("Line2");
ui7->EndMenu();
}
ui7->Update(delta);
}
void DrawFancyBG(float time) {
ren->DrawRect(vec2(0, 0), vec2(400, 240), 0xff64c9fd);
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);
ren->DrawTriangle(
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));
}
std::string TTime(const std::string& id) {
return PD::Strings::FormatNanos(PD::Sys::GetTraceRef(id)->GetLastDiff());
}
void UpdateLiTimes() {
if (frame) {
li_stats->Add(PD::Sys::GetTraceRef("LI_RenderAll")->GetLastDiff());
}
}
private:
PD::Hid::Ref inp;
PD::LI::Renderer::Ref ren;
PD::UI7::Context::Ref ui7;
PD::LI::Font::Ref font;
PD::TimeStats::Ref li_stats;
int test = 0;
float stime = 0.f;
std::vector<std::pair<std::string, std::vector<StatsRes>>> results;
int frame = 0;
};
int main() {
TestBench app;
app.Run();
return 0;
}

View File

@ -1,93 +0,0 @@
Copyright 2014 The Comic Neue Project Authors (https://github.com/crozynski/comicneue)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View File

@ -1,93 +0,0 @@
Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
https://openfontlicense.org
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 844 B

View File

@ -1,9 +0,0 @@
{
"ver": 0,
"id": "de",
"name": "Deutsch",
"author": "tobid7",
"keys": {
"TEST": "Test"
}
}

658
test/source/main.cpp Normal file
View File

@ -0,0 +1,658 @@
#include <pd.hpp>
PD::Net::Backend::Ref net_backend;
PD::LI::Backend::Ref backend;
PD::Hid::Ref inp;
#ifdef __3DS__
#include <3ds.h>
#include <li_backend_c3d.hpp>
#include <pd_hid_3ds.hpp>
#include <pd_net_3ds.hpp>
const u32 DisplayTransferFlags =
(GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) |
GX_TRANSFER_RAW_COPY(0) | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) |
GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) |
GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO));
#else
#include <li_backend_gl2.hpp>
#include <pd_hid_glfw.hpp>
#include <pd_net_desktop.hpp>
bool vs = true;
void WindowIcn(GLFWwindow* win, const std::string& path) {
auto img = PD::Image::New(path);
if (img->Fmt() == img->RGB) {
PD::Image::Convert(img, img->RGBA);
}
GLFWimage* i = new GLFWimage;
i->pixels = new unsigned char[img->GetBuffer().size()];
/** Use std::copy_n instead of memcpy (Weil nicht rot unterstrichen) */
std::copy_n(img->GetBuffer().data(), img->GetBuffer().size(), i->pixels);
i->width = img->Width();
i->height = img->Height();
glfwSetWindowIcon(win, 1, i);
}
#endif
class FileBrowserOderSo {
public:
struct Entry {
std::string Name;
std::string Path;
bool Directory;
std::shared_ptr<std::vector<Entry>> DirContent;
};
FileBrowserOderSo() { Listing = ParseDir(CurrentPath); }
~FileBrowserOderSo() = default;
std::vector<Entry> ParseDir(const std::string& path) {
std::vector<Entry> res;
try {
for (auto& it : std::filesystem::directory_iterator(path)) {
res.push_back({it.path().filename().string(), it.path().string(),
it.is_directory()});
}
} catch (const std::filesystem::filesystem_error& e) {
// Actually just keeping the App alive
}
return res;
}
/** Recursive Continue Tree View Generation */
void RCTVG(PD::UI7::Menu::Ref m, std::vector<Entry>& listing,
const std::string& cp) {
if (m->BeginTreeNode(cp)) {
for (auto& it : listing) {
if (it.Directory) {
if (!it.DirContent) {
it.DirContent = std::make_shared<std::vector<Entry>>();
*it.DirContent = ParseDir(it.Path);
}
RCTVG(m, *it.DirContent, it.Name);
} else {
m->Label(it.Name);
}
}
m->EndTreeNode();
}
}
void UI_Handle(PD::UI7::Context::Ref ui7) {
if (ui7->BeginMenu("FileBrowser", UI7MenuFlags_Scrolling)) {
auto m = ui7->GetCurrentMenu();
RCTVG(m, Listing, CurrentPath);
ui7->EndMenu();
}
}
std::string CurrentPath = "/";
std::vector<Entry> Listing;
};
#include <mutex>
#include <thread>
const int PORT = 8080;
const size_t MAX_LOGS = 100;
bool skill_thread = false;
std::mutex logMutex;
std::mutex coutCaptureMutex;
std::deque<std::string> logBuffer;
std::ostringstream capturedOutput;
class CoutRedirector : public std::streambuf {
public:
CoutRedirector(std::streambuf* original) : originalBuf(original) {}
protected:
int overflow(int c) override {
if (c != EOF) {
std::lock_guard<std::mutex> lock(coutCaptureMutex); // separate mutex
capturedOutput.put(c);
if (c == '\n') {
logBuffer.push_back(capturedOutput.str());
capturedOutput.str("");
capturedOutput.clear();
}
}
return originalBuf->sputc(c); // still forward to original
}
private:
std::streambuf* originalBuf;
};
CoutRedirector* redirector = nullptr;
void startCoutCapture() {
static std::streambuf* originalCoutBuffer = std::cout.rdbuf();
redirector = new CoutRedirector(originalCoutBuffer);
std::cout.rdbuf(redirector);
}
void logMessage(const std::string& msg) {
std::lock_guard<std::mutex> lock(logMutex);
if (logBuffer.size() >= MAX_LOGS) logBuffer.pop_front();
logBuffer.push_back(msg);
std::cout << msg << std::endl;
}
const char* css_file = R"(
html, body {
font-family: 'Montserrat', sans-serif;
background-color: #1e1e1e;
color: #e0e0e0;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
body {
display: flex;
flex-direction: column;
min-height: 100vh;
box-sizing: border-box;
}
main {
flex: 1;
padding: 2rem;
box-sizing: border-box;
}
h2 {
margin-bottom: 1rem;
}
pre {
background-color: #2e2e2e;
padding: 1rem;
border-radius: 8px;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
margin-bottom: 20px;
}
footer {
background-color: #333;
color: #e0e0e0;
padding: 1rem;
text-align: center;
width: 100%;
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.3);
}
img {
border-radius: 50%;
}
a {
color: #3498db;
text-decoration: none;
font-weight: bold;
}
a:hover {
text-decoration: underline;
}
footer a {
color: #3498db;
text-decoration: none;
font-weight: bold;
}
footer a:hover {
text-decoration: underline;
}
)";
const char* html_begin = R"(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTTP Server</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/style.css">
</head>
)";
const char* html_404 = R"(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="5">
<title>404 Not Found</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/style.css">
</head>
<body>
<img src="/assets/icon.png" width="100">
<h2>404 Page not found!</h2>
<a href="/">Return to main Page</a>
</body>
</html>
)";
const char* html_end = "<footer>2025 tobid7</footer></body></html>";
std::string getLogs() {
std::lock_guard<std::mutex> lock(logMutex);
std::ostringstream oss;
for (const auto& line : logBuffer) oss << line;
return oss.str();
}
std::string getIndexHTML() {
std::lock_guard<std::mutex> lock(logMutex);
std::ostringstream oss;
oss << html_begin;
oss << "<body><main><h1>Welcome</h1><ul><li><a href=\"/logs\">View "
"Logs</a></li><li><a href=\"/sysinfo\">System "
"Info</a></li></ul></main>";
oss << html_end;
return oss.str();
}
std::string getSystemInfo() {
std::ostringstream oss;
oss << "Compiler -> " << PD::Strings::GetCompilerVersion() << std::endl;
oss << "Lithium -> " << backend->pName << std::endl;
oss << "Input Driver -> " << inp->pName << std::endl;
oss << "Network Driver -> " << net_backend->pName << std::endl;
oss << "Lithium:" << std::endl;
oss << " Vertices: " << backend->VertexCounter << std::endl;
oss << " Indices: " << backend->IndexCounter << std::endl;
oss << " Triangles: " << backend->IndexCounter / 3 << std::endl;
#ifdef __3DS__
oss << "Section 3DS" << std::endl;
oss << " linear_mem: " << PD::Strings::FormatBytes(linearSpaceFree())
<< std::endl;
#endif
return oss.str();
}
void handleClient(PD::Net::Socket::Ref client) {
std::string buf;
int len = client->Receive(buf, 4096);
if (len > 0) {
buf[len] = '\0';
if (buf.find("GET / ") == 0 || buf.find("GET /HTTP") == 0 ||
buf.find("GET / HTTP") == 0) {
std::string body = getIndexHTML();
std::ostringstream response;
response << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: text/html\r\n"
<< "Content-Length: " << body.size() << "\r\n"
<< "Connection: close\r\n\r\n"
<< body;
client->Send(response.str());
} else if (buf.find("GET /logs") == 0) {
std::ostringstream body;
body << html_begin;
body << R"(
<body>
<main>
<h2>Logs</h2>
<pre id="logs">Fetching logs...</pre>
<script>
// Simply fetch a string by using an api endpoint
async function fetchLogs() {
const res = await fetch('/logdata');
const text = await res.text();
document.getElementById('logs').innerText = text;
}
setInterval(fetchLogs, 2000);
fetchLogs();
</script>
</main>
)";
body << html_end;
std::ostringstream response;
response << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: text/html\r\n"
<< "Content-Length: " << body.str().size() << "\r\n"
<< "Connection: close\r\n\r\n"
<< body.str();
client->Send(response.str());
} else if (buf.find("GET /sysinfo ") == 0) {
std::ostringstream body;
body << html_begin;
body << R"(
<body>
<main>
<h2>System Info</h2>
<pre id="sysinfo">Loading...</pre>
<script>
// Simply fetch a string by using an api endpoint
async function fetchSysInfo() {
const res = await fetch('/sysinfo/data');
const text = await res.text();
document.getElementById('sysinfo').innerText = text;
}
setInterval(fetchSysInfo, 2000);
fetchSysInfo();
</script>
</main>
)";
body << html_end;
std::ostringstream response;
response << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: text/html\r\n"
<< "Content-Length: " << body.str().size() << "\r\n"
<< "Connection: close\r\n\r\n"
<< body.str();
client->Send(response.str());
} else if (buf.find("GET /sysinfo/data") == 0) {
std::string body = getSystemInfo();
std::ostringstream response;
response << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: text/plain\r\n"
<< "Content-Length: " << body.size() << "\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Connection: close\r\n\r\n"
<< body;
client->Send(response.str());
} else if (buf.find("GET /logdata") == 0) {
std::string body = getLogs();
std::ostringstream response;
response << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: text/plain\r\n"
<< "Content-Length: " << body.size() << "\r\n"
<< "Cache-Control: no-cache\r\n"
<< "Connection: close\r\n\r\n"
<< body;
client->Send(response.str());
} else if (buf.find("GET /style.css") == 0) {
std::string body = css_file;
std::ostringstream response;
response << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: text/css\r\n"
<< "Content-Length: " << body.size() << "\r\n"
<< "Connection: close\r\n\r\n"
<< body;
client->Send(response.str());
} else if (buf.find("GET /assets/icon.png") == 0) {
std::ifstream f("test.png", std::ios::binary);
if (f) {
std::ostringstream body_stream;
body_stream << f.rdbuf();
std::string body = body_stream.str();
std::ostringstream header;
header << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: image/png\r\n"
<< "Content-Length: " << body.size() << "\r\n"
<< "Connection: close\r\n\r\n";
client->Send(header.str());
client->Send(body);
} else {
client->Send("HTTP/1.1 404 Not Found\r\nConnection: close\r\n\r\n");
}
std::string body = css_file;
std::ostringstream response;
response << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: text/css\r\n"
<< "Content-Length: " << body.size() << "\r\n"
<< "Connection: close\r\n\r\n"
<< body;
client->Send(response.str());
} else {
std::string body = html_404;
std::ostringstream response;
response << "HTTP/1.1 200 OK\r\n"
<< "Content-Type: text/html\r\n"
<< "Content-Length: " << body.size() << "\r\n"
<< "Connection: close\r\n\r\n"
<< body;
client->Send(response.str());
}
}
client->Close();
}
void startServer() {
auto server = PD::Net::Socket::New(net_backend, PORT);
server->Listen();
std::cout << "HTTP Logging Console running on http://localhost:" << PORT
<< "/logs\n";
while (!skill_thread) {
auto client = PD::Net::Socket::New(net_backend);
server->Accept(client);
std::thread(handleClient, client).detach();
}
}
class HttpServer {
public:
HttpServer(PD::Net::Backend::Ref backend) {}
void StartServer() {
auto server = PD::Net::Socket::New(pBackend, PORT);
server->Listen();
while (true) {
auto client = PD::Net::Socket::New(pBackend);
server->Accept(client);
}
}
PD::Net::Backend::Ref pBackend;
};
int main() {
bool m__ = false;
bool a__ = false;
bool s__ = false;
#ifdef __3DS__
net_backend = PD::NetBackend3DS::New();
net_backend->Init();
osSetSpeedupEnable(true);
gfxInitDefault();
cfguInit();
cfguExit();
// consoleInit(GFX_BOTTOM, nullptr);
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE * 2);
C3D_RenderTarget* Top =
C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTarget* Bottom =
C3D_RenderTargetCreate(240, 320, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
C3D_RenderTargetSetOutput(Top, GFX_TOP, GFX_LEFT, DisplayTransferFlags);
C3D_RenderTargetSetOutput(Bottom, GFX_BOTTOM, GFX_LEFT, DisplayTransferFlags);
backend = PD::LI::Backend_C3D::New();
inp = PD::Hid3DS::New();
#else
net_backend = PD::NetBackendDesktop::New();
net_backend->Init();
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
#ifdef __APPLE__
// Using This as frame buffer would be way too large
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, 0);
#endif
glfwWindowHint(GLFW_SAMPLES, 8); // Anti Aliasing
auto win = glfwCreateWindow(1280, 720, "Palladium", nullptr, nullptr);
glfwMakeContextCurrent(win);
glfwSwapInterval(1);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
std::cout << "OpenGL: " << GLVersion.major << "." << GLVersion.minor
<< std::endl;
if (!glCreateShader) {
std::cout << "glCreateShader wurde nicht gefunden oder so keine ahnung"
<< std::endl;
}
WindowIcn(win, "test.png");
backend = PD::LI::Backend_GL2::New();
inp = PD::HidGLFW::New(win);
#endif
startCoutCapture();
std::thread server_http(startServer);
server_http.detach();
#ifdef __3DS__
std::cout << "System freezed... Press A!" << std::endl;
while (aptMainLoop()) {
hidScanInput();
if (hidKeysDown() & KEY_A) {
break;
}
gspWaitForVBlank();
gfxSwapBuffers();
}
#endif
backend->Init();
auto font = PD::LI::Font::New(backend);
font->LoadTTF("ComicNeue.ttf", 32);
#ifdef __3DS__
font->DefaultPixelHeight = 24;
#else
font->DefaultPixelHeight = 32;
#endif
auto ren = PD::LI::Renderer::New(backend);
PD::Image img("test.png");
PD::Image img2("logo.png");
auto tex = backend->LoadTexture(
img, img.Width(), img.Height(),
img.Fmt() == img.RGBA ? PD::LI::Texture::RGBA32 : PD::LI::Texture::RGB24);
auto tex2 =
backend->LoadTexture(img2, img2.Width(), img2.Height(),
img2.Fmt() == img.RGBA ? PD::LI::Texture::RGBA32
: PD::LI::Texture::RGB24);
auto r = PD::LI::DrawList::New(ren->WhitePixel);
r->SetFont(font);
PD::UI7::Context::Ref ui7 = PD::UI7::Context::New(ren, inp);
ui7->GetIO()->Font = font;
FileBrowserOderSo fb;
#ifdef __3DS__
ui7->GetIO()->Theme->Set(UI7Color_Background, PD::Color("#222222aa"));
while (aptMainLoop()) {
backend->ViewPort = ivec2(320, 240);
#else
while (!glfwWindowShouldClose(win)) {
int wx, wy;
glfwGetWindowSize(win, &wx, &wy);
backend->ViewPort = ivec2(wx, wy);
#endif
inp->Update();
r->CurrentTex = ren->WhitePixel;
ren->CurrentTex = ren->WhitePixel;
ui7->DoMenuEx("TestInline", UI7MenuFlags_Scrolling,
[&](PD::UI7::ReMenu::Ref m) {
m->SeparatorText("Test");
m->Label("Test oder So");
static bool v;
static float v2;
m->Checkbox("Checkbox", v);
m->DragData("Test V2", &v2, 1);
m->Label("Test");
m->Separator();
if (m->Button("Hello1")) {
logMessage("Button Pressed");
}
m->Image(tex2);
});
/*if (ui7->BeginMenuEx("TestMenu")) {
auto m = ui7->GetCurrentMenuEx();
m->SeparatorText("Hello World!");
m->Separator();
ui7->EndMenuEx();
}*/
if (ui7->BeginMenu("Test")) {
auto m = ui7->GetCurrentMenu();
m->Button("Button");
m->Label("Label");
if (m->Button("Show Metrics")) {
m__ = true;
}
if (m->Button("Show About")) {
a__ = true;
}
if (m->Button("Show Style")) {
s__ = true;
}
m->PushAlignment(UI7Align_Mid);
m->SeparatorText("Extra");
m->PopAlignment();
m->DragData("FontScale", &font->DefaultPixelHeight);
#ifndef __3DS__
if (m->Button("Toggle VSYNC")) {
vs = !vs;
glfwSwapInterval(vs);
}
#endif
ui7->EndMenu();
}
// fb.UI_Handle(ui7);
ui7->StyleEditor(&s__);
ui7->AboutMenu(&a__);
ui7->MetricsMenu(&m__);
r->CurrentTex = tex;
r->DrawCircleFilled(
100, 24, 0xffffffff,
3 + int(((std::sin(ui7->GetIO()->Time->GetSeconds()) + 1) / 2) * 50));
ui7->Update(0);
// r->CurrentTex = smdhtex;
// r->DrawRectFilled(0, 48, 0xffffffff);
ren->RegisterDrawList(r);
#ifdef __3DS__
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C3D_FrameDrawOn(Top);
C3D_RenderTargetClear(Top, C3D_CLEAR_ALL, 0x00000000, 0);
auto l = PD::LI::DrawList::New(ren->WhitePixel);
l->DrawText(5, std::format("Tris: {}", ui7->GetIO()->NumIndices / 3),
0xffffffff);
ivec2 tvp = backend->ViewPort;
backend->ViewPort = ivec2(400, 240);
backend->NewFrame();
backend->RenderDrawData(l->pDrawList);
l->pDrawList.Clear();
backend->ViewPort = tvp;
C3D_FrameDrawOn(Bottom);
C3D_RenderTargetClear(Bottom, C3D_CLEAR_ALL, 0x00000000, 0);
PD::TT::Beg("R");
// backend->NewFrame();
backend->RenderDrawData(ui7->GetIO()->pRDL->pDrawList);
ui7->GetIO()->pRDL->pDrawList.Clear();
// ren->Render();
PD::TT::End("R");
C3D_FrameEnd(0);
#else
PD::TT::Beg("R");
ren->Render();
PD::TT::End("R");
glfwPollEvents();
glfwSwapBuffers(win);
#endif
}
backend->Deinit();
skill_thread = true;
if (server_http.joinable()) {
server_http.join();
}
net_backend->Deinit();
#ifdef __3DS__
C3D_Fini();
gfxExit();
#else
glfwTerminate();
#endif
return 0;
}

BIN
test/testassets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

BIN
test/testassets/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 KiB