Pixel-Composer/scripts/paddingBox/paddingBox.gml

142 lines
3.7 KiB
Text
Raw Normal View History

2023-03-19 09:17:39 +01:00
enum PADDING {
right,
top,
left,
bottom
}
2023-01-17 08:11:55 +01:00
function paddingBox(_onModify, _unit = noone) : widget() constructor {
2022-01-13 05:24:03 +01:00
onModify = _onModify;
2022-12-27 04:00:50 +01:00
unit = _unit;
2022-01-13 05:24:03 +01:00
2022-12-27 04:00:50 +01:00
linked = false;
b_link = button(function() { linked = !linked; });
b_link.icon = THEME.value_link;
2022-01-13 05:24:03 +01:00
2022-12-27 04:00:50 +01:00
onModifyIndex = function(index, val) {
if(linked) {
for( var i = 0; i < 4; i++ )
onModify(i, toNumber(val));
return;
}
onModify(index, toNumber(val));
2022-01-13 05:24:03 +01:00
}
2022-12-27 04:00:50 +01:00
onModifySingle[0] = function(val) { onModifyIndex(0, val); }
onModifySingle[1] = function(val) { onModifyIndex(1, val); }
onModifySingle[2] = function(val) { onModifyIndex(2, val); }
onModifySingle[3] = function(val) { onModifyIndex(3, val); }
2023-02-14 05:32:32 +01:00
for(var i = 0; i < 4; i++) {
tb[i] = new textBox(TEXTBOX_INPUT.number, onModifySingle[i]);
tb[i].slidable = true;
2024-03-26 04:03:45 +01:00
tb[i].hide = true;
2023-02-14 05:32:32 +01:00
}
2024-03-26 04:03:45 +01:00
tb[2].label = "l";
tb[0].label = "r";
tb[1].label = "t";
tb[3].label = "b";
static setSlideSpeed = function(speed) { for(var i = 0; i < 4; i++) tb[i].setSlidable(speed); }
2022-01-13 05:24:03 +01:00
2024-03-26 04:03:45 +01:00
static setInteract = function(interactable = noone) { #region
self.interactable = interactable;
2023-01-25 06:49:00 +01:00
b_link.interactable = interactable;
for( var i = 0; i < 4; i++ )
tb[i].interactable = interactable;
2024-03-26 04:03:45 +01:00
} #endregion
2023-01-25 06:49:00 +01:00
2024-03-26 04:03:45 +01:00
static register = function(parent = noone) { #region
2023-01-17 08:11:55 +01:00
b_link.register();
if(unit != noone && unit.reference != noone)
unit.triggerButton.register(parent);
2023-01-25 06:49:00 +01:00
tb[2].register(parent);
tb[0].register(parent);
2024-03-26 04:03:45 +01:00
tb[1].register(parent);
2023-01-25 06:49:00 +01:00
tb[3].register(parent);
2024-03-26 04:03:45 +01:00
} #endregion
2023-01-17 08:11:55 +01:00
2024-03-28 14:18:02 +01:00
static isHovering = function() {
for( var i = 0, n = array_length(tb); i < n; i++ ) if(tb[i].isHovering()) return true;
return false;
}
2024-03-26 04:03:45 +01:00
static drawParam = function(params) {
2024-03-27 11:51:14 +01:00
setParam(params);
for(var i = 0; i < 4; i++) tb[i].setParam(params);
2024-03-26 04:03:45 +01:00
return draw(params.x, params.y, params.w, params.h, params.data, params.m);
2023-07-30 19:56:53 +02:00
}
2024-03-26 04:03:45 +01:00
static draw = function(_x, _y, _w, _h, _data, _m) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
2024-03-26 04:03:45 +01:00
w = _w;
h = _h + ui(4) + _h;
2022-01-13 05:24:03 +01:00
2024-03-26 04:03:45 +01:00
for(var i = 0; i < 4; i++) tb[i].setFocusHover(active, hover);
2022-01-13 05:24:03 +01:00
2024-03-26 04:03:45 +01:00
var _bs = min(_h, ui(32));
2024-03-29 05:20:49 +01:00
if((_w - _bs) / 2 > ui(64)) {
b_link.setFocusHover(active, hover);
b_link.icon_index = linked;
b_link.icon_blend = linked? COLORS._main_accent : COLORS._main_icon;
b_link.tooltip = linked? __txt("Unlink values") : __txt("Link values");
var _bx = _x;
var _by = _y + _h / 2 - _bs / 2;
b_link.draw(_bx, _by, _bs, _bs, _m, THEME.button_hide);
2022-12-27 04:00:50 +01:00
2024-03-29 05:20:49 +01:00
_w -= _bs + ui(4);
_x += _bs + ui(4);
if(unit != noone && unit.reference != noone) {
unit.triggerButton.setFocusHover(iactive, ihover);
unit.draw(_bx, _by + ui(4) + _h, _bs, _bs, _m);
}
2022-12-27 04:00:50 +01:00
}
2022-01-13 05:24:03 +01:00
2024-03-26 04:03:45 +01:00
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, _h, c_white, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, _h, c_white, 0.5 + 0.5 * interactable);
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y + _h + ui(4), _w, _h, c_white, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y + _h + ui(4), _w, _h, c_white, 0.5 + 0.5 * interactable);
var tb_w = _w / 2;
var tb_h = _h;
var tb_lx = _x;
var tb_ly = _y;
var tb_rx = _x + tb_w;
var tb_ry = _y;
var tb_tx = _x;
var tb_ty = _y + _h + ui(4);
var tb_bx = _x + tb_w;
var tb_by = _y + _h + ui(4);
2024-03-31 05:36:11 +02:00
tb[2].draw(tb_lx, tb_ly, tb_w, tb_h, array_safe_get_fast(_data, 2), _m);
tb[0].draw(tb_rx, tb_ry, tb_w, tb_h, array_safe_get_fast(_data, 0), _m);
tb[1].draw(tb_tx, tb_ty, tb_w, tb_h, array_safe_get_fast(_data, 1), _m);
tb[3].draw(tb_bx, tb_by, tb_w, tb_h, array_safe_get_fast(_data, 3), _m);
2024-03-26 04:03:45 +01:00
2023-01-17 08:11:55 +01:00
resetFocus();
2023-07-30 19:56:53 +02:00
return h;
2022-01-13 05:24:03 +01:00
}
2024-03-31 11:10:14 +02:00
static clone = function() { #region
var cln = new paddingBox(onModify, unit);
return cln;
} #endregion
2022-01-13 05:24:03 +01:00
}