Pixel-Composer/scripts/preview_overlay_area/preview_overlay_area.gml

393 lines
10 KiB
Plaintext
Raw Normal View History

2023-11-23 13:39:35 +01:00
function preview_overlay_area_padding(interact, active, _x, _y, _s, _mx, _my, _snx, _sny, _flag, display_data) { #region
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_callable(display_data)) return hover;
2023-01-17 08:11:55 +01:00
2023-11-23 13:39:35 +01:00
var __ax = array_safe_get(_val, 0);
var __ay = array_safe_get(_val, 1);
var __aw = array_safe_get(_val, 2);
var __ah = array_safe_get(_val, 3);
2023-01-17 08:11:55 +01:00
var __at = array_safe_get(_val, 4);
2023-11-23 13:39:35 +01:00
var _x0 = __ax - __aw;
var _x1 = __ax + __aw;
var _y0 = __ay - __ah;
var _y1 = __ay + __ah;
var ss = display_data();
var _l = _x0;
var _r = ss[0] - _x1;
var _t = _y0;
var _b = ss[1] - _y1;
var _xc = __ax;
var _yc = __ay;
2023-01-17 08:11:55 +01:00
var x0 = _l * _s + _x;
var y0 = _t * _s + _y;
var x1 = (ss[0] - _r) * _s + _x;
var y1 = (ss[1] - _b) * _s + _y;
var xc = (x0 + x1) / 2;
var yc = (y0 + y1) / 2;
var drawPos = _flag & 0b0001;
var drawSize = _flag & 0b0010;
if(drawSize) {
draw_set_color(COLORS._main_accent);
draw_set_circle_precision(32);
switch(__at) {
case AREA_SHAPE.rectangle : draw_rectangle(x0, y0, x1, y1, true); break;
case AREA_SHAPE.elipse : draw_ellipse(x0, y0, x1, y1, true); break;
}
2023-01-17 08:11:55 +01:00
}
2023-04-05 20:13:27 +02:00
if(!interact) return -1;
2024-03-28 08:33:28 +01:00
var _hov = [ 0, 0, 0, 0 ], _hovPos = 0;
2023-01-17 08:11:55 +01:00
2023-11-23 13:39:35 +01:00
if(drag_type == 1) _r = value_snap(drag_sx - (_mx - drag_mx) / _s, _snx);
else if(drag_type == 2) _t = value_snap(drag_sy + (_my - drag_my) / _s, _sny);
else if(drag_type == 3) _l = value_snap(drag_sx + (_mx - drag_mx) / _s, _snx);
else if(drag_type == 4) _b = value_snap(drag_sy - (_my - drag_my) / _s, _sny);
2023-01-17 08:11:55 +01:00
2023-11-23 13:39:35 +01:00
if(drag_type) {
2024-03-28 08:33:28 +01:00
var _val = array_clone(showValue());
if(drag_type == 1) _val[0] = _r;
else if(drag_type == 2) _val[1] = _t;
else if(drag_type == 3) _val[2] = _l;
else if(drag_type == 4) _val[3] = _b;
2024-02-01 10:02:18 +01:00
if(setValueInspector(_val)) UNDO_HOLDING = true;
2023-11-23 13:39:35 +01:00
if(mouse_release(mb_left)) {
drag_type = 0;
UNDO_HOLDING = false;
}
2023-01-17 08:11:55 +01:00
}
2024-03-28 08:33:28 +01:00
if(drawSize && point_in_circle(_mx, _my, xc, y0, 16)) {
_hov[0] = 1;
hover = 1;
2023-01-17 08:11:55 +01:00
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-01-17 08:11:55 +01:00
drag_type = 2;
drag_sy = _t;
drag_my = _my;
}
2024-03-28 08:33:28 +01:00
} else if(drawSize && point_in_circle(_mx, _my, xc, y1, 16)) {
_hov[1] = 1;
2023-01-17 08:11:55 +01:00
hover = 3;
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-01-17 08:11:55 +01:00
drag_type = 4;
drag_sy = _b;
drag_my = _my;
}
2024-03-28 08:33:28 +01:00
} else if(drawSize && point_in_circle(_mx, _my, x0, yc, 16)) {
_hov[2] = 1;
2023-01-17 08:11:55 +01:00
hover = 0;
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-01-17 08:11:55 +01:00
drag_type = 3;
drag_sx = _l;
drag_mx = _mx;
}
2024-03-28 08:33:28 +01:00
} else if(drawSize && point_in_circle(_mx, _my, x1, yc, 16)) {
_hov[3] = 1;
2023-01-17 08:11:55 +01:00
hover = 2;
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-01-17 08:11:55 +01:00
drag_type = 1;
drag_sx = _r;
drag_mx = _mx;
}
}
2024-03-28 08:33:28 +01:00
for( var i = 0; i < 4; i++ )
__overlay_hover[i] = lerp_float(__overlay_hover[i], _hov[i], 4);
if(drawSize) {
if(drag_type == 0 || drag_type == 2) draw_anchor_line(__overlay_hover[0], xc, y0, 16, 0);
if(drag_type == 0 || drag_type == 4) draw_anchor_line(__overlay_hover[1], xc, y1, 16, 0);
if(drag_type == 0 || drag_type == 3) draw_anchor_line(__overlay_hover[2], x0, yc, 16, 90);
if(drag_type == 0 || drag_type == 1) draw_anchor_line(__overlay_hover[3], x1, yc, 16, 90);
}
//draw_set_text(_f_p2b, fa_center, fa_center, COLORS._main_accent);
//draw_text_add((x0 + x1) / 2, (y0 + y1) / 2, name);
2023-01-17 08:11:55 +01:00
return hover;
2023-11-23 13:39:35 +01:00
} #endregion
2023-01-17 08:11:55 +01:00
2023-11-23 13:39:35 +01:00
function preview_overlay_area_two_point(interact, active, _x, _y, _s, _mx, _my, _snx, _sny, _flag) { #region
2023-09-15 20:12:02 +02:00
var _val = array_clone(getValue());
2023-01-17 08:11:55 +01:00
var hover = -1;
2023-11-23 13:39:35 +01:00
var __ax = array_safe_get(_val, 0);
var __ay = array_safe_get(_val, 1);
var __aw = array_safe_get(_val, 2);
var __ah = array_safe_get(_val, 3);
2023-01-17 08:11:55 +01:00
var __at = array_safe_get(_val, 4);
2023-11-23 13:39:35 +01:00
var _x0 = __ax - __aw;
var _y0 = __ay - __ah;
var _x1 = __ax + __aw;
var _y1 = __ay + __ah;
2023-01-17 08:11:55 +01:00
var x0 = _x0 * _s + _x;
var y0 = _y0 * _s + _y;
var x1 = _x1 * _s + _x;
var y1 = _y1 * _s + _y;
2023-02-28 09:43:01 +01:00
var xc = (x0 + x1) / 2;
var yc = (y0 + y1) / 2;
2023-01-17 08:11:55 +01:00
var drawPos = _flag & 0b0001;
var drawSize = _flag & 0b0010;
if(drawSize) {
draw_set_color(COLORS._main_accent);
draw_set_circle_precision(32);
switch(__at) {
case AREA_SHAPE.rectangle : draw_rectangle(x0, y0, x1, y1, true); break;
case AREA_SHAPE.elipse : draw_ellipse(x0, y0, x1, y1, true); break;
}
2023-01-17 08:11:55 +01:00
}
2023-04-05 20:13:27 +02:00
if(!interact) return -1;
2024-03-28 08:33:28 +01:00
var _hov = [ 0, 0, 0 ];
var _r = 10;
2023-01-17 08:11:55 +01:00
if(drag_type == 1) {
var _xx = value_snap(drag_sx + (_mx - drag_mx) / _s, _snx);
var _yy = value_snap(drag_sy + (_my - drag_my) / _s, _sny);
2024-03-28 08:33:28 +01:00
var _sval = array_clone(showValue());
_sval[0] = _xx;
_sval[1] = _yy;
if(setValueInspector(_sval))
2023-01-17 08:11:55 +01:00
UNDO_HOLDING = true;
if(mouse_release(mb_left)) {
drag_type = 0;
UNDO_HOLDING = false;
}
2023-02-28 09:43:01 +01:00
} else if(drag_type == 2) {
2023-01-17 08:11:55 +01:00
var _xx = value_snap(drag_sx + (_mx - drag_mx) / _s, _snx);
var _yy = value_snap(drag_sy + (_my - drag_my) / _s, _sny);
2024-03-28 08:33:28 +01:00
var _sval = array_clone(showValue());
_sval[2] = _xx;
_sval[3] = _yy;
if(setValueInspector(_sval))
2023-02-28 09:43:01 +01:00
UNDO_HOLDING = true;
if(mouse_release(mb_left)) {
drag_type = 0;
UNDO_HOLDING = false;
}
} else if(drag_type == 3) {
var __x0 = value_snap(drag_sx + (_mx - drag_mx) / _s, _snx);
var __y0 = value_snap(drag_sy + (_my - drag_my) / _s, _sny);
var __x1 = value_snap(_x1 + (__x0 - _x0), _snx);
var __y1 = value_snap(_y1 + (__y0 - _y0), _sny);
2024-03-28 08:33:28 +01:00
_val[0] = __x0;
_val[1] = __y0;
_val[2] = __x1;
_val[3] = __y1;
2023-02-28 09:43:01 +01:00
2024-02-01 10:02:18 +01:00
if(setValueInspector(_val))
2023-01-17 08:11:55 +01:00
UNDO_HOLDING = true;
if(mouse_release(mb_left)) {
drag_type = 0;
UNDO_HOLDING = false;
}
}
2024-03-28 08:33:28 +01:00
if(drawSize && point_in_circle(_mx, _my, x0, y0, 8)) {
_hov[1] = 1;
hover = 1;
2023-01-17 08:11:55 +01:00
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-01-17 08:11:55 +01:00
drag_type = 1;
drag_sx = _x0;
drag_sy = _y0;
drag_mx = _mx;
drag_my = _my;
}
2024-03-28 08:33:28 +01:00
} else if(drawSize && point_in_circle(_mx, _my, x1, y1, 8)) {
_hov[2] = 1;
hover = 2;
2023-01-17 08:11:55 +01:00
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-01-17 08:11:55 +01:00
drag_type = 2;
drag_sx = _x1;
drag_sy = _y1;
drag_mx = _mx;
drag_my = _my;
}
2024-03-28 08:33:28 +01:00
} else if(drawPos && point_in_rectangle(_mx, _my, x0, y0, x1, y1)) {
_hov[0] = 1;
hover = 3;
2023-02-28 09:43:01 +01:00
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-02-28 09:43:01 +01:00
drag_type = 3;
drag_sx = _x0;
drag_sy = _y0;
drag_mx = _mx;
drag_my = _my;
}
2023-01-17 08:11:55 +01:00
}
2024-03-28 08:33:28 +01:00
for( var i = 0; i < 3; i++ )
__overlay_hover[i] = lerp_float(__overlay_hover[i], _hov[i], 4);
if(drawPos && (drag_type == 0 || drag_type == 3)) draw_anchor_cross(__overlay_hover[0], xc, yc, _r + 4);
if(drawSize) {
if(drag_type == 0 || drag_type == 1) draw_anchor(__overlay_hover[1], x0, y0, _r);
if(drag_type == 0 || drag_type == 2) draw_anchor(__overlay_hover[2], x1, y1, _r);
}
//draw_set_text(_f_p2b, fa_center, fa_center, COLORS._main_accent);
//draw_text_add((x0 + x1) / 2, (y0 + y1) / 2 - 4, name);
2023-01-17 08:11:55 +01:00
return hover;
2023-11-23 13:39:35 +01:00
} #endregion
2023-01-17 08:11:55 +01:00
2023-11-23 13:39:35 +01:00
function preview_overlay_area_span(interact, active, _x, _y, _s, _mx, _my, _snx, _sny, _flag) { #region
2023-09-15 20:12:02 +02:00
var _val = array_clone(getValue());
2023-01-17 08:11:55 +01:00
var hover = -1;
var __ax = array_safe_get(_val, 0);
var __ay = array_safe_get(_val, 1);
var __aw = array_safe_get(_val, 2);
var __ah = array_safe_get(_val, 3);
var __at = array_safe_get(_val, 4);
2023-11-23 13:39:35 +01:00
2023-01-17 08:11:55 +01:00
var _ax = __ax * _s + _x;
var _ay = __ay * _s + _y;
var _aw = __aw * _s;
var _ah = __ah * _s;
var drawPos = _flag & 0b0001;
var drawSize = _flag & 0b0010;
if(drawSize) {
draw_set_color(COLORS._main_accent);
draw_set_circle_precision(32);
switch(__at) {
case AREA_SHAPE.rectangle : draw_rectangle(_ax - _aw, _ay - _ah, _ax + _aw, _ay + _ah, true); break;
case AREA_SHAPE.elipse : draw_ellipse(_ax - _aw, _ay - _ah, _ax + _aw, _ay + _ah, true); break;
}
2023-01-17 08:11:55 +01:00
}
2023-04-05 20:13:27 +02:00
if(!interact) return -1;
2024-03-28 08:33:28 +01:00
var _hov = [ 0, 0 ];
var _r = 10;
if(point_in_circle(_mx, _my, _ax + _aw, _ay + _ah, _r))
_hov[1] = 1;
2023-01-17 08:11:55 +01:00
else if(point_in_rectangle(_mx, _my, _ax - _aw, _ay - _ah, _ax + _aw, _ay + _ah))
2024-03-28 08:33:28 +01:00
_hov[0] = 1;
__overlay_hover[0] = lerp_float(__overlay_hover[0], _hov[0], 4);
__overlay_hover[1] = lerp_float(__overlay_hover[1], _hov[1], 4);
if((drag_type == 0 || drag_type == 1) && drawPos) draw_anchor_cross(__overlay_hover[0], _ax, _ay, _r + 4);
if((drag_type == 0 || drag_type == 2) && drawSize) draw_anchor(__overlay_hover[1], _ax + _aw, _ay + _ah, _r);
2023-01-17 08:11:55 +01:00
if(drag_type == 1) {
var _xx = value_snap(drag_sx + (_mx - drag_mx) / _s, _snx);
var _yy = value_snap(drag_sy + (_my - drag_my) / _s, _sny);
if(key_mod_press(CTRL)) {
_val[0] = round(_xx);
_val[1] = round(_yy);
} else {
_val[0] = _xx;
_val[1] = _yy;
}
2024-02-01 10:02:18 +01:00
if(setValueInspector(_val))
2023-01-17 08:11:55 +01:00
UNDO_HOLDING = true;
if(mouse_release(mb_left)) {
drag_type = 0;
UNDO_HOLDING = false;
}
} else if(drag_type == 2) {
var _dx = value_snap((_mx - drag_mx) / _s, _snx);
var _dy = value_snap((_my - drag_my) / _s, _sny);
if(key_mod_press(CTRL)) {
_val[2] = round(_dx);
_val[3] = round(_dy);
} else {
_val[2] = _dx;
_val[3] = _dy;
}
if(keyboard_check(vk_shift)) {
_val[2] = max(_dx, _dy);
_val[3] = max(_dx, _dy);
}
2024-02-01 10:02:18 +01:00
if(setValueInspector(_val))
2023-01-17 08:11:55 +01:00
UNDO_HOLDING = true;
if(mouse_release(mb_left)) {
drag_type = 0;
UNDO_HOLDING = false;
}
}
2024-03-28 08:33:28 +01:00
if(drawSize && point_in_circle(_mx, _my, _ax + _aw, _ay + _ah, 8)) {
2023-01-17 08:11:55 +01:00
hover = 2;
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-01-17 08:11:55 +01:00
drag_type = 2;
drag_mx = _ax;
drag_my = _ay;
}
2024-03-28 08:33:28 +01:00
} else if(drawPos && point_in_rectangle(_mx, _my, _ax - _aw, _ay - _ah, _ax + _aw, _ay + _ah)) {
2023-01-17 08:11:55 +01:00
hover = 1;
2024-03-28 08:33:28 +01:00
if(mouse_press(mb_left, active)) {
2023-01-17 08:11:55 +01:00
drag_type = 1;
drag_sx = __ax;
drag_sy = __ay;
drag_mx = _mx;
drag_my = _my;
}
}
2024-03-28 08:33:28 +01:00
//draw_set_text(_f_p2b, fa_center, fa_bottom, COLORS._main_accent);
//draw_text_add(round(_ax), round(_ay - 4), name);
2023-01-17 08:11:55 +01:00
return hover;
2023-11-23 13:39:35 +01:00
} #endregion
2023-01-17 08:11:55 +01:00
function preview_overlay_area(interact, active, _x, _y, _s, _mx, _my, _snx, _sny, _flag, display_data) {
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 mode = editWidget.mode;
2024-03-28 08:33:28 +01:00
if(!struct_has(self, "__overlay_hover")) __overlay_hover = [ 0, 0, 0, 0, 0 ];
switch(mode) {
case AREA_MODE.area : return preview_overlay_area_span(interact, active, _x, _y, _s, _mx, _my, _snx, _sny, _flag);
case AREA_MODE.padding : return preview_overlay_area_padding(interact, active, _x, _y, _s, _mx, _my, _snx, _sny, _flag, display_data);
case AREA_MODE.two_point : return preview_overlay_area_two_point(interact, active, _x, _y, _s, _mx, _my, _snx, _sny, _flag);
}
2023-01-17 08:11:55 +01:00
return hover;
}