almost finishing theming support

This commit is contained in:
kin fuyuki 2026-02-20 07:55:55 -03:00
commit 3932589790
No known key found for this signature in database
GPG key ID: 0E4E8E519FB71401
8 changed files with 181 additions and 61 deletions

View file

@ -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;

View file

@ -108,15 +108,14 @@ namespace enginend {
protected: protected:
std::string result; std::string result;
public: public:
Font font;
float fs; float fs;
Color txc; Color txc;
std::string content; std::string content;
text(){fs=20;} 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): text(Texture2D* texture,enginend::theme* theme,float x,float y,float w,float h,float fsize,std::string txt):
font(f),fs(fsize),content(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; result=content;
size_t initp=0; size_t initp=0;
@ -138,14 +137,14 @@ namespace enginend {
} }
} }
void draw()override { void draw()override {
Vector2 minsize=MeasureTextEx(font,content.c_str(),fs,1); Vector2 minsize=MeasureTextEx(this->theme->font,content.c_str(),fs,1);
Vector2 charsize=MeasureTextEx(font," ",fs,1); Vector2 charsize=MeasureTextEx(this->theme->font," ",fs,1);
float p=charsize.x>charsize.y?charsize.x/minsize.x:charsize.y/minsize.y; float p=charsize.x>charsize.y?charsize.x/minsize.x:charsize.y/minsize.y;
p=p*2; p=p*2;
int minh=(minsize.y>size.y)?minsize.y:size.y; int minh=(minsize.y>size.y)?minsize.y:size.y;
int minw=(minsize.x>size.x)?minsize.x:size.x; int minw=(minsize.x>size.x)?minsize.x:size.x;
DrawRectangle(pos.x-charsize.x,pos.y-charsize.y,minw+p,minh+p,c); DrawRectangle(pos.x-charsize.x,pos.y-charsize.y,minw+p,minh+p,this->theme->background);
DrawTextEx(font,content.c_str(),pos,fs,1,txc); DrawTextEx(this->theme->font,content.c_str(),pos,fs,1,this->theme->text);
} }
void exit()override{this->tinted::exit();} void exit()override{this->tinted::exit();}
}; };
@ -154,12 +153,13 @@ namespace enginend {
bool pressed; bool pressed;
bool hover; bool hover;
const bool isboolean; const bool isboolean;
bool boolean=false;
button():pressed(false),isboolean(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){ 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=color; 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){ 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=color; 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 boot()override{this->tinted::boot();}
void tick()override{ void tick()override{
@ -177,8 +177,24 @@ namespace enginend {
} }
} }
void draw()override { 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();} void exit()override{this->tinted::exit();}
}; };
@ -187,10 +203,9 @@ namespace enginend {
Font font; Font font;
int fs; int fs;
Color txc; Color txc;
labeledbutton(std::string name,Texture2D* texture,Color color,Color text, labeledbutton(std::string name,Texture2D* texture,enginend::theme* theme,
float x,float y,float w,float h,std::function<void()> f, float x,float y,float w,float h,std::function<void()> f,int size):fs(size){
Font fnt,int size):font(fnt),fs(size),txc(text){ this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->theme=theme;
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->texture=texture;this->c=color;
this->func=f;this->pressed=false; this->func=f;this->pressed=false;
this->label=name; this->label=name;
} }
@ -198,6 +213,22 @@ namespace enginend {
void tick()override{this->button::tick();} void tick()override{this->button::tick();}
void draw()override{ void draw()override{
this->button::draw(); 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 tsize=MeasureTextEx(font,label.c_str(),fs,1);
Vector2 tpos={ Vector2 tpos={
pos.x+(size.x-tsize.x)/2, pos.x+(size.x-tsize.x)/2,
@ -235,19 +266,19 @@ namespace enginend {
}; };
struct textfield :public text{ struct textfield :public text{
textfield(){} textfield(){}
textfield(Texture2D* texture,Color txcol,Color color,float x,float y,float w,float h,Font f,float fsize,std::string txt): textfield(Texture2D* texture,enginend::theme* theme,float x,float y,float w,float h,float fsize,std::string txt):
text(texture,txcol,color,x,y,w,h,f,fsize,txt){} text(texture,theme,x,y,w,h,fsize,txt){}
void boot()override{this->text::boot();} void boot()override{this->text::boot();}
void tick()override{this->text::tick();} void tick()override{this->text::tick();}
void draw()override{ void draw()override{
Vector2 p=pos; Vector2 p=pos;
Vector2 charsize=MeasureTextEx(font," ",fs,0); Vector2 charsize=MeasureTextEx(this->theme->font," ",fs,0);
Vector2 minsize=MeasureTextEx(font,content.c_str(),fs,charsize.x/2); 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; 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 minh=(minsize.y>size.y)?minsize.y:size.y;
int minw=(minsize.x>size.x)?minsize.x:size.x; 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); 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();} void exit()override{this->text::exit();}
}; };
@ -255,9 +286,9 @@ namespace enginend {
bool active; bool active;
int cpos; int cpos;
textinput():active(false),cpos(0){} 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){ 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->c=color;this->font=f;this->content=""; this->pos=Vector2{x,y};this->size=Vector2{x,y};this->texture=texture;this->theme=theme;this->content="";
this->txc=txcol;this->fs=fsize; this->fs=fsize;
} }
void boot()override{this->text::boot();} void boot()override{this->text::boot();}
void tick()override{ void tick()override{
@ -291,8 +322,8 @@ namespace enginend {
bool active; bool active;
int cpos; int cpos;
textinputfield():active(false),cpos(0){} 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), textinputfield(Texture2D* texture,enginend::theme* theme,float x,float y,float w,float h,float fsize):active(false),cpos(0),
textfield(texture,txcol,color,x,y,w,h,f,fsize,""){} textfield(texture,theme,x,y,w,h,fsize,""){}
void boot()override{this->textfield::boot();} void boot()override{this->textfield::boot();}
void tick()override{ void tick()override{
this->textfield::tick(); this->textfield::tick();

View file

@ -187,7 +187,7 @@ namespace enginend{
} }
}; };
struct button :virtual public tinted{ struct button :virtual public tinted{
void(*func)(); std::function<void()> func;
bool pressed; bool pressed;
bool hover; bool hover;
const bool isboolean; const bool isboolean;
@ -214,14 +214,14 @@ namespace enginend{
}else{ }else{
pressed=false; pressed=false;
c=isboolean?boolean? c=isboolean?boolean?
this->theme->booleanbutton[4]:this->theme->button[1]: this->theme->booleanbutton[4]:this->theme->booleanbutton[1]:
this->theme->button[1]; this->theme->button[1];
} }
}else{ }else{
hover=false; hover=false;
pressed=false; pressed=false;
c=isboolean?boolean? c=isboolean?boolean?
this->theme->booleanbutton[3]:this->theme->button[0]: this->theme->booleanbutton[3]:this->theme->booleanbutton[0]:
this->theme->button[0]; this->theme->button[0];
} }
} }
@ -270,13 +270,13 @@ namespace enginend{
this->theme->buttontext[2]; this->theme->buttontext[2];
}else { }else {
txc=isboolean?boolean? txc=isboolean?boolean?
this->theme->booleantext[4]:this->theme->buttontext[1]: this->theme->booleantext[4]:this->theme->booleantext[1]:
this->theme->button[1]; this->theme->buttontext[1];
} }
}else { }else {
txc=isboolean?boolean? txc=isboolean?boolean?
this->theme->booleantext[3]:this->theme->button[0]: this->theme->booleantext[3]:this->theme->booleantext[0]:
this->theme->button[0]; this->theme->buttontext[0];
} }
DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc); DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc);
} }

