2023-03-19 09:17:39 +01:00
|
|
|
enum DIMENSION {
|
|
|
|
width,
|
|
|
|
height
|
|
|
|
}
|
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
function vectorBox(_size, _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;
|
2023-10-02 04:53:30 +02:00
|
|
|
|
|
|
|
linkable = true;
|
|
|
|
per_line = false;
|
2023-05-03 21:42:17 +02:00
|
|
|
current_value = [];
|
2023-10-02 08:57:44 +02:00
|
|
|
linked = false;
|
|
|
|
side_button = noone;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
link_inactive_color = noone;
|
|
|
|
|
|
|
|
tooltip = new tooltipSelector("Axis", [
|
|
|
|
__txt("Independent"),
|
|
|
|
__txt("Linked"),
|
|
|
|
]);
|
2022-12-27 04:00:50 +01:00
|
|
|
|
|
|
|
onModifyIndex = function(index, val) {
|
2023-05-03 21:42:17 +02:00
|
|
|
var v = toNumber(val);
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(linked) {
|
2023-02-14 05:32:32 +01:00
|
|
|
var modi = false;
|
2023-05-07 20:55:13 +02:00
|
|
|
for( var i = 0; i < size; i++ ) {
|
|
|
|
tb[i]._input_text = v;
|
|
|
|
|
|
|
|
if(is_callable(onModify))
|
|
|
|
modi |= onModify(i, v);
|
|
|
|
}
|
2023-02-14 05:32:32 +01:00
|
|
|
return modi;
|
2022-12-27 04:00:50 +01:00
|
|
|
}
|
|
|
|
|
2023-05-07 20:55:13 +02:00
|
|
|
if(is_callable(onModify))
|
|
|
|
return onModify(index, v);
|
|
|
|
return noone;
|
2022-12-27 04:00:50 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
axis = [ "x", "y", "z", "w" ];
|
2023-02-14 05:32:32 +01:00
|
|
|
onModifySingle[0] = function(val) { return onModifyIndex(0, val); }
|
|
|
|
onModifySingle[1] = function(val) { return onModifyIndex(1, val); }
|
|
|
|
onModifySingle[2] = function(val) { return onModifyIndex(2, val); }
|
|
|
|
onModifySingle[3] = function(val) { return onModifyIndex(3, val); }
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-04-16 15:26:52 +02:00
|
|
|
for(var i = 0; i < 4; i++) {
|
2023-05-03 21:42:17 +02:00
|
|
|
tb[i] = new textBox(TEXTBOX_INPUT.number, onModifySingle[i]);
|
2022-01-13 05:24:03 +01:00
|
|
|
tb[i].slidable = true;
|
|
|
|
}
|
|
|
|
|
2023-09-27 14:55:21 +02:00
|
|
|
static setLinkInactiveColor = function(color) {
|
|
|
|
link_inactive_color = color;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2023-02-14 05:32:32 +01:00
|
|
|
static setSlideSpeed = function(speed) {
|
|
|
|
for(var i = 0; i < size; i++)
|
2023-11-15 14:42:53 +01:00
|
|
|
tb[i].setSlidable(speed);
|
2023-09-27 14:55:21 +02:00
|
|
|
return self;
|
2023-02-14 05:32:32 +01:00
|
|
|
}
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
static setInteract = function(interactable) {
|
|
|
|
self.interactable = interactable;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(side_button != noone)
|
|
|
|
side_button.interactable = interactable;
|
2023-01-25 06:49:00 +01:00
|
|
|
|
|
|
|
for( var i = 0; i < size; i++ )
|
|
|
|
tb[i].interactable = interactable;
|
|
|
|
}
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
static register = function(parent = noone) {
|
|
|
|
for( var i = 0; i < size; i++ )
|
|
|
|
tb[i].register(parent);
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(side_button != noone)
|
|
|
|
side_button.register(parent);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
if(unit != noone && unit.reference != noone)
|
|
|
|
unit.triggerButton.register(parent);
|
|
|
|
}
|
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
static drawParam = function(params) {
|
2023-10-02 08:57:44 +02:00
|
|
|
return draw(params.x, params.y, params.w, params.h, params.data, params.display_data, params.m);
|
2023-07-21 12:40:20 +02:00
|
|
|
}
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
static draw = function(_x, _y, _w, _h, _data, _display_data, _m) {
|
2023-01-17 08:11:55 +01:00
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
w = _w;
|
2023-10-02 04:53:30 +02:00
|
|
|
h = per_line? (_h + ui(8)) * size - ui(8) : _h;
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(struct_has(_display_data, "linked")) linked = _display_data.linked;
|
|
|
|
if(struct_has(_display_data, "side_button")) side_button = _display_data.side_button;
|
|
|
|
tooltip.index = linked;
|
2023-09-27 14:55:21 +02:00
|
|
|
|
2023-08-24 11:59:05 +02:00
|
|
|
if(!is_array(_data)) return 0;
|
|
|
|
if(array_empty(_data)) return 0;
|
|
|
|
if(is_array(_data[0])) return 0;
|
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
current_value = _data;
|
|
|
|
|
2023-10-02 08:57:44 +02:00
|
|
|
if(side_button) {
|
|
|
|
side_button.setFocusHover(active, hover);
|
|
|
|
side_button.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
|
|
|
}
|
|
|
|
|
2022-12-27 04:00:50 +01:00
|
|
|
if(unit != noone && unit.reference != noone) {
|
|
|
|
_w += ui(4);
|
|
|
|
|
2023-06-21 20:36:53 +02:00
|
|
|
unit.triggerButton.setFocusHover(iactive, ihover);
|
2022-12-27 04:00:50 +01:00
|
|
|
unit.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m);
|
|
|
|
_w -= ui(40);
|
|
|
|
}
|
|
|
|
|
2023-10-02 04:53:30 +02:00
|
|
|
if(linkable) {
|
2023-10-02 08:57:44 +02:00
|
|
|
var _icon_blend = linked? COLORS._main_accent : (link_inactive_color == noone? COLORS._main_icon : link_inactive_color);
|
2023-10-02 04:53:30 +02:00
|
|
|
var bx = _x;
|
|
|
|
var by = _y + _h / 2 - ui(32 / 2);
|
2023-10-02 08:57:44 +02:00
|
|
|
if(buttonInstant(THEME.button_hide, bx + ui(4), by + ui(4), ui(24), ui(24), _m, active, hover, tooltip, THEME.value_link, linked, _icon_blend) == 2) {
|
|
|
|
linked = !linked;
|
|
|
|
_display_data.linked = linked;
|
|
|
|
|
|
|
|
if(linked) {
|
2023-10-02 04:53:30 +02:00
|
|
|
onModify(0, _data[0]);
|
|
|
|
onModify(1, _data[0]);
|
|
|
|
}
|
2023-09-27 14:55:21 +02:00
|
|
|
}
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-10-02 04:53:30 +02:00
|
|
|
_x += ui(28);
|
|
|
|
_w -= ui(28);
|
|
|
|
}
|
2022-12-27 04:00:50 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
var sz = min(size, array_length(_data));
|
2023-10-02 04:53:30 +02:00
|
|
|
var ww = per_line? _w : _w / sz;
|
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
for(var i = 0; i < sz; i++) {
|
2023-10-02 04:53:30 +02:00
|
|
|
draw_set_font(f_p0);
|
|
|
|
var lw = max(ui(24), string_width(axis[i]) + ui(16));
|
|
|
|
|
|
|
|
var bx = per_line? _x : _x + ww * i;
|
|
|
|
var by = per_line? _y + (_h + ui(8)) * i : _y;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-10-02 04:53:30 +02:00
|
|
|
tb[i].setFocusHover(active, hover);
|
|
|
|
tb[i].draw(bx + lw, by, ww - lw, _h, _data[i], _m);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-10 13:59:45 +02:00
|
|
|
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_inner);
|
2023-10-02 04:53:30 +02:00
|
|
|
draw_text_add(bx + ui(8), by + _h / 2, axis[i]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-01-17 08:11:55 +01:00
|
|
|
|
|
|
|
resetFocus();
|
2023-07-21 12:40:20 +02:00
|
|
|
|
2023-10-02 04:53:30 +02:00
|
|
|
return h;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
2023-05-03 21:42:17 +02:00
|
|
|
|
|
|
|
static apply = function() {
|
|
|
|
for( var i = 0; i < size; i++ ) {
|
|
|
|
tb[i].apply();
|
2023-05-07 20:55:13 +02:00
|
|
|
current_value[i] = toNumber(tb[i]._input_text);
|
2023-05-03 21:42:17 +02:00
|
|
|
}
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|