2023-01-17 08:11:55 +01:00
|
|
|
function rangeBox(_type, _onModify) : widget() constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
onModify = _onModify;
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
linked = false;
|
|
|
|
b_link = button(function() { linked = !linked; });
|
|
|
|
b_link.icon = THEME.value_link;
|
|
|
|
|
|
|
|
onModifyIndex = function(index, val) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var modi = false;
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
if(linked) {
|
|
|
|
for( var i = 0; i < 2; i++ )
|
2023-02-14 05:32:32 +01:00
|
|
|
modi |= onModify(i, toNumber(val));
|
|
|
|
return modi;
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
return onModify(index, toNumber(val));
|
2023-01-17 08:11:55 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
label = [ "min", "max" ];
|
2023-02-14 05:32:32 +01:00
|
|
|
onModifySingle[0] = function(val) { return onModifyIndex(0, toNumber(val)); }
|
|
|
|
onModifySingle[1] = function(val) { return onModifyIndex(1, toNumber(val)); }
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
extras = -1;
|
|
|
|
|
|
|
|
for(var i = 0; i < 2; i++) {
|
|
|
|
tb[i] = new textBox(_type, onModifySingle[i]);
|
|
|
|
tb[i].slidable = true;
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static setSlideSpeed = function(speed) {
|
|
|
|
for(var i = 0; i < 2; i++)
|
|
|
|
tb[i].slide_speed = speed;
|
|
|
|
}
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
static setInteract = function(interactable = noone) {
|
|
|
|
self.interactable = interactable;
|
|
|
|
b_link.interactable = interactable;
|
|
|
|
|
|
|
|
for( var i = 0; i < 2; i++ )
|
|
|
|
tb[i].interactable = interactable;
|
|
|
|
}
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
static register = function(parent = noone) {
|
|
|
|
b_link.register(parent);
|
|
|
|
|
|
|
|
for( var i = 0; i < 2; i++ )
|
|
|
|
tb[i].register(parent);
|
|
|
|
}
|
|
|
|
|
2022-01-24 02:21:25 +01:00
|
|
|
static draw = function(_x, _y, _w, _h, _data, _m) {
|
2023-01-17 08:11:55 +01:00
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
w = _w;
|
|
|
|
h = _h;
|
|
|
|
|
2023-03-25 12:27:04 +01:00
|
|
|
b_link.setActiveFocus(hover, active);
|
2023-01-17 08:11:55 +01:00
|
|
|
b_link.icon_index = linked;
|
|
|
|
b_link.icon_blend = linked? COLORS._main_accent : COLORS._main_icon;
|
|
|
|
b_link.tooltip = linked? "Unlink axis" : "Link axis";
|
|
|
|
|
|
|
|
var bx = _x;
|
|
|
|
var by = _y + _h / 2 - ui(32 / 2);
|
|
|
|
b_link.draw(bx + ui(4), by + ui(4), ui(24), ui(24), _m, THEME.button_hide);
|
|
|
|
|
|
|
|
_x += ui(28);
|
|
|
|
_w -= ui(28);
|
|
|
|
|
2022-12-23 04:45:52 +01:00
|
|
|
if(extras != -1 && is_struct(extras) && instanceof(extras) == "buttonClass") {
|
2023-03-25 12:27:04 +01:00
|
|
|
extras.setActiveFocus(hover, active);
|
2022-11-18 03:20:31 +01:00
|
|
|
extras.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m, THEME.button_hide);
|
2022-11-03 11:44:49 +01:00
|
|
|
_w -= ui(40);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(is_array(_data) && array_length(_data) >= 2) {
|
|
|
|
var ww = _w / 2;
|
|
|
|
for(var i = 0; i < 2; i++) {
|
2023-03-25 12:27:04 +01:00
|
|
|
tb[i].setActiveFocus(hover, active);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
var bx = _x + ww * i;
|
2022-11-03 11:44:49 +01:00
|
|
|
tb[i].draw(bx + ui(44), _y, ww - ui(44), _h, _data[i], _m);
|
2023-02-14 05:32:32 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
|
2022-11-03 11:44:49 +01:00
|
|
|
draw_text(bx + ui(8), _y + _h / 2, label[i]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
resetFocus();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|