View file

@ -30,8 +30,7 @@
void exit(){for (node* n: children){n->exit();}} void exit(){for (node* n: children){n->exit();}}
}; };
struct theme { typedef struct theme {
// in case if its a boolean button, it will use booleanbutton
Color booleanbutton[6],button[3],booleantext[6],buttontext[3],text,buttonborder[3],booleanborder[6],border,background Color booleanbutton[6],button[3],booleantext[6],buttontext[3],text,buttonborder[3],booleanborder[6],border,background
,textfieldbg ,textfieldbg
; ;
@ -42,4 +41,7 @@
Color tint; Color tint;
}; };
extern enginend::theme* DEFAULT;
} }

View file

@ -16,8 +16,8 @@ public:
s.nodes=std::list<nodes::node*>{ s.nodes=std::list<nodes::node*>{
new nodes::colored(Color{255,255,255,255},0,0,500,500), 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} new nodes::textfield(nullptr,enginend::DEFAULT
,100,100,220,32,GetFontDefault(),32, ,100,100,220,32,32,
"welcome to enginend!\n" "welcome to enginend!\n"
"hehe" "hehe"
) )

View file

@ -5,6 +5,9 @@
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>
#include "../../../engine/src/scenes/nodes.h"
#include "../../../engine/src/scenes/nodes.h"
#include"themes.h"
using namespace enginend; using namespace enginend;
using namespace enginend::nodes; using namespace enginend::nodes;
netio nete{}; netio nete{};
@ -60,10 +63,9 @@ private:
}; };
struct logi: public virtual textfield { struct logi: public virtual textfield {
logi(Texture2D* texture,Color textcol,Color color,float x,float y,float w,float h,Font f,float fs,std::string txt) { logi(Texture2D* texture,enginend::theme* theme,float x,float y,float w,float h,float fs,std::string txt) {
this->pos=Vector2{x,y};this->size=Vector2{w,h};this->content=txt; this->pos=Vector2{x,y};this->size=Vector2{w,h};this->content=txt;this->theme=theme;
this->texture=texture;this->txc=textcol;this->c=color; this->texture=texture;
this->font=f;
this->fs=fs; this->fs=fs;
} }
void draw() override { void draw() override {
@ -83,11 +85,11 @@ struct logi: public virtual textfield {
fc=Color{255,255,0,255}; fc=Color{255,255,0,255};
} }
DrawTextEx(font, str, charPos, (float)fs, spacing, fc); DrawTextEx(this->theme->font, str, charPos, (float)fs, spacing, fc);
charPos.x+=MeasureTextEx(font, str, (float)fs, spacing).x; charPos.x+=MeasureTextEx(this->theme->font, str, (float)fs, spacing).x;
} }
} else { } else {
DrawTextEx(font, line.c_str(), p, (float)fs, spacing, Color{0,255,255,255}); DrawTextEx(this->theme->font, line.c_str(), p, (float)fs, spacing, Color{0,255,255,255});
} }
p.y+=(fs+2); p.y+=(fs+2);
@ -138,44 +140,47 @@ public:
menubtn[1]=LoadTexture("res/btnhover.png"); menubtn[1]=LoadTexture("res/btnhover.png");
menubtn[2]=LoadTexture("res/btnpress.png"); menubtn[2]=LoadTexture("res/btnpress.png");
selectedversion=nete.currentversion; selectedversion=nete.currentversion;
version= text (nullptr,Color{255,255,255,255},Color{0,0,0,0},96,16*17,1,1,information,20,"version: "+selectedversion); enginend::DEFAULT->font=information;
GAMENAME.font=gamename;
CHANGELOG.font=changelog;
version= text (nullptr,enginend::DEFAULT,96,16*17,1,1,20,"version: "+selectedversion);
SetTraceLogLevel(LOG_ERROR); SetTraceLogLevel(LOG_ERROR);
buttons[0]=new button(&menubtn[0], {255,255,255,255},468,58,96,16,nullptr); buttons[0]=new button(&menubtn[0], enginend::DEFAULT,468,58,96,16,nullptr);
buttonslabel[0]=LoadTexture("res/options.png"); buttonslabel[0]=LoadTexture("res/options.png");
buttons[1]=new button(&menubtn[0], {255,255,255,255},468,58+(18*1),96,16,std::function<void()>([]() { buttons[1]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*1),96,16,std::function<void()>([]() {
OpenURL("http://kosumi.ddns.net:60000/"); OpenURL("http://kosumi.ddns.net:60000/");
})); }));
buttonslabel[1]=LoadTexture("res/website.png"); buttonslabel[1]=LoadTexture("res/website.png");
buttons[2]=new button(&menubtn[0], {255,255,255,255},468,58+(18*2),96,16,std::function<void()>([]() { buttons[2]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*2),96,16,std::function<void()>([]() {
OpenURL("http://kosumi.ddns.net:60001/"); OpenURL("http://kosumi.ddns.net:60001/");
})); }));
buttonslabel[2]=LoadTexture("res/forums.png"); buttonslabel[2]=LoadTexture("res/forums.png");
buttons[3]=new button(&menubtn[0], {255,255,255,255},468,58+(18*3),96,16,std::function<void()>([]() { buttons[3]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*3),96,16,std::function<void()>([]() {
OpenURL("https://github.com/kin-fuyuki/allgames/issues"); OpenURL("https://github.com/kin-fuyuki/allgames/issues");
})); }));
buttonslabel[3]=LoadTexture("res/help.png"); buttonslabel[3]=LoadTexture("res/help.png");
buttons[4]=new button(&menubtn[0], {255,255,255,255},468,58+(18*4),96,16,std::function<void()>([]() { buttons[4]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*4),96,16,std::function<void()>([]() {
nete.download(); nete.download();
})); }));
buttonslabel[4]=LoadTexture("res/update.png"); buttonslabel[4]=LoadTexture("res/update.png");
buttons[5]=new button(&menubtn[0], {255,255,255,255},468,58+(18*5),96,16,nullptr); buttons[5]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*5),96,16,nullptr);
buttonslabel[5]=LoadTexture("res/verify.png"); buttonslabel[5]=LoadTexture("res/verify.png");
buttons[6]=new button(&menubtn[0], {255,255,255,255},468,58+(18*6)+15,96,16,nullptr); buttons[6]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*6)+15,96,16,nullptr);
buttonslabel[6]=LoadTexture("res/versions.png"); buttonslabel[6]=LoadTexture("res/versions.png");
buttons[7]=new button(&menubtn[0], {255,255,255,255},468,58+(18*7)+17,96,16,std::function<void()>([]() { buttons[7]=new button(&menubtn[0], enginend::DEFAULT,468,58+(18*7)+17,96,16,std::function<void()>([]() {
quit(); quit();
})); }));
buttonslabel[7]=LoadTexture("res/exit.png"); buttonslabel[7]=LoadTexture("res/exit.png");
playbtn[0]=LoadTexture("res/playoff.png"); playbtn[0]=LoadTexture("res/playoff.png");
playbtn[1]=LoadTexture("res/playon.png"); playbtn[1]=LoadTexture("res/playon.png");
playbutton= new button(&playbtn[0], {255,255,255,255},406,(18*11)+17+9,153,59,std::function<void()>(playbuttonfunc)); playbutton= new button(&playbtn[0], enginend::DEFAULT,406,(18*11)+17+9,153,59,std::function<void()>(playbuttonfunc));
currentscene->nodes=std::list<node*>{ currentscene->nodes=std::list<node*>{
new background(&bg,0,0,600,300), new background(&bg,0,0,600,300),
new textured(&buttonfore,3,36,62,62), new textured(&buttonfore,3,36,62,62),
new textured(&buttonlock,3,36+((62+4)*1),62,62), new textured(&buttonlock,3,36+((62+4)*1),62,62),
new textured(&buttonlock,3,36+((62+4)*2),62,62), new textured(&buttonlock,3,36+((62+4)*2),62,62),
new textured(&buttonlock,3,36+((62+4)*3),62,62), new textured(&buttonlock,3,36+((62+4)*3),62,62),
new text(nullptr,Color{0,255,0,255},{0,0,0,0},232,19,1,1,gamename,16,"FORESPEND"), new text(nullptr,&GAMENAME,232,19,1,1,16,"FORESPEND"),
buttons[0],new textured(&buttonslabel[0],468,58,96,16), buttons[0],new textured(&buttonslabel[0],468,58,96,16),
buttons[1],new textured(&buttonslabel[1],468,58+(18*1),96,16), buttons[1],new textured(&buttonslabel[1],468,58+(18*1),96,16),
buttons[2],new textured(&buttonslabel[2],468,58+(18*2),96,16), buttons[2],new textured(&buttonslabel[2],468,58+(18*2),96,16),
@ -185,8 +190,8 @@ public:
buttons[6],new textured(&buttonslabel[6],468,58+(18*6)+15,96,16), buttons[6],new textured(&buttonslabel[6],468,58+(18*6)+15,96,16),
buttons[7],new textured(&buttonslabel[7],468,58+(18*7)+17,96,16), buttons[7],new textured(&buttonslabel[7],468,58+(18*7)+17,96,16),
playbutton, playbutton,
new logi(nullptr,Color{255,0,255,255},Color{0,0,0,0},90,58,466,159,changelog,8,nete.changelog), new logi(nullptr,&CHANGELOG,90,58,466,159,8,nete.changelog),
new text(nullptr,Color{255,255,255,255},Color{0,0,0,0},96+16,(16*14)-3,1,1,information,20,"downloaded verified"), new text(nullptr,enginend::DEFAULT,96+16,(16*14)-3,1,1,20,"downloaded verified"),
&version, &version,
}; };
currentscene->boot(); currentscene->boot();

View file

@ -0,0 +1,53 @@
#pragma once
enginend::theme GAMENAME={
.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 = {0,255,0,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 CHANGELOG={
.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}
}
};

View file

@ -33,4 +33,5 @@ enginend::group controls= enginend::group(
{ {
} }
); );