29 lines
819 B
C++
29 lines
819 B
C++
#include "jui.h"
|
|
#include "jdraw.h"
|
|
#include "jinput.h"
|
|
#include <string.h>
|
|
|
|
namespace ui
|
|
{
|
|
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) || 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;
|
|
|
|
draw::color(inside?(btnDown?15:LIGHT+TEAL):TEAL);
|
|
draw::fillrect(x, y, w, h);
|
|
draw::print(label, 1+txt_x, y+3, LIGHT+WHITE, PAPER);
|
|
|
|
if (inside)
|
|
{
|
|
if (input::mouseClk(1)) return 1;
|
|
if (input::mouseClk(3)) return 3;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|