Pixel-Composer/scripts/controlPointBox/controlPointBox.gml

153 lines
4.8 KiB
Plaintext
Raw Normal View History

2022-09-23 13:28:42 +02:00
enum PUPPET_CONTROL {
mode,
cx,
cy,
fx,
fy,
width,
height
}
enum PUPPET_FORCE_MODE {
move,
wind,
2024-01-28 09:53:41 +01:00
puppet,
2022-09-23 13:28:42 +02:00
}
2023-01-17 08:11:55 +01:00
function controlPointBox(_onModify) : widget() constructor {
2022-09-23 13:28:42 +02:00
onModify = _onModify;
onSurfaceSize = -1;
tbCx = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.cx, toNumber(val)); }); tbCx.hide = true; tbCx.slidable = true;
tbCy = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.cy, toNumber(val)); }); tbCy.hide = true; tbCy.slidable = true;
tbFx = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.fx, toNumber(val)); }); tbFx.hide = true; tbFx.slidable = true;
tbFy = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.fy, toNumber(val)); }); tbFy.hide = true; tbFy.slidable = true;
tbW = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.width, max(0, toNumber(val))); }); tbW.hide = true; tbW.slidable = true;
tbH = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.height, max(0, toNumber(val))); }); tbH.hide = true; tbH.slidable = true;
2023-02-14 05:32:32 +01:00
rot = new rotator(function(val) { return onModify(PUPPET_CONTROL.fy, toNumber(val)); });
2022-09-23 13:28:42 +02:00
sW = new textBox(TEXTBOX_INPUT.number, function(val) { onModify(PUPPET_CONTROL.width, toNumber(val)); })
.setSlidable(0.01, false, [ 1, 32 ]);
2022-09-23 13:28:42 +02:00
2024-03-26 04:03:45 +01:00
tbCx.label = "cx";
tbCy.label = "cy";
sMode = [
2024-01-28 09:53:41 +01:00
__txtx("widget_control_point_move", "Move"),
__txtx("widget_control_point_wind", "Wind"),
];
2022-09-23 13:28:42 +02:00
scMode = new scrollBox(
sMode,
function(val) { onModify(PUPPET_CONTROL.mode, toNumber(val)); }
);
widgets = [ scMode, tbCx, tbCy, tbFx, tbFy, tbW, tbH, rot, sW ];
2023-03-26 07:13:36 +02:00
2023-01-25 06:49:00 +01:00
static setInteract = function(interactable = noone) {
self.interactable = interactable;
2023-03-26 07:13:36 +02:00
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(widgets); i < n; i++ )
2023-03-26 07:13:36 +02:00
widgets[i].setInteract(interactable);
2023-01-25 06:49:00 +01:00
}
2023-01-17 08:11:55 +01:00
static register = function(parent = noone) {
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(widgets); i < n; i++ )
2023-03-26 07:13:36 +02:00
widgets[i].register(parent);
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(widgets); i < n; i++ ) if(widgets[i].isHovering()) return true;
return false;
}
2024-03-26 04:03:45 +01:00
static drawParam = function(params) { #region
2024-03-27 11:51:14 +01:00
setParam(params);
tbCx.setParam(params);
tbCy.setParam(params);
tbFx.setParam(params);
tbFy.setParam(params);
tbW.setParam(params);
tbH.setParam(params);
rot.setParam(params);
sW.setParam(params);setParam(params);
scMode.setParam(params);
2024-03-26 04:03:45 +01:00
return draw(params.x, params.y, params.w, params.h, params.data, params.m, params.rx, params.ry);
} #endregion
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, _rx, _ry) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
2023-08-24 11:59:05 +02:00
var _mode = array_safe_get(_data, PUPPET_CONTROL.mode);
var _cx = array_safe_get(_data, PUPPET_CONTROL.cx);
var _cy = array_safe_get(_data, PUPPET_CONTROL.cy);
var _fx = array_safe_get(_data, PUPPET_CONTROL.fx);
var _fy = array_safe_get(_data, PUPPET_CONTROL.fy);
var _wid = array_safe_get(_data, PUPPET_CONTROL.width);
if(is_array(_mode) || is_array(_cx) || is_array(_cy) || is_array(_fx) || is_array(_fy) || is_array(_wid))
return 0;
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(widgets); i < n; i++ )
2023-06-21 20:36:53 +02:00
widgets[i].setFocusHover(active, hover);
2022-09-23 13:28:42 +02:00
var yy = _y;
2024-03-26 04:03:45 +01:00
scMode.draw(_x, yy, _w, _h, sMode[_mode], _m, _rx, _ry);
yy += _h + ui(4);
2022-09-23 13:28:42 +02:00
var _ww = _w / 2;
2024-03-26 04:03:45 +01:00
var _wh = _h;
2022-09-23 13:28:42 +02:00
draw_sprite_stretched_ext(THEME.textbox, 3, _x, yy, _w, _wh, c_white, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x, yy, _w, _wh, c_white, 0.5 + 0.5 * interactable);
tbCx.draw(_x, yy, _ww, _wh, _cx, _m);
tbCy.draw(_x + _ww, yy, _ww, _wh, _cy, _m);
2024-03-26 04:03:45 +01:00
yy += _wh + ui(4);
2022-09-23 13:28:42 +02:00
2023-08-24 11:59:05 +02:00
switch(_mode) {
2022-09-23 13:28:42 +02:00
case PUPPET_FORCE_MODE.move:
2024-01-28 09:53:41 +01:00
case PUPPET_FORCE_MODE.puppet:
draw_sprite_stretched_ext(THEME.textbox, 3, _x, yy, _w, _wh, c_white, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x, yy, _w, _wh, c_white, 0.5 + 0.5 * interactable);
2024-03-26 04:03:45 +01:00
tbFx.label = "fx";
tbFy.label = "fy";
tbFx.draw(_x, yy, _ww, _wh, _fx, _m);
tbFy.draw(_x + _ww, yy, _ww, _wh, _fy, _m);
2024-03-26 04:03:45 +01:00
yy += _wh + ui(4);
2024-01-28 09:53:41 +01:00
if(_mode == PUPPET_FORCE_MODE.move) {
2024-03-26 04:03:45 +01:00
sW.label = __txt("radius");
sW.draw(_x, yy, _w, _wh, _wid, _m);
2024-03-26 04:03:45 +01:00
yy += _wh + ui(4);
2024-01-28 09:53:41 +01:00
}
2022-09-23 13:28:42 +02:00
break;
2022-09-23 13:28:42 +02:00
case PUPPET_FORCE_MODE.wind:
draw_sprite_stretched_ext(THEME.textbox, 3, _x, yy, _w, _wh, c_white, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x, yy, _w, _wh, c_white, 0.5 + 0.5 * interactable);
2024-03-26 04:03:45 +01:00
tbFx.label = __txt("strength");
tbW.label = __txt("width");
2022-09-23 13:28:42 +02:00
tbFx.draw(_x, yy, _ww, _wh, _fx, _m);
tbW.draw( _x + _ww, yy, _ww, _wh, _wid, _m);
2024-03-26 04:03:45 +01:00
yy += _wh + ui(4);
2022-09-23 13:28:42 +02:00
2024-03-26 04:03:45 +01:00
var _rh = rot.draw(_x, yy, _w, _wh, _fy, _m);
yy += _rh + ui(4);
2022-09-23 13:28:42 +02:00
break;
}
2023-01-17 08:11:55 +01:00
resetFocus();
2022-09-23 13:28:42 +02:00
return yy - _y;
}
}