Pixel-Composer/scripts/node_frame/node_frame.gml

102 lines
2.8 KiB
Plaintext
Raw Normal View History

2022-12-13 09:20:36 +01:00
function Node_Frame(_x, _y, _group = -1) : Node(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Empty frame";
w = 240;
h = 160;
2022-11-18 03:20:31 +01:00
bg_spr = THEME.node_frame_bg;
2022-01-13 05:24:03 +01:00
size_dragging = false;
size_dragging_w = w;
size_dragging_h = h;
size_dragging_mx = w;
size_dragging_my = h;
auto_height = false;
name_hover = false;
inputs[| 0] = nodeValue(0, "Size", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 240, 160 ] )
.setDisplay(VALUE_DISPLAY.vector);
2022-01-13 05:24:03 +01:00
inputs[| 1] = nodeValue(1, "Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white );
2022-01-13 05:24:03 +01:00
2022-01-18 05:31:19 +01:00
static step = function() {
2022-01-13 05:24:03 +01:00
var si = inputs[| 0].getValue();
w = si[0];
h = si[1];
color = inputs[| 1].getValue();
}
static drawNodeBase = function(xx, yy, _s) {
draw_sprite_stretched_ext(bg_spr, 0, xx, yy, w * _s, h * _s, color, 0.75);
2023-01-17 08:11:55 +01:00
2022-11-18 03:20:31 +01:00
draw_set_text(f_h5, fa_right, fa_bottom, COLORS._main_text);
2022-01-13 05:24:03 +01:00
draw_set_alpha(name_hover? 0.5 : 0.25);
2023-01-17 08:11:55 +01:00
draw_text_cut(xx + (w - 8) * _s, yy + (h - 8) * _s, name, w * _s);
2022-01-13 05:24:03 +01:00
draw_set_alpha(1);
}
draw_scale = 1;
static drawNode = function(_x, _y, _mx, _my, _s) {
draw_scale = _s;
if(group != PANEL_GRAPH.getCurrentContext()) return;
if(size_dragging) {
w = size_dragging_w + (mouse_mx - size_dragging_mx) / _s;
h = size_dragging_h + (mouse_my - size_dragging_my) / _s;
w = round(w / 32) * 32;
h = round(h / 32) * 32;
2022-12-10 05:06:01 +01:00
if(mouse_release(mb_left)) {
2022-01-13 05:24:03 +01:00
size_dragging = false;
inputs[| 0].setValue([ w, h ]);
}
}
var xx = x * _s + _x;
var yy = y * _s + _y;
drawNodeBase(xx, yy, _s);
if(active_draw_index > -1) {
2022-11-21 06:38:44 +01:00
draw_sprite_stretched_ext(bg_sel_spr, 0, x * _s + _x, y * _s + _y, w * _s, h * _s, COLORS._main_accent, 1);
2022-01-13 05:24:03 +01:00
active_draw_index = -1;
}
2022-12-12 09:08:03 +01:00
var x1 = xx + w * _s;
var y1 = yy + h * _s;
var x0 = xx + w * _s - 16 * _s;
var y0 = yy + h * _s - 16 * _s;
2023-01-17 08:11:55 +01:00
var ics = max(0.25, 0.5 * _s);
draw_sprite_ext(THEME.node_resize, 0, x1 - 4 * _s, y1 - 4 * _s, ics, ics, 0, c_white, 0.5);
2022-12-12 09:08:03 +01:00
if(!name_hover && point_in_rectangle(_mx, _my, x0, y0, x1, y1)) {
2023-01-17 08:11:55 +01:00
draw_sprite_ext(THEME.node_resize, 0, x1 - 4 * _s, y1 - 4 * _s, ics, ics, 0, c_white, 1);
2022-11-01 03:06:03 +01:00
PANEL_GRAPH.drag_locking = true;
2022-01-13 05:24:03 +01:00
2022-12-10 05:06:01 +01:00
if(mouse_press(mb_left)) {
2022-01-13 05:24:03 +01:00
size_dragging = true;
size_dragging_w = w;
size_dragging_h = h;
size_dragging_mx = mouse_mx;
size_dragging_my = mouse_my;
}
}
return noone;
}
2022-11-01 03:06:03 +01:00
static pointIn = function(_x, _y, _mx, _my, _s) {
2022-12-12 09:08:03 +01:00
var xx = x * _s + _x + w * _s;
var yy = y * _s + _y + h * _s;
2022-01-13 05:24:03 +01:00
draw_set_font(f_h5);
2022-11-01 03:06:03 +01:00
var ww = (string_width(name) + 16) / _s;
var hh = (string_height(name) + 16) / _s;
2022-01-13 05:24:03 +01:00
2022-12-12 09:08:03 +01:00
var _x0 = xx - ww;
var _y0 = yy - hh;
2022-01-13 05:24:03 +01:00
2022-12-12 09:08:03 +01:00
var hover = point_in_rectangle(_mx, _my, _x0, _y0, xx, yy) && !point_in_rectangle(_mx, _my, xx - 16 * _s, yy - 16 * _s, xx, yy);
2022-01-13 05:24:03 +01:00
name_hover = hover;
2022-12-12 09:08:03 +01:00
//print(string(_my) + ", " + string(_y0));
2022-01-13 05:24:03 +01:00
return hover;
}
}