Pixel-Composer/scripts/preview_overlay_puppet/preview_overlay_puppet.gml

206 lines
6.1 KiB
Text
Raw Normal View History

2023-04-05 20:13:27 +02:00
function preview_overlay_puppet(interact, active, _x, _y, _s, _mx, _my, _snx, _sny) {
2023-09-15 20:12:02 +02:00
var _val = array_clone(getValue());
2023-01-17 08:11:55 +01:00
var hover = -1;
if(is_array(_val[0])) return hover;
var __ax = _val[PUPPET_CONTROL.cx];
var __ay = _val[PUPPET_CONTROL.cy];
var __ax1 = _val[PUPPET_CONTROL.fx];
var __ay1 = _val[PUPPET_CONTROL.fy];
2023-03-26 07:13:36 +02:00
var __wd = _val[PUPPET_CONTROL.width];
2023-01-17 08:11:55 +01:00
var _ax = __ax * _s + _x;
var _ay = __ay * _s + _y;
var _ax1 = (__ax + __ax1) * _s + _x;
var _ay1 = (__ay + __ay1) * _s + _y;
draw_set_color(COLORS._main_accent);
2024-03-28 08:33:28 +01:00
2023-01-17 08:11:55 +01:00
switch(_val[PUPPET_CONTROL.mode]) {
case PUPPET_FORCE_MODE.move :
draw_line_width2(_ax, _ay, _ax1, _ay1, 6, 1);
2023-06-17 14:30:49 +02:00
draw_circle_prec(_ax, _ay, __wd * _s, true);
2023-03-26 07:13:36 +02:00
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_selector, 0, _ax, _ay);
draw_sprite_colored(THEME.anchor_selector, 2, _ax1, _ay1);
2023-03-26 07:13:36 +02:00
if(point_in_circle(_mx, _my, _ax + __wd * _s, _ay, 8)) {
hover = 3;
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_scale_hori, 1, _ax + __wd * _s, _ay);
2023-03-26 07:13:36 +02:00
if(mouse_press(mb_left, active)) {
drag_type = 3;
drag_mx = _mx;
drag_sx = __wd;
}
} else
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_scale_hori, drag_type == 3, _ax + __wd * _s, _ay);
2023-01-17 08:11:55 +01:00
break;
2024-03-28 08:33:28 +01:00
2023-01-17 08:11:55 +01:00
case PUPPET_FORCE_MODE.wind :
var dir = _val[PUPPET_CONTROL.fy];
2023-03-26 07:13:36 +02:00
var str = _val[PUPPET_CONTROL.fx] * _s;
2023-01-17 08:11:55 +01:00
var rad = _val[PUPPET_CONTROL.width] * _s;
2023-03-26 07:13:36 +02:00
var _lx = _ax + lengthdir_x(str, dir);
var _ly = _ay + lengthdir_y(str, dir);
2023-01-17 08:11:55 +01:00
var _l0x = _ax + lengthdir_x(rad, dir + 90);
var _l0y = _ay + lengthdir_y(rad, dir + 90);
var _l1x = _ax + lengthdir_x(rad, dir - 90);
var _l1y = _ay + lengthdir_y(rad, dir - 90);
var _l0x0 = _l0x + lengthdir_x(1000, dir);
var _l0y0 = _l0y + lengthdir_y(1000, dir);
var _l0x1 = _l0x + lengthdir_x(1000, dir + 180);
var _l0y1 = _l0y + lengthdir_y(1000, dir + 180);
var _l1x0 = _l1x + lengthdir_x(1000, dir);
var _l1y0 = _l1y + lengthdir_y(1000, dir);
var _l1x1 = _l1x + lengthdir_x(1000, dir + 180);
var _l1y1 = _l1y + lengthdir_y(1000, dir + 180);
2023-03-26 07:13:36 +02:00
2023-01-17 08:11:55 +01:00
draw_line(_l0x0, _l0y0, _l0x1, _l0y1);
draw_line(_l1x0, _l1y0, _l1x1, _l1y1);
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_selector, 0, _ax, _ay);
2023-03-26 07:13:36 +02:00
if(point_in_circle(_mx, _my, _l0x, _l0y, 8)) {
hover = 4;
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_scale_hori, 1, _l0x, _l0y,, dir + 90);
2023-03-26 07:13:36 +02:00
if(mouse_press(mb_left, active)) {
drag_type = 4;
drag_sx = _ax;
drag_sy = _ay;
}
} else
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_scale_hori, drag_type == 4, _l0x, _l0y,, dir + 90);
2023-03-26 07:13:36 +02:00
if(point_in_circle(_mx, _my, _lx, _ly, 8)) {
hover = 5;
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_scale_hori, 1, _lx, _ly,, dir);
2023-03-26 07:13:36 +02:00
if(mouse_press(mb_left, active)) {
drag_type = 5;
drag_sx = _ax;
drag_sy = _ay;
}
} else
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_scale_hori, drag_type == 5, _lx, _ly,, dir);
2023-03-26 07:13:36 +02:00
var rx = _ax + lengthdir_x(64, dir + 45);
var ry = _ay + lengthdir_y(64, dir + 45);
if(point_in_circle(_mx, _my, rx, ry, 8)) {
draw_set_color(COLORS._main_accent);
2023-06-17 14:30:49 +02:00
draw_circle_prec(_ax, _ay, 64, true);
2023-03-26 07:13:36 +02:00
hover = 6;
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_rotate, 1, rx, ry,, dir - 45);
2023-03-26 07:13:36 +02:00
if(mouse_press(mb_left, active)) {
drag_type = 6;
drag_sx = _ax;
drag_sy = _ay;
}
} else
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_rotate, drag_type == 6, rx, ry,, dir - 45);
2023-01-17 08:11:55 +01:00
break;
2024-01-28 09:53:41 +01:00
case PUPPET_FORCE_MODE.puppet :
draw_line_width2(_ax, _ay, _ax1, _ay1, 6, 1);
draw_sprite_colored(THEME.anchor_selector, 0, _ax, _ay);
draw_sprite_colored(THEME.anchor_selector, 2, _ax1, _ay1);
break;
2023-01-17 08:11:55 +01:00
}
if(drag_type == 1) {
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_selector, 1, _ax, _ay);
2023-01-17 08:11:55 +01:00
var _nx = value_snap(drag_sx + (_mx - drag_mx) / _s, _snx);
var _ny = value_snap(drag_sy + (_my - drag_my) / _s, _sny);
if(key_mod_press(CTRL)) {
_val[PUPPET_CONTROL.cx] = round(_nx);
_val[PUPPET_CONTROL.cy] = round(_ny);
} else {
_val[PUPPET_CONTROL.cx] = _nx;
_val[PUPPET_CONTROL.cy] = _ny;
}
} else if(drag_type == 2) {
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_selector, 0, _ax1, _ay1);
2023-01-17 08:11:55 +01:00
var _nx = value_snap(drag_sx + (_mx - drag_mx) / _s, _snx);
var _ny = value_snap(drag_sy + (_my - drag_my) / _s, _sny);
if(key_mod_press(CTRL)) {
_val[PUPPET_CONTROL.fx] = round(_nx);
_val[PUPPET_CONTROL.fy] = round(_ny);
} else {
_val[PUPPET_CONTROL.fx] = _nx;
_val[PUPPET_CONTROL.fy] = _ny;
}
2023-03-26 07:13:36 +02:00
} else if(drag_type == 3) {
var _nx = value_snap(drag_sx + (_mx - drag_mx) / _s, _snx);
if(key_mod_press(CTRL))
_val[PUPPET_CONTROL.width] = round(_nx);
else
_val[PUPPET_CONTROL.width] = _nx;
} else if(drag_type == 4) {
var _nx = value_snap(point_distance(_mx, _my, drag_sx, drag_sy) / _s, _snx);
if(key_mod_press(CTRL))
_val[PUPPET_CONTROL.width] = round(_nx);
else
_val[PUPPET_CONTROL.width] = _nx;
} else if(drag_type == 5) {
var _nx = value_snap(point_distance(_mx, _my, drag_sx, drag_sy) / _s, _snx);
if(key_mod_press(CTRL))
_val[PUPPET_CONTROL.fx] = round(_nx);
else
_val[PUPPET_CONTROL.fx] = _nx;
} else if(drag_type == 6) {
var _nx = point_direction(drag_sx, drag_sy, _mx, _my) - 45;
if(key_mod_press(CTRL))
_val[PUPPET_CONTROL.fy] = round(_nx);
else
_val[PUPPET_CONTROL.fy] = _nx;
}
2023-03-30 07:54:25 +02:00
if(drag_type > 0) {
2024-02-01 10:02:18 +01:00
if(setValueInspector( _val ))
2023-01-17 08:11:55 +01:00
UNDO_HOLDING = true;
2023-03-26 07:13:36 +02:00
2023-01-17 08:11:55 +01:00
if(mouse_release(mb_left)) {
drag_type = 0;
UNDO_HOLDING = false;
}
}
2023-10-18 14:58:55 +02:00
if(interact && active && point_in_circle(_mx, _my, _ax, _ay, 8)) {
2023-01-17 08:11:55 +01:00
hover = 1;
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_selector, 1, _ax, _ay);
2023-01-17 08:11:55 +01:00
if(mouse_press(mb_left, active)) {
drag_type = 1;
drag_mx = _mx;
drag_my = _my;
drag_sx = __ax;
drag_sy = __ay;
}
}
2024-01-28 09:53:41 +01:00
var _mode = _val[PUPPET_CONTROL.mode];
if(interact && active && (_mode == PUPPET_FORCE_MODE.move || _mode == PUPPET_FORCE_MODE.puppet) && point_in_circle(_mx, _my, _ax1, _ay1, 8)) {
2023-01-17 08:11:55 +01:00
hover = 2;
2023-04-08 20:06:27 +02:00
draw_sprite_colored(THEME.anchor_selector, 0, _ax1, _ay1);
2023-01-17 08:11:55 +01:00
if(mouse_press(mb_left, active)) {
drag_type = 2;
drag_mx = _mx;
drag_my = _my;
drag_sx = __ax1;
drag_sy = __ay1;
}
}
return hover;
}