ok ok i made a ton of progress on theming
This commit is contained in:
parent
9ebb95135b
commit
5cbb13cf4b
14 changed files with 128 additions and 61 deletions
|
|
@ -135,17 +135,15 @@ namespace enginend{
|
|||
protected:
|
||||
std::string result;
|
||||
public:
|
||||
Font font;
|
||||
float fs;
|
||||
Color txc;
|
||||
std::string content;
|
||||
text(){fs=20;}
|
||||
text(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize,std::string txt):
|
||||
text(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,float fsize,std::string txt):
|
||||
//tinted(texture,color,x,y,w,h),
|
||||
font(f),fs(fsize),content(txt),txc(txcol)
|
||||
fs(fsize),content(txt)
|
||||
{
|
||||
this->x=x;this->y=y;this->w=w;this->h=h;
|
||||
this->texture=texture;this->c=color;
|
||||
this->texture=texture;this->theme=theme;
|
||||
result=content;
|
||||
size_t initp=0;
|
||||
while((initp=result.find("\n",initp))!=std::string::npos){
|
||||
|
|
@ -175,14 +173,14 @@ namespace enginend{
|
|||
tiny::echo("og: %f %f %f %f", x,y,w,h);
|
||||
tiny::echo("drawing text: %s", content.c_str());
|
||||
tiny::echo("transformed: %f %f %f %f", ax, ay, aw, ah);
|
||||
Vector2 minsize=MeasureTextEx(font,content.c_str(),fs,1);
|
||||
Vector2 charsize=MeasureTextEx(font," ",fs,1);
|
||||
Vector2 minsize=MeasureTextEx(this->theme->font,content.c_str(),fs,1);
|
||||
Vector2 charsize=MeasureTextEx(this->theme->font," ",fs,1);
|
||||
float p=charsize.x>charsize.y?charsize.x/minsize.x:charsize.y/minsize.y;
|
||||
p=p*2;
|
||||
int minh=(minsize.y>ah)?minsize.y:ah;
|
||||
int minw=(minsize.x>aw)?minsize.x:aw;
|
||||
DrawRectangle(ax-charsize.x,ay-charsize.y,minw+p,minh+p,c);
|
||||
DrawTextEx(font,content.c_str(),{ax,ay},fs,1,txc);
|
||||
DrawRectangle(ax-charsize.x,ay-charsize.y,minw+p,minh+p,this->theme->background);
|
||||
DrawTextEx(this->theme->font,content.c_str(),{ax,ay},fs,1,this->theme->text);
|
||||
}
|
||||
void exit()override{
|
||||
tinted::exit();
|
||||
|
|
@ -192,8 +190,14 @@ namespace enginend{
|
|||
void(*func)();
|
||||
bool pressed;
|
||||
bool hover;
|
||||
button():func(nullptr),pressed(false),hover(false){}
|
||||
button(Texture2D* texture,Color color,double x,double y,double w,double h,void(*f)()):func(f),pressed(false),hover(false),tinted(texture,color,x,y,w,h){}
|
||||
const bool isboolean;
|
||||
bool boolean=false;
|
||||
button():func(nullptr),pressed(false),hover(false),isboolean(false){}
|
||||
button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,void(*f)()):func(f),pressed(false),hover(false),isboolean(false) {
|
||||
this->theme=theme;
|
||||
}button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,void(*f)(),bool isboolean):func(f),pressed(false),hover(false),isboolean(isboolean) {
|
||||
this->theme=theme;
|
||||
}
|
||||
void boot()override{}
|
||||
void tick()override{
|
||||
Vector2 mouse=GetMousePosition();
|
||||
|
|
@ -203,16 +207,26 @@ namespace enginend{
|
|||
if(CheckCollisionPointRec(mouse,r)){hover=true;
|
||||
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON)){
|
||||
pressed=true;
|
||||
c=isboolean?boolean?
|
||||
this->theme->booleanbutton[5]:this->theme->booleanbutton[2]:
|
||||
this->theme->button[2];
|
||||
if(func)func();
|
||||
}else{
|
||||
pressed=false;
|
||||
c=isboolean?boolean?
|
||||
this->theme->booleanbutton[4]:this->theme->button[1]:
|
||||
this->theme->button[1];
|
||||
}
|
||||
}else{
|
||||
hover=false;
|
||||
pressed=false;
|
||||
c=isboolean?boolean?
|
||||
this->theme->booleanbutton[3]:this->theme->button[0]:
|
||||
this->theme->button[0];
|
||||
}
|
||||
}
|
||||
void draw()override {
|
||||
|
||||
tinted::draw();
|
||||
}
|
||||
void exit()override{
|
||||
|
|
@ -221,13 +235,16 @@ namespace enginend{
|
|||
};
|
||||
struct labeledbutton :virtual public button {
|
||||
std::string label;
|
||||
Font font;
|
||||
int fs;
|
||||
Color txc;
|
||||
labeledbutton(std::string name,Texture2D* texture,Color color,Color text,
|
||||
labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,Color text,
|
||||
double x,double y,double w,double h,void(*f)(),int size):fs(size),txc(text),label(name),
|
||||
button(texture,theme,x,y,w,h,f)
|
||||
{}
|
||||
labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,Color text,
|
||||
double x,double y,double w,double h,void(*f)(),
|
||||
Font fnt,int size):font(fnt),fs(size),txc(text),label(name),
|
||||
button(texture,color,x,y,w,h,f)
|
||||
int size,bool isboolean):fs(size),txc(text),label(name),
|
||||
button(texture,theme,x,y,w,h,f,isboolean)
|
||||
{}
|
||||
void boot()override{}
|
||||
void tick()override{
|
||||
|
|
@ -241,12 +258,27 @@ namespace enginend{
|
|||
float ay=y*sh;
|
||||
float aw=w*sw;
|
||||
float ah=h*sh;
|
||||
Vector2 tsize=MeasureTextEx(font,label.c_str(),fs,1);
|
||||
Vector2 tsize=MeasureTextEx(this->theme->font,label.c_str(),fs,1);
|
||||
Vector2 tpos={
|
||||
ax+(aw-tsize.x)/2,
|
||||
ay+(ah-tsize.y)/2
|
||||
};
|
||||
DrawTextEx(font,label.c_str(),tpos,fs,1,txc);
|
||||
if (hover) {
|
||||
if (pressed) {
|
||||
txc=isboolean?boolean?
|
||||
this->theme->booleantext[5]:this->theme->booleantext[2]:
|
||||
this->theme->buttontext[2];
|
||||
}else {
|
||||
txc=isboolean?boolean?
|
||||
this->theme->booleantext[4]:this->theme->buttontext[1]:
|
||||
this->theme->button[1];
|
||||
}
|
||||
}else {
|
||||
txc=isboolean?boolean?
|
||||
this->theme->booleantext[3]:this->theme->button[0]:
|
||||
this->theme->button[0];
|
||||
}
|
||||
DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc);
|
||||
}
|
||||
void exit()override{
|
||||
button::exit();
|
||||
|
|
@ -288,8 +320,8 @@ namespace enginend{
|
|||
};
|
||||
struct textfield :public text{
|
||||
textfield(){}
|
||||
textfield(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize,std::string txt):
|
||||
text(texture,txcol,color,x,y,w,h,f,fsize,txt){}
|
||||
textfield(Texture2D* texture,enginend::theme *theme,double x,double y,double w,double h,float fsize,std::string txt):
|
||||
text(texture,theme,x,y,w,h,fsize,txt){}
|
||||
void boot()override{}
|
||||
void tick()override{
|
||||
text::tick();
|
||||
|
|
@ -301,13 +333,13 @@ namespace enginend{
|
|||
float ay=y*sh;
|
||||
float aw=w*sw;
|
||||
float ah=h*sh;
|
||||
Vector2 charsize=MeasureTextEx(font," ",fs,0);
|
||||
Vector2 minsize=MeasureTextEx(font,content.c_str(),fs,charsize.x/2);
|
||||
Vector2 charsize=MeasureTextEx(this->theme->font," ",fs,0);
|
||||
Vector2 minsize=MeasureTextEx(this->theme->font,content.c_str(),fs,charsize.x/2);
|
||||
float po=charsize.x>charsize.y?charsize.x/charsize.y:charsize.y/charsize.x;po=po*5;
|
||||
int minh=(minsize.y>ah)?minsize.y:ah;
|
||||
int minw=(minsize.x>aw)?minsize.x:aw;
|
||||
DrawRectangle(ax-(po/2),ay-(po/2),minw+(po*1.1),minh+(po*1.1),c);
|
||||
DrawTextEx(font,content.c_str(),{ax,ay},fs,charsize.x/2,txc);
|
||||
DrawRectangle(ax-(po/2),ay-(po/2),minw+(po*1.1),minh+(po*1.1),this->theme->textfieldbg);
|
||||
DrawTextEx(this->theme->font,content.c_str(),{ax,ay},fs,charsize.x/2,this->theme->text);
|
||||
}
|
||||
void exit()override{
|
||||
text::exit();
|
||||
|
|
@ -317,8 +349,8 @@ namespace enginend{
|
|||
bool active;
|
||||
int cpos;
|
||||
textinput():active(false),cpos(0){}
|
||||
textinput(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize):active(false),cpos(0),
|
||||
text(texture,txcol,color,x,y,w,h,f,fsize,""){}
|
||||
textinput(Texture2D* texture,enginend::theme *theme,double x,double y,double w,double h,float fsize):active(false),cpos(0),
|
||||
text(texture,theme,x,y,w,h,fsize,""){}
|
||||
void boot()override{}
|
||||
void tick()override{
|
||||
text::tick();
|
||||
|
|
@ -351,7 +383,7 @@ namespace enginend{
|
|||
float sh=GetScreenHeight();
|
||||
float ax=x*sw;
|
||||
float ay=y*sh;
|
||||
DrawRectangle(ax+MeasureTextEx(font,content.c_str(),fs,1).x,ay,2,fs,{0,0,0,127});
|
||||
DrawRectangle(ax+MeasureTextEx(this->theme->font,content.c_str(),fs,1).x,ay,2,fs,{0,0,0,127});
|
||||
}
|
||||
}
|
||||
void exit()override{
|
||||
|
|
@ -362,8 +394,8 @@ namespace enginend{
|
|||
bool active;
|
||||
int cpos;
|
||||
textinputfield():active(false),cpos(0){}
|
||||
textinputfield(Texture2D* texture,Color txcol,Color color,double x,double y,double w,double h,Font f,float fsize):active(false),cpos(0),
|
||||
textfield(texture,txcol,color,x,y,w,h,f,fsize,""){}
|
||||
textinputfield(Texture2D* texture,enginend::theme *theme,double x,double y,double w,double h,float fsize):active(false),cpos(0),
|
||||
textfield(texture,theme,x,y,w,h,fsize,""){}
|
||||
void boot()override{}
|
||||
void tick()override{
|
||||
textfield::tick();
|
||||
|
|
@ -411,7 +443,7 @@ namespace enginend{
|
|||
line+=ch;
|
||||
}
|
||||
}
|
||||
DrawRectangle(p.x+MeasureTextEx(font,line.c_str(),fs,1).x,p.y,2,fs,rl::BLACK);
|
||||
DrawRectangle(p.x+MeasureTextEx(this->theme->font,line.c_str(),fs,1).x,p.y,2,fs,rl::BLACK);
|
||||
}
|
||||
}
|
||||
void exit()override{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue