- [NEW] ui::label()
- [NEW] ui::check() - Unificats ui::textbox() i ui::combo()
This commit is contained in:
@@ -5,10 +5,19 @@
|
|||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
|
void label(const char *label, const int x, const int y, const int w, const int h)
|
||||||
|
{
|
||||||
|
draw::color(WHITE);
|
||||||
|
draw::fillrect(x, y, w, h);
|
||||||
|
draw::color(PAPER);
|
||||||
|
draw::rect(x, y, w, h);
|
||||||
|
draw::print(label, x+3, y+3, BLACK, 0);
|
||||||
|
}
|
||||||
|
|
||||||
const int button(const char *label, const int x, const int y, const int w, const int h, const int c1, const int c2, const int c3)
|
const int button(const char *label, const int x, const int y, const int w, const int h, const int c1, const int c2, const int c3)
|
||||||
{
|
{
|
||||||
const int mx = input::mouseX();
|
const int mx = draw::getLocalX(input::mouseX());
|
||||||
const int my = input::mouseY();
|
const int my = draw::getLocalY(input::mouseY());
|
||||||
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
||||||
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
|
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
|
||||||
const int txt_size = strlen(label)*4;
|
const int txt_size = strlen(label)*4;
|
||||||
@@ -26,30 +35,70 @@ namespace ui
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int combo(const char *label, const int x, const int y, const int w, const int h)
|
const int check(const char *label, const int x, const int y, const int w, const int h, const bool checked)
|
||||||
{
|
{
|
||||||
const int mx = input::mouseX();
|
const int mx = draw::getLocalX(input::mouseX());
|
||||||
const int my = input::mouseY();
|
const int my = draw::getLocalY(input::mouseY());
|
||||||
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
||||||
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
|
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;
|
||||||
|
const bool action = (inside&&btnDown)||checked;
|
||||||
|
|
||||||
draw::color(WHITE);
|
draw::color(WHITE);
|
||||||
draw::fillrect(x, y, w, h);
|
draw::fillrect(x, y, w, h);
|
||||||
|
|
||||||
draw::color(inside&&btnDown?BLACK:LIGHT+WHITE);
|
draw::color(action?BLACK:LIGHT+WHITE);
|
||||||
draw::hline(x, y, w);
|
draw::hline(x, y, w);
|
||||||
draw::vline(x, y, h);
|
draw::vline(x, y, h);
|
||||||
draw::vline(x+w-9,y,h);
|
|
||||||
|
|
||||||
draw::color(inside&&btnDown?LIGHT+WHITE:BLACK);
|
draw::color(action?LIGHT+WHITE:BLACK);
|
||||||
draw::hline(x, y+h-1, w);
|
draw::hline(x, y+h-1, w);
|
||||||
draw::vline(x+w-1, y, h);
|
draw::vline(x+w-1, y, h);
|
||||||
|
|
||||||
draw::print(label, x+3, y+3, inside?RED:PAPER, 0);
|
draw::print(label, 1+txt_x, y+3, action?LIGHT+WHITE:PAPER, action?PAPER:0);
|
||||||
draw::print("v", x+w-6, y+3, PAPER, 0);
|
|
||||||
|
|
||||||
if (inside)
|
if (inside)
|
||||||
{
|
{
|
||||||
|
draw::color(PAPER);
|
||||||
|
draw::rect(x+1, y+1, w-2, h-2);
|
||||||
|
if (input::mouseClk(1)) return 1;
|
||||||
|
if (input::mouseClk(3)) return 3;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int combo(const char *label, const int x, const int y, const int w, const int h)
|
||||||
|
{
|
||||||
|
const int mx = draw::getLocalX(input::mouseX());
|
||||||
|
const int my = draw::getLocalY(input::mouseY());
|
||||||
|
const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
||||||
|
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
|
||||||
|
|
||||||
|
draw::color(LIGHT+WHITE);
|
||||||
|
draw::fillrect(x, y, w, h);
|
||||||
|
draw::color(PAPER);
|
||||||
|
draw::rect(x, y, w, h);
|
||||||
|
draw::vline(x+w-11,y+1,h-2);
|
||||||
|
|
||||||
|
draw::color(WHITE);
|
||||||
|
draw::fillrect(x+w-10, y+1, 9, h-2);
|
||||||
|
|
||||||
|
draw::color(inside&&btnDown?BLACK:LIGHT+WHITE);
|
||||||
|
draw::hline(x+w-10,y+1,9);
|
||||||
|
draw::vline(x+w-10,y+1,h-2);
|
||||||
|
|
||||||
|
draw::color(inside&&btnDown?LIGHT+WHITE:BLACK);
|
||||||
|
draw::hline(x+w-10,y+h-2,9);
|
||||||
|
draw::vline(x+w-2,y+1,h-2);
|
||||||
|
|
||||||
|
draw::print(label, x+3, y+3, PAPER, 0);
|
||||||
|
draw::print("v", x+w-7, y+2, PAPER, 0);
|
||||||
|
|
||||||
|
if (inside)
|
||||||
|
{
|
||||||
|
draw::color(PAPER);
|
||||||
|
draw::rect(x+1, y+1, w-11, h-2);
|
||||||
if (input::mouseClk(1)) return 1;
|
if (input::mouseClk(1)) return 1;
|
||||||
if (input::mouseClk(3)) return 3;
|
if (input::mouseClk(3)) return 3;
|
||||||
}
|
}
|
||||||
@@ -58,8 +107,8 @@ namespace ui
|
|||||||
|
|
||||||
const int spin(const char *label, const int x, const int y, const int w, const int h)
|
const int spin(const char *label, const int x, const int y, const int w, const int h)
|
||||||
{
|
{
|
||||||
const int mx = input::mouseX();
|
const int mx = draw::getLocalX(input::mouseX());
|
||||||
const int my = input::mouseY();
|
const int my = draw::getLocalY(input::mouseY());
|
||||||
//const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
//const bool btnDown = input::mouseBtn(1) || input::mouseBtn(3);
|
||||||
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
|
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
|
||||||
//const int txt_size = strlen(label)*4;
|
//const int txt_size = strlen(label)*4;
|
||||||
@@ -83,13 +132,13 @@ namespace ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const int textbox(const char *label, const int x, const int y, const int w, const int h, const int c1, const int c2)
|
const int textbox(const char *label, const int x, const int y, const int w, const int h)
|
||||||
{
|
{
|
||||||
const int mx = input::mouseX();
|
const int mx = draw::getLocalX(input::mouseX());
|
||||||
const int my = input::mouseY();
|
const int my = draw::getLocalY(input::mouseY());
|
||||||
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
|
const bool inside = (mx>=x) && (mx<x+w) && (my>=y) && (my<y+h);
|
||||||
|
|
||||||
draw::color(inside?c2:c1);
|
draw::color(LIGHT+WHITE);
|
||||||
draw::fillrect(x, y, w, h);
|
draw::fillrect(x, y, w, h);
|
||||||
draw::color(PAPER);
|
draw::color(PAPER);
|
||||||
draw::rect(x, y, w, h);
|
draw::rect(x, y, w, h);
|
||||||
@@ -97,6 +146,8 @@ namespace ui
|
|||||||
|
|
||||||
if (inside)
|
if (inside)
|
||||||
{
|
{
|
||||||
|
draw::color(PAPER);
|
||||||
|
draw::rect(x+1, y+1, w-2, h-2);
|
||||||
return input::getKeyPressed();
|
return input::getKeyPressed();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
|
void label(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 c1, const int c2, const int c3);
|
const int button(const char *label, const int x, const int y, const int w, const int h, const int c1, const int c2, const int c3);
|
||||||
|
const int check(const char *label, const int x, const int y, const int w, const int h, const bool checked);
|
||||||
const int combo(const char *label, const int x, const int y, const int w, const int h);
|
const int combo(const char *label, const int x, const int y, const int w, const int h);
|
||||||
const int spin(const char *label, const int x, const int y, const int w, const int h);
|
const int spin(const char *label, const int x, const int y, const int w, const int h);
|
||||||
const int textbox(const char *label, const int x, const int y, const int w, const int h, const int c1, const int c2);
|
const int textbox(const char *label, const int x, const int y, const int w, const int h);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user