Pixel-Composer/scripts/paddingBox/paddingBox.gml

102 lines
2.7 KiB
Plaintext
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;
}
static setSlideSpeed = function(speed) {
for(var i = 0; i < 4; i++)
tb[i].setSlidable(speed);
2023-02-14 05:32:32 +01:00
}
2022-01-13 05:24:03 +01:00
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 < 4; i++ )
tb[i].interactable = interactable;
}
2023-01-17 08:11:55 +01:00
static register = function(parent = noone) {
b_link.register();
2023-01-25 06:49:00 +01:00
tb[1].register(parent);
2023-01-17 08:11:55 +01:00
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);
tb[3].register(parent);
2023-01-17 08:11:55 +01:00
}
2023-07-30 19:56:53 +02:00
static drawParam = function(params) {
return draw(params.x + params.w / 2, params.y + ui(32), params.data, params.m);
}
2022-12-27 04:00:50 +01:00
static draw = function(_x, _y, _data, _m) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = 0;
h = ui(192);
2022-11-18 03:20:31 +01:00
draw_sprite_ui_uniform(THEME.inspector_padding, 0, _x, _y + ui(64));
2022-01-13 05:24:03 +01:00
for(var i = 0; i < 4; i++) {
2023-06-21 20:36:53 +02:00
tb[i].setFocusHover(active, hover);
2022-01-13 05:24:03 +01:00
tb[i].align = fa_center;
}
2022-11-03 11:44:49 +01:00
tb[0].draw(_x + ui(64), _y + ui(64 - 17), ui(64), TEXTBOX_HEIGHT, _data[0], _m);
tb[1].draw(_x - ui(32), _y + ui(64 - 48 - 8 - 34), ui(64), TEXTBOX_HEIGHT, _data[1], _m);
tb[2].draw(_x - ui(64) - ui(64), _y + ui(64 - 17), ui(64), TEXTBOX_HEIGHT, _data[2], _m);
tb[3].draw(_x - ui(32), _y + ui(64 + 48 + 8), ui(64), TEXTBOX_HEIGHT, _data[3], _m);
2022-01-13 05:24:03 +01:00
2023-06-21 20:36:53 +02:00
b_link.setFocusHover(active, hover);
2022-12-27 04:00:50 +01:00
b_link.icon_index = linked;
b_link.icon_blend = linked? COLORS._main_accent : COLORS._main_icon;
2023-06-04 18:28:29 +02:00
b_link.tooltip = linked? __txt("Unlink values") : __txt("Link values");
2022-12-27 04:00:50 +01:00
2022-11-03 11:44:49 +01:00
var bx = _x - ui(80);
2022-12-27 04:00:50 +01:00
var by = _y - ui(24);
2022-12-27 13:30:02 +01:00
b_link.draw(bx + ui(4), by + ui(4), ui(24), ui(24), _m, THEME.button_hide);
2022-12-27 04:00:50 +01:00
if(unit != noone && unit.reference != noone) {
2023-06-21 20:36:53 +02:00
unit.triggerButton.setFocusHover(iactive, ihover);
2022-12-27 04:00:50 +01:00
unit.draw(_x + ui(48), _y - ui(25), ui(32), ui(32), _m);
}
2022-01-13 05:24:03 +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
}
}