Move things from crosslang to here

This commit is contained in:
2025-06-21 23:05:12 -05:00
parent 71a2c83e5a
commit 81f0d3be2e
41 changed files with 275029 additions and 96 deletions

View File

@ -38,6 +38,7 @@ template<typename T>
else
{
this->value = this->init();
this->hasInit=true;
mtx.Unlock();
return this->value;
}
@ -48,4 +49,4 @@ template<typename T>
if(hasInit) this->free(this->value);
}
};
}
}

View File

@ -0,0 +1,34 @@
#pragma once
#include "TessesFramework/Filesystem/VFSFix.hpp"
#include "TessesFramework/Filesystem/LocalFS.hpp"
#include <optional>
namespace Tesses::Framework::Platform::Environment
{
extern const char EnvPathSeperator;
namespace SpecialFolders {
Tesses::Framework::Filesystem::VFSPath GetHomeFolder();
Tesses::Framework::Filesystem::VFSPath GetDownloads();
Tesses::Framework::Filesystem::VFSPath GetMusic();
Tesses::Framework::Filesystem::VFSPath GetPictures();
Tesses::Framework::Filesystem::VFSPath GetVideos();
Tesses::Framework::Filesystem::VFSPath GetDocuments();
Tesses::Framework::Filesystem::VFSPath GetConfig();
Tesses::Framework::Filesystem::VFSPath GetDesktop();
Tesses::Framework::Filesystem::VFSPath GetState();
Tesses::Framework::Filesystem::VFSPath GetCache();
Tesses::Framework::Filesystem::VFSPath GetData();
}
std::string GetPlatform();
Tesses::Framework::Filesystem::VFSPath GetRealExecutablePath(Tesses::Framework::Filesystem::VFSPath realPath);
std::optional<std::string> GetVariable(std::string name);
void SetVariable(std::string name, std::optional<std::string> var);
void GetEnvironmentVariables(std::vector<std::pair<std::string,std::string>>& env);
}

View File

@ -0,0 +1,39 @@
#include <vector>
#include <string>
#include "TessesFramework/Streams/Stream.hpp"
#include "TessesFramework/HiddenField.hpp"
namespace Tesses::Framework::Platform {
class Process {
private:
HiddenField hidden;
public:
std::string name;
std::vector<std::string> args;
std::vector<std::pair<std::string,std::string>> env;
bool includeThisEnv;
bool redirectStdIn=false;
bool redirectStdOut=false;
bool redirectStdErr=false;
//YOU ARE RESPONSABLE FOR FREEING THIS STREAM
Tesses::Framework::Streams::Stream* GetStdinStream(bool closeUnderlying=true);
//YOU ARE RESPONSABLE FOR FREEING THIS STREAM
Tesses::Framework::Streams::Stream* GetStdoutStream(bool closeUnderlying=true);
//YOU ARE RESPONSABLE FOR FREEING THIS STREAM
Tesses::Framework::Streams::Stream* GetStderrStream(bool closeUnderlying=true);
Process();
Process(std::string name, std::vector<std::string> args,bool includeThisEnv=true);
Process(std::string name, std::vector<std::string> args, std::vector<std::pair<std::string,std::string>> env,bool includeThisEnv=false);
Process(std::string name, std::vector<std::string> args, std::vector<std::string> env,bool includeThisEnv=false);
bool Start();
void Kill(int signal);
int WaitForExit();
~Process();
};
}

View File

@ -61,6 +61,7 @@ namespace Tesses::Framework::SDL2
constexpr uint64_t VIEWFLAG_TABSTOP=(uint64_t)1<<3;
constexpr uint64_t VIEWFLAG_INTERCEPT_TAB=(uint64_t)1<<4;
constexpr uint64_t VIEWFLAG_CHECKED=(uint64_t)1<<5;
constexpr uint64_t VIEWFLAG_TOUCHED=(uint64_t)1<<6;
class GUIPopup;
class GUIWindow;
class ContainerView;
@ -96,6 +97,8 @@ namespace Tesses::Framework::SDL2
ContainerView* parent;
public:
bool GetViewFlag(uint64_t flag)
{
@ -124,6 +127,11 @@ namespace Tesses::Framework::SDL2
virtual std::string GetId();
virtual View* FindViewById(std::string id);
friend class ContainerView;
virtual std::pair<int,int> PreferedMinSize();
std::pair<int,int> GetCordFromEvent(SDL_Event& event);
};
class ContainerView : public View {
public:
@ -210,11 +218,15 @@ namespace Tesses::Framework::SDL2
friend class GUI;
friend class GUIPopup;
friend class View;
void SetText(std::string text);
void SetView(Tesses::Framework::Serialization::Json::JToken json);
SDL_Window* GetSDLWindow();
SDL_Renderer* GetSDLRenderer();
View* CreateViewFromJson(Tesses::Framework::Serialization::Json::JObject json);
};

View File

@ -0,0 +1,24 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class EditTextView : public View {
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
std::string hint;
size_t cursorPos;
size_t cursorEnd;
public:
EditTextView();
EditTextView(std::string hint);
virtual std::string GetHint();
virtual void SetHint(std::string hint);
virtual void SetText(std::string text);
virtual void TypeText(std::string text);
virtual std::pair<int,int> PreferedMinSize();
};
}
#endif

View File

@ -0,0 +1,22 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class PictureView : public View {
SDL_Texture* tex;
bool ownsTex;
SDL_Surface* surf;
bool ownsSurf;
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
public:
PictureView();
void SetPicture(SDL_Texture* tex, bool owns=true);
void SetPicture(SDL_Surface* surface,bool owns=true);
~PictureView();
};
}
#endif

View File

@ -0,0 +1,18 @@
#pragma once
#include "TessesFramework/Filesystem/VFSFix.hpp"
#include "TessesFramework/Filesystem/VFS.hpp"
#include <optional>
namespace Tesses::Framework::Serialization {
class SQLiteDatabase {
private:
void* data;
static int collector(void* user, int count,char** vals, char** keys);
public:
SQLiteDatabase(Tesses::Framework::Filesystem::VFSPath path);
static std::string Escape(std::string text);
static bool IsEnabled();
void Exec(std::string statement,std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>>& results);
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> Exec(std::string statement);
~SQLiteDatabase();
};
}

View File

@ -32,6 +32,8 @@
#include "Mail/Smtp.hpp"
#include "HiddenField.hpp"
#include "Serialization/Json.hpp"
#include "Serialization/SQLite.hpp"
#include "Platform/Environment.hpp"
#include "SDL2/FontCache.hpp"
#include "SDL2/Stream.hpp"
#include "SDL2/GUI.hpp"

View File

@ -11,13 +11,15 @@ namespace Tesses::Framework::Threading
class ThreadPool
{
std::vector<Thread*> threads;
std::queue<std::function<void()>> callbacks;
std::queue<std::function<void(size_t)>> callbacks;
Mutex mtx;
volatile bool isRunning;
public:
static size_t GetNumberOfCores();
ThreadPool(size_t threads);
void Schedule(std::function<void()> cb);
size_t ThreadCount();
bool Empty();
void Schedule(std::function<void(size_t)> cb);
~ThreadPool();
};
}