mirror of
https://onedev.site.tesses.net/tesses-framework
synced 2026-02-09 00:05:46 +00:00
Remove SDL2
This commit is contained in:
@@ -300,14 +300,14 @@ namespace Tesses::Framework::Http
|
||||
|
||||
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, Tesses::Framework::Streams::Stream* strm)
|
||||
{
|
||||
if(strm == nullptr) throw TextException("strm is null");
|
||||
if(strm == nullptr) throw std::runtime_error("strm is null");
|
||||
HttpRequest request;
|
||||
request.url = url;
|
||||
request.unixSocket = unixSocket;
|
||||
request.followRedirects=true;
|
||||
request.method = "GET";
|
||||
HttpResponse response(request);
|
||||
if(response.statusCode < 200 || response.statusCode > 299) throw TextException("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||
if(response.statusCode < 200 || response.statusCode > 299) throw std::runtime_error("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||
response.CopyToStream(strm);
|
||||
}
|
||||
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, Tesses::Framework::Streams::Stream& strm)
|
||||
@@ -317,16 +317,16 @@ namespace Tesses::Framework::Http
|
||||
|
||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFS* vfs, Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
if(vfs == nullptr) throw TextException("vfs is null");
|
||||
if(vfs == nullptr) throw std::runtime_error("vfs is null");
|
||||
auto strm = vfs->OpenFile(path,"wb");
|
||||
if(strm == nullptr) throw TextException("strm is null");
|
||||
if(strm == nullptr) throw std::runtime_error("strm is null");
|
||||
DownloadUnixSocketToStreamSimple(unixSocket,url,strm);
|
||||
delete strm;
|
||||
}
|
||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFS& vfs, Tesses::Framework::Filesystem::VFSPath path)
|
||||
{
|
||||
auto strm = vfs.OpenFile(path,"wb");
|
||||
if(strm == nullptr) throw TextException("strm is null");
|
||||
if(strm == nullptr) throw std::runtime_error("strm is null");
|
||||
DownloadUnixSocketToStreamSimple(unixSocket,url,strm);
|
||||
delete strm;
|
||||
}
|
||||
@@ -342,7 +342,7 @@ namespace Tesses::Framework::Http
|
||||
request.followRedirects=true;
|
||||
request.method = "GET";
|
||||
HttpResponse response(request);
|
||||
if(response.statusCode < 200 || response.statusCode > 299) throw TextException("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||
if(response.statusCode < 200 || response.statusCode > 299) throw std::runtime_error("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||
return response.ReadAsString();
|
||||
}
|
||||
void DownloadToStreamSimple(std::string url, Tesses::Framework::Streams::Stream* strm)
|
||||
@@ -373,7 +373,7 @@ namespace Tesses::Framework::Http
|
||||
request.followRedirects=true;
|
||||
request.method = "GET";
|
||||
HttpResponse response(request);
|
||||
if(response.statusCode < 200 || response.statusCode > 299) throw TextException("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||
if(response.statusCode < 200 || response.statusCode > 299) throw std::runtime_error("Status code does not indicate success: " + std::to_string(response.statusCode) + " " + HttpUtils::StatusCodeString(response.statusCode));
|
||||
return response.ReadAsString();
|
||||
|
||||
}
|
||||
|
||||
@@ -730,8 +730,8 @@ namespace Tesses::Framework::Http
|
||||
void ServerContext::SendStream(Stream& strm)
|
||||
{
|
||||
if(sent) return;
|
||||
if(!strm.CanRead()) throw TextException("Cannot read from stream");
|
||||
if(strm.EndOfStream()) throw TextException("End of stream");
|
||||
if(!strm.CanRead()) throw std::runtime_error("Cannot read from stream");
|
||||
if(strm.EndOfStream()) throw std::runtime_error("End of stream");
|
||||
if(strm.CanSeek())
|
||||
{
|
||||
int64_t len=strm.GetLength();
|
||||
@@ -1013,13 +1013,24 @@ namespace Tesses::Framework::Http
|
||||
ctx.SendNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
catch(std::exception& ex)
|
||||
{
|
||||
ctx.SendException(ex);
|
||||
}
|
||||
catch(std::string& ex)
|
||||
{
|
||||
std::runtime_error re(ex);
|
||||
ctx.SendException(re);
|
||||
}
|
||||
catch(const char* ex)
|
||||
{
|
||||
std::runtime_error re(ex);
|
||||
ctx.SendException(re);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
TextException ex("An unknown error occurred");
|
||||
std::runtime_error ex("An unknown error occurred");
|
||||
ctx.SendException(ex);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,279 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/FontCache.hpp"
|
||||
#include "TessesFramework/Http/HttpUtils.hpp"
|
||||
#include "TessesFramework/TanoheSans-Regular.h"
|
||||
using HU= Tesses::Framework::Http::HttpUtils;
|
||||
namespace Tesses::Framework::SDL2 {
|
||||
void FontCache::Load(SDL_Renderer* renderer,TTF_Font* font)
|
||||
{
|
||||
this->mw=0;
|
||||
this->mh=0;
|
||||
this->ps=ps;
|
||||
|
||||
for(size_t i = 0; i < this->font_chrs.size();i++)
|
||||
{
|
||||
SDL_Surface* surf = TTF_RenderGlyph_Blended(font,(Uint16)(i+32),{.r=255,.g=255,.b=255,.a=255});
|
||||
if(surf->w > this->mw) mw = surf->w;
|
||||
if(surf->h > this->mh) mh = surf->h;
|
||||
this->font_chrs[i] = SDL_CreateTextureFromSurface(renderer,surf);
|
||||
SDL_FreeSurface(surf);
|
||||
|
||||
}
|
||||
}
|
||||
FontCache::FontCache(SDL_Renderer* renderer,std::string font,int sz)
|
||||
{
|
||||
TTF_Font* f = TTF_OpenFont(font.c_str(),sz);
|
||||
Load(renderer,f);
|
||||
TTF_CloseFont(f);
|
||||
}
|
||||
FontCache::FontCache(SDL_Renderer* renderer,const uint8_t* mem,size_t cnt,int sz)
|
||||
{
|
||||
|
||||
TTF_Font* f = TTF_OpenFontRW(SDL_RWFromConstMem(mem,cnt),1,sz);
|
||||
Load(renderer,f);
|
||||
TTF_CloseFont(f);
|
||||
}
|
||||
FontCache::FontCache(SDL_Renderer* renderer,const std::vector<uint8_t>& v,int sz) : FontCache(renderer,v.data(),v.size(),sz)
|
||||
{
|
||||
|
||||
}
|
||||
FontCache::FontCache(SDL_Renderer* renderer,TTF_Font* font)
|
||||
{
|
||||
this->Load(renderer,font);
|
||||
}
|
||||
FontCache::FontCache(SDL_Renderer* renderer,int sz) : FontCache(renderer,TANOHESANSREGULAR,TANOHESANSREGULAR_SIZE,sz)
|
||||
{
|
||||
|
||||
}
|
||||
void FontCache::CalculateSize(std::string text, int& x,int& y)
|
||||
{
|
||||
int myX = 0;
|
||||
x=0;
|
||||
y=0;
|
||||
int maxH = MaxHeight();
|
||||
y=maxH;
|
||||
for(auto c : text)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case '\n':
|
||||
{
|
||||
y += maxH;
|
||||
if(myX > x) x = myX;
|
||||
myX = 0;
|
||||
}
|
||||
break;
|
||||
case '\t':
|
||||
{
|
||||
auto tex = operator[](' ');
|
||||
int wi;
|
||||
SDL_QueryTexture(tex,NULL,NULL,&wi,NULL);
|
||||
|
||||
myX += wi * 4;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
auto tex = operator[](c);
|
||||
int wi;
|
||||
int he;
|
||||
SDL_QueryTexture(tex,NULL,NULL,&wi,&he);
|
||||
|
||||
myX += wi;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
if(myX > x) x = myX;
|
||||
}
|
||||
void FontCache::Render(SDL_Renderer* renderer,int x,int y, std::string text,const SDL_Color& color, size_t begin, size_t end)
|
||||
{
|
||||
int myX = x;
|
||||
int maxH = MaxHeight();
|
||||
if(begin >= text.size()) return;
|
||||
if(end > text.size()) end = text.size();
|
||||
|
||||
for(size_t i = begin; i < end; i++)
|
||||
{
|
||||
switch(text[i])
|
||||
{
|
||||
case '\n':
|
||||
{
|
||||
y += maxH;
|
||||
myX = x;
|
||||
}
|
||||
break;
|
||||
case '\t':
|
||||
{
|
||||
auto tex = GetCharOfColor(' ',color);
|
||||
int wi;
|
||||
SDL_QueryTexture(tex,NULL,NULL,&wi,NULL);
|
||||
|
||||
myX += wi * 4;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
auto tex = GetCharOfColor(text[i],color);
|
||||
int wi;
|
||||
int he;
|
||||
SDL_QueryTexture(tex,NULL,NULL,&wi,&he);
|
||||
SDL_Rect src={.x=0,.y=0,.w=wi,.h=he};
|
||||
|
||||
SDL_Rect dest={.x=myX,.y=y,.w=wi,.h=he};
|
||||
|
||||
myX += wi;
|
||||
SDL_RenderCopy(renderer,tex,&src,&dest);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_Texture* FontCache::GetCharOfColor(char c, const SDL_Color& color)
|
||||
{
|
||||
auto res = (c >= 32 && c <= 126) ? this->font_chrs[c-32] : this->font_chrs[95];
|
||||
SDL_SetTextureColorMod(res,color.r,color.g,color.b);
|
||||
return res;
|
||||
}
|
||||
SDL_Texture* FontCache::operator[](char c)
|
||||
{
|
||||
return GetCharOfColor(c,{.r=255,.g=255,.b=255,.a=255});
|
||||
}
|
||||
FontCache::~FontCache()
|
||||
{
|
||||
for(auto item : this->font_chrs)
|
||||
SDL_DestroyTexture(item);
|
||||
}
|
||||
int FontCache::MaxWidth()
|
||||
{
|
||||
return this->mw;
|
||||
}
|
||||
int FontCache::MaxHeight()
|
||||
{
|
||||
return this->mh;
|
||||
}
|
||||
|
||||
int FontCache::PointSize()
|
||||
{
|
||||
return this->ps;
|
||||
}
|
||||
|
||||
bool TryParseSDLColor(std::string str, SDL_Color& col)
|
||||
{
|
||||
str = HU::Replace(str," ","");
|
||||
//rgba(255,255,255,1.0)
|
||||
//rgb(197, 30, 30)
|
||||
//#rgb
|
||||
//#rgba
|
||||
//#rrggbb
|
||||
//#rrggbbaa
|
||||
|
||||
if(str.size() >= 4 && str[0] == '#')
|
||||
{
|
||||
if(str.size() == 4)
|
||||
{
|
||||
auto r = HU::HexToNibble(str[1]);
|
||||
r |= r << 4;
|
||||
auto g = HU::HexToNibble(str[2]);
|
||||
g |= g << 4;
|
||||
auto b = HU::HexToNibble(str[3]);
|
||||
b |= b << 4;
|
||||
col.r = r;
|
||||
col.g = g;
|
||||
col.b = b;
|
||||
col.a = 255;
|
||||
return true;
|
||||
}
|
||||
else if(str.size() == 5)
|
||||
{
|
||||
auto r = HU::HexToNibble(str[1]);
|
||||
r |= r << 4;
|
||||
auto g = HU::HexToNibble(str[2]);
|
||||
g |= g << 4;
|
||||
auto b = HU::HexToNibble(str[3]);
|
||||
b |= b << 4;
|
||||
auto a = HU::HexToNibble(str[4]);
|
||||
a |= a << 4;
|
||||
col.r = r;
|
||||
col.g = g;
|
||||
col.b = b;
|
||||
col.a = a;
|
||||
return true;
|
||||
}
|
||||
else if(str.size() == 7) {
|
||||
auto r = HU::HexToNibble(str[1]);
|
||||
r |= HU::HexToNibble(str[2]) << 4;
|
||||
auto g = HU::HexToNibble(str[3]);
|
||||
g |= HU::HexToNibble(str[4]) << 4;
|
||||
auto b = HU::HexToNibble(str[5]);
|
||||
b |= HU::HexToNibble(str[6]) << 4;
|
||||
|
||||
col.r = r;
|
||||
col.g = g;
|
||||
col.b = b;
|
||||
col.a = 255;
|
||||
return true;
|
||||
}
|
||||
else if(str.size() == 9)
|
||||
{
|
||||
auto r = HU::HexToNibble(str[1]);
|
||||
r |= HU::HexToNibble(str[2]) << 4;
|
||||
auto g = HU::HexToNibble(str[3]);
|
||||
g |= HU::HexToNibble(str[4]) << 4;
|
||||
auto b = HU::HexToNibble(str[5]);
|
||||
b |= HU::HexToNibble(str[6]) << 4;
|
||||
auto a = HU::HexToNibble(str[7]);
|
||||
a |= HU::HexToNibble(str[8]) << 4;
|
||||
|
||||
col.r = r;
|
||||
col.g = g;
|
||||
col.b = b;
|
||||
col.a = a;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(str.size() > 4 && strncmp(str.c_str(),"rgb(",4) == 0 && str[str.size()-1] == ')')
|
||||
{
|
||||
str = HU::Replace(str.substr(4),")","");
|
||||
auto parts = HU::SplitString(str,",");
|
||||
if(parts.size() != 3) return false;
|
||||
try{
|
||||
auto r = std::stoul(parts[0]);
|
||||
auto g = std::stoul(parts[1]);
|
||||
auto b = std::stoul(parts[2]);
|
||||
col.r = (Uint8)r;
|
||||
col.g = (Uint8)g;
|
||||
col.b = (Uint8)b;
|
||||
col.a = 255;
|
||||
} catch(...) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(str.size() > 5 && strncmp(str.c_str(),"rgba(",5) == 0 && str[str.size()-1] == ')')
|
||||
{
|
||||
str = HU::Replace(str.substr(5),")","");
|
||||
auto parts = HU::SplitString(str,",");
|
||||
if(parts.size() != 4) return false;
|
||||
try{
|
||||
auto r = std::stoul(parts[0]);
|
||||
auto g = std::stoul(parts[1]);
|
||||
auto b = std::stoul(parts[2]);
|
||||
double a= std::stod(parts[3]);
|
||||
col.r = (Uint8)r;
|
||||
col.g = (Uint8)g;
|
||||
col.b = (Uint8)b;
|
||||
col.a = (Uint8)(a * 255);
|
||||
} catch(...) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
273
src/SDL2/GUI.cpp
273
src/SDL2/GUI.cpp
@@ -1,273 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/GUI.hpp"
|
||||
#include <iostream>
|
||||
#if defined(__SWITCH__)
|
||||
extern "C" {
|
||||
#include <switch.h>
|
||||
}
|
||||
#endif
|
||||
namespace Tesses::Framework::SDL2
|
||||
{
|
||||
GUI gui;
|
||||
void GUI::CloseWindows()
|
||||
{
|
||||
auto wins=this->windows;
|
||||
for(auto win : wins) delete win;
|
||||
this->windows.clear();
|
||||
}
|
||||
void GUI::Update()
|
||||
{
|
||||
if(this->windows.empty()) return;
|
||||
for(auto index = this->windows.begin(); index != this->windows.end(); index++)
|
||||
{
|
||||
if(*index == nullptr)
|
||||
{
|
||||
this->windows.erase(index);
|
||||
index--;
|
||||
}
|
||||
}
|
||||
if(this->windows.empty()) return;
|
||||
|
||||
|
||||
|
||||
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event))
|
||||
{
|
||||
auto windows = this->windows;
|
||||
for(auto& win : windows)
|
||||
{
|
||||
if(win == nullptr) continue;
|
||||
auto id = SDL_GetWindowID(win->window);
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_EventType::SDL_WINDOWEVENT:
|
||||
if(event.window.windowID == id)
|
||||
{
|
||||
if(event.window.event == SDL_WINDOWEVENT_CLOSE)
|
||||
{
|
||||
GUIWindowClosingEventArgs e;
|
||||
e.cancel=false;
|
||||
win->Closing.Invoke(win,e);
|
||||
if(!e.cancel)
|
||||
{
|
||||
delete win;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_FINGERDOWN:
|
||||
case SDL_EventType::SDL_FINGERUP:
|
||||
if(event.tfinger.windowID == id)
|
||||
{
|
||||
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_EventType::SDL_MOUSEBUTTONUP:
|
||||
if(event.button.windowID == id)
|
||||
{
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_MOUSEMOTION:
|
||||
if(event.motion.windowID == id)
|
||||
{
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_MOUSEWHEEL:
|
||||
if(event.wheel.windowID == id)
|
||||
{
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_KEYUP:
|
||||
case SDL_EventType::SDL_KEYDOWN:
|
||||
if(event.key.windowID == id)
|
||||
{
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_TEXTEDITING:
|
||||
if(event.edit.windowID == id)
|
||||
{
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_TEXTEDITING_EXT:
|
||||
if(event.editExt.windowID == id)
|
||||
{
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_TEXTINPUT:
|
||||
if(event.text.windowID == id)
|
||||
{
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
case SDL_EventType::SDL_DROPBEGIN:
|
||||
case SDL_EventType::SDL_DROPCOMPLETE:
|
||||
case SDL_EventType::SDL_DROPFILE:
|
||||
case SDL_EventType::SDL_DROPTEXT:
|
||||
if(event.drop.windowID == id)
|
||||
{
|
||||
win->Event(event);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
win->Event(event);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(event.type == SDL_QUIT)
|
||||
{
|
||||
TF_SetIsRunning(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(auto item : this->windows)
|
||||
{
|
||||
if(item != nullptr)
|
||||
item->Draw();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Clipper::Clipper(SDL_Renderer* renderer, SDL_Rect& myRect)
|
||||
{
|
||||
this->isClipped=SDL_RenderIsClipEnabled(renderer);
|
||||
SDL_RenderGetClipRect(renderer,&this->theRect);
|
||||
if(!this->isClipped) this->theRect = myRect;
|
||||
this->renderer = renderer;
|
||||
}
|
||||
void Clipper::ClipRect(SDL_Rect& child, SDL_Rect& parent)
|
||||
{
|
||||
if(child.x < parent.x)
|
||||
{
|
||||
int rem = parent.x- child.x;
|
||||
child.x += rem;
|
||||
child.w -= rem;
|
||||
}
|
||||
if(child.y < parent.y)
|
||||
{
|
||||
int rem = parent.y- child.y;
|
||||
child.y += rem;
|
||||
child.h -= rem;
|
||||
}
|
||||
|
||||
if((child.x + child.w) > (parent.x + parent.w))
|
||||
child.w = (parent.x + parent.w) - child.x;
|
||||
|
||||
if((child.y + child.h) > (parent.y + parent.h))
|
||||
child.h = (parent.y + parent.h) - child.y;
|
||||
|
||||
}
|
||||
bool Clipper::Clip(SDL_Rect rect)
|
||||
{
|
||||
ClipRect(rect,this->theRect);
|
||||
if(rect.w <= 0 || rect.h <= 0) return false;
|
||||
|
||||
SDL_RenderSetClipRect(renderer, &rect);
|
||||
return true;
|
||||
}
|
||||
Clipper::~Clipper()
|
||||
{
|
||||
if(isClipped) SDL_RenderSetClipRect(renderer, &this->theRect);
|
||||
else SDL_RenderSetClipRect(renderer, nullptr);
|
||||
}
|
||||
|
||||
GUIPalette::GUIPalette()
|
||||
{
|
||||
this->fontSize=24;
|
||||
this->borderSize = 2;
|
||||
}
|
||||
SDL_Color& GUIPalette::GetBorderColor(bool isHovering, bool isActive, bool isMouseDown)
|
||||
{
|
||||
bool isHovering2=isHovering ^ isMouseDown;
|
||||
if(isHovering2 && isActive)
|
||||
return this->borderHoverActive;
|
||||
if(isHovering2)
|
||||
return this->borderHover;
|
||||
if(isActive)
|
||||
return this->borderActive;
|
||||
return this->borderColor;
|
||||
}
|
||||
|
||||
GUIPalette::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,int borderSize)
|
||||
{
|
||||
|
||||
this->accent=accent;
|
||||
this->background = background;
|
||||
this->borderColor=border_color;
|
||||
this->borderHover = border_hover;
|
||||
this->borderActive = border_active;
|
||||
this->borderHoverActive=border_hover_active;
|
||||
this->fontSize = fontSize;
|
||||
this->borderSize = borderSize;
|
||||
}
|
||||
|
||||
std::string GUIEventArgs::Type()
|
||||
{
|
||||
return "Base";
|
||||
}
|
||||
GUIEventArgs::~GUIEventArgs()
|
||||
{
|
||||
|
||||
}
|
||||
std::string GUIMouseButtonEventArgs::Type()
|
||||
{
|
||||
return "MouseButton";
|
||||
}
|
||||
std::string GUIJsonViewNotFoundEventArgs::Type()
|
||||
{
|
||||
return "JsonViewNotFound";
|
||||
}
|
||||
std::string GUISDLEventEventArgs::Type()
|
||||
{
|
||||
return "SDLEvent";
|
||||
}
|
||||
std::string GUIWindowClosingEventArgs::Type()
|
||||
{
|
||||
return "WindowClosing";
|
||||
}
|
||||
|
||||
|
||||
GUIPalette::GUIPalette(bool isDarkMode, SDL_Color accent,int fontSize,int borderSize)
|
||||
{
|
||||
this->accent = accent;
|
||||
this->fontSize = fontSize;
|
||||
this->borderSize = borderSize;
|
||||
|
||||
if(isDarkMode)
|
||||
{
|
||||
this->background = {.r = 42,.g=42,.b=42,.a=255};
|
||||
this->borderColor = {.r=0,.g=0,.b=0,.a=255};
|
||||
this->borderHover = {.r=92,.g=92,.b=92,.a=255};
|
||||
|
||||
this->borderActive = {.r=200,.g=200,.b=200,.a=255};
|
||||
this->borderHoverActive = {.r=(uint8_t)(255-accent.r),.g=(uint8_t)(255-accent.g),.b=(uint8_t)(255-accent.b),.a=255};
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this->background = {.r=239,.g=239,.b=239,.a=255};
|
||||
this->borderColor = {.r=0,.g=0,.b=0,.a=255};
|
||||
|
||||
this->borderActive = {.r=92,.g=92,.b=92,.a=255};
|
||||
|
||||
this->borderHover = {.r=200,.g=200,.b=200,.a=255};
|
||||
|
||||
this->borderHoverActive = {.r=(uint8_t)(255-accent.r),.g=(uint8_t)(255-accent.g),.b=(uint8_t)(255-accent.b),.a=255};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,105 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/GUI.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2 {
|
||||
size_t GUIPopup::ViewCount()
|
||||
{
|
||||
return this->GetView() != nullptr ? 1 : 0;
|
||||
}
|
||||
View* GUIPopup::GetViewAt(size_t index)
|
||||
{
|
||||
if(index > 0) return nullptr;
|
||||
return this->GetView();
|
||||
}
|
||||
GUIPopup::GUIPopup() : GUIPopup(0,0,0,0)
|
||||
{
|
||||
|
||||
}
|
||||
GUIPopup::GUIPopup(SDL_Rect bounds)
|
||||
{
|
||||
this->bounds = bounds;
|
||||
}
|
||||
GUIPopup::GUIPopup(int x, int y,int w, int h)
|
||||
{
|
||||
this->bounds.x = x;
|
||||
this->bounds.y = y;
|
||||
this->bounds.w = w;
|
||||
this->bounds.h = h;
|
||||
}
|
||||
View* GUIContainerPopup::GetView()
|
||||
{
|
||||
return this->child;
|
||||
}
|
||||
GUIContainerPopup::GUIContainerPopup() : GUIPopup()
|
||||
{
|
||||
|
||||
}
|
||||
GUIContainerPopup::GUIContainerPopup(SDL_Rect bounds) : GUIPopup(bounds)
|
||||
{
|
||||
|
||||
}
|
||||
GUIContainerPopup::GUIContainerPopup(int x, int y,int w, int h) : GUIPopup(x,y,w,h)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GUIContainerPopup::SetView(View* view, bool owns)
|
||||
{
|
||||
if(this->ownsChild && this->child != view)
|
||||
delete this->child;
|
||||
this->child = view;
|
||||
this->ownsChild=owns;
|
||||
this->AssignChildParentToThis(view);
|
||||
}
|
||||
GUIContainerPopup::~GUIContainerPopup()
|
||||
{
|
||||
if(this->ownsChild)
|
||||
delete this->child;
|
||||
}
|
||||
GUIPopup::~GUIPopup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GUIPopup::Close()
|
||||
{
|
||||
|
||||
this->closed=true;
|
||||
}
|
||||
bool GUIPopup::IsClosed()
|
||||
{
|
||||
return this->closed;
|
||||
}
|
||||
|
||||
void GUIPopup::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.background.r,win->palette.background.g,win->palette.background.b,win->palette.background.a);
|
||||
SDL_RenderFillRect(renderer,&r);
|
||||
auto view = GetView();
|
||||
if(view != nullptr)
|
||||
CallOnDraw(view,renderer,r);
|
||||
}
|
||||
bool GUIPopup::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
||||
{
|
||||
auto view = GetView();
|
||||
if(view != nullptr)
|
||||
{
|
||||
if(CallOnEvent(view,event,myBounds,myVisibleBounds)) return true;
|
||||
}
|
||||
|
||||
return View::OnEvent(event,myBounds,myVisibleBounds);
|
||||
}
|
||||
|
||||
bool GUIPopup::IsActive()
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
if(win == nullptr) return false;
|
||||
if(win->popups.empty()) return false;
|
||||
|
||||
return win->popups.back() == this;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,772 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/GUI.hpp"
|
||||
#include "TessesFramework/aardvark-fixed-regular.h"
|
||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/ProgressView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/TextListView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/AbsoluteView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/EditTextView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/MultilineEditTextView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/PictureView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/ScrollableTextListView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/HScrollView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/VScrollView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/HStackView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/VStackView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/DropDownView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/TabView.hpp"
|
||||
#include "TessesFramework/SDL2/ParseColor.hpp"
|
||||
|
||||
#if defined(__SWITCH__)
|
||||
extern "C" {
|
||||
#include <switch.h>
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace Tesses::Framework::SDL2
|
||||
{
|
||||
GUIWindow::operator bool()
|
||||
{
|
||||
if(this == nullptr) return false;
|
||||
for(auto item : gui.windows)
|
||||
if(item == this) return true;
|
||||
return false;
|
||||
}
|
||||
void GUIWindow::MakeActive(View* view)
|
||||
{
|
||||
if(!view->GetViewFlag(VIEWFLAG_TABSTOP)) return;
|
||||
if(view->GetViewFlag(VIEWFLAG_ISACTIVE)) return;
|
||||
if(this->popups.empty())
|
||||
DeactivateAll(this);
|
||||
else
|
||||
{
|
||||
DeactivateAll(this->popups.back());
|
||||
}
|
||||
view->SetViewFlag(VIEWFLAG_ISACTIVE,true);
|
||||
}
|
||||
void GUIWindow::DeactivateAll(View* view)
|
||||
{
|
||||
view->SetViewFlag(VIEWFLAG_ISACTIVE,false);
|
||||
auto cv = dynamic_cast<ContainerView*>(view);
|
||||
if(cv != nullptr)
|
||||
{
|
||||
for(size_t i = 0; i < cv->ViewCount();i++)
|
||||
{
|
||||
DeactivateAll(cv->GetViewAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
void GUIWindow::TabNext(View* view,TabNextResult& nr)
|
||||
{
|
||||
if(nr == TabNextResult::Done)
|
||||
return;
|
||||
auto cv = dynamic_cast<ContainerView*>(view);
|
||||
if(cv != nullptr)
|
||||
{
|
||||
for(size_t i = 0; i < cv->ViewCount();i++)
|
||||
{
|
||||
TabNext(cv->GetViewAt(i),nr);
|
||||
if(nr == TabNextResult::Done)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(view->GetViewFlag(VIEWFLAG_ISACTIVE))
|
||||
{
|
||||
if(view->GetViewFlag(VIEWFLAG_INTERCEPT_TAB))
|
||||
{
|
||||
SDL_Rect r;
|
||||
r.x=0;
|
||||
r.y=0;
|
||||
r.w=0;
|
||||
r.h=0;
|
||||
SDL_Event event;
|
||||
event.type = SDL_KEYDOWN;
|
||||
event.key.keysym.mod = SDL_Keymod::KMOD_NONE;
|
||||
event.key.keysym.scancode = SDL_SCANCODE_TAB;
|
||||
event.key.keysym.sym = SDL_KeyCode::SDLK_TAB;
|
||||
view->CallOnEvent(view,event,r,r);
|
||||
nr = TabNextResult::Done;
|
||||
}
|
||||
view->SetViewFlag(VIEWFLAG_ISACTIVE,false);
|
||||
nr= TabNextResult::TabNext;
|
||||
}
|
||||
else if(view->GetViewFlag(VIEWFLAG_TABSTOP) && nr == TabNextResult::TabNext)
|
||||
{
|
||||
view->SetViewFlag(VIEWFLAG_ISACTIVE,true);
|
||||
nr = TabNextResult::Done;
|
||||
}
|
||||
}
|
||||
}
|
||||
void GUIWindow::TabNext()
|
||||
{
|
||||
TabNextResult nr=TabNextResult::KeepGoing;
|
||||
TabNext(this,nr);
|
||||
if(nr != TabNextResult::Done)
|
||||
{
|
||||
nr = TabNextResult::TabNext;
|
||||
TabNext(this,nr);
|
||||
}
|
||||
}
|
||||
|
||||
void GUIWindow::SetView(View* view,bool owns)
|
||||
{
|
||||
if(this->ownsChild && this->child != view)
|
||||
delete this->child;
|
||||
this->child = view;
|
||||
this->ownsChild = owns;
|
||||
if(view != nullptr)
|
||||
view->parent = this;
|
||||
}
|
||||
GUIWindow* GUIWindow::GetWindow()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
size_t GUIWindow::ViewCount()
|
||||
{
|
||||
return this->child != nullptr ? 1 : 0;
|
||||
}
|
||||
View* GUIWindow::GetViewAt(size_t index)
|
||||
{
|
||||
if(index > 0) return nullptr;
|
||||
return this->child;
|
||||
}
|
||||
void GUIWindow::Draw()
|
||||
{
|
||||
int w,h;
|
||||
SDL_GetWindowSize(window,&w,&h);
|
||||
SDL_Rect r={.x=0,.y=0,.w=w,.h=h};
|
||||
OnDraw(renderer,r);
|
||||
}
|
||||
void GUIWindow::Event(SDL_Event& event)
|
||||
{
|
||||
|
||||
int w,h;
|
||||
SDL_GetWindowSize(window,&w,&h);
|
||||
SDL_Rect r={.x=0,.y=0,.w=w,.h=h};
|
||||
OnEvent(event,r,r);
|
||||
}
|
||||
|
||||
void GUIWindow::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer,this->palette.background.r,this->palette.background.g,this->palette.background.b,this->palette.background.a);
|
||||
SDL_RenderClear(renderer);
|
||||
if(this->child != nullptr)
|
||||
this->child->OnDraw(renderer,r);
|
||||
for(auto popup : this->popups)
|
||||
popup->OnDraw(renderer,popup->bounds);
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
bool GUIWindow::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
||||
{
|
||||
|
||||
if(event.type == SDL_EventType::SDL_KEYDOWN && event.key.keysym.sym ==SDL_KeyCode::SDLK_TAB)
|
||||
{
|
||||
GUISDLEventEventArgs sdle;
|
||||
sdle.event = event;
|
||||
this->SDLEvent.Invoke(this,sdle);
|
||||
if(this->popups.empty())
|
||||
TabNext();
|
||||
else
|
||||
{
|
||||
TabNextResult nr=TabNextResult::KeepGoing;
|
||||
TabNext(this->popups.back(),nr);
|
||||
if(nr != TabNextResult::Done)
|
||||
{
|
||||
nr = TabNextResult::TabNext;
|
||||
TabNext(this->popups.back(),nr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if(this->child != nullptr) {
|
||||
GUISDLEventEventArgs sdle;
|
||||
sdle.event = event; this->SDLEvent.Invoke(this,sdle);
|
||||
retry:
|
||||
if(this->popups.empty())
|
||||
return this->child->OnEvent(event,myBounds,myVisibleBounds);
|
||||
else {
|
||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
auto popup = this->popups.back();
|
||||
if(event.button.x >= popup->bounds.x && event.button.x < popup->bounds.x+popup->bounds.w && event.button.y >= popup->bounds.y && event.button.y < popup->bounds.y+popup->bounds.h)
|
||||
{
|
||||
return popup->OnEvent(event,popup->bounds,popup->bounds);
|
||||
}
|
||||
else if(popup->closeIfClickOutside) {
|
||||
popup->closed=true;
|
||||
this->popups.pop_back();
|
||||
goto retry;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
auto popup = this->popups.back();
|
||||
return popup->OnEvent(event,popup->bounds,popup->bounds);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
retry2:
|
||||
if(!this->popups.empty())
|
||||
{
|
||||
|
||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
auto popup = this->popups.back();
|
||||
if(event.button.x >= popup->bounds.x && event.button.x < popup->bounds.x+popup->bounds.w && event.button.y >= popup->bounds.y && event.button.y < popup->bounds.y+popup->bounds.h)
|
||||
{
|
||||
return popup->OnEvent(event,popup->bounds,popup->bounds);
|
||||
}
|
||||
else if(popup->closeIfClickOutside)
|
||||
{
|
||||
popup->closed=true;
|
||||
this->popups.pop_back();
|
||||
goto retry2;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto popup = this->popups.back();
|
||||
return popup->OnEvent(event,popup->bounds,popup->bounds);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return View::OnEvent(event,myBounds,myVisibleBounds);
|
||||
}
|
||||
GUIWindow::GUIWindow(std::string title, int w, int h, Uint32 flags, const GUIPalette& palette) : ContainerView(title)
|
||||
{
|
||||
TF_LOG("About to create window");
|
||||
|
||||
#if defined(__SWITCH__)
|
||||
auto nxwin = nwindowGetDefault();
|
||||
w = (int)nxwin->default_width;
|
||||
h = (int)nxwin->default_height;
|
||||
flags = 0;
|
||||
std::string onSwitch = "On switch: " + std::to_string(w) + "x" + std::to_string(h);
|
||||
TF_LOG(onSwitch);
|
||||
|
||||
#endif
|
||||
|
||||
this->window = SDL_CreateWindow(title.c_str(),SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,w,h,flags);
|
||||
std::string sdl_window_is_null = "SDL_Window is";
|
||||
|
||||
if(this->window != nullptr)
|
||||
sdl_window_is_null.append(" not");
|
||||
|
||||
sdl_window_is_null.append(" null");
|
||||
|
||||
if(this->window == nullptr)
|
||||
{
|
||||
sdl_window_is_null.append(" reason ");
|
||||
sdl_window_is_null.append(SDL_GetError());
|
||||
}
|
||||
|
||||
TF_LOG(sdl_window_is_null);
|
||||
/*#if defined(__SWITCH__) || defined(__PS2__) || defined(GEKKO)
|
||||
|
||||
this->renderer = SDL_CreateRenderer(this->window,-1,SDL_RENDERER_SOFTWARE);
|
||||
#else*/
|
||||
TF_LOG("About to create renderer");
|
||||
this->renderer = SDL_CreateRenderer(this->window,-1,SDL_RENDERER_ACCELERATED);
|
||||
sdl_window_is_null = "SDL_Renderer is";
|
||||
|
||||
if(this->renderer!= nullptr)
|
||||
sdl_window_is_null.append(" not");
|
||||
|
||||
sdl_window_is_null.append(" null");
|
||||
|
||||
if(this->renderer == nullptr)
|
||||
{
|
||||
sdl_window_is_null.append(" reason ");
|
||||
sdl_window_is_null.append(SDL_GetError());
|
||||
}
|
||||
|
||||
TF_LOG(sdl_window_is_null);
|
||||
//#endif
|
||||
SDL_SetRenderDrawBlendMode(renderer,SDL_BlendMode::SDL_BLENDMODE_BLEND);
|
||||
TF_LOG("Renderer blend mode set");
|
||||
this->child=nullptr;
|
||||
this->parent=nullptr;
|
||||
this->ownsChild=false;
|
||||
this->normal_font=nullptr;
|
||||
this->monospaced_font=nullptr;
|
||||
gui.windows.push_back(this);
|
||||
this->SetPalette(palette);
|
||||
}
|
||||
void GUIWindow::SetText(std::string text)
|
||||
{
|
||||
this->text = text;
|
||||
SDL_SetWindowTitle(this->window,text.c_str());
|
||||
}
|
||||
|
||||
void GUIWindow::SetPalette(const GUIPalette& palette)
|
||||
{
|
||||
this->palette = palette;
|
||||
if(this->normal_font != nullptr)
|
||||
delete this->normal_font;
|
||||
if(this->monospaced_font != nullptr)
|
||||
delete this->monospaced_font;
|
||||
this->normal_font = new FontCache(this->renderer,this->palette.fontSize);
|
||||
this->monospaced_font = new FontCache(this->renderer,AARDVARKFIXEDREGULAR,AARDVARKFIXEDREGULAR_SIZE,this->palette.fontSize);
|
||||
}
|
||||
|
||||
GUIWindow::~GUIWindow()
|
||||
{
|
||||
if(this->ownsChild)
|
||||
delete this->child;
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
for(auto index = gui.windows.begin(); index < gui.windows.end(); index++)
|
||||
{
|
||||
if(*index == this)
|
||||
{
|
||||
*index = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GUIWindow::ShowPopup(GUIPopup* popup)
|
||||
{
|
||||
popup->closed=false;
|
||||
bool has = false;
|
||||
for(auto item : this->popups)
|
||||
if(item == popup) { has=true; break;}
|
||||
if(!has)
|
||||
this->popups.push_back(popup);
|
||||
|
||||
|
||||
|
||||
AssignChildParentToThis(popup);
|
||||
|
||||
auto v = popup->GetView();
|
||||
if(v != nullptr) this->MakeActive(v);
|
||||
|
||||
while(!popup->IsClosed() && TF_IsRunning())
|
||||
{
|
||||
TF_RunEventLoopItteration();
|
||||
}
|
||||
if(!this->popups.empty() && this->popups.back() == popup)
|
||||
this->popups.pop_back();
|
||||
popup->closed=true;
|
||||
}
|
||||
void GUIWindow::ShowPopup(GUIPopup& popup)
|
||||
{
|
||||
ShowPopup(&popup);
|
||||
}
|
||||
|
||||
void GUIWindow::SetView(Tesses::Framework::Serialization::Json::JToken item)
|
||||
{
|
||||
Tesses::Framework::Serialization::Json::JObject dict;
|
||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
||||
{
|
||||
Tesses::Framework::Serialization::Json::JObject o;
|
||||
Tesses::Framework::Serialization::Json::JObject sz;
|
||||
Tesses::Framework::Serialization::Json::JObject pal0;
|
||||
std::string title;
|
||||
if(dict.TryGetValueAsType("Child",o))
|
||||
{
|
||||
this->SetView(CreateViewFromJson(o));
|
||||
}
|
||||
if(dict.TryGetValueAsType("Size",sz))
|
||||
{
|
||||
int w0,h0;
|
||||
|
||||
|
||||
SDL_GetWindowSize(this->window,&w0,&h0);
|
||||
int64_t w=w0;
|
||||
int64_t h=h0;
|
||||
|
||||
sz.TryGetValueAsType("Width",w);
|
||||
sz.TryGetValueAsType("Height",h);
|
||||
|
||||
SDL_SetWindowSize(this->window,(int)w,(int)h);
|
||||
}
|
||||
if(dict.TryGetValueAsType("Palette",pal0))
|
||||
{
|
||||
bool darkMode=true;
|
||||
SDL_Color accent={.r=255,.g=0,.b=0,.a=255};
|
||||
std::string _str;
|
||||
int64_t fontSize=20;
|
||||
|
||||
pal0.TryGetValueAsType("IsDarkMode",darkMode);
|
||||
pal0.TryGetValueAsType("FontSize",fontSize);
|
||||
if(pal0.TryGetValueAsType("Accent",_str))
|
||||
TryParseSDLColor(_str,accent);
|
||||
|
||||
GUIPalette pal(darkMode,accent,fontSize);
|
||||
if(pal0.TryGetValueAsType("Background",_str))
|
||||
TryParseSDLColor(_str,pal.background);
|
||||
if(pal0.TryGetValueAsType("Border",_str))
|
||||
TryParseSDLColor(_str,pal.borderColor);
|
||||
if(pal0.TryGetValueAsType("BorderActive",_str))
|
||||
TryParseSDLColor(_str,pal.borderActive);
|
||||
if(pal0.TryGetValueAsType("BorderHover",_str))
|
||||
TryParseSDLColor(_str,pal.borderHover);
|
||||
if(pal0.TryGetValueAsType("BorderHoverActive",_str))
|
||||
TryParseSDLColor(_str,pal.borderHoverActive);
|
||||
this->SetPalette(pal);
|
||||
}
|
||||
if(dict.TryGetValueAsType("Title",title) || dict.TryGetValueAsType("Text",title))
|
||||
{
|
||||
this->SetText(title);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_Window* GUIWindow::GetSDLWindow()
|
||||
{
|
||||
return this->window;
|
||||
}
|
||||
SDL_Renderer* GUIWindow::GetSDLRenderer()
|
||||
{
|
||||
return this->renderer;
|
||||
}
|
||||
|
||||
static int szStr2size(std::string sz)
|
||||
{
|
||||
if(sz.empty()) return GUI_MIN;
|
||||
if(sz == "min") return GUI_MIN;
|
||||
if(sz == "*") return GUI_EXPAND;
|
||||
if(sz[0] == '*') {
|
||||
return GUI_EXPAND_N(std::stoi(sz.substr(1)));
|
||||
}
|
||||
else {
|
||||
return std::stoi(sz);
|
||||
}
|
||||
}
|
||||
|
||||
View* GUIWindow::CreateViewFromJson(Tesses::Framework::Serialization::Json::JObject json)
|
||||
{
|
||||
std::string type;
|
||||
if(json.TryGetValueAsType("Type",type))
|
||||
{
|
||||
std::string id={};
|
||||
std::string text={};
|
||||
bool active=false;
|
||||
json.TryGetValueAsType("Id",id);
|
||||
json.TryGetValueAsType("Text",text);
|
||||
json.TryGetValueAsType("Active",active);
|
||||
if(type == "ButtonView")
|
||||
{
|
||||
auto btn = new Views::ButtonView(text);
|
||||
btn->SetId(id);
|
||||
btn->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
||||
return btn;
|
||||
}
|
||||
else if(type == "CheckView")
|
||||
{
|
||||
bool checked;
|
||||
json.TryGetValueAsType("Checked",checked);
|
||||
auto cv = new Views::CheckView(checked,text);
|
||||
cv->SetId(id);
|
||||
|
||||
cv->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
||||
return cv;
|
||||
}
|
||||
else if(type == "LabelView")
|
||||
{
|
||||
auto lv = new Views::LabelView(text);
|
||||
lv->SetId(id);
|
||||
return lv;
|
||||
}
|
||||
else if(type == "ProgressView")
|
||||
{
|
||||
double v=0;
|
||||
json.TryGetValueAsType("Value",v);
|
||||
auto pv = new Views::ProgressView(v);
|
||||
pv->SetId(id);
|
||||
return pv;
|
||||
}
|
||||
else if(type == "TextListView")
|
||||
{
|
||||
std::vector<std::string> items;
|
||||
Tesses::Framework::Serialization::Json::JArray arr;
|
||||
if(json.TryGetValueAsType("Items",arr))
|
||||
{
|
||||
std::string str;
|
||||
for(auto item : arr)
|
||||
{
|
||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,str)) items.push_back(str);
|
||||
}
|
||||
}
|
||||
int64_t index=-1;
|
||||
int64_t first=0;
|
||||
json.TryGetValueAsType("SelectedIndex",index);
|
||||
json.TryGetValueAsType("FirstIndex",first);
|
||||
|
||||
auto tlv = new Views::TextListView();
|
||||
|
||||
tlv->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
||||
tlv->SetId(id);
|
||||
tlv->items = items;
|
||||
tlv->firstIndex = (size_t)first;
|
||||
tlv->selected = (int)index;
|
||||
return tlv;
|
||||
}
|
||||
else if(type == "ScrollableTextListView")
|
||||
{
|
||||
std::vector<std::string> items;
|
||||
Tesses::Framework::Serialization::Json::JArray arr;
|
||||
if(json.TryGetValueAsType("Items",arr))
|
||||
{
|
||||
std::string str;
|
||||
for(auto item : arr)
|
||||
{
|
||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,str)) items.push_back(str);
|
||||
}
|
||||
}
|
||||
int64_t index=-1;
|
||||
int64_t first=0;
|
||||
json.TryGetValueAsType("SelectedIndex",index);
|
||||
json.TryGetValueAsType("FirstIndex",first);
|
||||
|
||||
auto tlv = new Views::ScrollableTextListView();
|
||||
|
||||
tlv->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
||||
tlv->SetId(id);
|
||||
tlv->items = items;
|
||||
tlv->firstIndex = (size_t)first;
|
||||
tlv->selected = (int)index;
|
||||
return tlv;
|
||||
}
|
||||
|
||||
else if(type == "AbsoluteView")
|
||||
{
|
||||
auto av = new Views::AbsoluteView();
|
||||
av->SetId(id);
|
||||
Tesses::Framework::Serialization::Json::JArray arr;
|
||||
if(json.TryGetValueAsType("Items",arr))
|
||||
{
|
||||
for(auto item : arr)
|
||||
{
|
||||
Tesses::Framework::Serialization::Json::JObject dict;
|
||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
||||
{
|
||||
Tesses::Framework::Serialization::Json::JObject boundsDict;
|
||||
SDL_Rect r={.x=0,.y=0,.w=200,.h=200};
|
||||
|
||||
if(dict.TryGetValueAsType("Bounds",boundsDict))
|
||||
{
|
||||
int64_t n;
|
||||
if(boundsDict.TryGetValueAsType("X",n)) r.x = (int)n;
|
||||
if(boundsDict.TryGetValueAsType("Y",n)) r.y = (int)n;
|
||||
if(boundsDict.TryGetValueAsType("Width",n)) r.w = (int)n;
|
||||
if(boundsDict.TryGetValueAsType("Height",n)) r.h = (int)n;
|
||||
}
|
||||
|
||||
auto myO = CreateViewFromJson(dict);
|
||||
if(myO != nullptr)
|
||||
{
|
||||
av->Add(r,myO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return av;
|
||||
}
|
||||
else if(type == "EditTextView")
|
||||
{
|
||||
auto etv = new Views::EditTextView();
|
||||
etv->SetId(id);
|
||||
etv->SetText(text);
|
||||
std::string hint;
|
||||
json.TryGetValueAsType("Hint",hint);
|
||||
etv->SetHint(hint);
|
||||
return etv;
|
||||
}
|
||||
else if(type == "MultilineEditTextView")
|
||||
{
|
||||
auto etv = new Views::MultilineEditTextView();
|
||||
etv->SetId(id);
|
||||
etv->SetText(text);
|
||||
std::string hint;
|
||||
json.TryGetValueAsType("Hint",hint);
|
||||
etv->SetHint(hint);
|
||||
return etv;
|
||||
}
|
||||
|
||||
else if(type == "PictureView")
|
||||
{
|
||||
auto pv = new Views::PictureView();
|
||||
pv->SetId(id);
|
||||
return pv;
|
||||
}
|
||||
else if(type == "DropDownView")
|
||||
{
|
||||
std::vector<std::string> items;
|
||||
Tesses::Framework::Serialization::Json::JArray arr;
|
||||
if(json.TryGetValueAsType("Items",arr))
|
||||
{
|
||||
std::string str;
|
||||
for(auto item : arr)
|
||||
{
|
||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,str)) items.push_back(str);
|
||||
}
|
||||
}
|
||||
int64_t index=-1;
|
||||
int64_t first=0;
|
||||
json.TryGetValueAsType("SelectedIndex",index);
|
||||
|
||||
auto tlv = new Views::DropDownView();
|
||||
|
||||
tlv->SetViewFlag(VIEWFLAG_ISACTIVE,active);
|
||||
tlv->SetId(id);
|
||||
tlv->GetItems() = items;
|
||||
|
||||
tlv->SetIndex((int)index);
|
||||
return tlv;
|
||||
}
|
||||
else if(type == "VScrollView")
|
||||
{
|
||||
int64_t value=0;
|
||||
int64_t min = 0;
|
||||
int64_t max = 10;
|
||||
json.TryGetValueAsType("Value",value);
|
||||
|
||||
json.TryGetValueAsType("Min",min);
|
||||
|
||||
json.TryGetValueAsType("Max",max);
|
||||
auto vscroll=new Views::VScrollView();
|
||||
vscroll->value = (uint64_t)value;
|
||||
vscroll->min = (uint64_t)min;
|
||||
vscroll->max = (uint64_t)max;
|
||||
vscroll->SetId(id);
|
||||
return vscroll;
|
||||
}
|
||||
else if(type == "HScrollView")
|
||||
{
|
||||
int64_t value=0;
|
||||
int64_t min = 0;
|
||||
int64_t max = 10;
|
||||
json.TryGetValueAsType("Value",value);
|
||||
|
||||
json.TryGetValueAsType("Min",min);
|
||||
|
||||
json.TryGetValueAsType("Max",max);
|
||||
auto hscroll=new Views::VScrollView();
|
||||
hscroll->value = (uint64_t)value;
|
||||
hscroll->min = (uint64_t)min;
|
||||
hscroll->max = (uint64_t)max;
|
||||
hscroll->SetId(id);
|
||||
return hscroll;
|
||||
}
|
||||
else if(type == "VStackView")
|
||||
{
|
||||
auto sv = new Views::VStackView();
|
||||
sv->SetId(id);
|
||||
Tesses::Framework::Serialization::Json::JArray arr;
|
||||
if(json.TryGetValueAsType("Items",arr))
|
||||
{
|
||||
for(auto item : arr)
|
||||
{
|
||||
Tesses::Framework::Serialization::Json::JObject dict;
|
||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
||||
{
|
||||
std::string n="min";
|
||||
|
||||
dict.TryGetValueAsType("Size",n);
|
||||
|
||||
|
||||
auto myO = CreateViewFromJson(dict);
|
||||
if(myO != nullptr)
|
||||
{
|
||||
sv->Add(szStr2size(n),myO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sv;
|
||||
}
|
||||
else if(type == "HStackView")
|
||||
{
|
||||
auto sv = new Views::HStackView();
|
||||
sv->SetId(id);
|
||||
Tesses::Framework::Serialization::Json::JArray arr;
|
||||
if(json.TryGetValueAsType("Items",arr))
|
||||
{
|
||||
for(auto item : arr)
|
||||
{
|
||||
Tesses::Framework::Serialization::Json::JObject dict;
|
||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
||||
{
|
||||
std::string n="min";
|
||||
|
||||
dict.TryGetValueAsType("Size",n);
|
||||
|
||||
|
||||
auto myO = CreateViewFromJson(dict);
|
||||
if(myO != nullptr)
|
||||
{
|
||||
sv->Add(szStr2size(n),myO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return sv;
|
||||
}
|
||||
else if(type == "TabView")
|
||||
{
|
||||
//Item.TabLabel
|
||||
auto tv = new Views::TabView();
|
||||
tv->SetId(id);
|
||||
int64_t firstTab=0;
|
||||
int64_t curTab=0;
|
||||
bool tabsVisible=true;
|
||||
|
||||
json.TryGetValueAsType("SelectedTab",curTab);
|
||||
|
||||
json.TryGetValueAsType("FirstTab",firstTab);
|
||||
json.TryGetValueAsType("TabsVisible", tabsVisible);
|
||||
|
||||
tv->firstTab = (int64_t)firstTab;
|
||||
tv->selectedTab = (int64_t)curTab;
|
||||
tv->tabsVisible=tabsVisible;
|
||||
|
||||
|
||||
Tesses::Framework::Serialization::Json::JArray arr;
|
||||
|
||||
if(json.TryGetValueAsType("Items",arr))
|
||||
{
|
||||
for(auto item : arr)
|
||||
{
|
||||
Tesses::Framework::Serialization::Json::JObject dict;
|
||||
if(Tesses::Framework::Serialization::Json::TryGetJToken(item,dict))
|
||||
{
|
||||
std::string n="";
|
||||
|
||||
dict.TryGetValueAsType("TabText",n);
|
||||
|
||||
|
||||
auto myO = CreateViewFromJson(dict);
|
||||
if(myO != nullptr)
|
||||
{
|
||||
tv->AddTab(n,myO,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return tv;
|
||||
}
|
||||
else {
|
||||
GUIJsonViewNotFoundEventArgs e;
|
||||
e.destView = nullptr;
|
||||
e.jsonObject = json;
|
||||
e.typeString = type;
|
||||
|
||||
JsonViewNotFound.Invoke(this,e);
|
||||
|
||||
return e.destView;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,77 +0,0 @@
|
||||
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
|
||||
#include "TessesFramework/SDL2/Stream.hpp"
|
||||
namespace Tesses::Framework::SDL2 {
|
||||
|
||||
static SDLCALL size_t rwops_stream_read(struct SDL_RWops * context, void *ptr,
|
||||
size_t size, size_t maxnum)
|
||||
{
|
||||
if(context->hidden.unknown.data1 == nullptr) return 0;
|
||||
auto ctx = static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
||||
if(ctx->CanRead())
|
||||
return ctx->Read((uint8_t*)ptr,size*maxnum) / size;
|
||||
return 0;
|
||||
}
|
||||
static SDLCALL size_t rwops_stream_write(struct SDL_RWops * context, const void *ptr,
|
||||
size_t size, size_t maxnum)
|
||||
{
|
||||
if(context->hidden.unknown.data1 == nullptr) return 0;
|
||||
auto ctx = static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
||||
if(ctx->CanWrite())
|
||||
return ctx->Write((const uint8_t*)ptr,size*maxnum) / size;
|
||||
return 0;
|
||||
}
|
||||
static SDLCALL Sint64 rwops_stream_seek(struct SDL_RWops * context, Sint64 offset,
|
||||
int whence)
|
||||
{
|
||||
|
||||
if(context->hidden.unknown.data1 == nullptr) return -1;
|
||||
auto ctx = static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
||||
if(!ctx->CanSeek()) return -1;
|
||||
|
||||
switch(whence)
|
||||
{
|
||||
case RW_SEEK_SET:
|
||||
ctx->Seek(offset,Tesses::Framework::Streams::SeekOrigin::Begin);
|
||||
break;
|
||||
case RW_SEEK_CUR:
|
||||
ctx->Seek(offset,Tesses::Framework::Streams::SeekOrigin::Current);
|
||||
break;
|
||||
case RW_SEEK_END:
|
||||
ctx->Seek(offset,Tesses::Framework::Streams::SeekOrigin::End);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return ctx->GetPosition();
|
||||
}
|
||||
static SDLCALL Sint64 rwops_stream_size(struct SDL_RWops * context)
|
||||
{
|
||||
if(context->hidden.unknown.data1 == nullptr) return -1;
|
||||
auto ctx = static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
||||
return ctx->GetLength();
|
||||
}
|
||||
static SDLCALL int rwops_stream_close(struct SDL_RWops* context)
|
||||
{
|
||||
if(context->hidden.unknown.data2 == nullptr) return 0;
|
||||
delete static_cast<Tesses::Framework::Streams::Stream*>(context->hidden.unknown.data1);
|
||||
return 0;
|
||||
}
|
||||
SDL_RWops* RwopsFromStream(Tesses::Framework::Streams::Stream* strm, bool owns)
|
||||
{
|
||||
auto rw=SDL_AllocRW();
|
||||
rw->type = SDL_RWOPS_UNKNOWN;
|
||||
rw->hidden.unknown.data1 = static_cast<void*>(strm);
|
||||
rw->hidden.unknown.data2 = (void*)(uintptr_t)(owns?1:0);
|
||||
rw->read = rwops_stream_read;
|
||||
rw->write = rwops_stream_write;
|
||||
rw->seek = rwops_stream_seek;
|
||||
rw->size = rwops_stream_size;
|
||||
rw->close = rwops_stream_close;
|
||||
|
||||
|
||||
return rw;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,209 +0,0 @@
|
||||
#include "TessesFramework/SDL2/GUI.hpp"
|
||||
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
||||
namespace Tesses::Framework::SDL2
|
||||
{
|
||||
ContainerView::ContainerView() : View()
|
||||
{
|
||||
this->flags = 0;
|
||||
}
|
||||
ContainerView::ContainerView(std::string text) : View(text)
|
||||
{
|
||||
this->flags = 0;
|
||||
}
|
||||
View::View() : View((std::string){})
|
||||
{
|
||||
|
||||
}
|
||||
View::View(std::string text)
|
||||
{
|
||||
this->text = text;
|
||||
this->flags=VIEWFLAG_TABSTOP;
|
||||
}
|
||||
void View::SetText(std::string text)
|
||||
{
|
||||
this->text=text;
|
||||
}
|
||||
std::string View::GetText()
|
||||
{
|
||||
return this->text;
|
||||
}
|
||||
void View::OnMouseUp(GUIMouseButtonEventArgs& click)
|
||||
{
|
||||
|
||||
}
|
||||
void View::OnMouseDown(GUIMouseButtonEventArgs& click)
|
||||
{
|
||||
|
||||
}
|
||||
void View::OnClick(GUIEventArgs& click)
|
||||
{
|
||||
|
||||
}
|
||||
GUIWindow* View::GetWindow()
|
||||
{
|
||||
if(this->parent ==nullptr) return nullptr;
|
||||
return this->parent->GetWindow();
|
||||
}
|
||||
void View::OnDragDropFile(Tesses::Framework::Filesystem::VFSPath filePath,SDL_Rect myRect, SDL_Point dropLoc)
|
||||
{
|
||||
|
||||
}
|
||||
void View::OnDragDropText(std::string text,SDL_Rect myRect, SDL_Point dropLoc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void View::OnEnter(GUIEventArgs& evt)
|
||||
{
|
||||
|
||||
}
|
||||
void View::OnLeave(GUIEventArgs& evt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void View::OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect)
|
||||
{
|
||||
|
||||
}
|
||||
void View::OnSetParent(View* v)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool View::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
||||
{
|
||||
GUISDLEventEventArgs sdle;
|
||||
sdle.event = event;
|
||||
this->SDLEvent.Invoke(this,sdle);
|
||||
if(event.type == SDL_FINGERUP)
|
||||
{
|
||||
auto cord = this->GetCordFromEvent(event);
|
||||
if(cord.first >= myVisibleBounds.x && cord.first < myVisibleBounds.x+myVisibleBounds.w && cord.second >= myVisibleBounds.y && cord.second < myVisibleBounds.y+myVisibleBounds.h) {
|
||||
GUIEventArgs cea2;
|
||||
OnClick(cea2);
|
||||
this->Click.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
if(event.button.x >= myVisibleBounds.x && event.button.x < myVisibleBounds.x+myVisibleBounds.w && event.button.y >= myVisibleBounds.y && event.button.y < myVisibleBounds.y+myVisibleBounds.h)
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,true);
|
||||
OnMouseDown(cea);
|
||||
this->MouseDown.Invoke(this,cea);
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,false);
|
||||
OnMouseUp(cea);
|
||||
this->MouseUp.Invoke(this,cea);
|
||||
GUIEventArgs cea2;
|
||||
OnClick(cea2);
|
||||
this->Click.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else if(event.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
bool inside = event.motion.x >= myVisibleBounds.x && event.motion.x < myVisibleBounds.x+myVisibleBounds.w && event.motion.y >= myVisibleBounds.y && event.motion.y < myVisibleBounds.y+myVisibleBounds.h;
|
||||
bool hoverFlag = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
if(inside && !hoverFlag)
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
||||
GUIEventArgs e;
|
||||
this->OnEnter(e);
|
||||
this->Enter.Invoke(this,e);
|
||||
}
|
||||
else if(!inside && hoverFlag)
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
GUIEventArgs e;
|
||||
this->OnLeave(e);
|
||||
this->Leave.Invoke(this,e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::string View::GetId()
|
||||
{
|
||||
return this->id;
|
||||
}
|
||||
void View::SetId(std::string id)
|
||||
{
|
||||
this->id = id;
|
||||
}
|
||||
View* View::FindViewById(std::string id)
|
||||
{
|
||||
if(this->GetId() == id) return this;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
View* ContainerView::FindViewById(std::string id)
|
||||
{
|
||||
if(this->GetId() == id) return this;
|
||||
for(size_t i = 0; i <this->ViewCount(); i++)
|
||||
{
|
||||
auto v = this->GetViewAt(i);
|
||||
auto v2 = v->FindViewById(id);
|
||||
if(v2 != nullptr) return v2;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
std::pair<int,int> View::PreferedMinSize()
|
||||
{
|
||||
return std::pair<int,int>(-1,-1);
|
||||
}
|
||||
|
||||
std::pair<int,int> View::GetCordFromEvent(SDL_Event& event)
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
return std::pair<int,int>(event.button.x,event.button.y);
|
||||
break;
|
||||
case SDL_FINGERUP:
|
||||
case SDL_FINGERDOWN:
|
||||
{
|
||||
GUIWindow* win = this->GetWindow();
|
||||
int w,h;
|
||||
SDL_GetWindowSize(win->window,&w,&h);
|
||||
return std::pair<int,int>(w*event.tfinger.x,h*event.tfinger.y);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return std::pair<int,int>(-1,-1);
|
||||
|
||||
}
|
||||
|
||||
View::~View()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,109 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/AbsoluteView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
void AbsoluteView::OnDraw(SDL_Renderer* renderer, SDL_Rect& myRect)
|
||||
{
|
||||
Clipper clipper(renderer,myRect);
|
||||
SDL_Rect oldClip;
|
||||
bool isClipped=SDL_RenderIsClipEnabled(renderer);
|
||||
SDL_RenderGetClipRect(renderer,&oldClip);
|
||||
if(!isClipped) oldClip = myRect;
|
||||
|
||||
for(auto& ctrl : this->views)
|
||||
{
|
||||
SDL_Rect childRect = ctrl.second;
|
||||
childRect.x += oldClip.x;
|
||||
childRect.y += oldClip.y;
|
||||
|
||||
|
||||
if(clipper.Clip(childRect))
|
||||
CallOnDraw(ctrl.first.first,renderer,childRect);
|
||||
}
|
||||
|
||||
}
|
||||
bool AbsoluteView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
bool handled=false;
|
||||
|
||||
for(auto& item : this->views)
|
||||
{
|
||||
SDL_Rect theirBounds = item.second;
|
||||
theirBounds.x += myBounds.x;
|
||||
theirBounds.y += myBounds.y;
|
||||
|
||||
SDL_Rect theirVisibleBounds = item.second;
|
||||
theirVisibleBounds.x += visibleBounds.x;
|
||||
theirVisibleBounds.y += visibleBounds.y;
|
||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
||||
|
||||
|
||||
if(CallOnEvent(item.first.first,event,theirBounds, theirVisibleBounds))
|
||||
handled=true;
|
||||
if(handled && event.type != SDL_MOUSEBUTTONUP && event.type != SDL_MOUSEMOTION && event.type != SDL_FINGERUP)
|
||||
{
|
||||
GUISDLEventEventArgs sdle;
|
||||
sdle.event = event; this->SDLEvent.Invoke(this,sdle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(handled) {GUISDLEventEventArgs sdle;
|
||||
sdle.event = event; this->SDLEvent.Invoke(this,sdle);return true;}
|
||||
return View::OnEvent(event,myBounds,visibleBounds);
|
||||
}
|
||||
size_t AbsoluteView::ViewCount()
|
||||
{
|
||||
return this->views.size();
|
||||
}
|
||||
View* AbsoluteView::GetViewAt(size_t index)
|
||||
{
|
||||
return this->views.at(index).first.first;
|
||||
}
|
||||
AbsoluteView::AbsoluteView() : ContainerView()
|
||||
{
|
||||
|
||||
}
|
||||
void AbsoluteView::Add(SDL_Rect rect, View* view, bool owns)
|
||||
{
|
||||
for(auto& item : this->views)
|
||||
{
|
||||
if(item.first.first == view) return;
|
||||
}
|
||||
this->AssignChildParentToThis(view);
|
||||
this->views.push_back(std::pair<std::pair<View*,bool>,SDL_Rect>(std::pair<View*,bool>(view,owns),rect));
|
||||
}
|
||||
void AbsoluteView::Set(View* view, SDL_Rect rect)
|
||||
{
|
||||
for(auto& item : this->views)
|
||||
{
|
||||
if(item.first.first == view)
|
||||
{
|
||||
item.second = rect;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void AbsoluteView::Remove(View* view)
|
||||
{
|
||||
for(auto index = this->views.begin(); index != this->views.end(); index++)
|
||||
{
|
||||
if(index->first.first == view)
|
||||
{
|
||||
if(index->first.second) delete index->first.first;
|
||||
this->views.erase(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
AbsoluteView::~AbsoluteView()
|
||||
{
|
||||
for(auto& item : this->views)
|
||||
{
|
||||
if(item.first.second) delete item.first.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/ButtonView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
ButtonView::ButtonView() : View()
|
||||
{
|
||||
|
||||
}
|
||||
ButtonView::ButtonView(std::string text) : View(text)
|
||||
{
|
||||
|
||||
}
|
||||
std::pair<int,int> ButtonView::PreferedMinSize()
|
||||
{
|
||||
int w=-2;
|
||||
int h=-2;
|
||||
|
||||
auto win = GetWindow();
|
||||
if(win != nullptr)
|
||||
{
|
||||
win->normal_font->CalculateSize(text,w,h);
|
||||
|
||||
w += win->palette.borderSize*3;
|
||||
|
||||
h += win->palette.borderSize*3;
|
||||
}
|
||||
return std::pair<int,int>(w,h);
|
||||
}
|
||||
bool ButtonView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
||||
{
|
||||
if(event.type == SDL_KEYUP)
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDL_KeyCode::SDLK_SPACE:
|
||||
{
|
||||
GUIEventArgs e;
|
||||
this->OnClick(e);
|
||||
this->Click.Invoke(this,e);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
if(event.button.x >= myVisibleBounds.x && event.button.x < myVisibleBounds.x+myVisibleBounds.w && event.button.y >= myVisibleBounds.y && event.button.y < myVisibleBounds.y+myVisibleBounds.h)
|
||||
{
|
||||
this->GetWindow()->MakeActive(this);
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_FINGERUP)
|
||||
{
|
||||
auto pos = this->GetCordFromEvent(event);
|
||||
if(pos.first >= myVisibleBounds.x && pos.first < myVisibleBounds.x+myVisibleBounds.w && pos.second >= myVisibleBounds.y && pos.second < myVisibleBounds.y+myVisibleBounds.h)
|
||||
{
|
||||
this->GetWindow()->MakeActive(this);
|
||||
}
|
||||
}
|
||||
return View::OnEvent(event,myBounds,myVisibleBounds);
|
||||
}
|
||||
void ButtonView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
SDL_RenderFillRect(renderer,&r);
|
||||
int textW;
|
||||
int textH;
|
||||
win->normal_font->CalculateSize(this->text,textW,textH);
|
||||
|
||||
int x=(r.w/2)-(textW/2);
|
||||
int y=(r.h/2)-(textH/2);
|
||||
x+=r.x;
|
||||
y+=r.y;
|
||||
|
||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
||||
|
||||
win->normal_font->Render(renderer,x,y,this->text,color);
|
||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
||||
|
||||
SDL_Rect r2={.x=r.x,.y=r.y,.w=r.w,.h=r.h};
|
||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawRect(renderer,&r2);
|
||||
r2.x++;
|
||||
r2.y++;
|
||||
r2.w-=2;
|
||||
r2.h-=2;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,134 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/CheckView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
void CheckView::OnCheckChanged(GUIEventArgs& event)
|
||||
{
|
||||
|
||||
}
|
||||
void CheckView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
|
||||
const int checkSz=32;
|
||||
|
||||
SDL_Rect checkBoxRect={.x=r.x,.y=r.y+((r.h/2)-(checkSz/2)),.w=checkSz,.h=checkSz};
|
||||
|
||||
int textW;
|
||||
int textH;
|
||||
win->normal_font->CalculateSize(this->text,textW,textH);
|
||||
|
||||
//we only need the y
|
||||
|
||||
int x = r.x+checkSz+(win->palette.borderSize*2);
|
||||
int y = r.y+((r.h/2)-(textH/2));
|
||||
|
||||
win->normal_font->Render(renderer,x,y,text,win->palette.accent);
|
||||
|
||||
|
||||
|
||||
if(this->GetViewFlag(VIEWFLAG_CHECKED))
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
|
||||
//x=0,y=0.5, x=0.5, y=1
|
||||
|
||||
int x1=checkBoxRect.x+win->palette.borderSize;
|
||||
int y1=checkBoxRect.y+win->palette.borderSize+((checkSz-(win->palette.borderSize*2))/2);
|
||||
int x2=checkBoxRect.x+win->palette.borderSize+((checkSz-(win->palette.borderSize*2))/2);
|
||||
int y2=checkBoxRect.y+win->palette.borderSize+(checkSz-(win->palette.borderSize*8));
|
||||
|
||||
int x3=checkBoxRect.x+win->palette.borderSize+(checkSz-(win->palette.borderSize*2));
|
||||
int y3=checkBoxRect.y+win->palette.borderSize;
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,x1,y1-i,x2,y2-i);
|
||||
SDL_RenderDrawLine(renderer,x2-i,y2,x3-i,y3);
|
||||
}
|
||||
}
|
||||
|
||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
SDL_RenderDrawRect(renderer,&checkBoxRect);
|
||||
checkBoxRect.x++;
|
||||
checkBoxRect.y++;
|
||||
checkBoxRect.w-=2;
|
||||
checkBoxRect.h-=2;
|
||||
}
|
||||
}
|
||||
bool CheckView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
||||
{
|
||||
if(event.type == SDL_KEYUP)
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDL_KeyCode::SDLK_SPACE:
|
||||
{
|
||||
GUIEventArgs e;
|
||||
|
||||
this->SetViewFlag(VIEWFLAG_CHECKED,!this->GetViewFlag(VIEWFLAG_CHECKED));
|
||||
this->OnClick(e);
|
||||
this->Click.Invoke(this,e);
|
||||
this->OnCheckChanged(e);
|
||||
this->CheckChanged.Invoke(this,e);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_FINGERUP)
|
||||
{
|
||||
auto pos = this->GetCordFromEvent(event);
|
||||
if(pos.first >= visibleBounds.x && pos.first < visibleBounds.x+visibleBounds.w && pos.second >= visibleBounds.y && pos.second < visibleBounds.y+visibleBounds.h)
|
||||
{
|
||||
this->GetWindow()->MakeActive(this);
|
||||
this->SetViewFlag(VIEWFLAG_CHECKED,!this->GetViewFlag(VIEWFLAG_CHECKED));
|
||||
GUIEventArgs e;
|
||||
this->OnCheckChanged(e);
|
||||
this->CheckChanged.Invoke(this,e);
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
||||
{
|
||||
this->GetWindow()->MakeActive(this);
|
||||
this->SetViewFlag(VIEWFLAG_CHECKED,!this->GetViewFlag(VIEWFLAG_CHECKED));
|
||||
GUIEventArgs e;
|
||||
this->OnCheckChanged(e);
|
||||
this->CheckChanged.Invoke(this,e);
|
||||
}
|
||||
}
|
||||
return View::OnEvent(event,myBounds,visibleBounds);
|
||||
}
|
||||
|
||||
CheckView::CheckView(bool checked, std::string label) : View(label)
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_CHECKED,checked);
|
||||
}
|
||||
CheckView::CheckView() : View()
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_CHECKED,false);
|
||||
}
|
||||
|
||||
bool CheckView::GetChecked()
|
||||
{
|
||||
return this->GetViewFlag(VIEWFLAG_CHECKED);
|
||||
}
|
||||
void CheckView::SetChecked(bool value)
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_CHECKED,true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,114 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/DropDownView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views {
|
||||
|
||||
void DropDownView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
std::string text = this->text;
|
||||
if(this->listView.selected > -1 && this->listView.selected < this->listView.items.size())
|
||||
{
|
||||
text = this->listView.items[this->listView.selected];
|
||||
}
|
||||
auto win = this->GetWindow();
|
||||
|
||||
int textW;
|
||||
int textH;
|
||||
win->normal_font->CalculateSize(text,textW,textH);
|
||||
|
||||
int x=win->palette.borderSize*2;
|
||||
int y=(r.h/2)-(textH/2);
|
||||
x+=r.x;
|
||||
y+=r.y;
|
||||
|
||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
||||
|
||||
win->normal_font->Render(renderer,x,y,text,win->palette.accent);
|
||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
||||
|
||||
SDL_Rect r2={.x=r.x,.y=r.y,.w=r.w,.h=r.h};
|
||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawRect(renderer,&r2);
|
||||
r2.x++;
|
||||
r2.y++;
|
||||
r2.w-=2;
|
||||
r2.h-=2;
|
||||
}
|
||||
|
||||
}
|
||||
bool DropDownView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
||||
{
|
||||
win->MakeActive(this);
|
||||
this->popup.bounds.x = myBounds.x;
|
||||
this->popup.bounds.y = myBounds.y+myBounds.h;
|
||||
this->popup.bounds.w = myBounds.w;
|
||||
this->popup.bounds.h = 150;
|
||||
auto pu = &this->popup;
|
||||
if(!this->hasSet) {
|
||||
|
||||
this->listView.ValueChanged += std::make_shared<FunctionalEvent<View*,GUIEventArgs&>>([pu](View* view,GUIEventArgs& args)->void {
|
||||
pu->Close();
|
||||
});
|
||||
|
||||
this->popup.SetView(&this->listView,false);
|
||||
this->hasSet=true;
|
||||
}
|
||||
win->ShowPopup(pu);
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_KEYDOWN && this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_UP:
|
||||
{
|
||||
this->listView.selected--;
|
||||
if(this->listView.selected < 0 || this->listView.selected >= this->listView.items.size())
|
||||
{
|
||||
this->listView.selected = (int)(this->listView.items.size()-1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
{
|
||||
this->listView.selected++;
|
||||
if(this->listView.selected < -1 || this->listView.selected >= this->listView.items.size())
|
||||
{
|
||||
this->listView.selected=0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
DropDownView::DropDownView() : View("--PLEASE SELECT ONE--")
|
||||
{
|
||||
this->hasSet=false;
|
||||
|
||||
}
|
||||
std::vector<std::string>& DropDownView::GetItems()
|
||||
{
|
||||
return this->listView.items;
|
||||
}
|
||||
void DropDownView::SetIndex(int index)
|
||||
{
|
||||
this->listView.selected = index;
|
||||
}
|
||||
int DropDownView::GetIndex()
|
||||
{
|
||||
return this->listView.selected;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,384 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/EditTextView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
EditTextView::EditTextView() : EditTextView(std::string())
|
||||
{
|
||||
|
||||
}
|
||||
EditTextView::EditTextView(std::string hint) : View()
|
||||
{
|
||||
this->hint = hint;
|
||||
this->cursorPos=0;
|
||||
this->cursorEnd=std::string::npos;
|
||||
}
|
||||
void EditTextView::TypeText(std::string text)
|
||||
{
|
||||
size_t cursorBegin = this->cursorPos;
|
||||
size_t cursorEnd = this->cursorEnd;
|
||||
if(cursorBegin > cursorEnd)
|
||||
{
|
||||
cursorBegin ^= cursorEnd;
|
||||
cursorEnd ^= cursorBegin;
|
||||
cursorBegin ^= cursorEnd;
|
||||
}
|
||||
|
||||
if(cursorEnd != std::string::npos && cursorEnd <= this->text.size())
|
||||
{
|
||||
this->text.erase(cursorBegin,cursorEnd-cursorBegin);
|
||||
this->text.insert(cursorBegin,text);
|
||||
}
|
||||
else if(cursorBegin <= this->text.size()) {
|
||||
this->text.insert(cursorBegin,text);
|
||||
|
||||
}
|
||||
|
||||
this->cursorPos = cursorBegin+text.size();
|
||||
this->cursorEnd = std::string::npos;
|
||||
|
||||
}
|
||||
void EditTextView::SetText(std::string text)
|
||||
{
|
||||
View::SetText(text);
|
||||
this->cursorPos=0;
|
||||
this->cursorEnd = std::string::npos;
|
||||
|
||||
}
|
||||
void EditTextView::SetHint(std::string hint)
|
||||
{
|
||||
this->hint = hint;
|
||||
}
|
||||
std::string EditTextView::GetHint()
|
||||
{
|
||||
return this->hint;
|
||||
}
|
||||
std::pair<int,int> EditTextView::PreferedMinSize()
|
||||
{
|
||||
int x=-1;
|
||||
int y=-1;
|
||||
auto win = this->GetWindow();
|
||||
if(win != nullptr)
|
||||
{
|
||||
x=-1;
|
||||
y=win->monospaced_font->MaxHeight()+(win->palette.borderSize*4);
|
||||
|
||||
}
|
||||
|
||||
return std::pair<int,int>(x,y);
|
||||
}
|
||||
|
||||
bool EditTextView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& myVisibleBounds)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
||||
{
|
||||
if(event.type == SDL_TEXTINPUT)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_TOUCHED))
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_TOUCHED,false);
|
||||
|
||||
if(!this->text.empty())
|
||||
{
|
||||
this->cursorPos=0;
|
||||
this->cursorEnd=this->text.size();
|
||||
}
|
||||
}
|
||||
TypeText(event.text.text);
|
||||
}
|
||||
else if(event.type == SDL_KEYDOWN)
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDL_KeyCode::SDLK_c:
|
||||
{
|
||||
if((event.key.keysym.mod & KMOD_CTRL) != 0)
|
||||
{
|
||||
size_t cursorBegin = cursorPos;
|
||||
size_t cursorEnd = this->cursorEnd;
|
||||
if(cursorBegin > cursorEnd)
|
||||
{
|
||||
cursorBegin ^= cursorEnd;
|
||||
cursorEnd ^= cursorBegin;
|
||||
cursorBegin ^= cursorEnd;
|
||||
}
|
||||
|
||||
if(cursorEnd != std::string::npos && cursorEnd <= this->text.size() && this->text.size() > 0)
|
||||
{
|
||||
std::string res = this->text.substr(cursorBegin,cursorEnd-cursorBegin);
|
||||
//SDL_GetClipboardText()
|
||||
SDL_SetClipboardText(res.c_str());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KeyCode::SDLK_v:
|
||||
{
|
||||
if((event.key.keysym.mod & KMOD_CTRL) != 0)
|
||||
{
|
||||
if(SDL_HasClipboardText())
|
||||
{
|
||||
char* text = SDL_GetClipboardText();
|
||||
if(text != NULL)
|
||||
{
|
||||
TypeText(text);
|
||||
}
|
||||
SDL_free(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KeyCode::SDLK_x:
|
||||
{
|
||||
if((event.key.keysym.mod & KMOD_CTRL) != 0)
|
||||
{
|
||||
size_t cursorBegin = cursorPos;
|
||||
size_t cursorEnd = this->cursorEnd;
|
||||
if(cursorBegin > cursorEnd)
|
||||
{
|
||||
cursorBegin ^= cursorEnd;
|
||||
cursorEnd ^= cursorBegin;
|
||||
cursorBegin ^= cursorEnd;
|
||||
}
|
||||
|
||||
if(cursorEnd != std::string::npos && cursorEnd <= this->text.size() && this->text.size() > 0)
|
||||
{
|
||||
std::string res = this->text.substr(cursorBegin,cursorEnd-cursorBegin);
|
||||
//SDL_GetClipboardText()
|
||||
SDL_SetClipboardText(res.c_str());
|
||||
|
||||
TypeText("");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KeyCode::SDLK_a:
|
||||
{
|
||||
if((event.key.keysym.mod & KMOD_CTRL) != 0)
|
||||
{
|
||||
this->cursorPos=0;
|
||||
this->cursorEnd=this->text.size();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KeyCode::SDLK_BACKSPACE:
|
||||
{
|
||||
if(this->cursorEnd == std::string::npos)
|
||||
{
|
||||
if(this->cursorPos > 0)
|
||||
{
|
||||
this->cursorPos--;
|
||||
this->text.erase(this->cursorPos,1);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
TypeText("");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KeyCode::SDLK_DELETE:
|
||||
{
|
||||
if(this->cursorEnd == std::string::npos)
|
||||
{
|
||||
if(this->cursorPos + 1 <= this->text.size())
|
||||
{
|
||||
this->text.erase(this->cursorPos,1);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
TypeText("");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KeyCode::SDLK_LEFT:
|
||||
{
|
||||
if((event.key.keysym.mod & KMOD_SHIFT) != 0)
|
||||
{
|
||||
if(this->cursorEnd > this->text.size())
|
||||
this->cursorEnd = this->cursorPos;
|
||||
|
||||
this->cursorEnd--;
|
||||
|
||||
|
||||
if(this->cursorEnd > this->text.size()) this->cursorEnd=0;
|
||||
if(this->cursorEnd == this->cursorPos) this->cursorEnd = std::string::npos;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cursorPos > cursorEnd)
|
||||
{
|
||||
cursorPos ^= cursorEnd;
|
||||
cursorEnd ^= cursorPos;
|
||||
cursorPos ^= cursorEnd;
|
||||
}
|
||||
this->cursorPos--;
|
||||
this->cursorEnd=std::string::npos;
|
||||
if(this->cursorPos > this->text.size()) this->cursorPos=0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KeyCode::SDLK_RIGHT:
|
||||
if((event.key.keysym.mod & KMOD_SHIFT) != 0)
|
||||
{
|
||||
if(this->cursorEnd == std::string::npos)
|
||||
this->cursorEnd = this->cursorPos;
|
||||
|
||||
this->cursorEnd++;
|
||||
|
||||
|
||||
if(this->cursorEnd > this->text.size()) this->cursorEnd=this->text.size();
|
||||
if(this->cursorEnd == this->cursorPos) this->cursorEnd = std::string::npos;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cursorPos > cursorEnd)
|
||||
{
|
||||
cursorPos ^= cursorEnd;
|
||||
cursorEnd ^= cursorPos;
|
||||
cursorPos ^= cursorEnd;
|
||||
}
|
||||
if(cursorEnd != std::string::npos)
|
||||
{
|
||||
this->cursorPos=cursorEnd+1;
|
||||
|
||||
}else {
|
||||
this->cursorPos++;
|
||||
}
|
||||
this->cursorEnd=std::string::npos;
|
||||
if(this->cursorPos > this->text.size()) this->cursorPos=this->text.size();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
if(event.button.x >= myVisibleBounds.x && event.button.x < myVisibleBounds.x+myVisibleBounds.w && event.button.y >= myVisibleBounds.y && event.button.y < myVisibleBounds.y+myVisibleBounds.h)
|
||||
{
|
||||
this->GetWindow()->MakeActive(this);
|
||||
this->SetViewFlag(VIEWFLAG_TOUCHED,false);
|
||||
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_FINGERDOWN)
|
||||
{
|
||||
auto pos = this->GetCordFromEvent(event);
|
||||
if(pos.first >= myVisibleBounds.x && pos.first < myVisibleBounds.x+myVisibleBounds.w && pos.second >= myVisibleBounds.y && pos.second < myVisibleBounds.y+myVisibleBounds.h)
|
||||
{
|
||||
this->GetWindow()->MakeActive(this);
|
||||
|
||||
this->SetViewFlag(VIEWFLAG_TOUCHED,true);
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
}
|
||||
return View::OnEvent(event,myBounds,myVisibleBounds);
|
||||
}
|
||||
void EditTextView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
size_t cursorBegin = this->cursorPos;
|
||||
size_t cursorEnd = this->cursorEnd;
|
||||
if(cursorBegin > cursorEnd)
|
||||
{
|
||||
cursorBegin ^= cursorEnd;
|
||||
cursorEnd ^= cursorBegin;
|
||||
cursorBegin ^= cursorEnd;
|
||||
}
|
||||
auto win = this->GetWindow();
|
||||
//SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
//SDL_RenderFillRect(renderer,&r);
|
||||
|
||||
int textW=win->monospaced_font->MaxWidth()+2;
|
||||
int textH=win->monospaced_font->MaxHeight();
|
||||
|
||||
int noChars = (r.w-(win->palette.borderSize*4)) / textW;
|
||||
|
||||
|
||||
int x=0;
|
||||
int y=(r.h/2)-((textH+(win->palette.borderSize*4))/2);
|
||||
x+=r.x+(win->palette.borderSize*2);
|
||||
y+=r.y+(win->palette.borderSize*2);
|
||||
|
||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
||||
|
||||
size_t tracking = this->cursorPos;
|
||||
if(cursorEnd != std::string::npos)
|
||||
tracking = this->cursorEnd;
|
||||
|
||||
|
||||
size_t off = noChars == 0 ? (size_t)0 : ((tracking / (size_t)noChars) * (size_t)noChars);
|
||||
|
||||
|
||||
std::string& datext = this->text.empty() ? this->hint : this->text;
|
||||
|
||||
//printf("%i %i %i\n",(int) tracking,(int)off,(int)noChars);
|
||||
|
||||
for(size_t i = 0; i < (size_t)noChars; i++)
|
||||
{
|
||||
if(cursorEnd == std::string::npos && (i+off) == cursorBegin)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
||||
int x1=((int)i*textW)+x;
|
||||
int y1 = y;
|
||||
int y2 = y+textH;
|
||||
SDL_RenderDrawLine(renderer,x1,y1,x1,y2);
|
||||
}
|
||||
if(i + off < datext.size())
|
||||
{
|
||||
if(cursorEnd != std::string::npos && (i+off) >= cursorBegin && (i+off) < cursorEnd)
|
||||
{
|
||||
SDL_Rect r0={.x=((int)i*textW)+x,.y=y,.w=textW,.h=textH+8};
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
SDL_RenderFillRect(renderer,&r0);
|
||||
|
||||
auto ch=win->monospaced_font->GetCharOfColor(datext[i+off],color);
|
||||
|
||||
SDL_Rect src={.x=0,.y=0,.w=0,.h=0};
|
||||
SDL_QueryTexture(ch,NULL,NULL,&src.w,&src.h);
|
||||
SDL_Rect dest = {.x=((int)i*textW)+x+1,.y=y,.w=src.w,.h=src.h};
|
||||
SDL_RenderCopy(renderer,ch,&src,&dest);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
|
||||
|
||||
auto ch=win->monospaced_font->GetCharOfColor(datext[i+off],this->text.empty() ? color : win->palette.accent);
|
||||
|
||||
SDL_Rect src={.x=0,.y=0,.w=0,.h=0};
|
||||
SDL_QueryTexture(ch,NULL,NULL,&src.w,&src.h);
|
||||
SDL_Rect dest = {.x=((int)i*textW)+x+1,.y=y,.w=src.w,.h=src.h};
|
||||
SDL_RenderCopy(renderer,ch,&src,&dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
||||
|
||||
SDL_Rect r2={.x=r.x,.y=y-(win->palette.borderSize*2),.w=r.w,.h=textH+16};
|
||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawRect(renderer,&r2);
|
||||
r2.x++;
|
||||
r2.y++;
|
||||
r2.w-=2;
|
||||
r2.h-=2;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,329 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
|
||||
#include "TessesFramework/SDL2/Views/HScrollView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
std::pair<int,int> HScrollView::PreferedMinSize()
|
||||
{
|
||||
return std::pair<int,int>(-1,32);
|
||||
}
|
||||
void HScrollView::OnValueChanged(GUIEventArgs& e)
|
||||
{
|
||||
|
||||
}
|
||||
HScrollView::HScrollView() : HScrollView(0, 0, 100)
|
||||
{
|
||||
|
||||
}
|
||||
HScrollView::HScrollView(uint64_t value, uint64_t min, uint64_t max,uint64_t step) : View()
|
||||
{
|
||||
this->value = value;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
|
||||
this->step=step;
|
||||
}
|
||||
void HScrollView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
auto leftIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B1STATE);
|
||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
||||
auto leftIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE);
|
||||
|
||||
auto middleIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
|
||||
auto middleIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
|
||||
auto rightIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
||||
|
||||
auto rightIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE);
|
||||
|
||||
SDL_Color& leftColor = win->palette.GetBorderColor(leftIsHovering,isActive,leftIsMouseDown);
|
||||
SDL_Color& leftMiddleColor = win->palette.GetBorderColor(leftIsHovering||middleIsHovering,isActive,leftIsMouseDown||middleIsMouseDown);
|
||||
SDL_Color& middleColor = win->palette.GetBorderColor(middleIsHovering,isActive,middleIsMouseDown);
|
||||
SDL_Color& rightMiddleColor = win->palette.GetBorderColor(rightIsHovering||middleIsHovering,isActive,rightIsMouseDown||middleIsMouseDown);
|
||||
SDL_Color& rightColor = win->palette.GetBorderColor(rightIsHovering,isActive,rightIsMouseDown);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,leftColor.r,leftColor.g,leftColor.b,leftColor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,r.x+i,r.y,r.x+i,r.y+r.h); //horizontal
|
||||
|
||||
|
||||
SDL_RenderDrawLine(renderer,r.x,r.y+i,r.x+32,r.y+i); //horizontal
|
||||
|
||||
SDL_RenderDrawLine(renderer,r.x,r.y+r.h-(1+i),r.x+32,r.y+r.h-(1+i)); //horizontal
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,leftMiddleColor.r,leftMiddleColor.g,leftMiddleColor.b,leftMiddleColor.a);
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,(r.x+32)-i,r.y,(r.x+32)-i,r.y+r.h); //horizontal
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,middleColor.r,middleColor.g,middleColor.b,middleColor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,r.x+33,r.y+i,r.x+(r.w-33),r.y+i); //horizontal
|
||||
SDL_RenderDrawLine(renderer,r.x+33,r.y+r.h-(1+i),r.x+(r.w-33),r.y+r.h-(1+i)); //horizontal
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,rightColor.r,rightColor.g,rightColor.b,rightColor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,(r.x+r.w)-(i+1),r.y,(r.x+r.w)-(i+1),r.y+r.h); //horizontal
|
||||
|
||||
SDL_RenderDrawLine(renderer,r.x+(r.w-32),r.y+i,r.x+r.w,r.y+i); //horizontal
|
||||
SDL_RenderDrawLine(renderer,r.x+(r.w-32),r.y+r.h-(1+i),r.x+r.w,r.y+r.h-(1+i)); //horizonal
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,rightMiddleColor.r,rightMiddleColor.g,rightMiddleColor.b,rightMiddleColor.a);
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,(r.x+(r.w-32))+i,r.y,(r.x+(r.w-32))+i,r.y+r.h); //horizontal
|
||||
}
|
||||
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
int y1 = 15;
|
||||
int x1 = 8 + i;
|
||||
|
||||
int y2 = 9;
|
||||
int x2 = 18 + i;
|
||||
|
||||
SDL_RenderDrawLine(renderer,x1+r.x,y1+r.y,x2+r.x,y2+r.y);
|
||||
|
||||
int y3 = 31-y1;
|
||||
int y4 = 31-y2;
|
||||
|
||||
SDL_RenderDrawLine(renderer,x1+r.x,y3+r.y,x2+r.x,y4+r.y);
|
||||
|
||||
int x3 = 31-x1;
|
||||
int x4 = 31-x2;
|
||||
|
||||
|
||||
SDL_RenderDrawLine(renderer,x3+r.x+(r.w-32),y1+r.y,x4+r.x+(r.w-32),y2+r.y);
|
||||
|
||||
SDL_RenderDrawLine(renderer,x3+r.x+(r.w-32),y3+r.y,x4+r.x+(r.w-32),y4+r.y);
|
||||
}
|
||||
|
||||
uint64_t width = (uint64_t)r.w - 66;
|
||||
uint64_t scrollSize = 4;
|
||||
uint64_t dif = max-min;
|
||||
if(dif > 0)
|
||||
scrollSize = width / dif;
|
||||
|
||||
if(scrollSize < 4) scrollSize=4;
|
||||
|
||||
|
||||
double scroll = 0;
|
||||
if(dif > 0)
|
||||
scroll = (double)(value-min) / (double)dif;
|
||||
|
||||
uint64_t scrollX = scroll * (width-scrollSize);
|
||||
|
||||
|
||||
|
||||
if(scrollX > width-scrollSize) scrollX = width-scrollSize;
|
||||
SDL_Rect r2={.x=(int)scrollX+r.x+32,.y=r.y+win->palette.borderSize,.w=(int)scrollSize,.h = r.h-(win->palette.borderSize*2)};
|
||||
SDL_RenderFillRect(renderer,&r2);
|
||||
}
|
||||
bool HScrollView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
if(event.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
bool inside = event.motion.x >= visibleBounds.x && event.motion.x < visibleBounds.x+visibleBounds.w && event.motion.y >= visibleBounds.y && event.motion.y < visibleBounds.y+visibleBounds.h;
|
||||
bool hoverFlag = this->GetViewFlag(VIEWFLAG_HOVER_STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B1STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
||||
if(inside && !hoverFlag)
|
||||
{
|
||||
int x = event.motion.x - myBounds.x;
|
||||
if(x <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else if(x >= myBounds.w-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
||||
}
|
||||
|
||||
GUIEventArgs e;
|
||||
this->OnEnter(e);
|
||||
this->Enter.Invoke(this,e);
|
||||
}
|
||||
else if(!inside && hoverFlag)
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
GUIEventArgs e;
|
||||
this->OnLeave(e);
|
||||
this->Leave.Invoke(this,e);
|
||||
} else if(inside) {
|
||||
int x = event.motion.x - myBounds.x;
|
||||
if(x <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else if(x >= myBounds.w-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
||||
{
|
||||
int x = event.motion.x - myBounds.x;
|
||||
if(x <= 32)
|
||||
{
|
||||
value = min;
|
||||
}
|
||||
else if(x >= myBounds.w-32)
|
||||
{
|
||||
value=max;
|
||||
}
|
||||
else {
|
||||
uint64_t width = (uint64_t)myBounds.w - 66;
|
||||
uint64_t x2 = x-33;
|
||||
|
||||
double off = (double)x2 / (double)width;
|
||||
|
||||
value = round((max-min)*off)+min;
|
||||
GUIEventArgs cea2;
|
||||
this->ValueChanged.Invoke(this,cea2);
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
if(cea.x <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,true);
|
||||
}
|
||||
else if(cea.x >= myBounds.w-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,true);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,true);
|
||||
|
||||
uint64_t width = (uint64_t)myBounds.w - 66;
|
||||
uint64_t x2 = cea.x-33;
|
||||
|
||||
double off = (double)x2 / (double)width;
|
||||
|
||||
value = round((max-min)*off)+min;
|
||||
GUIEventArgs cea2;
|
||||
this->ValueChanged.Invoke(this,cea2);
|
||||
}
|
||||
OnMouseDown(cea);
|
||||
this->MouseDown.Invoke(this,cea);
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,false);
|
||||
OnMouseUp(cea);
|
||||
this->MouseUp.Invoke(this,cea);
|
||||
GUIEventArgs cea2;
|
||||
OnClick(cea2);
|
||||
this->Click.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE))
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,false);
|
||||
OnMouseUp(cea);
|
||||
this->MouseUp.Invoke(this,cea);
|
||||
GUIEventArgs cea2;
|
||||
OnClick(cea2);
|
||||
this->Click.Invoke(this,cea2);
|
||||
this->value -= step;
|
||||
if(this->value < min) this->value=min;
|
||||
if(this->value >= max) this->value=min;
|
||||
OnValueChanged(cea2);
|
||||
this->ValueChanged.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE))
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,false);
|
||||
OnMouseUp(cea);
|
||||
this->MouseUp.Invoke(this,cea);
|
||||
GUIEventArgs cea2;
|
||||
OnClick(cea2);
|
||||
this->Click.Invoke(this,cea2);
|
||||
this->value += step;
|
||||
if(this->value > max) this->value=max;
|
||||
OnValueChanged(cea2);
|
||||
this->ValueChanged.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return View::OnEvent(event,myBounds,visibleBounds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,273 +0,0 @@
|
||||
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/HStackView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
void HStackView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
int numberOfCells = 0;
|
||||
int freeWidth = r.w;
|
||||
std::vector<int> sizes;
|
||||
sizes.resize(this->items.size());
|
||||
|
||||
freeWidth -= (this->items.size() - 1) * this->spacing;
|
||||
|
||||
for(size_t i = 0; i < this->items.size(); i++)
|
||||
{
|
||||
if(this->items[i].first > 0)
|
||||
{
|
||||
//static size
|
||||
sizes[i] = this->items[i].first;
|
||||
freeWidth-= this->items[i].first;
|
||||
}
|
||||
else if(this->items[i].first == 0)
|
||||
{
|
||||
auto prefered = this->items[i].second.first->PreferedMinSize();
|
||||
if(prefered.first > 0)
|
||||
{
|
||||
sizes[i] = prefered.first;
|
||||
freeWidth -= prefered.first;
|
||||
}
|
||||
else {
|
||||
sizes[i] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
numberOfCells -= this->items[i].first;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cellSize = numberOfCells == 0 ? 0 : freeWidth / numberOfCells;
|
||||
|
||||
|
||||
for(int i = 0; i < this->items.size();i++)
|
||||
{
|
||||
if(this->items[i].first < 0)
|
||||
{
|
||||
int myWidth =((-(this->items[i].first)) * cellSize);
|
||||
|
||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
||||
if(minSz.first > myWidth) {
|
||||
sizes[i] = minSz.first;
|
||||
freeWidth-= minSz.first;
|
||||
numberOfCells -= -(this->items[i].first);
|
||||
}
|
||||
}
|
||||
}
|
||||
cellSize = numberOfCells == 0 ? 0 : freeWidth/ numberOfCells;
|
||||
int x = 0;
|
||||
|
||||
|
||||
for(size_t i = 0; i < this->items.size(); i++)
|
||||
{
|
||||
if(i > 0) x += spacing;
|
||||
|
||||
if(sizes[i] == 0)
|
||||
{
|
||||
int myWidth =((-(this->items[i].first)) * cellSize);
|
||||
|
||||
|
||||
SDL_Rect theirBounds = {
|
||||
.x =x,
|
||||
.y=0,
|
||||
.w=myWidth,
|
||||
.h=r.h
|
||||
};
|
||||
|
||||
|
||||
theirBounds.x += r.x;
|
||||
theirBounds.y += r.y;
|
||||
|
||||
|
||||
|
||||
CallOnDraw(this->items[i].second.first,renderer, theirBounds);
|
||||
x+=myWidth;
|
||||
}
|
||||
else {
|
||||
|
||||
SDL_Rect theirBounds = {
|
||||
.x =x,
|
||||
.y=0,
|
||||
.w=sizes[i],
|
||||
.h=r.h
|
||||
};
|
||||
|
||||
|
||||
theirBounds.x += r.x;
|
||||
theirBounds.y += r.y;
|
||||
|
||||
|
||||
|
||||
CallOnDraw(this->items[i].second.first,renderer, theirBounds);
|
||||
x+=sizes[i];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
bool HStackView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
int numberOfCells = 0;
|
||||
int freeWidth = myBounds.w;
|
||||
std::vector<int> sizes;
|
||||
sizes.resize(this->items.size());
|
||||
|
||||
|
||||
freeWidth -= (this->items.size() - 1) * this->spacing;
|
||||
for(size_t i = 0; i < this->items.size(); i++)
|
||||
{
|
||||
if(this->items[i].first > 0)
|
||||
{
|
||||
//static size
|
||||
sizes[i] = this->items[i].first;
|
||||
freeWidth-= this->items[i].first;
|
||||
}
|
||||
else if(this->items[i].first == 0)
|
||||
{
|
||||
auto prefered = this->items[i].second.first->PreferedMinSize();
|
||||
if(prefered.first > 0)
|
||||
{
|
||||
sizes[i] = prefered.first;
|
||||
freeWidth -= prefered.first;
|
||||
}
|
||||
else {
|
||||
sizes[i] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
numberOfCells -= this->items[i].first;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cellSize = numberOfCells == 0 ? 0 : freeWidth/ numberOfCells;
|
||||
|
||||
for(int i = 0; i < this->items.size();i++)
|
||||
{
|
||||
if(this->items[i].first < 0)
|
||||
{
|
||||
int myWidth =((-(this->items[i].first)) * cellSize);
|
||||
|
||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
||||
if(minSz.first > myWidth) {
|
||||
sizes[i] = minSz.first;
|
||||
myWidth -= minSz.first;
|
||||
numberOfCells -= -(this->items[i].first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cellSize = numberOfCells == 0 ? 0 : freeWidth/ numberOfCells;
|
||||
int x = 0;
|
||||
|
||||
|
||||
for(size_t i = 0; i < this->items.size(); i++)
|
||||
{
|
||||
if(i > 0) x += spacing;
|
||||
if(sizes[i] == 0)
|
||||
{
|
||||
int myWidth =((-(this->items[i].first)) * cellSize);
|
||||
|
||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
||||
if(minSz.first > myWidth) myWidth = minSz.first;
|
||||
|
||||
SDL_Rect theirBounds = {
|
||||
.x = x,
|
||||
.y=0,
|
||||
.w=myWidth,
|
||||
.h=myBounds.h
|
||||
};
|
||||
|
||||
SDL_Rect theirVisibleBounds = theirBounds;
|
||||
theirVisibleBounds.x += visibleBounds.x;
|
||||
theirVisibleBounds.y += visibleBounds.y;
|
||||
|
||||
theirBounds.x += myBounds.x;
|
||||
theirBounds.y += myBounds.y;
|
||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
||||
|
||||
|
||||
|
||||
CallOnEvent(this->items[i].second.first,event,theirBounds,theirVisibleBounds);
|
||||
|
||||
x+=myWidth;
|
||||
}
|
||||
else {
|
||||
|
||||
SDL_Rect theirBounds = {
|
||||
.x = x,
|
||||
.y=0,
|
||||
.w=sizes[i],
|
||||
.h=myBounds.h
|
||||
};
|
||||
|
||||
SDL_Rect theirVisibleBounds = theirBounds;
|
||||
theirVisibleBounds.x += visibleBounds.x;
|
||||
theirVisibleBounds.y += visibleBounds.y;
|
||||
|
||||
theirBounds.x += myBounds.x;
|
||||
theirBounds.y += myBounds.y;
|
||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
||||
|
||||
|
||||
|
||||
CallOnEvent(this->items[i].second.first,event,theirBounds,theirVisibleBounds);
|
||||
|
||||
x+=sizes[i];
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
HStackView::HStackView() : ContainerView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void HStackView::Add(int sz, View* view, bool owns)
|
||||
{
|
||||
this->items.push_back(std::pair<int,std::pair<View*,bool>>(sz,std::pair<View*,bool>(view,owns)));
|
||||
this->AssignChildParentToThis(view);
|
||||
}
|
||||
void HStackView::Remove(View* view)
|
||||
{
|
||||
for(auto index = this->items.begin(); index < this->items.end(); index++)
|
||||
{
|
||||
if(index->second.first == view)
|
||||
{
|
||||
|
||||
if(index->second.first != nullptr && index->second.second)
|
||||
delete view;
|
||||
this->items.erase(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void HStackView::Clear()
|
||||
{
|
||||
for(auto& item : this->items)
|
||||
if(item.second.second && item.second.first != nullptr) delete item.second.first;
|
||||
items = {};
|
||||
}
|
||||
|
||||
size_t HStackView::ViewCount()
|
||||
{
|
||||
return this->items.size();
|
||||
}
|
||||
View* HStackView::GetViewAt(size_t index)
|
||||
{
|
||||
return this->items.at(index).second.first;
|
||||
}
|
||||
|
||||
HStackView::~HStackView()
|
||||
{
|
||||
for(auto& item : this->items)
|
||||
if(item.second.second && item.second.first != nullptr) delete item.second.first;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/LabelView.hpp"
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
void LabelView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
auto win =this->GetWindow();
|
||||
win->normal_font->Render(renderer,r.x+win->palette.borderSize,r.y+win->palette.borderSize,text,win->palette.accent);
|
||||
}
|
||||
|
||||
LabelView::LabelView() : View()
|
||||
{
|
||||
this->flags &= ~VIEWFLAG_TABSTOP;
|
||||
}
|
||||
LabelView::LabelView(std::string text) : View(text)
|
||||
{
|
||||
this->flags &= ~VIEWFLAG_TABSTOP;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,232 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/MultilineEditTextView.hpp"
|
||||
#include "TessesFramework/Http/HttpUtils.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
static int numberWidth(size_t n)
|
||||
{
|
||||
if(n == 0) return 1;
|
||||
size_t digits = 0;
|
||||
while(n != 0)
|
||||
{
|
||||
n /= 10;
|
||||
digits++;
|
||||
}
|
||||
return digits;
|
||||
}
|
||||
|
||||
void MultilineEditTextView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
//1 |
|
||||
|
||||
// 9 |
|
||||
//10 |
|
||||
|
||||
auto win = this->GetWindow();
|
||||
auto w = win->monospaced_font->MaxWidth();
|
||||
auto h = win->monospaced_font->MaxHeight();
|
||||
auto digitsTotal = numberWidth(this->lines.size());
|
||||
|
||||
auto numLines = (r.h - (win->palette.borderSize*4)) / h;
|
||||
|
||||
if(numLines+this->topLeft.y > this->lines.size()) numLines = this->lines.size() - this->topLeft.y;
|
||||
|
||||
for(size_t i = 0; i < numLines; i++)
|
||||
{
|
||||
win->monospaced_font->Render(renderer, r.x+(win->palette.borderSize*2),r.y+(h*i), Http::HttpUtils::LeftPad(std::to_string(i+this->topLeft.y+1),digitsTotal,' '),win->palette.accent);
|
||||
win->monospaced_font->Render(renderer,r.x+(win->palette.borderSize*2)+(w*(digitsTotal+5)),r.y+(h*i),this->lines[i+this->topLeft.y],win->palette.accent,this->topLeft.x);
|
||||
}
|
||||
|
||||
}
|
||||
bool MultilineEditTextView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
if(event.type == SDL_TEXTINPUT)
|
||||
{
|
||||
TypeText(event.text.text);
|
||||
}
|
||||
else if(event.type == SDL_KEYDOWN)
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_RETURN:
|
||||
TypeText("\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
MultilineEditTextView::MultilineEditTextView() :MultilineEditTextView(std::string())
|
||||
{
|
||||
|
||||
}
|
||||
MultilineEditTextView::MultilineEditTextView(std::string hint) : View()
|
||||
{
|
||||
this->hint = hint;
|
||||
}
|
||||
std::string MultilineEditTextView::GetHint()
|
||||
{
|
||||
return this->hint;
|
||||
}
|
||||
void MultilineEditTextView::SetHint(std::string hint)
|
||||
{
|
||||
this->hint = hint;
|
||||
}
|
||||
std::string MultilineEditTextView::GetText()
|
||||
{
|
||||
if(this->lines.empty()) return {};
|
||||
std::string text = this->lines.front();
|
||||
for(size_t i = 1; i < this->lines.size(); i++)
|
||||
{
|
||||
text.push_back('\n');
|
||||
text.append(this->lines[i]);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
void MultilineEditTextView::SetText(std::string text)
|
||||
{
|
||||
lines.clear();
|
||||
std::string line = "";
|
||||
for(auto c : text)
|
||||
{
|
||||
if(c == '\n') {
|
||||
lines.push_back(line);
|
||||
line = "";
|
||||
}
|
||||
else {
|
||||
line += c;
|
||||
}
|
||||
}
|
||||
if(!line.empty()) lines.push_back(line);
|
||||
|
||||
this->cursorPos.x=0;
|
||||
this->cursorPos.y=0;
|
||||
this->cursorEnd.x=-1;
|
||||
this->cursorEnd.y=-1;
|
||||
}
|
||||
void MultilineEditTextView::TypeText(std::string text)
|
||||
{
|
||||
|
||||
SDL_Point cursorBegin = this->cursorPos;
|
||||
SDL_Point cursorEnd = this->cursorEnd;
|
||||
if((cursorBegin.y > cursorEnd.y || ((cursorBegin.y == cursorEnd.y) && (cursorBegin.x > cursorEnd.x))) && this->cursorEnd.x != -1 && this->cursorEnd.y != -1)
|
||||
{
|
||||
cursorBegin.y ^= cursorEnd.y;
|
||||
cursorEnd.y ^= cursorBegin.y;
|
||||
cursorBegin.y ^= cursorEnd.y;
|
||||
|
||||
cursorBegin.x ^= cursorEnd.x;
|
||||
cursorEnd.x ^= cursorBegin.x;
|
||||
cursorBegin.x ^= cursorEnd.x;
|
||||
}
|
||||
/*
|
||||
|
||||
if(cursorEnd != std::string::npos && cursorEnd <= this->text.size())
|
||||
{
|
||||
this->text.erase(cursorBegin,cursorEnd-cursorBegin);
|
||||
this->text.insert(cursorBegin,text);
|
||||
}
|
||||
else if(cursorBegin <= this->text.size()) {
|
||||
this->text.insert(cursorBegin,text);
|
||||
|
||||
}
|
||||
|
||||
this->cursorPos = cursorBegin+text.size();
|
||||
this->cursorEnd = std::string::npos;*/
|
||||
|
||||
if(this->cursorEnd.y != -1 && this->cursorEnd.x != -1)
|
||||
{
|
||||
int line = cursorBegin.y;
|
||||
for(int y = cursorBegin.y; y <= cursorEnd.y && y < lines.size(); y++)
|
||||
{
|
||||
if(y == cursorBegin.y && y == cursorEnd.y && cursorBegin.x == 0 && cursorEnd.x == this->lines[y].size()-1)
|
||||
{
|
||||
this->lines.erase(this->lines.begin()+line);
|
||||
}
|
||||
else if(y == cursorBegin.y && y == cursorEnd.y)
|
||||
{
|
||||
this->lines[line]=this->lines[line].substr(0,cursorBegin.x) + this->lines[line].substr(cursorEnd.x);
|
||||
line++;
|
||||
}
|
||||
else if(y == cursorBegin.y && cursorBegin.x == 0)
|
||||
{
|
||||
this->lines.erase(this->lines.begin()+line);
|
||||
}
|
||||
else if(y == cursorBegin.y)
|
||||
{
|
||||
this->lines[line]=this->lines[line].substr(0,cursorBegin.x);
|
||||
line++;
|
||||
}
|
||||
else if(y > cursorBegin.y && y < cursorEnd.y)
|
||||
{
|
||||
this->lines.erase(this->lines.begin()+line);
|
||||
}
|
||||
else if(y == cursorEnd.y && cursorEnd.x < this->lines[line].size()-1)
|
||||
{
|
||||
this->lines[line]=this->lines[line].substr(cursorBegin.x);
|
||||
}
|
||||
else {
|
||||
this->lines.erase(this->lines.begin()+line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
auto mylines = text == "\n" ? std::vector<std::string>({"",""}) : Http::HttpUtils::SplitString(text,"\n");
|
||||
|
||||
if(!mylines.empty())
|
||||
{
|
||||
int setXTo = 0;
|
||||
if(mylines.size()==1)
|
||||
{
|
||||
setXTo=mylines[0].size()+cursorBegin.x;
|
||||
}
|
||||
else {
|
||||
setXTo=mylines.back().size();
|
||||
}
|
||||
if(cursorBegin.y < this->lines.size())
|
||||
{
|
||||
|
||||
|
||||
if(cursorBegin.x > 0)
|
||||
{
|
||||
mylines[0] = this->lines[cursorBegin.y].substr(0,cursorBegin.x) + mylines[0];
|
||||
}
|
||||
if(cursorBegin.x < this->lines[cursorBegin.y].size())
|
||||
{
|
||||
mylines.back() += this->lines[cursorBegin.y].substr(cursorBegin.x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
this->lines.erase(this->lines.begin()+cursorBegin.y);
|
||||
}
|
||||
|
||||
|
||||
bool first=true;
|
||||
for(auto& item : mylines)
|
||||
{
|
||||
if(!first)
|
||||
{
|
||||
cursorBegin.y++;
|
||||
}
|
||||
this->lines.insert(this->lines.begin()+cursorBegin.y,{item});
|
||||
first=false;
|
||||
}
|
||||
cursorBegin.x = setXTo;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
this->cursorPos = cursorBegin;
|
||||
this->cursorEnd = {.x=-1,.y=-1};
|
||||
}
|
||||
std::pair<int,int> MultilineEditTextView::PreferedMinSize()
|
||||
{
|
||||
return std::pair<int,int>(128,128);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,54 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/PictureView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
PictureView::PictureView()
|
||||
{
|
||||
this->tex = nullptr;
|
||||
this->ownsTex=false;
|
||||
this->surf = nullptr;
|
||||
this->ownsSurf=false;
|
||||
}
|
||||
|
||||
void PictureView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
if(this->surf != nullptr)
|
||||
{
|
||||
this->SetPicture(SDL_CreateTextureFromSurface(renderer,this->surf));
|
||||
if(this->ownsSurf) SDL_FreeSurface(this->surf);
|
||||
this->surf=nullptr;
|
||||
}
|
||||
if(this->tex != nullptr)
|
||||
{
|
||||
SDL_Rect sr={.x=0,.y=0};
|
||||
SDL_QueryTexture(this->tex,nullptr,nullptr,&sr.w,&sr.h);
|
||||
SDL_RenderCopy(renderer,this->tex,&sr,&r);
|
||||
}
|
||||
}
|
||||
|
||||
void PictureView::SetPicture(SDL_Texture* tex, bool owns)
|
||||
{
|
||||
|
||||
if(this->tex != nullptr && this->tex != tex && this->ownsTex)
|
||||
SDL_DestroyTexture(this->tex);
|
||||
this->tex = tex;
|
||||
this->ownsTex = owns;
|
||||
}
|
||||
void PictureView::SetPicture(SDL_Surface* surface,bool owns)
|
||||
{
|
||||
if(this->surf != nullptr && this->surf != surf && this->ownsSurf)
|
||||
SDL_FreeSurface(this->surf);
|
||||
this->surf = surface;
|
||||
this->ownsSurf = owns;
|
||||
}
|
||||
|
||||
PictureView::~PictureView()
|
||||
{
|
||||
if(this->tex != nullptr && this->ownsTex)
|
||||
SDL_DestroyTexture(this->tex);
|
||||
if(this->surf != nullptr && this->ownsSurf)
|
||||
SDL_FreeSurface(this->surf);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,39 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
|
||||
#include "TessesFramework/SDL2/Views/ProgressView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
ProgressView::ProgressView() : ProgressView(0.0)
|
||||
{
|
||||
|
||||
}
|
||||
ProgressView::ProgressView(double v) : View()
|
||||
{
|
||||
this->value = v;
|
||||
this->SetViewFlag(VIEWFLAG_TABSTOP,false);
|
||||
}
|
||||
void ProgressView::OnDraw(SDL_Renderer* renderer, SDL_Rect& rect)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.borderColor.r,win->palette.borderColor.g,win->palette.borderColor.b,win->palette.borderColor.a);
|
||||
|
||||
SDL_Rect r2={.x=rect.x,.y=rect.y,.w=rect.w,.h=rect.h};
|
||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawRect(renderer,&r2);
|
||||
r2.x++;
|
||||
r2.y++;
|
||||
r2.w-=2;
|
||||
r2.h-=2;
|
||||
}
|
||||
|
||||
auto res = (int)((rect.w-(win->palette.borderSize*2))*(this->value/100.0));
|
||||
r2={.x=rect.x+win->palette.borderSize,.y=rect.y+win->palette.borderSize,.w=res,.h=rect.h-8};
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
SDL_RenderFillRect(renderer,&r2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,444 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
|
||||
#include "TessesFramework/SDL2/Views/ScrollableTextListView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
ScrollableTextListView::ScrollableTextListView() : View()
|
||||
{
|
||||
this->firstIndex=0;
|
||||
this->selected=-1;
|
||||
}
|
||||
bool ScrollableTextListView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
auto item_height = win->normal_font->MaxHeight()+(win->palette.borderSize*2);
|
||||
auto no_items = (myBounds.h-(win->palette.borderSize*2)) / item_height;
|
||||
auto max_items = no_items;
|
||||
|
||||
if(this->firstIndex + no_items > this->items.size())
|
||||
{
|
||||
|
||||
no_items = this->items.size()-this->firstIndex;
|
||||
}
|
||||
|
||||
|
||||
if(event.type == SDL_KEYDOWN)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_RETURN:
|
||||
{
|
||||
|
||||
GUIEventArgs e;
|
||||
if(this->selected > -1)
|
||||
this->ValueChanged.Invoke(this,e);
|
||||
}
|
||||
break;
|
||||
case SDLK_HOME:
|
||||
this->selected=0;
|
||||
this->firstIndex=0;
|
||||
break;
|
||||
case SDLK_END:
|
||||
this->selected = (int)(this->items.size()-1);
|
||||
|
||||
this->firstIndex= this->selected-(this->selected % max_items);
|
||||
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
this->selected++;
|
||||
if(this->selected < -1 || this->selected >= this->items.size())
|
||||
{
|
||||
this->selected=0;
|
||||
}
|
||||
this->firstIndex= this->selected-(this->selected % max_items);
|
||||
|
||||
break;
|
||||
case SDLK_UP:
|
||||
this->selected--;
|
||||
if(this->selected < 0 || this->selected >= this->items.size())
|
||||
{
|
||||
this->selected = (int)(this->items.size()-1);
|
||||
}
|
||||
|
||||
this->firstIndex= this->selected-(this->selected % max_items);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(event.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
bool inside = event.motion.x >= visibleBounds.x && event.motion.x < visibleBounds.x+visibleBounds.w && event.motion.y >= visibleBounds.y && event.motion.y < visibleBounds.y+visibleBounds.h;
|
||||
bool hoverFlag = this->GetViewFlag(VIEWFLAG_HOVER_STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B1STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
||||
if(inside && !hoverFlag)
|
||||
{
|
||||
int y = event.motion.y - myBounds.y;
|
||||
if(y <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else if(y >= myBounds.h-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
||||
}
|
||||
|
||||
GUIEventArgs e;
|
||||
this->OnEnter(e);
|
||||
this->Enter.Invoke(this,e);
|
||||
}
|
||||
else if(!inside && hoverFlag)
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
GUIEventArgs e;
|
||||
this->OnLeave(e);
|
||||
this->Leave.Invoke(this,e);
|
||||
} else if(inside) {
|
||||
int y = event.motion.y - myBounds.y;
|
||||
if(y <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else if(y >= myBounds.h-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
||||
{
|
||||
int y = event.motion.y - myBounds.y;
|
||||
if(y <= 32)
|
||||
{
|
||||
this->firstIndex = 0;
|
||||
}
|
||||
else if(y >= myBounds.h-32)
|
||||
{
|
||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
||||
|
||||
if((items.size() % max_items) == 0) count--;
|
||||
|
||||
this->firstIndex = count*max_items;
|
||||
}
|
||||
else {
|
||||
uint64_t height = (uint64_t)myBounds.h - 66;
|
||||
uint64_t y2 = y-33;
|
||||
|
||||
double off = (double)y2 / (double)height;
|
||||
|
||||
|
||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
||||
if((items.size() % max_items) == 0) count--;
|
||||
|
||||
this->firstIndex = round(off*count) * max_items;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
||||
{
|
||||
int x= event.button.x - myBounds.x;
|
||||
int y = event.button.y - myBounds.y;
|
||||
|
||||
if(x >= myBounds.w-32)
|
||||
{
|
||||
|
||||
if(y <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,true);
|
||||
}
|
||||
else if(y >= myBounds.h-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,true);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,true);
|
||||
|
||||
uint64_t height = (uint64_t)myBounds.h - 66;
|
||||
uint64_t y2 = y-33;
|
||||
|
||||
double off = (double)y2 / (double)height;
|
||||
|
||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
||||
if((items.size() % max_items) == 0) count--;
|
||||
|
||||
this->firstIndex = round(off*count) * max_items;
|
||||
//value = round((max-min)*off)+min;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
int x= event.button.x - myBounds.x;
|
||||
if(x < myBounds.w-32 && event.button.x >= (visibleBounds.x+win->palette.borderSize) && event.button.y >= (visibleBounds.y+win->palette.borderSize) && event.button.y < (visibleBounds.y+visibleBounds.h)-(win->palette.borderSize*2))
|
||||
{
|
||||
win->MakeActive(this);
|
||||
auto myRealY=event.button.y - (myBounds.y+win->palette.borderSize);
|
||||
auto yThing = myRealY / item_height;
|
||||
|
||||
if(yThing < no_items)
|
||||
{
|
||||
auto high= yThing+this->firstIndex;
|
||||
this->selected = (int)high;
|
||||
GUIEventArgs e;
|
||||
this->ValueChanged.Invoke(this,e);
|
||||
}
|
||||
|
||||
}
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
||||
{
|
||||
|
||||
win->MakeActive(this);
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,false);
|
||||
|
||||
return true;
|
||||
}
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE))
|
||||
{
|
||||
|
||||
win->MakeActive(this);
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,false);
|
||||
|
||||
//this->value -= step;
|
||||
//if(this->value < min) this->value=min;
|
||||
//if(this->value >= max) this->value=min;
|
||||
//OnValueChanged(cea2);
|
||||
//this->ValueChanged.Invoke(this,cea2);
|
||||
|
||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
||||
|
||||
if((items.size() % max_items) == 0) count--;
|
||||
|
||||
auto c = max_items == 0 ? 0 : (this->firstIndex / max_items);
|
||||
c--;
|
||||
if(c > count) c = 0;
|
||||
this->firstIndex = c * max_items;
|
||||
|
||||
return true;
|
||||
}
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE))
|
||||
{
|
||||
|
||||
win->MakeActive(this);
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,false);
|
||||
|
||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
||||
|
||||
if((items.size() % max_items) == 0) count--;
|
||||
|
||||
auto c = max_items == 0 ? 0 : (this->firstIndex / max_items);
|
||||
c++;
|
||||
if(c > count) c = count;
|
||||
this->firstIndex = c * max_items;
|
||||
//this->value += step;
|
||||
//if(this->value > max) this->value=max;
|
||||
//OnValueChanged(cea2);
|
||||
//this->ValueChanged.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return View::OnEvent(event,myBounds,visibleBounds);
|
||||
}
|
||||
|
||||
void ScrollableTextListView::OnDraw(SDL_Renderer* renderer,SDL_Rect& rect)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
auto item_height = win->normal_font->MaxHeight()+(win->palette.borderSize*2);
|
||||
auto no_items = (rect.h-(win->palette.borderSize*2)) / item_height;
|
||||
auto max_items = no_items;
|
||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(this->firstIndex + no_items > this->items.size())
|
||||
{
|
||||
|
||||
no_items = this->items.size()-this->firstIndex;
|
||||
}
|
||||
|
||||
SDL_Rect _r2={.x=rect.x,.y=rect.y,.w=rect.w-32,.h=rect.h};
|
||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawRect(renderer,&_r2);
|
||||
_r2.x++;
|
||||
_r2.y++;
|
||||
_r2.w-=2;
|
||||
_r2.h-=2;
|
||||
}
|
||||
|
||||
for(int i = 0; i < no_items; i++)
|
||||
{
|
||||
int realI = i+(int)firstIndex;
|
||||
if(realI == this->selected)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
SDL_Rect r2={.x=rect.x+win->palette.borderSize,.y=rect.y+win->palette.borderSize+(item_height*i),.w=rect.w-(win->palette.borderSize*2)-32,.h=item_height};
|
||||
SDL_RenderFillRect(renderer,&r2);
|
||||
win->normal_font->Render(renderer,rect.x+(win->palette.borderSize*3),(rect.y+(win->palette.borderSize*3))+(item_height*i),this->items[realI],color);
|
||||
}
|
||||
else {
|
||||
win->normal_font->Render(renderer,rect.x+(win->palette.borderSize*3),(rect.y+(win->palette.borderSize*3))+(item_height*i),this->items[realI],win->palette.accent);
|
||||
}
|
||||
}
|
||||
|
||||
auto scrollX = (rect.w-32)+rect.x;
|
||||
auto topIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B1STATE);
|
||||
|
||||
auto topIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE);
|
||||
|
||||
auto middleIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
|
||||
auto middleIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
|
||||
auto bottomIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
||||
|
||||
auto bottomIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE);
|
||||
|
||||
SDL_Color& topcolor = win->palette.GetBorderColor(topIsHovering,isActive,topIsMouseDown);
|
||||
SDL_Color& topMiddleColor = win->palette.GetBorderColor(topIsHovering||middleIsHovering,isActive,topIsMouseDown||middleIsMouseDown);
|
||||
SDL_Color& middleColor = win->palette.GetBorderColor(middleIsHovering,isActive,middleIsMouseDown);
|
||||
SDL_Color& bottomMiddleColor = win->palette.GetBorderColor(bottomIsHovering||middleIsHovering,isActive,bottomIsMouseDown||middleIsMouseDown);
|
||||
SDL_Color& bottomColor = win->palette.GetBorderColor(bottomIsHovering,isActive,bottomIsMouseDown);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,topcolor.r,topcolor.g,topcolor.b,topcolor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,scrollX,rect.y+i,scrollX+32,rect.y+i);
|
||||
SDL_RenderDrawLine(renderer,scrollX+i,rect.y,scrollX+i,rect.y+32);
|
||||
SDL_RenderDrawLine(renderer,scrollX+32-(1+i),rect.y,scrollX+32-(1+i),rect.y+32);
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,topMiddleColor.r,topMiddleColor.g,topMiddleColor.b,topMiddleColor.a);
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,scrollX,(rect.y+32)-i,scrollX+32,(rect.y+32)-i);
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,middleColor.r,middleColor.g,middleColor.b,middleColor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,scrollX+i,rect.y+33,scrollX+i,rect.y+(rect.h-33));
|
||||
SDL_RenderDrawLine(renderer,scrollX+32-(1+i),rect.y+33,scrollX+32-(1+i),rect.y+(rect.h-33));
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,bottomColor.r,bottomColor.g,bottomColor.b,bottomColor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,scrollX,(rect.y+rect.h)-(i+1),scrollX+32,(rect.y+rect.h)-(i+1));
|
||||
SDL_RenderDrawLine(renderer,scrollX+i,rect.y+(rect.h-32),scrollX+i,rect.y+rect.h);
|
||||
SDL_RenderDrawLine(renderer,scrollX+32-(1+i),rect.y+(rect.h-32),scrollX+32-(1+i),rect.y+rect.h);
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,bottomMiddleColor.r,bottomMiddleColor.g,bottomMiddleColor.b,bottomMiddleColor.a);
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,scrollX,(rect.y+(rect.h-32))+i,scrollX+32,(rect.y+(rect.h-32))+i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
int x1 = 15;
|
||||
int y1 = 8 + i;
|
||||
|
||||
int x2 = 9;
|
||||
int y2 = 18 + i;
|
||||
|
||||
SDL_RenderDrawLine(renderer,x1+scrollX,y1+rect.y,x2+scrollX,y2+rect.y);
|
||||
|
||||
int x3 = 31-x1;
|
||||
int x4 = 31-x2;
|
||||
SDL_RenderDrawLine(renderer,x3+scrollX,y1+rect.y,x4+scrollX,y2+rect.y);
|
||||
|
||||
int y3 = 31-y1;
|
||||
int y4 = 31-y2;
|
||||
|
||||
SDL_RenderDrawLine(renderer,x1+scrollX,y3+rect.y+(rect.h-32),x2+scrollX,y4+rect.y+(rect.h-32));
|
||||
SDL_RenderDrawLine(renderer,x3+scrollX,y3+rect.y+(rect.h-32),x4+scrollX,y4+rect.y+(rect.h-32));
|
||||
}
|
||||
|
||||
uint64_t height = (uint64_t)rect.h - 66;
|
||||
uint64_t scrollSize = 4;
|
||||
uint64_t count = max_items == 0 ? 0 : this->items.size() / max_items;
|
||||
|
||||
if((items.size() % max_items) == 0) count--;
|
||||
|
||||
if(count > 0)
|
||||
scrollSize = height / count;
|
||||
|
||||
if(scrollSize < 4) scrollSize=4;
|
||||
|
||||
|
||||
double scroll = 0;
|
||||
if(count > 0 && max_items > 0)
|
||||
scroll = (double)(this->firstIndex / max_items) / (double)count;
|
||||
|
||||
uint64_t scrollY = scroll * (height-scrollSize);
|
||||
|
||||
|
||||
|
||||
if(scrollY > height-scrollSize) scrollY = height-scrollSize;
|
||||
SDL_Rect r2={.x=scrollX+win->palette.borderSize,.y=(int)scrollY+rect.y+32,.w = 32-(win->palette.borderSize*2),.h=(int)scrollSize};
|
||||
SDL_RenderFillRect(renderer,&r2);
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,245 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/TabView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
void TabView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
auto view = this->GetViewAt(0);
|
||||
auto win =this->GetWindow();
|
||||
if(this->tabsVisible)
|
||||
{
|
||||
|
||||
int h =
|
||||
win->monospaced_font->MaxHeight() + (win->palette.borderSize*3);
|
||||
int w = win->monospaced_font->MaxWidth() + (win->palette.borderSize*3);
|
||||
|
||||
size_t noItems = this->items.size();
|
||||
size_t offset = 0;
|
||||
size_t width = noItems == 0 ? 0 : (r.w / noItems);
|
||||
if(noItems > 0 && (r.w / noItems) < w*5)
|
||||
{
|
||||
offset=this->firstTab;
|
||||
noItems = (r.w - (w*2)) / (w * 5);
|
||||
width = noItems == 0 ? 0 : ((r.w - (w*2)) / noItems);
|
||||
if(offset > items.size())
|
||||
offset = items.size()-3;
|
||||
if((offset+noItems)>items.size()) noItems = items.size()-offset;
|
||||
}
|
||||
|
||||
|
||||
for(size_t i = 0; i < noItems; i++)
|
||||
{
|
||||
|
||||
Clipper clipper(renderer,r);
|
||||
int yBottom = (h - 1)+r.y;
|
||||
//auto bc = win->palette.GetBorderColor(false,(i+offset)==this->selectedTab,false);
|
||||
std::string text = this->items[i+offset].first;
|
||||
int textW;
|
||||
int textH;
|
||||
win->monospaced_font->CalculateSize(text,textW,textH);
|
||||
|
||||
|
||||
|
||||
|
||||
/*if(i>0)
|
||||
{
|
||||
//auto bc2 = win->palette.GetBorderColor(false,(i+offset)==this->selectedTab || ((i+offset)-1)==this->selectedTab,false);
|
||||
//SDL_SetRenderDrawColor(renderer,bc2.r,bc2.g,bc2.b,bc2.a);
|
||||
// SDL_RenderDrawLine(renderer,(width*i)+r.x,r.y,(width*i)+r.x,yBottom);
|
||||
}*/
|
||||
|
||||
//SDL_SetRenderDrawColor(renderer,bc.r,bc.g,bc.b,bc.a);
|
||||
if((i+offset)==this->selectedTab)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
SDL_Rect r0={.x=(int)(width*i+1)+r.x,.y=r.y,.w=(int)width-2,.h=yBottom-r.y};
|
||||
SDL_RenderFillRect(renderer,&r0);
|
||||
}
|
||||
//SDL_RenderDrawLine(renderer,(width*i+1)+r.x,yBottom,(width*(i+1)-2),yBottom);
|
||||
clipper.Clip({.x=(int)(width*i+1)+r.x,.y=r.y,.w=(int)width-2,.h=yBottom-r.y});
|
||||
int textX = ((width-2)/2) - (textW/2);
|
||||
int textY = ((yBottom-r.y)/2) - (textH/2);
|
||||
|
||||
win->monospaced_font->Render(renderer,textX+r.x+(width*i+2),textY+r.y,text,((i+offset)==this->selectedTab) ? win->palette.background : win->palette.accent);
|
||||
}
|
||||
|
||||
if(noItems != items.size())
|
||||
{
|
||||
auto greaterThanX=(r.w-w)+r.x;
|
||||
auto lessThanX = greaterThanX-w;
|
||||
int lgtX;
|
||||
int lgtY;
|
||||
win->monospaced_font->CalculateSize("<",lgtX,lgtY);
|
||||
lgtX = (w/2)-(lgtX/2);
|
||||
lgtY = (h/2)-(lgtY/2);
|
||||
win->monospaced_font->Render(renderer,lessThanX+lgtX,r.y+lgtY,"<",win->palette.accent);
|
||||
|
||||
win->monospaced_font->CalculateSize(">",lgtX,lgtY);
|
||||
lgtX = (w/2)-(lgtX/2);
|
||||
lgtY = (h/2)-(lgtY/2);
|
||||
win->monospaced_font->Render(renderer,greaterThanX+lgtX,r.y+lgtY,">",win->palette.accent);
|
||||
}
|
||||
|
||||
SDL_Rect viewBounds = {
|
||||
.x=r.x,
|
||||
.y=h+r.y,
|
||||
.w=r.w,
|
||||
.h=r.h-h
|
||||
};
|
||||
CallOnDraw(view,renderer,viewBounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(view != nullptr) CallOnDraw(view,renderer,r);
|
||||
}
|
||||
}
|
||||
bool TabView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
auto view = this->GetViewAt(0);
|
||||
auto win =this->GetWindow();
|
||||
if(this->tabsVisible)
|
||||
{
|
||||
int h =
|
||||
win->monospaced_font->MaxHeight() + (win->palette.borderSize*3);
|
||||
|
||||
int w = win->monospaced_font->MaxWidth() + (win->palette.borderSize*3);
|
||||
int yBottom = (h - 1)+myBounds.y;
|
||||
size_t noItems = this->items.size();
|
||||
size_t offset = 0;
|
||||
|
||||
size_t width = noItems == 0 ? 0 : (myBounds.w / noItems);
|
||||
if(noItems > 0 && (myBounds.w / noItems) < w*5)
|
||||
{
|
||||
offset=this->firstTab;
|
||||
noItems = (myBounds.w - (w*2)) / (w * 5);
|
||||
width = noItems == 0 ? 0 : ((myBounds.w - (w*2)) / noItems);
|
||||
if(offset > items.size())
|
||||
offset = items.size()-3;
|
||||
if((offset+noItems)>items.size()) noItems = items.size()-offset;
|
||||
}
|
||||
|
||||
int width_total = width*noItems;
|
||||
|
||||
if(event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT)
|
||||
{
|
||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
||||
{
|
||||
|
||||
if(event.button.y < myBounds.y+h && event.button.x < myBounds.x+width_total)
|
||||
{
|
||||
this->selectedTab = offset + ((event.button.x-myBounds.x) / width);
|
||||
return true;
|
||||
}
|
||||
if(event.button.y < myBounds.y+h && event.button.x < myBounds.x+myBounds.w)
|
||||
{
|
||||
if(noItems != items.size())
|
||||
{
|
||||
auto greaterThanX=myBounds.w-w+myBounds.x;
|
||||
auto lessThanX = greaterThanX-w;
|
||||
|
||||
|
||||
if(event.button.x >= lessThanX && event.button.x < greaterThanX)
|
||||
{
|
||||
firstTab--;
|
||||
if(firstTab >= items.size())
|
||||
firstTab=0;
|
||||
}
|
||||
else if(event.button.x >= greaterThanX)
|
||||
{
|
||||
firstTab++;
|
||||
if(firstTab >= items.size())
|
||||
firstTab = items.size()-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SDL_Rect viewBounds = {
|
||||
.x=0,
|
||||
.y=h,
|
||||
.w=myBounds.w,
|
||||
.h=myBounds.h-h
|
||||
};
|
||||
|
||||
SDL_Rect theirVisibleBounds = viewBounds;
|
||||
theirVisibleBounds.x += visibleBounds.x;
|
||||
theirVisibleBounds.y += visibleBounds.y;
|
||||
|
||||
viewBounds.x += myBounds.x;
|
||||
viewBounds.y += myBounds.y;
|
||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
||||
return CallOnEvent(view,event,viewBounds,theirVisibleBounds);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(view != nullptr) return CallOnEvent(view,event,myBounds,visibleBounds);
|
||||
}
|
||||
return View::OnEvent(event,myBounds,visibleBounds);
|
||||
}
|
||||
|
||||
|
||||
TabView::TabView() : TabView(true)
|
||||
{
|
||||
|
||||
}
|
||||
TabView::TabView(bool tabsVisible) : ContainerView()
|
||||
{
|
||||
this->tabsVisible=tabsVisible;
|
||||
this->firstTab=0;
|
||||
this->selectedTab=0;
|
||||
}
|
||||
|
||||
|
||||
void TabView::AddTab(std::string name, View* view, bool owns)
|
||||
{
|
||||
for(auto& item : this->items)
|
||||
{
|
||||
if(item.second.first == view) return;
|
||||
}
|
||||
this->AssignChildParentToThis(view);
|
||||
this->items.push_back(std::pair<std::string,std::pair<View*,bool>>(name,std::pair<View*,bool>(view,owns)));
|
||||
}
|
||||
void TabView::RemoveTab(View* view)
|
||||
{
|
||||
for(auto index = this->items.begin(); index != this->items.end(); index++)
|
||||
{
|
||||
if(index->second.first == view)
|
||||
{
|
||||
if(index->second.second) delete index->second.first;
|
||||
this->items.erase(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void TabView::Clear()
|
||||
{
|
||||
for(auto& item : this->items)
|
||||
{
|
||||
if(item.second.second) delete item.second.first;
|
||||
}
|
||||
items.clear();
|
||||
}
|
||||
size_t TabView::ViewCount()
|
||||
{
|
||||
return this->items.empty() ? 0 : 1;
|
||||
}
|
||||
View* TabView::GetViewAt(size_t index)
|
||||
{
|
||||
if(this->items.empty()) return nullptr;
|
||||
if(this->selectedTab >= this->items.size()) return this->items.back().second.first;
|
||||
return this->items[this->selectedTab].second.first;
|
||||
}
|
||||
TabView::~TabView()
|
||||
{
|
||||
for(auto& item : this->items)
|
||||
{
|
||||
if(item.second.second) delete item.second.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,140 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
|
||||
#include "TessesFramework/SDL2/Views/TextListView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
TextListView::TextListView() : View()
|
||||
{
|
||||
this->firstIndex=0;
|
||||
this->selected=-1;
|
||||
}
|
||||
bool TextListView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
auto item_height = win->normal_font->MaxHeight()+(win->palette.borderSize*2);
|
||||
auto no_items = (myBounds.h-(win->palette.borderSize*2)) / item_height;
|
||||
|
||||
if(this->items.size() > no_items)
|
||||
{
|
||||
|
||||
if(this->items.size() - this->firstIndex < no_items)
|
||||
{
|
||||
this->firstIndex = this->items.size() - no_items;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
this->firstIndex=0;
|
||||
|
||||
no_items = (int)this->items.size();
|
||||
}
|
||||
if(event.type == SDL_KEYDOWN)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_ISACTIVE))
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_HOME:
|
||||
this->selected=0;
|
||||
this->firstIndex=0;
|
||||
break;
|
||||
case SDLK_END:
|
||||
this->selected = (int)(this->items.size()-1);
|
||||
this->firstIndex = (this->selected/no_items) * no_items;
|
||||
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
this->selected++;
|
||||
if(this->selected < -1 || this->selected >= this->items.size())
|
||||
{
|
||||
this->selected=0;
|
||||
}
|
||||
this->firstIndex = (this->selected/no_items) * no_items;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
this->selected--;
|
||||
if(this->selected < 0 || this->selected >= this->items.size())
|
||||
{
|
||||
this->selected = (int)(this->items.size()-1);
|
||||
}
|
||||
|
||||
this->firstIndex = (this->selected/no_items) * no_items;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_MOUSEBUTTONUP && event.button.x >= (visibleBounds.x+win->palette.borderSize) && event.button.x < (visibleBounds.x+visibleBounds.w)-(win->palette.borderSize*2) && event.button.y >= (visibleBounds.y+win->palette.borderSize) && event.button.y < (visibleBounds.y+visibleBounds.h)-(win->palette.borderSize*2))
|
||||
{
|
||||
win->MakeActive(this);
|
||||
auto myRealY=event.button.y - (myBounds.y+win->palette.borderSize);
|
||||
auto yThing = myRealY / item_height;
|
||||
|
||||
if(yThing < no_items)
|
||||
{
|
||||
auto high= yThing+this->firstIndex;
|
||||
this->selected = (int)high;
|
||||
}
|
||||
|
||||
}
|
||||
return View::OnEvent(event,myBounds,visibleBounds);
|
||||
}
|
||||
|
||||
void TextListView::OnDraw(SDL_Renderer* renderer,SDL_Rect& rect)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
auto item_height = win->normal_font->MaxHeight()+(win->palette.borderSize*2);
|
||||
auto no_items = (rect.h-(win->palette.borderSize*2)) / item_height;
|
||||
auto isHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
||||
auto isMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
SDL_Color& color = win->palette.GetBorderColor(isHovering,isActive,isMouseDown);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,color.r,color.g,color.b,color.a);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(this->items.size() > no_items)
|
||||
{
|
||||
|
||||
if(this->items.size() - this->firstIndex < no_items)
|
||||
{
|
||||
this->firstIndex = this->items.size() - no_items;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this->firstIndex=0;
|
||||
no_items = (int)this->items.size();
|
||||
}
|
||||
|
||||
SDL_Rect r2={.x=rect.x,.y=rect.y,.w=rect.w,.h=rect.h};
|
||||
for(size_t i=0;i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawRect(renderer,&r2);
|
||||
r2.x++;
|
||||
r2.y++;
|
||||
r2.w-=2;
|
||||
r2.h-=2;
|
||||
}
|
||||
|
||||
for(int i = 0; i < no_items; i++)
|
||||
{
|
||||
int realI = i+(int)firstIndex;
|
||||
if(realI == this->selected)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
SDL_Rect r2={.x=rect.x+win->palette.borderSize,.y=rect.y+win->palette.borderSize+(item_height*i),.w=rect.w-(win->palette.borderSize*2),.h=item_height};
|
||||
SDL_RenderFillRect(renderer,&r2);
|
||||
win->normal_font->Render(renderer,rect.x+(win->palette.borderSize*3),(rect.y+(win->palette.borderSize*3))+(item_height*i),this->items[realI],color);
|
||||
}
|
||||
else {
|
||||
win->normal_font->Render(renderer,rect.x+(win->palette.borderSize*3),(rect.y+(win->palette.borderSize*3))+(item_height*i),this->items[realI],win->palette.accent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,322 +0,0 @@
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
|
||||
#include "TessesFramework/SDL2/Views/VScrollView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
std::pair<int,int> VScrollView::PreferedMinSize()
|
||||
{
|
||||
return std::pair<int,int>(32,-1);
|
||||
}
|
||||
void VScrollView::OnValueChanged(GUIEventArgs& e)
|
||||
{
|
||||
|
||||
}
|
||||
VScrollView::VScrollView() : VScrollView(0, 0, 100)
|
||||
{
|
||||
|
||||
}
|
||||
VScrollView::VScrollView(uint64_t value, uint64_t min, uint64_t max,uint64_t step) : View()
|
||||
{
|
||||
this->value = value;
|
||||
this->min = min;
|
||||
this->max = max;
|
||||
|
||||
this->step=step;
|
||||
}
|
||||
void VScrollView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
auto win = this->GetWindow();
|
||||
auto topIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B1STATE);
|
||||
auto isActive = this->GetViewFlag(VIEWFLAG_ISACTIVE);
|
||||
auto topIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE);
|
||||
|
||||
auto middleIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_STATE);
|
||||
|
||||
auto middleIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE);
|
||||
|
||||
|
||||
auto bottomIsHovering = this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
||||
|
||||
auto bottomIsMouseDown = this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE);
|
||||
|
||||
SDL_Color& topcolor = win->palette.GetBorderColor(topIsHovering,isActive,topIsMouseDown);
|
||||
SDL_Color& topMiddleColor = win->palette.GetBorderColor(topIsHovering||middleIsHovering,isActive,topIsMouseDown||middleIsMouseDown);
|
||||
SDL_Color& middleColor = win->palette.GetBorderColor(middleIsHovering,isActive,middleIsMouseDown);
|
||||
SDL_Color& bottomMiddleColor = win->palette.GetBorderColor(bottomIsHovering||middleIsHovering,isActive,bottomIsMouseDown||middleIsMouseDown);
|
||||
SDL_Color& bottomColor = win->palette.GetBorderColor(bottomIsHovering,isActive,bottomIsMouseDown);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,topcolor.r,topcolor.g,topcolor.b,topcolor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,r.x,r.y+i,r.x+r.w,r.y+i);
|
||||
SDL_RenderDrawLine(renderer,r.x+i,r.y,r.x+i,r.y+32);
|
||||
SDL_RenderDrawLine(renderer,r.x+r.w-(1+i),r.y,r.x+r.w-(1+i),r.y+32);
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,topMiddleColor.r,topMiddleColor.g,topMiddleColor.b,topMiddleColor.a);
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,r.x,(r.y+32)-i,r.x+r.w,(r.y+32)-i);
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,middleColor.r,middleColor.g,middleColor.b,middleColor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,r.x+i,r.y+33,r.x+i,r.y+(r.h-33));
|
||||
SDL_RenderDrawLine(renderer,r.x+r.w-(1+i),r.y+33,r.x+r.w-(1+i),r.y+(r.h-33));
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,bottomColor.r,bottomColor.g,bottomColor.b,bottomColor.a);
|
||||
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,r.x,(r.y+r.h)-(i+1),r.x+r.w,(r.y+r.h)-(i+1));
|
||||
SDL_RenderDrawLine(renderer,r.x+i,r.y+(r.h-32),r.x+i,r.y+r.h);
|
||||
SDL_RenderDrawLine(renderer,r.x+r.w-(1+i),r.y+(r.h-32),r.x+r.w-(1+i),r.y+r.h);
|
||||
}
|
||||
SDL_SetRenderDrawColor(renderer,bottomMiddleColor.r,bottomMiddleColor.g,bottomMiddleColor.b,bottomMiddleColor.a);
|
||||
for(int i = 0; i < win->palette.borderSize; i++)
|
||||
{
|
||||
SDL_RenderDrawLine(renderer,r.x,(r.y+(r.h-32))+i,r.x+r.w,(r.y+(r.h-32))+i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
SDL_SetRenderDrawColor(renderer,win->palette.accent.r,win->palette.accent.g,win->palette.accent.b,win->palette.accent.a);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
int x1 = 15;
|
||||
int y1 = 8 + i;
|
||||
|
||||
int x2 = 9;
|
||||
int y2 = 18 + i;
|
||||
|
||||
SDL_RenderDrawLine(renderer,x1+r.x,y1+r.y,x2+r.x,y2+r.y);
|
||||
|
||||
int x3 = 31-x1;
|
||||
int x4 = 31-x2;
|
||||
SDL_RenderDrawLine(renderer,x3+r.x,y1+r.y,x4+r.x,y2+r.y);
|
||||
|
||||
int y3 = 31-y1;
|
||||
int y4 = 31-y2;
|
||||
|
||||
SDL_RenderDrawLine(renderer,x1+r.x,y3+r.y+(r.h-32),x2+r.x,y4+r.y+(r.h-32));
|
||||
SDL_RenderDrawLine(renderer,x3+r.x,y3+r.y+(r.h-32),x4+r.x,y4+r.y+(r.h-32));
|
||||
}
|
||||
|
||||
uint64_t height = (uint64_t)r.h - 66;
|
||||
uint64_t scrollSize = 4;
|
||||
uint64_t dif = max-min;
|
||||
if(dif > 0)
|
||||
scrollSize = height / dif;
|
||||
|
||||
if(scrollSize < 4) scrollSize=4;
|
||||
|
||||
|
||||
double scroll = 0;
|
||||
if(dif > 0)
|
||||
scroll = (double)(value-min) / (double)dif;
|
||||
|
||||
uint64_t scrollY = scroll * (height-scrollSize);
|
||||
|
||||
|
||||
|
||||
if(scrollY > height-scrollSize) scrollY = height-scrollSize;
|
||||
SDL_Rect r2={.x=r.x+win->palette.borderSize,.y=(int)scrollY+r.y+32,.w = r.w-(win->palette.borderSize*2),.h=(int)scrollSize};
|
||||
SDL_RenderFillRect(renderer,&r2);
|
||||
}
|
||||
bool VScrollView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
if(event.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
bool inside = event.motion.x >= visibleBounds.x && event.motion.x < visibleBounds.x+visibleBounds.w && event.motion.y >= visibleBounds.y && event.motion.y < visibleBounds.y+visibleBounds.h;
|
||||
bool hoverFlag = this->GetViewFlag(VIEWFLAG_HOVER_STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B1STATE) || this->GetViewFlag(VIEWFLAG_HOVER_B2STATE);
|
||||
if(inside && !hoverFlag)
|
||||
{
|
||||
int y = event.motion.y - myBounds.y;
|
||||
if(y <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else if(y >= myBounds.h-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
||||
}
|
||||
|
||||
GUIEventArgs e;
|
||||
this->OnEnter(e);
|
||||
this->Enter.Invoke(this,e);
|
||||
}
|
||||
else if(!inside && hoverFlag)
|
||||
{
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
GUIEventArgs e;
|
||||
this->OnLeave(e);
|
||||
this->Leave.Invoke(this,e);
|
||||
} else if(inside) {
|
||||
int y = event.motion.y - myBounds.y;
|
||||
if(y <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else if(y >= myBounds.h-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,true);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,false);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B1STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_B2STATE,false);
|
||||
this->SetViewFlag(VIEWFLAG_HOVER_STATE,true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
||||
{
|
||||
int y = event.motion.y - myBounds.y;
|
||||
if(y <= 32)
|
||||
{
|
||||
value = min;
|
||||
}
|
||||
else if(y >= myBounds.h-32)
|
||||
{
|
||||
value=max;
|
||||
}
|
||||
else {
|
||||
uint64_t height = (uint64_t)myBounds.h - 66;
|
||||
uint64_t y2 = y-33;
|
||||
|
||||
double off = (double)y2 / (double)height;
|
||||
|
||||
value = round((max-min)*off)+min;
|
||||
GUIEventArgs cea2;
|
||||
this->ValueChanged.Invoke(this,cea2);
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
if(event.button.x >= visibleBounds.x && event.button.x < visibleBounds.x+visibleBounds.w && event.button.y >= visibleBounds.y && event.button.y < visibleBounds.y+visibleBounds.h)
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
if(cea.y <= 32)
|
||||
{
|
||||
//up btn
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,true);
|
||||
}
|
||||
else if(cea.y >= myBounds.h-32)
|
||||
{
|
||||
//down btn
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,true);
|
||||
}
|
||||
else {
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,true);
|
||||
|
||||
uint64_t height = (uint64_t)myBounds.h - 66;
|
||||
uint64_t y2 = cea.y-33;
|
||||
|
||||
double off = (double)y2 / (double)height;
|
||||
|
||||
value = round((max-min)*off)+min;
|
||||
GUIEventArgs cea2;
|
||||
this->ValueChanged.Invoke(this,cea2);
|
||||
}
|
||||
OnMouseDown(cea);
|
||||
this->MouseDown.Invoke(this,cea);
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_STATE))
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_STATE,false);
|
||||
OnMouseUp(cea);
|
||||
this->MouseUp.Invoke(this,cea);
|
||||
GUIEventArgs cea2;
|
||||
OnClick(cea2);
|
||||
this->Click.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE))
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B1STATE,false);
|
||||
OnMouseUp(cea);
|
||||
this->MouseUp.Invoke(this,cea);
|
||||
GUIEventArgs cea2;
|
||||
OnClick(cea2);
|
||||
this->Click.Invoke(this,cea2);
|
||||
this->value -= step;
|
||||
if(this->value < min) this->value=min;
|
||||
if(this->value >= max) this->value=min;
|
||||
OnValueChanged(cea2);
|
||||
this->ValueChanged.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
if(this->GetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE))
|
||||
{
|
||||
GUIMouseButtonEventArgs cea;
|
||||
cea.button = (int)event.button.button;
|
||||
cea.x = event.button.x - myBounds.x;
|
||||
cea.y = event.button.y - myBounds.y;
|
||||
cea.which = event.button.which;
|
||||
this->SetViewFlag(VIEWFLAG_MOUSEDOWN_B2STATE,false);
|
||||
OnMouseUp(cea);
|
||||
this->MouseUp.Invoke(this,cea);
|
||||
GUIEventArgs cea2;
|
||||
OnClick(cea2);
|
||||
this->Click.Invoke(this,cea2);
|
||||
this->value += step;
|
||||
if(this->value > max) this->value=max;
|
||||
OnValueChanged(cea2);
|
||||
this->ValueChanged.Invoke(this,cea2);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return View::OnEvent(event,myBounds,visibleBounds);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,270 +0,0 @@
|
||||
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include "TessesFramework/SDL2/Views/VStackView.hpp"
|
||||
|
||||
namespace Tesses::Framework::SDL2::Views
|
||||
{
|
||||
void VStackView::OnDraw(SDL_Renderer* renderer, SDL_Rect& r)
|
||||
{
|
||||
int numberOfCells = 0;
|
||||
int freeHeight = r.h;
|
||||
std::vector<int> sizes;
|
||||
sizes.resize(this->items.size());
|
||||
|
||||
freeHeight -= (this->items.size() - 1) * this->spacing;
|
||||
|
||||
for(size_t i = 0; i < this->items.size(); i++)
|
||||
{
|
||||
if(this->items[i].first > 0)
|
||||
{
|
||||
//static size
|
||||
sizes[i] = this->items[i].first;
|
||||
freeHeight-= this->items[i].first;
|
||||
}
|
||||
else if(this->items[i].first == 0)
|
||||
{
|
||||
auto prefered = this->items[i].second.first->PreferedMinSize();
|
||||
if(prefered.second > 0)
|
||||
{
|
||||
sizes[i] = prefered.second;
|
||||
freeHeight -= prefered.second;
|
||||
}
|
||||
else {
|
||||
sizes[i] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
numberOfCells -= this->items[i].first;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cellSize = numberOfCells == 0 ? 0 : freeHeight / numberOfCells;
|
||||
|
||||
|
||||
for(int i = 0; i < this->items.size();i++)
|
||||
{
|
||||
if(this->items[i].first < 0)
|
||||
{
|
||||
int myHeight =((-(this->items[i].first)) * cellSize);
|
||||
|
||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
||||
if(minSz.second > myHeight) {
|
||||
sizes[i] = minSz.second;
|
||||
freeHeight -= minSz.second;
|
||||
numberOfCells -= -(this->items[i].first);
|
||||
}
|
||||
}
|
||||
}
|
||||
cellSize = numberOfCells == 0 ? 0 : freeHeight / numberOfCells;
|
||||
int y = 0;
|
||||
|
||||
|
||||
for(size_t i = 0; i < this->items.size(); i++)
|
||||
{
|
||||
if(i > 0) y += spacing;
|
||||
|
||||
if(sizes[i] == 0)
|
||||
{
|
||||
int myHeight =((-(this->items[i].first)) * cellSize);
|
||||
|
||||
|
||||
SDL_Rect theirBounds = {
|
||||
.x = 0,
|
||||
.y=y,
|
||||
.w=r.w,
|
||||
.h=myHeight
|
||||
};
|
||||
|
||||
|
||||
theirBounds.x += r.x;
|
||||
theirBounds.y += r.y;
|
||||
|
||||
|
||||
|
||||
CallOnDraw(this->items[i].second.first,renderer, theirBounds);
|
||||
y+=myHeight;
|
||||
}
|
||||
else {
|
||||
|
||||
SDL_Rect theirBounds = {
|
||||
.x = 0,
|
||||
.y=y,
|
||||
.w=r.w,
|
||||
.h=sizes[i]
|
||||
};
|
||||
|
||||
|
||||
theirBounds.x += r.x;
|
||||
theirBounds.y += r.y;
|
||||
|
||||
|
||||
|
||||
CallOnDraw(this->items[i].second.first,renderer, theirBounds);
|
||||
y+=sizes[i];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
bool VStackView::OnEvent(SDL_Event& event, SDL_Rect& myBounds, SDL_Rect& visibleBounds)
|
||||
{
|
||||
int numberOfCells = 0;
|
||||
int freeHeight = myBounds.h;
|
||||
std::vector<int> sizes;
|
||||
sizes.resize(this->items.size());
|
||||
|
||||
|
||||
freeHeight -= (this->items.size() - 1) * this->spacing;
|
||||
for(size_t i = 0; i < this->items.size(); i++)
|
||||
{
|
||||
if(this->items[i].first > 0)
|
||||
{
|
||||
//static size
|
||||
sizes[i] = this->items[i].first;
|
||||
freeHeight-= this->items[i].first;
|
||||
}
|
||||
else if(this->items[i].first == 0)
|
||||
{
|
||||
auto prefered = this->items[i].second.first->PreferedMinSize();
|
||||
if(prefered.second > 0)
|
||||
{
|
||||
sizes[i] = prefered.second;
|
||||
freeHeight -= prefered.second;
|
||||
}
|
||||
else {
|
||||
sizes[i] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
numberOfCells -= this->items[i].first;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cellSize = numberOfCells == 0 ? 0 : freeHeight / numberOfCells;
|
||||
|
||||
for(int i = 0; i < this->items.size();i++)
|
||||
{
|
||||
if(this->items[i].first < 0)
|
||||
{
|
||||
int myHeight =((-(this->items[i].first)) * cellSize);
|
||||
|
||||
auto minSz = this->items[i].second.first->PreferedMinSize();
|
||||
if(minSz.second > myHeight) {
|
||||
sizes[i] = minSz.second;
|
||||
freeHeight -= minSz.second;
|
||||
numberOfCells -= -(this->items[i].first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cellSize = numberOfCells == 0 ? 0 : freeHeight / numberOfCells;
|
||||
int y = 0;
|
||||
|
||||
|
||||
for(size_t i = 0; i < this->items.size(); i++)
|
||||
{
|
||||
if(i > 0) y += spacing;
|
||||
if(sizes[i] == 0)
|
||||
{
|
||||
int myHeight =((-(this->items[i].first)) * cellSize);
|
||||
|
||||
SDL_Rect theirBounds = {
|
||||
.x = 0,
|
||||
.y=y,
|
||||
.w=myBounds.w,
|
||||
.h=myHeight
|
||||
};
|
||||
|
||||
SDL_Rect theirVisibleBounds = theirBounds;
|
||||
theirVisibleBounds.x += visibleBounds.x;
|
||||
theirVisibleBounds.y += visibleBounds.y;
|
||||
|
||||
theirBounds.x += myBounds.x;
|
||||
theirBounds.y += myBounds.y;
|
||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
||||
|
||||
|
||||
|
||||
CallOnEvent(this->items[i].second.first,event,theirBounds,theirVisibleBounds);
|
||||
|
||||
y+=myHeight;
|
||||
}
|
||||
else {
|
||||
|
||||
SDL_Rect theirBounds = {
|
||||
.x = 0,
|
||||
.y=y,
|
||||
.w=myBounds.w,
|
||||
.h=sizes[i]
|
||||
};
|
||||
|
||||
SDL_Rect theirVisibleBounds = theirBounds;
|
||||
theirVisibleBounds.x += visibleBounds.x;
|
||||
theirVisibleBounds.y += visibleBounds.y;
|
||||
|
||||
theirBounds.x += myBounds.x;
|
||||
theirBounds.y += myBounds.y;
|
||||
Clipper::ClipRect(theirVisibleBounds, visibleBounds);
|
||||
|
||||
|
||||
|
||||
CallOnEvent(this->items[i].second.first,event,theirBounds,theirVisibleBounds);
|
||||
|
||||
y+=sizes[i];
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
VStackView::VStackView() : ContainerView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VStackView::Add(int sz, View* view, bool owns)
|
||||
{
|
||||
this->items.push_back(std::pair<int,std::pair<View*,bool>>(sz,std::pair<View*,bool>(view,owns)));
|
||||
this->AssignChildParentToThis(view);
|
||||
}
|
||||
void VStackView::Remove(View* view)
|
||||
{
|
||||
for(auto index = this->items.begin(); index < this->items.end(); index++)
|
||||
{
|
||||
if(index->second.first == view)
|
||||
{
|
||||
|
||||
if(index->second.first != nullptr && index->second.second)
|
||||
delete view;
|
||||
this->items.erase(index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void VStackView::Clear()
|
||||
{
|
||||
for(auto& item : this->items)
|
||||
if(item.second.second && item.second.first != nullptr) delete item.second.first;
|
||||
items = {};
|
||||
}
|
||||
|
||||
size_t VStackView::ViewCount()
|
||||
{
|
||||
return this->items.size();
|
||||
}
|
||||
View* VStackView::GetViewAt(size_t index)
|
||||
{
|
||||
return this->items.at(index).second.first;
|
||||
}
|
||||
|
||||
VStackView::~VStackView()
|
||||
{
|
||||
for(auto& item : this->items)
|
||||
if(item.second.second && item.second.first != nullptr) delete item.second.first;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -203,7 +203,7 @@ namespace Tesses::Framework::Serialization::Json
|
||||
}
|
||||
if((v & 0xFC00) != 0xDC00)
|
||||
{
|
||||
throw TextException("Not a lower utf-16 surrogate pair.");
|
||||
throw std::runtime_error("Not a lower utf-16 surrogate pair.");
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ namespace Tesses::Framework::Serialization::Json
|
||||
else
|
||||
{
|
||||
|
||||
throw TextException("Could not read lower utf-16 surrogate pair.");
|
||||
throw std::runtime_error("Could not read lower utf-16 surrogate pair.");
|
||||
}
|
||||
if(v2 <= 0x7F)
|
||||
{
|
||||
@@ -297,7 +297,7 @@ namespace Tesses::Framework::Serialization::Json
|
||||
size_t tokenIndex=0;
|
||||
|
||||
std::function<std::pair<std::string,bool>()> pop_token=[&tokens,&tokenIndex]()->std::pair<std::string,bool> {
|
||||
if(tokenIndex >= tokens.size()) throw TextException("Json tokens out of bounds.");
|
||||
if(tokenIndex >= tokens.size()) throw std::runtime_error("Json tokens out of bounds.");
|
||||
return tokens[tokenIndex++];
|
||||
};
|
||||
|
||||
@@ -324,7 +324,7 @@ namespace Tesses::Framework::Serialization::Json
|
||||
tkn = pop_token();
|
||||
if(tkn.second || tkn.first != ":")
|
||||
{
|
||||
throw TextException("Invalid JSON key value seperator.");
|
||||
throw std::runtime_error("Invalid JSON key value seperator.");
|
||||
}
|
||||
|
||||
auto value = read_token();
|
||||
@@ -341,7 +341,7 @@ namespace Tesses::Framework::Serialization::Json
|
||||
else
|
||||
{
|
||||
|
||||
throw TextException("Invalid JSON object.");
|
||||
throw std::runtime_error("Invalid JSON object.");
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Tesses::Framework::Serialization {
|
||||
if(rc)
|
||||
{
|
||||
std::string error = sqlite3_errmsg(sqlite);
|
||||
throw TextException(error);
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
this->data = static_cast<void*>(sqlite);
|
||||
#endif
|
||||
@@ -54,7 +54,9 @@ namespace Tesses::Framework::Serialization {
|
||||
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> SQLiteDatabase::Exec(std::string statement)
|
||||
{
|
||||
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> items;
|
||||
|
||||
Exec(statement,items);
|
||||
|
||||
return items;
|
||||
}
|
||||
void SQLiteDatabase::Exec(std::string statement,std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>>& items)
|
||||
@@ -67,7 +69,7 @@ namespace Tesses::Framework::Serialization {
|
||||
{
|
||||
std::string errstr = err == nullptr ? "" : err;
|
||||
sqlite3_free(err);
|
||||
throw TextException(errstr);
|
||||
throw std::runtime_error(errstr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -77,4 +79,4 @@ namespace Tesses::Framework::Serialization {
|
||||
sqlite3_close(static_cast<sqlite3*>(this->data));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace Tesses::Framework::Streams
|
||||
uint8_t ByteReader::ReadU8()
|
||||
{
|
||||
auto r = this->strm->ReadByte();
|
||||
if(r < 0) throw TextException("End of file");
|
||||
if(r < 0) throw std::runtime_error("End of file");
|
||||
return (uint8_t)r;
|
||||
}
|
||||
uint16_t ByteReader::ReadU16BE()
|
||||
{
|
||||
uint8_t data[2];
|
||||
if(this->strm->ReadBlock(data,2) != 2) throw TextException("End of file");
|
||||
if(this->strm->ReadBlock(data,2) != 2) throw std::runtime_error("End of file");
|
||||
uint16_t n = 0;
|
||||
n |= (uint16_t)data[0] << 8;
|
||||
n |= (uint16_t)data[1];
|
||||
@@ -33,7 +33,7 @@ namespace Tesses::Framework::Streams
|
||||
uint16_t ByteReader::ReadU16LE()
|
||||
{
|
||||
uint8_t data[2];
|
||||
if(this->strm->ReadBlock(data,2) != 2) throw TextException("End of file");
|
||||
if(this->strm->ReadBlock(data,2) != 2) throw std::runtime_error("End of file");
|
||||
uint16_t n = 0;
|
||||
n |= (uint16_t)data[0];
|
||||
n |= (uint16_t)data[1] << 8;
|
||||
@@ -45,7 +45,7 @@ namespace Tesses::Framework::Streams
|
||||
{
|
||||
|
||||
uint8_t data[4];
|
||||
if(this->strm->ReadBlock(data,4) != 4) throw TextException("End of file");
|
||||
if(this->strm->ReadBlock(data,4) != 4) throw std::runtime_error("End of file");
|
||||
uint32_t n = 0;
|
||||
n |= (uint32_t)data[0] << 24;
|
||||
n |= (uint32_t)data[1] << 16;
|
||||
@@ -57,7 +57,7 @@ namespace Tesses::Framework::Streams
|
||||
uint32_t ByteReader::ReadU32LE()
|
||||
{
|
||||
uint8_t data[4];
|
||||
if(this->strm->ReadBlock(data,4) != 4) throw TextException("End of file");
|
||||
if(this->strm->ReadBlock(data,4) != 4) throw std::runtime_error("End of file");
|
||||
uint32_t n = 0;
|
||||
n |= (uint32_t)data[0];
|
||||
n |= (uint32_t)data[1] << 8;
|
||||
@@ -68,7 +68,7 @@ namespace Tesses::Framework::Streams
|
||||
uint64_t ByteReader::ReadU64BE()
|
||||
{
|
||||
uint8_t data[8];
|
||||
if(this->strm->ReadBlock(data,8) != 8) throw TextException("End of file");
|
||||
if(this->strm->ReadBlock(data,8) != 8) throw std::runtime_error("End of file");
|
||||
uint64_t n = 0;
|
||||
n |= (uint64_t)data[0] << 56;
|
||||
n |= (uint64_t)data[1] << 48;
|
||||
@@ -84,7 +84,7 @@ namespace Tesses::Framework::Streams
|
||||
uint64_t ByteReader::ReadU64LE()
|
||||
{
|
||||
uint8_t data[8];
|
||||
if(this->strm->ReadBlock(data,8) != 8) throw TextException("End of file");
|
||||
if(this->strm->ReadBlock(data,8) != 8) throw std::runtime_error("End of file");
|
||||
uint64_t n = 0;
|
||||
n |= (uint64_t)data[0];
|
||||
n |= (uint64_t)data[1] << 8;
|
||||
|
||||
@@ -50,12 +50,12 @@ namespace Tesses::Framework::Streams
|
||||
}
|
||||
size_t FileStream::Read(uint8_t* buff, size_t sz)
|
||||
{
|
||||
if(!CanRead()) throw TextException("Cannot read from stream");
|
||||
if(!CanRead()) throw std::runtime_error("Cannot read from stream");
|
||||
return fread(buff,1, sz, this->f);
|
||||
}
|
||||
size_t FileStream::Write(const uint8_t* buff, size_t sz)
|
||||
{
|
||||
if(!CanWrite()) throw TextException("Cannot write to stream");
|
||||
if(!CanWrite()) throw std::runtime_error("Cannot write to stream");
|
||||
return fwrite(buff,1, sz, f);
|
||||
}
|
||||
bool FileStream::CanRead()
|
||||
|
||||
@@ -45,23 +45,10 @@ static GXRModeObj *rmode = NULL;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_THREADING)
|
||||
#include "TessesFramework/Threading/Mutex.hpp"
|
||||
#endif
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
#include <SDL2/SDL.h>
|
||||
#if defined(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
#include <SDL_ttf.h>
|
||||
#include <SDL_image.h>
|
||||
#else
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#endif
|
||||
#include "TessesFramework/SDL2/GUI.hpp"
|
||||
#endif
|
||||
|
||||
namespace Tesses::Framework
|
||||
{
|
||||
|
||||
EventList<uint64_t> OnItteraton;
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_THREADING) && (defined(GEKKO) || defined(__SWITCH__))
|
||||
namespace Threading
|
||||
@@ -104,11 +91,6 @@ namespace Tesses::Framework
|
||||
static void _sigInt(int c)
|
||||
{
|
||||
isRunningSig=false;
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
SDL_Event quitEvent;
|
||||
quitEvent.type = SDL_QUIT;
|
||||
SDL_PushEvent(&quitEvent);
|
||||
#endif
|
||||
}
|
||||
void TF_RunEventLoop()
|
||||
{
|
||||
@@ -177,9 +159,7 @@ namespace Tesses::Framework
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
Tesses::Framework::SDL2::gui.Update();
|
||||
#endif
|
||||
|
||||
}
|
||||
void TF_SetIsRunning(bool _isRunning)
|
||||
{
|
||||
@@ -191,11 +171,7 @@ namespace Tesses::Framework
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_THREADING) && (defined(GEKKO) || defined(__SWITCH__))
|
||||
Tesses::Framework::Threading::JoinAllThreads();
|
||||
#endif
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
SDL_Quit();
|
||||
Tesses::Framework::SDL2::gui.CloseWindows();
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
void TF_Init()
|
||||
{
|
||||
@@ -206,20 +182,6 @@ namespace Tesses::Framework
|
||||
sqlite3_vfs_register(sqlite3_demovfs(),1);
|
||||
#endif
|
||||
#endif
|
||||
#if defined(TESSESFRAMEWORK_ENABLE_SDL2)
|
||||
//SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS,"1");
|
||||
SDL_Init(SDL_INIT_EVERYTHING);
|
||||
TTF_Init();
|
||||
int r = IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_TIF | IMG_INIT_WEBP
|
||||
#if !defined(GEKKO) && !defined(__SWITCH__) && !defined(__PS2__)
|
||||
| IMG_INIT_JXL |IMG_INIT_AVIF
|
||||
#endif
|
||||
;
|
||||
IMG_Init(
|
||||
r
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -335,4 +297,4 @@ if (iResult != 0) {
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user