2018-04-11 19:46:08 +02:00
|
|
|
:struct more_less_box
|
|
|
|
{
|
|
|
|
unsigned value, min, max;
|
|
|
|
dword text;
|
2018-04-16 00:44:36 +02:00
|
|
|
int click_delta;
|
2018-04-19 16:16:32 +02:00
|
|
|
int x,y;
|
|
|
|
unsigned id_inc, id_dec;
|
2019-04-22 20:19:43 +02:00
|
|
|
bool disabled;
|
2018-04-19 16:16:32 +02:00
|
|
|
void check_values();
|
2018-04-11 19:46:08 +02:00
|
|
|
bool click();
|
2018-04-19 16:16:32 +02:00
|
|
|
bool inc();
|
|
|
|
bool dec();
|
2018-04-11 19:46:08 +02:00
|
|
|
void draw();
|
2018-04-19 16:16:32 +02:00
|
|
|
void redraw();
|
2018-04-11 19:46:08 +02:00
|
|
|
};
|
|
|
|
|
2018-04-19 16:16:32 +02:00
|
|
|
:void more_less_box::check_values()
|
2018-04-11 19:46:08 +02:00
|
|
|
{
|
2018-04-19 16:16:32 +02:00
|
|
|
if (!id_inc) id_inc = GetFreeButtonId();
|
|
|
|
if (!id_dec) id_dec = GetFreeButtonId();
|
2018-04-16 00:44:36 +02:00
|
|
|
if (!click_delta) click_delta = 1;
|
2018-04-11 19:46:08 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 16:16:32 +02:00
|
|
|
:bool more_less_box::click(unsigned id)
|
2018-04-11 19:46:08 +02:00
|
|
|
{
|
2020-04-13 23:08:28 +02:00
|
|
|
if (disabled) return 0;
|
2018-04-19 16:16:32 +02:00
|
|
|
if (id==id_dec) { value = math.max(value-click_delta, min); redraw(); return 1; }
|
|
|
|
if (id==id_inc) { value = math.min(value+click_delta, max); redraw(); return 1; }
|
|
|
|
return 0;
|
|
|
|
}
|
2018-04-11 19:46:08 +02:00
|
|
|
|
2018-04-19 16:16:32 +02:00
|
|
|
:bool more_less_box::inc()
|
|
|
|
{
|
|
|
|
click(id_inc);
|
|
|
|
}
|
2018-04-11 19:46:08 +02:00
|
|
|
|
2018-04-19 16:16:32 +02:00
|
|
|
:bool more_less_box::dec()
|
|
|
|
{
|
|
|
|
click(id_dec);
|
2018-04-11 19:46:08 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 16:16:32 +02:00
|
|
|
:void more_less_box::draw(dword _x,_y)
|
2018-04-11 19:46:08 +02:00
|
|
|
{
|
|
|
|
#define VALUE_FIELD_W 34
|
|
|
|
#define SIZE 18
|
2020-04-13 23:08:28 +02:00
|
|
|
dword text_col;
|
2018-04-11 19:46:08 +02:00
|
|
|
dword value_text = itoa(value);
|
|
|
|
|
2018-04-19 16:16:32 +02:00
|
|
|
check_values();
|
|
|
|
x=_x; y=_y;
|
|
|
|
|
2022-01-09 07:36:16 +01:00
|
|
|
DrawRectangle(x, y, VALUE_FIELD_W+1, SIZE, sc.line);
|
2018-04-11 19:46:08 +02:00
|
|
|
DrawRectangle3D(x+1, y+1, VALUE_FIELD_W-2, SIZE-2, 0xDDDddd, 0xffffff);
|
2019-04-22 20:19:43 +02:00
|
|
|
|
|
|
|
if (disabled)
|
|
|
|
{
|
|
|
|
DrawRectangle(x+1, y+1, VALUE_FIELD_W-2, SIZE-2, 0xffffff);
|
|
|
|
DrawBar(x+2, y+2, VALUE_FIELD_W-3, SIZE-3, 0xCCCccc);
|
2022-01-09 07:36:16 +01:00
|
|
|
text_col = sc.line;
|
2019-04-22 20:19:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DrawBar(x+2, y+2, VALUE_FIELD_W-3, SIZE-3, 0xffffff);
|
2020-04-18 01:52:24 +02:00
|
|
|
text_col = sc.work_text;
|
2019-04-22 20:19:43 +02:00
|
|
|
}
|
|
|
|
|
2018-04-11 19:46:08 +02:00
|
|
|
WriteText( -strlen(value_text)+3*8 + x+6, SIZE / 2 + y -6, 0x90, 0x333333, value_text);
|
|
|
|
|
2020-04-18 01:52:24 +02:00
|
|
|
DrawCaptButton(VALUE_FIELD_W + x + 1, y, SIZE, SIZE, id_inc, sc.button, sc.button_text, "+");
|
|
|
|
DrawCaptButton(VALUE_FIELD_W + x + SIZE, y, SIZE, SIZE, id_dec, sc.button, sc.button_text, "-");
|
|
|
|
WriteTextWithBg(x+VALUE_FIELD_W+SIZE+SIZE+10, SIZE / 2 + y -7, 0xD0, text_col, text, sc.work);
|
2022-01-09 07:36:16 +01:00
|
|
|
DrawRectangle3D(x-1,y-1,VALUE_FIELD_W+SIZE+SIZE+2,SIZE+2,sc.dark,sc.light);
|
2018-04-11 19:46:08 +02:00
|
|
|
}
|
2018-04-19 16:16:32 +02:00
|
|
|
|
|
|
|
:void more_less_box::redraw()
|
|
|
|
{
|
|
|
|
draw(x,y);
|
|
|
|
}
|
|
|
|
|