- Treballant en algo de UI

This commit is contained in:
2023-06-06 11:55:47 +02:00
parent f7f6131a79
commit 0460efc64a
8 changed files with 81 additions and 16 deletions

23
source/jui.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "jui.h"
#include "jdraw.h"
#include "jinput.h"
#include <string.h>
namespace ui
{
const bool button(const char *label, const int x, const int y, const int w, const int h)
{
const int mx = input::mouseX();
const int my = input::mouseY();
const bool btnDown = input::mouseBtn(1);
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
const int txt_size = strlen(label)*4;
const int txt_x = x+(w-txt_size)/2;
draw::color(inside?(btnDown?15:13):5);
draw::fillrect(x, y, w, h);
draw::print(label, 1+txt_x, y+3, 15, 8);
return inside && input::mouseClk(1);
}
}