- Codi de UI mes clar. Variables van amunt o avall segons botó del ratolí

This commit is contained in:
2023-06-06 14:03:03 +02:00
parent 6e166c5e77
commit 845772ed16
3 changed files with 28 additions and 42 deletions

View File

@@ -5,11 +5,11 @@
namespace ui
{
const bool button(const char *label, const int x, const int y, const int w, const int h)
const int 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 btnDown = input::mouseBtn(1) || input::mouseBtn(3);
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;
@@ -18,6 +18,11 @@ namespace ui
draw::fillrect(x, y, w, h);
draw::print(label, 1+txt_x, y+3, 15, 8);
return inside && input::mouseClk(1);
if (inside)
{
if (input::mouseClk(1)) return 1;
if (input::mouseClk(3)) return 3;
}
return 0;
}
}