Remove SDL2

This commit is contained in:
2025-07-22 14:21:23 -05:00
parent e870773fe2
commit 374e34d896
61 changed files with 54 additions and 6457 deletions

View File

@@ -9,24 +9,7 @@
#include <vector>
#include <functional>
#include "Threading/Mutex.hpp"
class TextException : public std::exception {
std::string error_message;
public:
TextException(std::string ex)
{
error_message = "TextException: ";
error_message.append(ex);
}
const char * what() const noexcept override
{
return error_message.c_str();
}
};
namespace Tesses::Framework
{
template<typename...TArgs>

View File

@@ -1,31 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include <array>
#include "SDL_Headers.hpp"
#include <string>
#include <vector>
namespace Tesses::Framework::SDL2
{
class FontCache
{
std::array<SDL_Texture*,96> font_chrs;
int mw,mh,ps;
void Load(SDL_Renderer* renderer,TTF_Font* font);
public:
FontCache(SDL_Renderer* renderer,TTF_Font* font);
FontCache(SDL_Renderer* renderer,std::string font,int sz);
FontCache(SDL_Renderer* renderer,const uint8_t* mem,size_t cnt,int sz);
FontCache(SDL_Renderer* renderer,const std::vector<uint8_t>& v,int sz);
FontCache(SDL_Renderer* renderer,int sz);
SDL_Texture* operator[](char c);
SDL_Texture* GetCharOfColor(char c, const SDL_Color& color);
int MaxWidth();
int MaxHeight();
int PointSize();
void CalculateSize(std::string text, int& x,int& y);
void Render(SDL_Renderer* renderer,int x,int y, std::string text, const SDL_Color& color,size_t begin=0,size_t end=std::string::npos);
~FontCache();
};
}
#endif

View File

@@ -1,328 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "SDL_Headers.hpp"
#include "FontCache.hpp"
#include "../Filesystem/VFSFix.hpp"
#include "../Filesystem/VFS.hpp"
#include "../Common.hpp"
#include "../Serialization/Json.hpp"
namespace Tesses::Framework::SDL2
{
class GUIPalette {
public:
GUIPalette();
GUIPalette(bool isDarkMode, SDL_Color accent,int fontSize=24,int borderSize=2);
GUIPalette(SDL_Color accent, SDL_Color background, SDL_Color borderColor, SDL_Color borderHover, SDL_Color borderActive, SDL_Color borderHoverActive, int fontSize=24,int borderSize=2);
SDL_Color accent; //color is used for font when not over accent background
SDL_Color background;
SDL_Color borderColor; //color is used for font when over accent background
SDL_Color borderHover;
SDL_Color borderActive;
SDL_Color borderHoverActive;
int fontSize;
int borderSize;
SDL_Color& GetBorderColor(bool isHovering, bool isActive, bool isMouseDown);
};
class GUIEventArgs
{
public:
virtual std::string Type();
virtual ~GUIEventArgs();
};
class View;
class GUIWindowClosingEventArgs : public GUIEventArgs
{
public:
bool cancel;
std::string Type();
};
class GUIMouseButtonEventArgs : public GUIEventArgs
{
public:
Uint32 which;
int x;
int y;
Uint8 button;
std::string Type();
};
class GUIJsonViewNotFoundEventArgs : public GUIEventArgs
{
public:
std::string Type();
View* destView;
Tesses::Framework::Serialization::Json::JObject jsonObject;
std::string typeString;
};
class GUISDLEventEventArgs : public GUIEventArgs
{
public:
std::string Type();
SDL_Event event;
};
constexpr uint64_t VIEWFLAG_HOVER_STATE=(uint64_t)1 << 0;
constexpr uint64_t VIEWFLAG_MOUSEDOWN_STATE =(uint64_t)1<<1;
constexpr uint64_t VIEWFLAG_ISACTIVE=(uint64_t)1<<2;
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;
constexpr uint64_t VIEWFLAG_HOVER_B1STATE=(uint64_t)1<<7; //for scrollbar buttons
constexpr uint64_t VIEWFLAG_HOVER_B2STATE=(uint64_t)1<<8; //for scrollbar buttons
constexpr uint64_t VIEWFLAG_MOUSEDOWN_B1STATE=(uint64_t)1<<9; //for scrollbar buttons
constexpr uint64_t VIEWFLAG_MOUSEDOWN_B2STATE=(uint64_t)1<<10; //for scrollbar buttons
constexpr int GUI_EXPAND = -1;
constexpr int GUI_MIN = 0;
constexpr int GUI_EXPAND_N(int n)
{
if(n < 0) return n;
return -n;
}
class GUIPopup;
class GUIWindow;
class ContainerView;
class View {
protected:
std::string text;
std::string id;
uint64_t flags;
protected:
View();
View(std::string text);
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual void OnDragDropFile(Tesses::Framework::Filesystem::VFSPath filePath,SDL_Rect myRect, SDL_Point dropLoc);
virtual void OnDragDropText(std::string text,SDL_Rect myRect, SDL_Point dropLoc);
virtual void OnEnter(GUIEventArgs& evt);
virtual void OnLeave(GUIEventArgs& evt);
virtual void OnMouseDown(GUIMouseButtonEventArgs& evt);
virtual void OnMouseUp(GUIMouseButtonEventArgs& evt);
virtual void OnClick(GUIEventArgs& evt);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
virtual void OnSetParent(View* v);
void CallOnDraw(View* view, SDL_Renderer* renderer, SDL_Rect& myRect)
{
view->OnDraw(renderer,myRect);
}
bool CallOnEvent(View* view,SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
{
return view->OnEvent(event,myBounds,visibleBounds);
}
ContainerView* parent;
public:
bool GetViewFlag(uint64_t flag)
{
return (this->flags & flag) != 0;
}
void SetViewFlag(uint64_t flag, bool value)
{
if(value)
this->flags |= flag;
else
this->flags &= ~flag;
}
EventList<View*,GUIMouseButtonEventArgs&> MouseUp;
EventList<View*,GUIMouseButtonEventArgs&> MouseDown;
EventList<View*,GUIEventArgs&> Click;
EventList<View*,GUIEventArgs&> Enter;
EventList<View*,GUIEventArgs&> Leave;
EventList<View*,GUISDLEventEventArgs&> SDLEvent;
virtual ~View();
friend class GUIWindow;
virtual GUIWindow* GetWindow();
virtual std::string GetText();
virtual void SetText(std::string text);
virtual void SetId(std::string id);
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:
virtual size_t ViewCount()=0;
virtual View* GetViewAt(size_t index)=0;
virtual View* FindViewById(std::string id);
protected:
ContainerView();
ContainerView(std::string text);
void AssignChildParentToThis(View* view)
{
if(view != nullptr)
{
view->parent = this;
view->OnSetParent(this);
}
}
};
enum class TabNextResult {
KeepGoing,
TabNext,
Done
};
class GUIPopup : public ContainerView {
protected:
bool closed=true;
virtual View* GetView()=0;
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
GUIPopup();
GUIPopup(SDL_Rect bounds);
GUIPopup(int x, int y,int w, int h);
SDL_Rect bounds;
bool closeIfClickOutside=true;
virtual void Close();
virtual bool IsClosed();
virtual ~GUIPopup();
size_t ViewCount();
View* GetViewAt(size_t index);
bool IsActive();
friend class GUIWindow;
};
class GUIContainerPopup : public GUIPopup
{
View* child;
bool ownsChild;
protected:
View* GetView();
public:
GUIContainerPopup();
GUIContainerPopup(SDL_Rect bounds);
GUIContainerPopup(int x, int y,int w, int h);
void SetView(View* view, bool owns=true);
~GUIContainerPopup();
};
class GUIDialog : public GUIPopup {
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
GUIDialog();
GUIDialog(SDL_Rect bounds);
GUIDialog(int x,int y, int w, int h);
virtual ~GUIDialog();
};
class GUIContainerDialog : public GUIDialog
{
View* v;
bool owns=false;
protected:
View* GetView();
public:
GUIContainerDialog();
GUIContainerDialog(SDL_Rect bounds);
GUIContainerDialog(int x, int y,int w, int h);
void SetView(View* view, bool owns=true);
size_t ViewCount();
View* GetViewAt(size_t index);
~GUIContainerDialog();
};
class GUIWindow : public ContainerView
{
std::vector<GUIPopup*> popups;
View* child;
bool ownsChild;
SDL_Window* window;
SDL_Renderer* renderer;
void Event(SDL_Event& event);
void Draw();
void DeactivateAll(View* view);
void TabNext(View* view,TabNextResult& nr);
protected:
void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
EventList<View*,GUIJsonViewNotFoundEventArgs&> JsonViewNotFound;
EventList<View*,GUIWindowClosingEventArgs&> Closing;
size_t ViewCount();
View* GetViewAt(size_t index);
FontCache* normal_font;
FontCache* monospaced_font;
GUIPalette palette;
GUIWindow(std::string title, int w, int h, Uint32 flags, const GUIPalette& palette);
void SetPalette(const GUIPalette& palette);
void SetView(View* view,bool owns=true);
void ShowPopup(GUIPopup* popup);
void ShowPopup(GUIPopup& popup);
void MakeActive(View* view);
void TabNext();
GUIWindow* GetWindow();
~GUIWindow();
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);
operator bool();
};
class GUI {
std::vector<GUIWindow*> windows;
public:
void Update();
void CloseWindows();
friend class GUIWindow;
};
extern GUI gui;
class Clipper {
SDL_Rect theRect;
SDL_Renderer* renderer;
bool isClipped;
public:
Clipper(SDL_Renderer* renderer, SDL_Rect& myRect);
bool Clip(SDL_Rect rect);
~Clipper();
static void ClipRect(SDL_Rect& child, SDL_Rect& parent);
};
}
#endif

View File

@@ -1,12 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include <SDL2/SDL.h>
#include <string>
namespace Tesses::Framework::SDL2
{
bool TryParseSDLColor(std::string str, SDL_Color& col);
}
#endif

View File

@@ -1,13 +0,0 @@
#pragma once
#include <TessesFramework/TessesFrameworkFeatures.h>
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#if defined(TESSESFRAMEWORK_FETCHCONTENT)
#include <SDL_image.h>
#include <SDL_ttf.h>
#else
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#endif
#endif

View File

@@ -1,9 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../Streams/Stream.hpp"
#include <SDL2/SDL_rwops.h>
namespace Tesses::Framework::SDL2
{
SDL_RWops* RwopsFromStream(Tesses::Framework::Streams::Stream* strm, bool owns=true);
}
#endif

View File

@@ -1,33 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class AbsoluteView : public ContainerView {
std::vector<std::pair<std::pair<View*,bool>,SDL_Rect>> views;
protected:
void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
size_t ViewCount();
View* GetViewAt(size_t index);
AbsoluteView();
void Add(SDL_Rect rect, View* view, bool owns=true);
void Set(View* view, SDL_Rect rect);
void Remove(View* view);
~AbsoluteView();
};
/* class AbsoluteContainer : public View {
std::vector<std::pair<std::pair<View*,bool>,SDL_Rect>> views;
public:
void Add(SDL_Rect rect, View* view, bool owns=true);
void Set(View* view, SDL_Rect rect);
void Remove(View* view);
~AbsoluteContainer();
};*/
}
#endif

