Pixel-Composer/scripts/controlPointBox/controlPointBox.gml

169 lines
5.1 KiB
Text
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(toNumber(val), PUPPET_CONTROL.cx ); }); tbCx.hide = true; tbCx.slidable = true;
tbCy = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(toNumber(val), PUPPET_CONTROL.cy ); }); tbCy.hide = true; tbCy.slidable = true;
tbFx = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(toNumber(val), PUPPET_CONTROL.fx ); }); tbFx.hide = true; tbFx.slidable = true;
tbFy = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(toNumber(val), PUPPET_CONTROL.fy ); }); tbFy.hide = true; tbFy.slidable = true;
tbW = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(max(0, toNumber(val)), PUPPET_CONTROL.width ); }); tbW.hide = true; tbW.slidable = true;
tbH = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(max(0, toNumber(val)), PUPPET_CONTROL.height); }); tbH.hide = true; tbH.slidable = true;
rot = new rotator(function(val) { return onModify(toNumber(val), PUPPET_CONTROL.fy); });
2022-09-23 13:28:42 +02:00
2024-07-26 09:38:39 +02:00
sW = new textBox(TEXTBOX_INPUT.number, function(val) { onModify(toNumber(val), PUPPET_CONTROL.width); });
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(toNumber(val), PUPPET_CONTROL.mode); }
2022-09-23 13:28:42 +02:00
);
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;
}
static drawParam = function(params) {
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);
}
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;
2024-03-31 05:36:11 +02:00
var _mode = array_safe_get_fast(_data, PUPPET_CONTROL.mode);
var _cx = array_safe_get_fast(_data, PUPPET_CONTROL.cx);
var _cy = array_safe_get_fast(_data, PUPPET_CONTROL.cy);
var _fx = array_safe_get_fast(_data, PUPPET_CONTROL.fx);
var _fy = array_safe_get_fast(_data, PUPPET_CONTROL.fy);
var _wid = array_safe_get_fast(_data, PUPPET_CONTROL.width);
2023-08-24 11:59:05 +02:00
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, boxColor, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x, yy, _w, _wh, boxColor, 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, boxColor, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x, yy, _w, _wh, boxColor, 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, boxColor, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _x, yy, _w, _wh, boxColor, 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;
}
2024-03-31 11:10:14 +02:00
static clone = function() {
2024-03-31 11:10:14 +02:00
var cln = new controlPointBox(onModify);
return cln;
}
2024-11-24 11:39:17 +01:00
static free = function() {
tbCx.free();
tbCy.free();
tbFx.free();
tbFy.free();
tbW.free();
tbH.free();
rot.free();
sW.free();
}
2022-09-23 13:28:42 +02:00
}