okie menus are working

This commit is contained in:
kin fuyuki 2026-02-20 09:58:58 -03:00
commit 05e28fe820
No known key found for this signature in database
GPG key ID: 0E4E8E519FB71401
11 changed files with 135 additions and 55 deletions

View file

@ -163,6 +163,9 @@ namespace enginend {
}
void boot()override{this->tinted::boot();}
void tick()override{
}
void draw()override {
this->tinted::tick();
Vector2 mouse=GetMousePosition();
if(CheckCollisionPointRec(mouse,{pos.x,pos.y,size.x,size.y})){hover=true;
@ -175,9 +178,6 @@ namespace enginend {
}else{
hover=false;
}
}
void draw()override {
if (hover) {
if (pressed) {
c=isboolean?boolean?
@ -195,6 +195,7 @@ namespace enginend {
}
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();}
};

View file

@ -118,7 +118,10 @@ namespace enginend{
void boot()override{}
void tick()override{}
void draw()override{
if(texture==nullptr)return;
if(texture==nullptr) {
colored::draw();
return;
}
float sw=GetScreenWidth();
float sh=GetScreenHeight();
float ax=x*sw;
@ -181,6 +184,7 @@ namespace enginend{
int minw=(minsize.x>aw)?minsize.x:aw;
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);
DrawRectangleLines(ax, ay, aw, ah, this->theme->border);
}
void exit()override{
tinted::exit();
@ -193,13 +197,16 @@ namespace enginend{
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;
button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,std::function<void()> f):func(f),pressed(false),hover(false),isboolean(false) {
this->theme=theme;this->texture=texture;this->x=x;this->y=y;this->w=w;this->h=h;
}button(Texture2D* texture,enginend::theme* theme,double x,double y,double w,double h,std::function<void()> f,bool isboolean):func(f),pressed(false),hover(false),isboolean(isboolean) {
this->theme=theme;this->texture=texture;this->x=x;this->y=y;this->w=w;this->h=h;
}
void boot()override{}
void tick()override{
}
void draw()override {
Vector2 mouse=GetMousePosition();
float sw=GetScreenWidth();
float sh=GetScreenHeight();
@ -224,10 +231,12 @@ namespace enginend{
this->theme->booleanbutton[3]:this->theme->booleanbutton[0]:
this->theme->button[0];
}
}
void draw()override {
tinted::draw();
float ax=x*sw;
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
DrawRectangle(ax,ay,aw,ah,c);
DrawRectangleLines(ax, ay, aw, ah, this->theme->border);
}
void exit()override{
tinted::exit();
@ -237,13 +246,13 @@ namespace enginend{
std::string label;
int fs;
Color txc;
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),
labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,
double x,double y,double w,double h,std::function<void()> f,int size):fs(size),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)(),
int size,bool isboolean):fs(size),txc(text),label(name),
labeledbutton(std::string name,Texture2D* texture,enginend::theme*theme,
double x,double y,double w,double h,std::function<void()> f,
int size,bool isboolean):fs(size),label(name),
button(texture,theme,x,y,w,h,f,isboolean)
{}
void boot()override{}
@ -258,11 +267,17 @@ namespace enginend{
float ay=y*sh;
float aw=w*sw;
float ah=h*sh;
tiny::echo("ax %f x %f sw %f",ax,x,sw);
tiny::echo("ay %f y %f sh %f",ay,y,sh);
tiny::echo("aw %f w %f sw %f",aw,w,sw);
tiny::echo("ah %f h %f sh %f",ah,h,sh);
Vector2 tsize=MeasureTextEx(this->theme->font,label.c_str(),fs,1);
Vector2 tpos={
ax+(aw-tsize.x)/2,
ay+(ah-tsize.y)/2
};
tiny::echo("tsize\nw %f h %f",tsize.x,tsize.y);
tiny::echo("tpos\nx %f y %f",tpos.x,tpos.y);
if (hover) {
if (pressed) {
txc=isboolean?boolean?
@ -279,6 +294,7 @@ namespace enginend{
this->theme->buttontext[0];
}
DrawTextEx(this->theme->font,label.c_str(),tpos,fs,1,txc);
DrawRectangleLinesEx({ax, ay, aw, ah},5., this->theme->border);
}
void exit()override{
button::exit();

View file

@ -8,7 +8,7 @@
namespace enginend {
struct theme;
namespace nodes {
struct node{
public:
@ -29,7 +29,7 @@
void draw(){for (node* n: children){n->draw();}}
void exit(){for (node* n: children){n->exit();}}
};
typedef struct theme {
Color booleanbutton[6],button[3],booleantext[6],buttontext[3],text,buttonborder[3],booleanborder[6],border,background
,textfieldbg
@ -42,6 +42,6 @@
Color tint;
};
extern enginend::theme* DEFAULT;
}

View file

@ -8,7 +8,7 @@
namespace enginend {
struct scene{
std::list<enginend::nodes::node*> nodes;
std::vector<enginend::nodes::node*> nodes;
virtual void boot() {
int i=0;
tiny::echo((char*)"initializing scene");