almost finishing theming support
This commit is contained in:
parent
5cbb13cf4b
commit
3932589790
8 changed files with 181 additions and 61 deletions
|
|
@ -1 +1,29 @@
|
|||
#include "engine.h"
|
||||
#include "engine.h"
|
||||
|
||||
enginend::theme DEFAULTTHEMECODE={
|
||||
.textfieldbg ={127,0,0,127},
|
||||
.background = {0,0,0,0},
|
||||
.border = {0,0,0,0},
|
||||
.booleanbutton = {
|
||||
{0,200,0,180},
|
||||
{100,200,100,180},
|
||||
{100,255,100,255},
|
||||
{200,0,0,180},
|
||||
{200,100,100,180},
|
||||
{255,100,100,255},
|
||||
},
|
||||
.text = {255,255,255,255},
|
||||
.tint = {255,255,255,255},
|
||||
.button = {
|
||||
{0,0,0,0},
|
||||
{255,255,255,80},
|
||||
{255,255,255,160}
|
||||
},
|
||||
.buttontext = {
|
||||
{255,255,255,255},
|
||||
{255,255,255,255},
|
||||
{255,255,255,255}
|
||||
}
|
||||
|
||||
};
|
||||
enginend::theme* enginend::DEFAULT=&DEFAULTTHEMECODE;
|
||||
|
|
@ -108,15 +108,14 @@ 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,float x,float y,float w,float h,Font f,float fsize,std::string txt):
|
||||
font(f),fs(fsize),content(txt)
|
||||
text(Texture2D* texture,enginend::theme* theme,float x,float y,float w,float h,float fsize,std::string txt):
|
||||
fs(fsize),content(txt)
|
||||
{
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->c=color;this->txc=txcol;
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->theme=theme;
|
||||
|
||||
result=content;
|
||||
size_t initp=0;
|
||||
|
|
@ -138,14 +137,14 @@ namespace enginend {
|
|||
}
|
||||
}
|
||||
void draw()override {
|
||||
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>size.y)?minsize.y:size.y;
|
||||
int minw=(minsize.x>size.x)?minsize.x:size.x;
|
||||
DrawRectangle(pos.x-charsize.x,pos.y-charsize.y,minw+p,minh+p,c);
|
||||
DrawTextEx(font,content.c_str(),pos,fs,1,txc);
|
||||
DrawRectangle(pos.x-charsize.x,pos.y-charsize.y,minw+p,minh+p,this->theme->background);
|
||||
DrawTextEx(this->theme->font,content.c_str(),pos,fs,1,this->theme->text);
|
||||
}
|
||||
void exit()override{this->tinted::exit();}
|
||||
};
|
||||
|
|
@ -154,12 +153,13 @@ namespace enginend {
|
|||
bool pressed;
|
||||
bool hover;
|
||||
const bool isboolean;
|
||||
bool boolean=false;
|
||||
button():pressed(false),isboolean(false){}
|
||||
button(Texture2D* texture,Color color,float x,float y,float w,float h,std::function<void()> f):func(f),pressed(false),isboolean(false){
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->c=color;
|
||||
button(Texture2D* texture,enginend::theme* theme,float x,float y,float w,float h,std::function<void()> f):func(f),pressed(false),isboolean(false){
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->c=theme->tint;this->theme=theme;
|
||||
}
|
||||
button(Texture2D* texture,Color color,float x,float y,float w,float h,std::function<void()> f,bool isboolean):func(f),pressed(false),isboolean(true){
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->c=color;
|
||||
button(Texture2D* texture,enginend::theme* theme,float x,float y,float w,float h,std::function<void()> f,bool isboolean):func(f),pressed(false),isboolean(isboolean){
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->c=theme->tint;this->theme=theme;
|
||||
}
|
||||
void boot()override{this->tinted::boot();}
|
||||
void tick()override{
|
||||
|
|
@ -177,8 +177,24 @@ namespace enginend {
|
|||
}
|
||||
}
|
||||
void draw()override {
|
||||
if(this->texture!=nullptr)DrawTexture(*texture,pos.x,pos.y,c);
|
||||
else DrawRectangle(pos.x,pos.y,size.x,size.y,c);
|
||||
|
||||
if (hover) {
|
||||
if (pressed) {
|
||||
c=isboolean?boolean?
|
||||
this->theme->booleanbutton[5]:this->theme->booleanbutton[2]:
|
||||
this->theme->button[2];
|
||||
}else {
|
||||
c=isboolean?boolean?
|
||||
this->theme->booleanbutton[4]:this->theme->booleanbutton[1]:
|
||||
this->theme->button[1];
|
||||
}
|
||||
}else {
|
||||
c=isboolean?boolean?
|
||||
this->theme->booleanbutton[3]:this->theme->booleanbutton[0]:
|
||||
this->theme->button[0];
|
||||
}
|
||||
if(this->texture!=nullptr)DrawTexture(*texture,pos.x,pos.y,this->theme->tint);
|
||||
else DrawRectangle(pos.x,pos.y,size.x,size.y,this->theme->tint);
|
||||
}
|
||||
void exit()override{this->tinted::exit();}
|
||||
};
|
||||
|
|
@ -187,10 +203,9 @@ namespace enginend {
|
|||
Font font;
|
||||
int fs;
|
||||
Color txc;
|
||||
labeledbutton(std::string name,Texture2D* texture,Color color,Color text,
|
||||
float x,float y,float w,float h,std::function<void()> f,
|
||||
Font fnt,int size):font(fnt),fs(size),txc(text){
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->c=color;
|
||||
labeledbutton(std::string name,Texture2D* texture,enginend::theme* theme,
|
||||
float x,float y,float w,float h,std::function<void()> f,int size):fs(size){
|
||||
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->theme=theme;
|
||||
this->func=f;this->pressed=false;
|
||||
this->label=name;
|
||||
}
|
||||
|
|
@ -198,6 +213,22 @@ namespace enginend {
|
|||
void tick()override{this->button::tick();}
|
||||
void draw()override{
|
||||
this->button::draw();
|
||||
|
||||
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->booleantext[1]:
|
||||
this->theme->buttontext[1];
|
||||
}
|
||||
}else {
|
||||
txc=isboolean?boolean?
|
||||
this->theme->booleantext[3]:this->theme->booleantext[0]:
|
||||
this->theme->buttontext[0];
|
||||
}
|
||||
Vector2 tsize=MeasureTextEx(font,label.c_str(),fs,1);
|
||||
Vector2 tpos={
|
||||
pos.x+(size.x-tsize.x)/2,
|
||||
|
|
@ -235,19 +266,19 @@ namespace enginend {
|
|||
};
|
||||
struct textfield :public text{
|
||||
textfield(){}
|
||||
textfield(Texture2D* texture,Color txcol,Color color,float x,float y,float w,float 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,float x,float y,float w,float h,float fsize,std::string txt):
|
||||
text(texture,theme,x,y,w,h,fsize,txt){}
|
||||
void boot()override{this->text::boot();}
|
||||
void tick()override{this->text::tick();}
|
||||
void draw()override{
|
||||
Vector2 p=pos;
|
||||
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>size.y)?minsize.y:size.y;
|
||||
int minw=(minsize.x>size.x)?minsize.x:size.x;
|
||||
DrawRectangle(pos.x-(po/2),pos.y-(po/2),minw+(po*1.1),minh+(po*1.1),c);
|
||||
DrawTextEx(font,content.c_str(),p,fs,charsize.x/2,this->txc);
|
||||
DrawTextEx(this->theme->font,content.c_str(),p,fs,charsize.x/2,this->txc);
|
||||
}
|
||||
void exit()override{this->text::exit();}
|
||||
};
|
||||
|
|
@ -255,9 +286,9 @@ namespace enginend {
|
|||
bool active;
|
||||
int cpos;
|
||||
textinput():active(false),cpos(0){}
|
||||
textinput(Texture2D* texture,Color txcol,Color color,float x,float y,float w,float h,Font f,float fsize):active(false),cpos(0){
|
||||
this->pos=Vector2{x,y};this->size=Vector2{x,y};this->texture=texture;this->c=color;this->font=f;this->content="";
|
||||
this->txc=txcol;this->fs=fsize;
|
||||
textinput(Texture2D* texture,enginend::theme* theme,float x,float y,float w,float h,float fsize):active(false),cpos(0){
|
||||
this->pos=Vector2{x,y};this->size=Vector2{x,y};this->texture=texture;this->theme=theme;this->content="";
|
||||
this->fs=fsize;
|
||||
}
|
||||
void boot()override{this->text::boot();}
|
||||
void tick()override{
|
||||
|
|
@ -291,8 +322,8 @@ namespace enginend {
|
|||
bool active;
|
||||
int cpos;
|
||||
textinputfield():active(false),cpos(0){}
|
||||
textinputfield(Texture2D* texture,Color txcol,Color color,float x,float y,float w,float 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,float x,float y,float w,float h,float fsize):active(false),cpos(0),
|
||||
textfield(texture,theme,x,y,w,h,fsize,""){}
|
||||
void boot()override{this->textfield::boot();}
|
||||
void tick()override{
|
||||
this->textfield::tick();
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ namespace enginend{
|
|||
}
|
||||
};
|
||||
struct button :virtual public tinted{
|
||||
void(*func)();
|
||||
std::function<void()> func;
|
||||
bool pressed;
|
||||
bool hover;
|
||||
const bool isboolean;
|
||||
|
|
@ -214,14 +214,14 @@ namespace enginend{
|
|||
}else{
|
||||
pressed=false;
|
||||
c=isboolean?boolean?
|
||||
this->theme->booleanbutton[4]:this->theme->button[1]:
|
||||
this->theme->booleanbutton[4]:this->theme->booleanbutton[1]:
|
||||
this->theme->button[1];
|
||||
}
|
||||
}else{
|
||||
hover=false;
|
||||
pressed=false;
|
||||
c=isboolean?boolean?
|
||||
this->theme->booleanbutton[3]:this->theme->button[0]:
|
||||
this->theme->booleanbutton[3]:this->theme->booleanbutton[0]:
|
||||
this->theme->button[0];
|
||||
}
|
||||
}
|
||||
|
|
@ -270,13 +270,13 @@ namespace enginend{
|
|||
this->theme->buttontext[2];
|
||||
}else {
|
||||
txc=isboolean?boolean?
|
||||
this->theme->booleantext[4]:this->theme->buttontext[1]:
|
||||
this->theme->button[1];
|
||||
this->theme->booleantext[4]:this->theme->booleantext[1]:
|
||||
this->theme->buttontext[1];
|
||||
}
|
||||
}else {
|
||||
txc=isboolean?boolean?
|
||||
this->theme->booleantext[3]:this->theme->button[0]:
|
||||
this->theme->button[0];
|
||||
this->theme->booleantext[3]:this->theme->booleantext[0]:
|
||||
this->theme->buttontext[0];
|
||||
}
|
||||
DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,7 @@
|
|||
void exit(){for (node* n: children){n->exit();}}
|
||||
};
|
||||
|
||||
struct theme {
|
||||
// in case if its a boolean button, it will use booleanbutton
|
||||
typedef struct theme {
|
||||
Color booleanbutton[6],button[3],booleantext[6],buttontext[3],text,buttonborder[3],booleanborder[6],border,background
|
||||
,textfieldbg
|
||||
;
|
||||
|
|
@ -42,4 +41,7 @@
|
|||
|
||||
Color tint;
|
||||
};
|
||||
extern enginend::theme* DEFAULT;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ public:
|
|||
s.nodes=std::list<nodes::node*>{
|
||||
|
||||
new nodes::colored(Color{255,255,255,255},0,0,500,500),
|
||||
new nodes::textfield(nullptr,Color{255,127,127,255},Color{127,127,127,255}
|
||||
,100,100,220,32,GetFontDefault(),32,
|
||||
new nodes::textfield(nullptr,enginend::DEFAULT
|
||||
,100,100,220,32,32,
|
||||
"welcome to enginend!\n"
|
||||
"hehe"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue