2022-01-13 05:24:03 +01:00
|
|
|
function sliderRange(_min, _max, _step, _onModify) constructor {
|
|
|
|
active = false;
|
|
|
|
hover = false;
|
|
|
|
|
|
|
|
minn = _min;
|
|
|
|
maxx = _max;
|
|
|
|
step = _step;
|
|
|
|
|
|
|
|
onModify = _onModify;
|
|
|
|
|
|
|
|
dragging = -1;
|
|
|
|
drag_mx = 0;
|
|
|
|
drag_sx = 0;
|
|
|
|
|
|
|
|
tb_value_min = new textBox(TEXTBOX_INPUT.float, function(val) { onModify(0, val); });
|
|
|
|
tb_value_max = new textBox(TEXTBOX_INPUT.float, function(val) { onModify(1, val); });
|
|
|
|
|
2022-01-24 02:21:25 +01:00
|
|
|
static draw = function(_x, _y, _w, _h, _data, _m) {
|
2022-11-03 11:44:49 +01:00
|
|
|
var tb_w = ui(64);
|
|
|
|
var sw = _w - (tb_w + ui(16)) * 2;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
tb_value_min.hover = hover;
|
|
|
|
tb_value_min.active = active;
|
2022-11-03 11:44:49 +01:00
|
|
|
tb_value_min.draw(_x, _y, tb_w, TEXTBOX_HEIGHT, _data[0], _m);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
tb_value_max.hover = hover;
|
|
|
|
tb_value_max.active = active;
|
2022-11-03 11:44:49 +01:00
|
|
|
tb_value_max.draw(_x + _w - tb_w, _y, tb_w, TEXTBOX_HEIGHT, _data[1], _m);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
var _x0 = _x + tb_w + ui(16);
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.slider, 0, _x0, _y + _h / 2 - ui(4), sw, ui(8));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var _slider_x0 = _x0 + clamp((_data[0] - minn) / (maxx - minn), 0, 1) * sw;
|
|
|
|
var _slider_x1 = _x0 + clamp((_data[1] - minn) / (maxx - minn), 0, 1) * sw;
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.slider, 4, min(_slider_x0, _slider_x1), _y + _h / 2 - ui(4), abs(_slider_x1 - _slider_x0), ui(8));
|
|
|
|
draw_sprite_stretched(THEME.slider, 1, _slider_x0 - ui(10), _y, ui(20), _h);
|
|
|
|
draw_sprite_stretched(THEME.slider, 1, _slider_x1 - ui(10), _y, ui(20), _h);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(dragging > -1) {
|
|
|
|
if(dragging == 0)
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.slider, 3, _slider_x0 - ui(10), _y, ui(20), _h);
|
2022-01-13 05:24:03 +01:00
|
|
|
else if(dragging == 1)
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.slider, 3, _slider_x1 - ui(10), _y, ui(20), _h);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
var val = (_m[0] - _x0) / sw * (maxx - minn) + minn;
|
|
|
|
val = round(val / step) * step;
|
|
|
|
val = clamp(val, minn, maxx);
|
|
|
|
onModify(dragging, val);
|
2022-11-22 14:25:39 +01:00
|
|
|
UNDO_HOLDING = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-22 14:25:39 +01:00
|
|
|
if(mouse_check_button_released(mb_left)) {
|
|
|
|
UNDO_HOLDING = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging = -1;
|
2022-11-22 14:25:39 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
} else {
|
|
|
|
if(hover) {
|
|
|
|
var _hover = -1;
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
if(point_in_rectangle(_m[0], _m[1], _slider_x0 - ui(10), _y, _slider_x0 + ui(10), _y + _h)) {
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.slider, 2, _slider_x0 - ui(10), _y, ui(20), _h);
|
2022-01-13 05:24:03 +01:00
|
|
|
_hover = 0;
|
|
|
|
}
|
2022-11-03 11:44:49 +01:00
|
|
|
if(point_in_rectangle(_m[0], _m[1], _slider_x1 - ui(10), _y, _slider_x1 + ui(10), _y + _h)) {
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_stretched(THEME.slider, 2, _slider_x1 - ui(10), _y, ui(20), _h);
|
2022-01-13 05:24:03 +01:00
|
|
|
_hover = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_hover > -1 && active && mouse_check_button_pressed(mb_left)) {
|
|
|
|
dragging = _hover;
|
|
|
|
drag_mx = _m[0];
|
|
|
|
drag_sx = _data[_hover];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hover = false;
|
|
|
|
active = false;
|
|
|
|
}
|
|
|
|
}
|