Pixel-Composer/scripts/transformBox/transformBox.gml

110 lines
3.4 KiB
Plaintext
Raw Normal View History

2023-06-21 20:36:53 +02:00
enum TRANSFORM {
pos_x,
pos_y,
rot,
sca_x,
sca_y
}
function transformBox(_onModify) : widget() constructor {
onModify = _onModify;
onModifySingle[TRANSFORM.pos_x] = function(val) { onModify(TRANSFORM.pos_x, val); }
onModifySingle[TRANSFORM.pos_y] = function(val) { onModify(TRANSFORM.pos_y, val); }
2023-06-23 15:39:24 +02:00
onModifySingle[TRANSFORM.rot ] = function(val) { onModify(TRANSFORM.rot , val); } //unused
2023-06-21 20:36:53 +02:00
onModifySingle[TRANSFORM.sca_x] = function(val) { onModify(TRANSFORM.sca_x, val); }
onModifySingle[TRANSFORM.sca_y] = function(val) { onModify(TRANSFORM.sca_y, val); }
2023-06-23 15:39:24 +02:00
rot = new rotator(function(val) { onModify(TRANSFORM.rot , val); });
2023-06-21 20:36:53 +02:00
for(var i = 0; i < 5; i++) {
tb[i] = new textBox(TEXTBOX_INPUT.number, onModifySingle[i]);
tb[i].slidable = true;
}
static setInteract = function(interactable = noone) {
self.interactable = interactable;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(tb); i < n; i++ )
2023-06-23 15:39:24 +02:00
tb[i].setInteract(interactable);
rot.setInteract(interactable);
2023-06-21 20:36:53 +02:00
}
static register = function(parent = noone) {
2023-06-23 15:39:24 +02:00
tb[TRANSFORM.pos_x].register(parent);
tb[TRANSFORM.pos_y].register(parent);
rot.register(parent);
tb[TRANSFORM.sca_x].register(parent);
tb[TRANSFORM.sca_y].register(parent);
2023-06-21 20:36:53 +02:00
}
2023-07-21 12:40:20 +02:00
static drawParam = function(params) {
return draw(params.x, params.y, params.w, params.data, params.m);
2023-06-21 20:36:53 +02:00
}
static draw = function(_x, _y, _w, _data, _m) {
x = _x;
y = _y;
w = _w;
2023-06-23 15:39:24 +02:00
h = ui(148);
2023-06-21 20:36:53 +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-06-23 15:39:24 +02:00
rot.setFocusHover(active, hover);
for(var i = 0; i < array_length(_data); i++) {
2023-06-21 20:36:53 +02:00
tb[i].setFocusHover(active, hover);
tb[i].hide = true;
}
2023-06-21 20:36:53 +02:00
2023-06-23 15:39:24 +02:00
var lbw = ui(80);
var tbw = (_w - lbw) / 2;
var tbh = TEXTBOX_HEIGHT;
2023-06-21 20:36:53 +02:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_inner);
draw_text_add(_x, _y + tbh / 2, __txt("Position"));
2023-06-23 15:39:24 +02:00
draw_sprite_stretched_ext(THEME.textbox, 3, _x + lbw, _y, _w - lbw, tbh, c_white, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x + lbw, _y, _w - lbw, tbh, c_white, 0.5 + 0.5 * interactable);
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
draw_set_alpha(0.5);
draw_text_add(_x + lbw + ui(8), _y + tbh / 2, "x");
draw_text_add(_x + lbw + tbw + ui(8), _y + tbh / 2, "y");
draw_set_alpha(1);
tb[TRANSFORM.pos_x].draw(_x + lbw, _y, tbw, tbh, _data[TRANSFORM.pos_x], _m);
tb[TRANSFORM.pos_y].draw(_x + lbw + tbw, _y, tbw, tbh, _data[TRANSFORM.pos_y], _m);
2023-06-23 15:39:24 +02:00
_y += ui(40);
2023-07-31 11:47:18 +02:00
rot.draw(_x, _y, _w, _data[TRANSFORM.rot], _m);
2023-06-21 20:36:53 +02:00
2023-06-23 15:39:24 +02:00
_y += ui(72);
2023-06-21 20:36:53 +02:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_inner);
draw_text_add(_x, _y + tbh / 2, __txt("Scale"));
2023-06-21 20:36:53 +02:00
draw_sprite_stretched_ext(THEME.textbox, 3, _x + lbw, _y, _w - lbw, tbh, c_white, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x + lbw, _y, _w - lbw, tbh, c_white, 0.5 + 0.5 * interactable);
tbw = array_length(_data) > 4? (_w - lbw) / 2 : _w - lbw;
2023-06-21 20:36:53 +02:00
if(array_length(_data) > 4) {
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_sub);
draw_set_alpha(0.5);
draw_text_add(_x + lbw + ui(8), _y + tbh / 2, "x");
draw_text_add(_x + lbw + tbw + ui(8), _y + tbh / 2, "y");
draw_set_alpha(1);
}
2023-06-23 15:39:24 +02:00
tb[TRANSFORM.sca_x].draw(_x + lbw, _y, tbw, tbh, _data[TRANSFORM.sca_x], _m);
2023-06-21 20:36:53 +02:00
if(array_length(_data) > 4)
tb[TRANSFORM.sca_y].draw(_x + lbw + tbw, _y, tbw, tbh, _data[TRANSFORM.sca_y], _m);
2023-06-21 20:36:53 +02:00
resetFocus();
return h;
}
}