View File

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

View File

@@ -1,25 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class CheckView : public View {
protected:
virtual void OnCheckChanged(GUIEventArgs& event);
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
CheckView(bool checked, std::string label);
CheckView();
virtual bool GetChecked();
virtual void SetChecked(bool value);
EventList<View*,GUIEventArgs&> CheckChanged;
};
}
#endif

View File

@@ -1,23 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
#include "ScrollableTextListView.hpp"
namespace Tesses::Framework::SDL2::Views
{
class DropDownView : public View {
GUIContainerPopup popup;
ScrollableTextListView listView;
bool hasSet=false;
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
DropDownView();
std::vector<std::string>& GetItems();
void SetIndex(int index);
int GetIndex();
};
}
#endif

View File

@@ -1,24 +0,0 @@
#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

@@ -1,24 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class HScrollView : public View {
protected:
virtual void OnValueChanged(GUIEventArgs& e);
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
HScrollView();
HScrollView(uint64_t value, uint64_t min, uint64_t max,uint64_t step=1);
uint64_t value;
uint64_t min;
uint64_t max;
uint64_t step;
EventList<View*,GUIEventArgs&> ValueChanged;
std::pair<int,int> PreferedMinSize();
};
}
#endif

View File

@@ -1,27 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class HStackView : public ContainerView {
std::vector<std::pair<int,std::pair<View*,bool>>> items;
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
HStackView();
int spacing=0;
void Add(int sz, View* view, bool owns=true);
void Remove(View* view);
void Clear();
virtual size_t ViewCount();
virtual View* GetViewAt(size_t index);
virtual ~HStackView();
};
}
#endif

