# Rewrite 5
- Move Libraries Source into pd directory and give them all their own CMakeLists.txt - Partial rewrite core (color, autogenerated vec), lithium (now uses UNIQUE PTR for Commands), UI7 - Use MenuV2 as new standart in UI7 - Implementz ViewPort Pre alpha to UI7 - Add Line Drawing to DrawList (not Working) - Implement a Complete new drievrs API (static Drivers) - NO SUPPORT FOR SHARED LIBRARY BUILDS IN VERSION 5 YET - Add Tools to Autogenerate Headers and Stuff
This commit is contained in:
44
test/CMakeLists.txt
Normal file → Executable file
44
test/CMakeLists.txt
Normal file → Executable file
@ -5,26 +5,36 @@ project(test)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS true)
|
||||
|
||||
set(CMAKE_INSTALL_BINDIR ".")
|
||||
add_subdirectory(.. palladium)
|
||||
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
add_subdirectory(../backends/desktop backend-desktop)
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
if(${PD_BUILD_SHARED})
|
||||
message(ERROR "3DS Only supports Static libraries")
|
||||
endif()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-psabi -O2")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions")
|
||||
endif()
|
||||
|
||||
add_subdirectory(../ palladium)
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
add_subdirectory(../backends/3ds pd-3ds)
|
||||
else()
|
||||
add_subdirectory(../backends/3ds backend-3ds)
|
||||
add_subdirectory(../backends/desktop pd-desktop)
|
||||
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 ".")
|
||||
${BKND_SRC})
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Nintendo3DS")
|
||||
target_link_libraries(test PUBLIC pd-3ds palladium)
|
||||
else()
|
||||
target_link_libraries(test PUBLIC pd-backend-3ds ctru citro3d)
|
||||
endif()
|
||||
target_link_libraries(test PUBLIC pd-desktop palladium)
|
||||
endif()
|
||||
|
||||
#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()
|
725
test/source/main.cpp
Normal file → Executable file
725
test/source/main.cpp
Normal file → Executable file
@ -1,658 +1,149 @@
|
||||
#include <pd.hpp>
|
||||
|
||||
PD::Net::Backend::Ref net_backend;
|
||||
PD::LI::Backend::Ref backend;
|
||||
PD::Hid::Ref inp;
|
||||
|
||||
#include <palladium>
|
||||
#ifdef __3DS__
|
||||
#include <3ds.h>
|
||||
|
||||
#include <li_backend_c3d.hpp>
|
||||
#include <pd_hid_3ds.hpp>
|
||||
#include <pd_net_3ds.hpp>
|
||||
|
||||
#include <pd-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);
|
||||
}
|
||||
|
||||
#include <pd-desktop.hpp>
|
||||
#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 RoundedRect(PD::Li::DrawList::Ref l, PD::fvec2 p, PD::fvec2 s, PD::u32 clr,
|
||||
float r = 10.f) {
|
||||
l->PathRect(p, p + s, r);
|
||||
l->PathFill(clr);
|
||||
}
|
||||
|
||||
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 v = 20;
|
||||
|
||||
int main() {
|
||||
bool m__ = false;
|
||||
bool a__ = false;
|
||||
bool s__ = false;
|
||||
#ifdef __3DS__
|
||||
net_backend = PD::NetBackend3DS::New();
|
||||
net_backend->Init();
|
||||
void *PD_INIT_DATA = nullptr;
|
||||
#ifndef __3DS__
|
||||
/** Setup Window and Context */
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
|
||||
glfwWindowHint(GLFW_SAMPLES, 8);
|
||||
auto win = glfwCreateWindow(1280, 720, "Test", nullptr, nullptr);
|
||||
glfwMakeContextCurrent(win);
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
PD_INIT_DATA = win;
|
||||
#else
|
||||
osSetSpeedupEnable(true);
|
||||
gfxInitDefault();
|
||||
cfguInit();
|
||||
cfguExit();
|
||||
// consoleInit(GFX_BOTTOM, nullptr);
|
||||
C3D_Init(C3D_DEFAULT_CMDBUF_SIZE * 2);
|
||||
C3D_RenderTarget* Top =
|
||||
C3D_RenderTarget *Top =
|
||||
C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8);
|
||||
C3D_RenderTarget* Bottom =
|
||||
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();
|
||||
/** Init Palaldium Drivers */
|
||||
PD::Init(PD_INIT_DATA);
|
||||
/** Create DrawList and Load Font */
|
||||
PD::Li::DrawList::Ref List = PD::Li::DrawList::New();
|
||||
PD::Li::Font::Ref font = PD::Li::Font::New();
|
||||
#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("sdmc:/ComicNeue.ttf", 32);
|
||||
auto img = PD::Image::New("sdmc:/pb.png");
|
||||
#else
|
||||
font->LoadTTF("ComicNeue.ttf", 32);
|
||||
#ifdef __3DS__
|
||||
font->DefaultPixelHeight = 24;
|
||||
#else
|
||||
font->DefaultPixelHeight = 32;
|
||||
auto img = PD::Image::New("pb.png");
|
||||
#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
|
||||
List->SetFont(font);
|
||||
PD::Image::Convert(img, img->RGBA);
|
||||
auto tex = PD::Li::Gfx::LoadTex(img->pBuffer, img->pWidth, img->pHeight);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
auto ui7 = PD::UI7::Context::New();
|
||||
PD::UI7::ID VpTop("Default");
|
||||
ui7->AddViewPort(VpTop, PD::ivec4(0, 0, 400, 240));
|
||||
ui7->UseViewPort(VpTop);
|
||||
ui7->pIO->Font = font;
|
||||
PD::UI7::Menu::Ref menu = PD::UI7::Menu::New("Test", ui7->pIO);
|
||||
bool open_haxx = true;
|
||||
menu->pIsShown = &open_haxx;
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/** MainLoop */
|
||||
#ifndef __3DS__
|
||||
font->DefaultPixelHeight = 32;
|
||||
while (!glfwWindowShouldClose(win)) {
|
||||
#else
|
||||
PD::Li::Gfx::pGfx->ViewPort = PD::ivec2(400, 240);
|
||||
while (aptMainLoop()) {
|
||||
#endif
|
||||
PD::Hid::Update();
|
||||
#ifndef __3DS__
|
||||
/** Auto ViewPort Resize */
|
||||
int wx, wy;
|
||||
glfwGetWindowSize(win, &wx, &wy);
|
||||
backend->ViewPort = ivec2(wx, wy);
|
||||
PD::Li::Gfx::pGfx->ViewPort = PD::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;
|
||||
/** Rendering some stuff */
|
||||
List->DrawSolid();
|
||||
RoundedRect(List, 10, PD::fvec2(380, 220), 0xffffffff);
|
||||
RoundedRect(List, PD::fvec2(15, 183), PD::fvec2(100, 40), 0xaa222222);
|
||||
List->DrawTexture(tex);
|
||||
RoundedRect(List, PD::fvec2(200, 50), 100, 0xffffffff,
|
||||
((1 + std::sin(PD::OS::GetTime() / 1000.f)) * 0.5f) * 100.f);
|
||||
List->DrawText(PD::fvec2(50, 190), "OK", 0xffffffff);
|
||||
List->DrawLine(PD::fvec2(0), PD::fvec2(1000, 600), 0xffffffff);
|
||||
// List->DrawRectFilled(PD::fvec2(10, 10), PD::fvec2(1260, 700),
|
||||
// 0xffffffff);
|
||||
/** Draw text */
|
||||
List->DrawText(
|
||||
20,
|
||||
"Test String oder So\nPalladium 0.5.0\n" +
|
||||
std::format("{}\nMousePos: {}",
|
||||
PD::Strings::FormatNanos(
|
||||
PD::OS::GetTraceRef("REN")->GetLastDiff()),
|
||||
PD::Hid::MousePos()) +
|
||||
"\nUI7 Version: " + PD::UI7::GetVersion(),
|
||||
0xff000000);
|
||||
ui7->pIO->InputHandler->CurrentMenu = menu->pID;
|
||||
if (menu->pIsOpen) {
|
||||
menu->Label("Hello");
|
||||
menu->Label("World!");
|
||||
if (menu->Button("Test")) {
|
||||
break;
|
||||
}
|
||||
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();
|
||||
menu->Label(std::format("MousePos: {}", PD::Hid::MousePos()));
|
||||
menu->Label(std::format("this->Pos: {}", menu->pLayout->GetPosition()));
|
||||
menu->Label(std::format("Dragged; #{:08X}",
|
||||
ui7->pIO->InputHandler->DraggedObject));
|
||||
menu->Label(
|
||||
std::format("Left: {}", PD::Hid::IsHeld(PD::Hid::Key::Touch)));
|
||||
menu->DragData("Value", &v, 1);
|
||||
}
|
||||
// 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);
|
||||
|
||||
menu->Update();
|
||||
ui7->Update();
|
||||
/** Render DrawData */
|
||||
#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");
|
||||
#endif
|
||||
PD::TT::Beg("REN");
|
||||
PD::Li::Gfx::NewFrame();
|
||||
PD::Li::Gfx::RenderDrawData(List->pDrawList);
|
||||
PD::Li::Gfx::RenderDrawData(menu->pLayout->GetDrawList()->pDrawList);
|
||||
/** Clear The List */
|
||||
List->Clear();
|
||||
menu->pLayout->GetDrawList()->pDrawList.clear();
|
||||
PD::TT::End("REN");
|
||||
#ifndef __3DS__
|
||||
/** Do OS Specifc Stuff (swapp buffers / window buttan events) */
|
||||
glfwPollEvents();
|
||||
glfwSwapBuffers(win);
|
||||
#else
|
||||
C3D_FrameEnd(0);
|
||||
#endif
|
||||
}
|
||||
backend->Deinit();
|
||||
skill_thread = true;
|
||||
if (server_http.joinable()) {
|
||||
server_http.join();
|
||||
}
|
||||
net_backend->Deinit();
|
||||
#ifdef __3DS__
|
||||
C3D_Fini();
|
||||
gfxExit();
|
||||
#else
|
||||
#ifndef __3DS__
|
||||
glfwTerminate();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
0
test/testassets/ComicNeue.ttf → test/temp/ComicNeue.ttf
Normal file → Executable file
0
test/testassets/ComicNeue.ttf → test/temp/ComicNeue.ttf
Normal file → Executable file
BIN
test/temp/pb.png
Executable file
BIN
test/temp/pb.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
Binary file not shown.
Before Width: | Height: | Size: 8.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 195 KiB |
Reference in New Issue
Block a user