Add GUI Support

This commit is contained in:
2025-06-12 15:43:58 -05:00
parent dd4527645e
commit 71a2c83e5a
59 changed files with 3114 additions and 103 deletions

75
apps/guilayouttester.cpp Normal file
View File

@ -0,0 +1,75 @@
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "TessesFramework/SDL2/GUI.hpp"
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
#include "TessesFramework/SDL2/Views/AbsoluteView.hpp"
#include "TessesFramework/SDL2/Views/LabelView.hpp"
#include "TessesFramework/SDL2/Views/TextListView.hpp"
#include "TessesFramework/Filesystem/LocalFS.hpp"
#include "TessesFramework/SDL2/Views/ProgressView.hpp"
#include "TessesFramework/SDL2/Views/CheckView.hpp"
#include "TessesFramework/TextStreams/StreamReader.hpp"
#include "TessesFramework/Streams/FileStream.hpp"
#include <iostream>
using namespace Tesses::Framework;
using namespace Tesses::Framework::SDL2;
using namespace Tesses::Framework::Streams;
using namespace Tesses::Framework::TextStreams;
using namespace Tesses::Framework::Serialization::Json;
void Load(GUIWindow& window, std::string jsonFile)
{
FILE* f = fopen(jsonFile.c_str(),"rb");
if(f != NULL)
{
FileStream strm(f,true,"rb");
StreamReader r(&strm,false);
auto text = r.ReadToEnd();
try {
auto obj = Json::Decode(text);
window.SetView(obj);
} catch(...)
{
}
}
}
#endif
int main(int argc,char** argv)
{
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
if(argc < 2)
{
std::cout << "USAGE: " << argv[0] << " layout.json" << std::endl;
return 0;
}
std::string jsonFile = argv[1];
TF_Init();
GUIPalette pal0(true,(SDL_Color){.r=255,.g=0,.b=0,.a=255},20);
GUIWindow window("Press ALT+R to Reload",640,480,SDL_WINDOW_RESIZABLE,pal0);
window.SDLEvent += std::make_shared<FunctionalEvent<View*,GUISDLEventEventArgs&>>([&window,jsonFile](View* sender, GUISDLEventEventArgs& e)->void{
if(e.event.type == SDL_KEYUP && (uint64_t)(e.event.key.keysym.mod & SDL_Keymod::KMOD_ALT) != 0 && e.event.key.keysym.sym == SDLK_r)
{
Load(window,jsonFile);
}
});
Load(window,jsonFile);
TF_RunEventLoop();
TF_Quit();
#endif
return 0;
}

94
apps/tanonydrop.cpp Normal file
View File

@ -0,0 +1,94 @@
#include "TessesFramework/TessesFramework.hpp"
#include <iostream>
using namespace Tesses::Framework;
using namespace Tesses::Framework::Streams;
using namespace Tesses::Framework::Http;
using namespace Tesses::Framework::Filesystem;
VFS* vfs;
int main(int argc, char** argv)
{
TF_InitWithConsole();
vfs = new SubdirFilesystem(&LocalFS,Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory(),false);
CallbackServer cb([](ServerContext& ctx)->bool{
if(ctx.path == "/")
{
ctx.WithMimeType("text/html")
.SendText(
"<!DOCTYPE html>"
"<html>"
"<head><meta charset=\"UTF-8\"><title>AnonyDump</title></head>"
"<body>"
"<h1>AnonyDump</h1>"
"<a href=\"./files/\">Files</a>"
"<form action=\"./upload\" method=\"post\" enctype=\"multipart/form-data\" accept-charset=\"UTF-8\">"
"<input type=\"file\" name=\"file\" multiple>"
"<input type=\"submit\" value=\"Upload\">"
"</form>"
"</body>"
"</html>"
);
return true;
}
else if(ctx.path == "/upload")
{
if(ctx.NeedToParseFormData())
{
ctx.ParseFormData([](std::string mime, std::string filename,std::string name)->Stream* {
if(name != "file") return nullptr;
VFSPath path("/"+filename);
auto strm = vfs->OpenFile(path,"wb");
return strm;
});
ctx.WithMimeType("text/html")
.SendText(
"<!DOCTYPE html>"
"<html>"
"<head><title>AnonyDump - Uploaded successfully</title>"
"<body>"
"<h1>Uploaded successfully</h1>"
"<a href=\"./\">Back</a>"
"</form>"
"</body>"
"</html>"
);
return true;
}
else {
ctx.statusCode= Tesses::Framework::Http::BadRequest;
ctx.WithMimeType("text/html")
.SendText(
"<!DOCTYPE html>"
"<html>"
"<head><title>AnonyDump - Error: Must contain multipart and POST</title>"
"<body>"
"<h1>Error: Must contain multipart and POST</h1>"
"<a href=\"./\">Back</a>"
"</form>"
"</body>"
"</html>"
);
}
}
return false;
});
Tesses::Framework::Http::MountableServer mountable(cb);
mountable.Mount("/files/",new FileServer(vfs,true,true,false),true);
HttpServer srv(4985,mountable);
srv.StartAccepting();
TF_RunEventLoop();
TF_Quit();
return 0;
}