View File

@@ -1,15 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class LabelView : public View {
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
public:
LabelView();
LabelView(std::string text);
};
}
#endif

View File

@@ -1,27 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class MultilineEditTextView : 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;
std::vector<std::string> lines;
SDL_Point topLeft={.x=0,.y=0};
SDL_Point cursorPos={.x=0,.y=0};
SDL_Point cursorEnd={.x=-1,.y=-1};
public:
MultilineEditTextView();
MultilineEditTextView(std::string hint);
virtual std::string GetHint();
virtual void SetHint(std::string hint);
virtual std::string GetText();
virtual void SetText(std::string text);
virtual void TypeText(std::string text);
virtual std::pair<int,int> PreferedMinSize();
};
}
#endif

View File

@@ -1,22 +0,0 @@
#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

@@ -1,17 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class ProgressView : public View
{
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
public:
ProgressView();
ProgressView(double value);
double value;
};
};
#endif

View File

@@ -1,21 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class ScrollableTextListView : public View {
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
ScrollableTextListView();
size_t firstIndex;
int selected;
std::vector<std::string> items;
EventList<View*,GUIEventArgs&> ValueChanged;
};
}
#endif

View File

@@ -1,29 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class TabView : public ContainerView {
protected:
std::vector<std::pair<std::string,std::pair<View*,bool>>> items;
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
TabView();
TabView(bool tabsVisible);
bool tabsVisible;
size_t firstTab;
size_t selectedTab;
void AddTab(std::string name, View* view, bool owns=true);
void RemoveTab(View* view);
void Clear();
virtual size_t ViewCount();
virtual View* GetViewAt(size_t index);
~TabView();
};
}
#endif

