mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-14 06:23:55 +01:00
133 lines
3.1 KiB
Plaintext
133 lines
3.1 KiB
Plaintext
enum DIMENSION {
|
|
width,
|
|
height
|
|
}
|
|
|
|
function vectorBox(_size, _onModify, _unit = noone) : widget() constructor {
|
|
size = _size;
|
|
onModify = _onModify;
|
|
unit = _unit;
|
|
current_value = [];
|
|
|
|
linked = false;
|
|
b_link = button(function() { linked = !linked; });
|
|
b_link.icon = THEME.value_link;
|
|
|
|
onModifyIndex = function(index, val) {
|
|
var v = toNumber(val);
|
|
|
|
if(linked) {
|
|
var modi = false;
|
|
for( var i = 0; i < size; i++ ) {
|
|
tb[i]._input_text = v;
|
|
|
|
if(is_callable(onModify))
|
|
modi |= onModify(i, v);
|
|
}
|
|
return modi;
|
|
}
|
|
|
|
if(is_callable(onModify))
|
|
return onModify(index, v);
|
|
return noone;
|
|
}
|
|
|
|
axis = [ "x", "y", "z", "w" ];
|
|
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); }
|
|
|
|
extras = -1;
|
|
|
|
for(var i = 0; i < 4; i++) {
|
|
tb[i] = new textBox(TEXTBOX_INPUT.number, onModifySingle[i]);
|
|
tb[i].slidable = true;
|
|
}
|
|
|
|
static setSlideSpeed = function(speed) {
|
|
for(var i = 0; i < size; i++)
|
|
tb[i].slide_speed = speed;
|
|
}
|
|
|
|
static setInteract = function(interactable) {
|
|
self.interactable = interactable;
|
|
b_link.interactable = interactable;
|
|
|
|
if(extras)
|
|
extras.interactable = interactable;
|
|
|
|
for( var i = 0; i < size; i++ )
|
|
tb[i].interactable = interactable;
|
|
}
|
|
|
|
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);
|
|
|
|
if(unit != noone && unit.reference != noone)
|
|
unit.triggerButton.register(parent);
|
|
}
|
|
|
|
static draw = function(_x, _y, _w, _h, _data, _m) {
|
|
x = _x;
|
|
y = _y;
|
|
w = _w;
|
|
h = _h;
|
|
|
|
if(!is_array(_data)) return;
|
|
current_value = _data;
|
|
|
|
if(extras && instanceof(extras) == "buttonClass") {
|
|
extras.setActiveFocus(hover, active);
|
|
extras.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m, THEME.button_hide);
|
|
_w -= ui(40);
|
|
}
|
|
|
|
if(unit != noone && unit.reference != noone) {
|
|
_w += ui(4);
|
|
|
|
unit.triggerButton.setActiveFocus(ihover, iactive);
|
|
unit.draw(_x + _w - ui(32), _y + _h / 2 - ui(32 / 2), ui(32), ui(32), _m);
|
|
_w -= ui(40);
|
|
}
|
|
|
|
b_link.setActiveFocus(hover, 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);
|
|
|
|
var sz = min(size, array_length(_data));
|
|
var ww = _w / sz;
|
|
for(var i = 0; i < sz; i++) {
|
|
tb[i].setActiveFocus(hover, active);
|
|
|
|
var bx = _x + ww * i;
|
|
tb[i].draw(bx + ui(24), _y, ww - ui(24), _h, _data[i], _m);
|
|
|
|
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
|
|
draw_text(bx + ui(8), _y + _h / 2, axis[i]);
|
|
}
|
|
|
|
resetFocus();
|
|
}
|
|
|
|
static apply = function() {
|
|
for( var i = 0; i < size; i++ ) {
|
|
tb[i].apply();
|
|
current_value[i] = toNumber(tb[i]._input_text);
|
|
}
|
|
}
|
|
} |