Switch to gitea

This commit is contained in:
2025-07-03 15:49:14 -05:00
parent 4040dfe98f
commit 7199939260
32 changed files with 2820 additions and 94 deletions

View File

@ -12,15 +12,16 @@ namespace Tesses::Framework::SDL2
class GUIPalette {
public:
GUIPalette();
GUIPalette(bool isDarkMode, SDL_Color accent,int fontSize=24);
GUIPalette(SDL_Color accent, SDL_Color background, SDL_Color border_color, SDL_Color border_hover, SDL_Color border_active, SDL_Color border_hover_active, int fontSize=24);
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 border_color; //color is used for font when over accent background
SDL_Color border_hover;
SDL_Color border_active;
SDL_Color border_hover_active;
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);
};
@ -32,6 +33,12 @@ namespace Tesses::Framework::SDL2
virtual ~GUIEventArgs();
};
class View;
class GUIWindowClosingEventArgs : public GUIEventArgs
{
public:
bool cancel;
std::string Type();
};
class GUIMouseButtonEventArgs : public GUIEventArgs
{
public:
@ -62,6 +69,22 @@ namespace Tesses::Framework::SDL2
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;
@ -161,25 +184,71 @@ namespace Tesses::Framework::SDL2
Done
};
class GUIPopup : public ContainerView {
View* child;
bool ownsChild;
protected:
void OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect);
bool OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds);
public:
bool closed=true;
virtual View* GetView()=0;
size_t ViewCount();
View* GetViewAt(size_t index);
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;
void SetView(View* view, bool owns=true);
~GUIPopup();
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;
@ -198,6 +267,7 @@ namespace Tesses::Framework::SDL2
public:
EventList<View*,GUIJsonViewNotFoundEventArgs&> JsonViewNotFound;
EventList<View*,GUIWindowClosingEventArgs&> Closing;
size_t ViewCount();
View* GetViewAt(size_t index);
FontCache* normal_font;
@ -228,6 +298,7 @@ namespace Tesses::Framework::SDL2
SDL_Renderer* GetSDLRenderer();
View* CreateViewFromJson(Tesses::Framework::Serialization::Json::JObject json);
operator bool();
};
@ -235,6 +306,7 @@ namespace Tesses::Framework::SDL2
std::vector<GUIWindow*> windows;
public:
void Update();
void CloseWindows();
friend class GUIWindow;
};
extern GUI gui;

View File

@ -12,7 +12,7 @@ namespace Tesses::Framework::SDL2::Views
public:
ButtonView();
ButtonView(std::string text);
virtual std::pair<int,int> PreferedMinSize();
};
}
#endif

View File

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

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

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

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

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

@ -15,6 +15,7 @@ namespace Tesses::Framework::SDL2::Views
int selected;
std::vector<std::string> items;
EventList<View*,GUIEventArgs&> ValueChanged;
};
}
#endif

View File

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

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