View File

@@ -1,21 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class TextListView : public View {
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
TextListView();
size_t firstIndex;
int selected;
std::vector<std::string> items;
EventList<View*,GUIEventArgs&> ValueChanged;
};
}
#endif

View File

@@ -1,24 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class VScrollView : public View {
protected:
virtual void OnValueChanged(GUIEventArgs& e);
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
VScrollView();
VScrollView(uint64_t value, uint64_t min, uint64_t max,uint64_t step=1);
uint64_t value;
uint64_t min;
uint64_t max;
uint64_t step;
EventList<View*,GUIEventArgs&> ValueChanged;
std::pair<int,int> PreferedMinSize();
};
}
#endif

View File

@@ -1,29 +0,0 @@
#pragma once
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
#include "../GUI.hpp"
namespace Tesses::Framework::SDL2::Views
{
class VStackView : public ContainerView {
std::vector<std::pair<int,std::pair<View*,bool>>> items;
protected:
virtual void OnDraw(SDL_Renderer* renderer, SDL_Rect& r);
virtual bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
VStackView();
int spacing=0;
void Add(int sz, View* view, bool owns=true);
void Remove(View* view);
void Clear();
virtual size_t ViewCount();
virtual View* GetViewAt(size_t index);
virtual ~VStackView();
};
}
#endif

View File

@@ -37,4 +37,3 @@
#include "Platform/Environment.hpp"
#include "Platform/Process.hpp"
#include "Text/StringConverter.hpp"
#include "SDL2/SDL_Headers.hpp"