Pixel-Composer/scripts/controlPointBox/controlPointBox.gml

123 lines
4.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,
}
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;
2023-02-14 05:32:32 +01:00
tbCx = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.cx, toNumber(val)); });
tbCy = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.cy, toNumber(val)); });
tbFx = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.fx, toNumber(val)); });
tbFy = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.fy, toNumber(val)); });
tbW = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.width, max(0, toNumber(val))); });
tbH = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(PUPPET_CONTROL.height, max(0, toNumber(val))); });
rot = new rotator(function(val) { return onModify(PUPPET_CONTROL.fy, toNumber(val)); });
2022-09-23 13:28:42 +02:00
tbFx.slidable = true;
tbFy.slidable = true;
tbW.slidable = true;
tbH.slidable = true;
sW = new slider(0, 32, 0.1, function(val) { onModify(PUPPET_CONTROL.width, toNumber(val)); });
2023-03-26 07:13:36 +02:00
sMode = ["Move", "Wind"];
2022-09-23 13:28:42 +02:00
scMode = new scrollBox(
sMode,
function(val) { onModify(PUPPET_CONTROL.mode, toNumber(val)); }
);
2023-03-26 07:13:36 +02:00
widgets = [ scMode, tbCx, tbCy, tbFx, tbFy, tbW, tbH, rot ];
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
}
2023-07-30 19:56:53 +02:00
static drawParam = function(params) {
return draw(params.x, params.y, params.w, params.data, params.m, params.rx, params.ry);
}
2022-09-23 13:28:42 +02:00
static draw = function(_x, _y, _w, _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;
2023-08-24 11:59:05 +02:00
scMode.draw(_x, yy, _w, TEXTBOX_HEIGHT, sMode[_mode], _m, _rx, _ry);
2022-11-03 11:44:49 +01:00
yy += TEXTBOX_HEIGHT + ui(8);
2022-09-23 13:28:42 +02:00
2022-11-03 11:44:49 +01:00
var lw = ui(80);
2022-09-23 13:28:42 +02:00
var w = _w / 2 - lw;
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
2022-11-03 11:44:49 +01:00
draw_text(_x, yy + ui(17), "cx");
draw_text(_x + _w / 2 + ui(10), yy + ui(17), "cy");
2023-08-24 11:59:05 +02:00
tbCx.draw(_x + lw, yy, w, TEXTBOX_HEIGHT, _cx, _m);
tbCy.draw(_x + _w / 2 + lw, yy, w, TEXTBOX_HEIGHT, _cy, _m);
2022-11-03 11:44:49 +01:00
yy += TEXTBOX_HEIGHT + ui(8);
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:
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
2022-11-03 11:44:49 +01:00
draw_text(_x, yy + ui(17), "fx");
draw_text(_x + _w / 2 + ui(10), yy + ui(17), "fy");
2023-08-24 11:59:05 +02:00
tbFx.draw(_x + lw, yy, w, TEXTBOX_HEIGHT, _fx, _m);
tbFy.draw(_x + _w / 2 + lw, yy, w, TEXTBOX_HEIGHT, _fy, _m);
2022-11-03 11:44:49 +01:00
yy += TEXTBOX_HEIGHT + ui(8);
2022-09-23 13:28:42 +02:00
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
2022-11-03 11:44:49 +01:00
draw_text(_x, yy + ui(17), "radius");
2023-08-24 11:59:05 +02:00
sW.draw(_x + lw, yy, _w - lw, TEXTBOX_HEIGHT, _wid, _m);
2022-11-03 11:44:49 +01:00
yy += TEXTBOX_HEIGHT + ui(8);
2022-09-23 13:28:42 +02:00
break;
case PUPPET_FORCE_MODE.wind:
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
2023-03-26 07:13:36 +02:00
draw_text(_x, yy + ui(17), "strength");
2023-08-24 11:59:05 +02:00
tbFx.draw(_x + lw, yy, _w - lw, TEXTBOX_HEIGHT, _fx, _m);
2022-11-03 11:44:49 +01:00
yy += TEXTBOX_HEIGHT + ui(8);
2022-09-23 13:28:42 +02:00
2022-11-18 03:20:31 +01:00
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
2022-11-03 11:44:49 +01:00
draw_text(_x, yy + ui(17), "width");
2023-08-24 11:59:05 +02:00
tbW.draw(_x + lw, yy, _w - lw, TEXTBOX_HEIGHT, _wid, _m);
2022-11-03 11:44:49 +01:00
yy += TEXTBOX_HEIGHT + ui(8);
2022-09-23 13:28:42 +02:00
2023-08-24 11:59:05 +02:00
rot.draw(_x + _w / 2, yy, _fy, _m);
2022-11-03 11:44:49 +01:00
yy += ui(94 + 8);
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;
}
}