2023-01-17 08:11:55 +01:00
|
|
|
function vectorRangeBox(_size, _type, _onModify, _unit = noone) : widget() constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
size = _size;
|
|
|
|
onModify = _onModify;
|
2022-12-27 04:00:50 +01:00
|
|
|
unit = _unit;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
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) {
|
|
|
|
if(linked) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var modi = false;
|
|
|
|
modi |= onModify(floor(index / 2) * 2 + 0, toNumber(val));
|
|
|
|
modi |= onModify(floor(index / 2) * 2 + 1, 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
|
|
|
|
|
|
|
axis = [ "x", "y", "z", "w"];
|
|
|
|
label = [];
|
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)); }
|
|
|
|
onModifySingle[2] = function(val) { return onModifyIndex(2, toNumber(val)); }
|
|
|
|
onModifySingle[3] = function(val) { return onModifyIndex(3, toNumber(val)); }
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
extras = -1;
|
|
|
|
|
|
|
|
for(var i = 0; i < size; i++) {
|
|
|
|
tb[i] = new textBox(_type, onModifySingle[i]);
|
|
|
|
tb[i].slidable = true;
|
|
|
|
|
|
|
|
label[i] = (i % 2? "max " : "min ") + axis[floor(i / 2)];
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static setSlideSpeed = function(speed) {
|
|
|
|
for(var i = 0; i < size; 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 < size; i++ )
|
|
|
|
tb[i].interactable = interactable;
|
|
|
|
if(extras)
|
|
|
|
extras.interactable = interactable;
|
|
|
|
}
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
static register = function(parent = noone) {
|
|
|
|
b_link.register(parent);
|
|
|
|
|
|
|
|
for( var i = 0; i < size; i++ )
|
|
|
|
tb[i].register(parent);
|
|
|
|
if(extras) extras.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 * 2 + ui(4);
|
|
|
|
|
|
|
|
b_link.hover = hover;
|
|
|
|
b_link.active = active;
|
|
|
|
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-01-13 05:24:03 +01:00
|
|
|
if(extras && instanceof(extras) == "buttonClass") {
|
|
|
|
extras.hover = hover;
|
|
|
|
extras.active = 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
|
|
|
}
|
|
|
|
|
|
|
|
var ww = _w / size * 2;
|
|
|
|
for(var i = 0; i < size; i++) {
|
|
|
|
tb[i].hover = hover;
|
|
|
|
tb[i].active = active;
|
|
|
|
|
|
|
|
var bx = _x + ww * floor(i / 2);
|
2022-12-10 05:06:01 +01:00
|
|
|
var by = _y + i % 2 * (_h + ui(4));
|
|
|
|
tb[i].draw(bx + ui(56), by, ww - ui(56), _h, _data[i], _m);
|
2022-01-13 05:24:03 +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), by + _h / 2, label[i]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
resetFocus();
|
2022-11-21 06:38:44 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
return _h * 2 + ui(4);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|