2023-10-04 05:52:20 +02:00
|
|
|
global.__FRAME_LABEL_SCALE = 1;
|
|
|
|
|
2023-02-28 09:43:01 +01:00
|
|
|
function Node_Frame(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
2024-01-08 08:10:50 +01:00
|
|
|
name = "Frame";
|
|
|
|
w = 240;
|
|
|
|
h = 160;
|
2023-11-03 14:43:28 +01:00
|
|
|
bg_spr = THEME.node_frame_bg;
|
2024-07-15 10:43:30 +02:00
|
|
|
|
2023-11-03 14:43:28 +01:00
|
|
|
size_dragging = false;
|
|
|
|
size_dragging_w = w;
|
|
|
|
size_dragging_h = h;
|
2022-01-13 05:24:03 +01:00
|
|
|
size_dragging_mx = w;
|
|
|
|
size_dragging_my = h;
|
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
auto_height = false;
|
|
|
|
name_hover = false;
|
|
|
|
hover_progress = 0;
|
2023-10-04 05:52:20 +02:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
color = c_white;
|
|
|
|
alpha = 1;
|
|
|
|
scale = 1;
|
|
|
|
lcolor = false;
|
|
|
|
|
2024-07-15 05:54:28 +02:00
|
|
|
tb_name = new textBox(TEXTBOX_INPUT.text, function(txt) /*=>*/ { setDisplayName(txt); });
|
|
|
|
tb_name.font = f_p2;
|
|
|
|
tb_name.hide = true;
|
|
|
|
tb_name.align = fa_center;
|
|
|
|
|
2024-07-25 11:43:51 +02:00
|
|
|
name_height = 18;
|
2024-07-12 10:35:01 +02:00
|
|
|
|
|
|
|
draw_x0 = 0;
|
|
|
|
draw_y0 = 0;
|
|
|
|
draw_x1 = 0;
|
|
|
|
draw_y1 = 0;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-15 05:54:28 +02:00
|
|
|
|
2024-08-12 13:42:05 +02:00
|
|
|
inputs[0] = nodeValue_Vec2("Size", self, [ 240, 160 ] )
|
2023-02-14 05:32:32 +01:00
|
|
|
.rejectArray();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[1] = nodeValue_Color("Color", self, cola(c_white) )
|
2023-02-14 05:32:32 +01:00
|
|
|
.rejectArray();
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[2] = nodeValue_Float("Alpha", self, 0.75 )
|
2023-10-02 08:57:44 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider)
|
2023-03-05 07:16:44 +01:00
|
|
|
.rejectArray();
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[3] = nodeValue_Float("Label size", self, global.__FRAME_LABEL_SCALE )
|
2023-10-04 05:52:20 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider)
|
|
|
|
.rejectArray();
|
|
|
|
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[4] = nodeValue_Float("Blend label", self, 0 )
|
2023-10-04 05:52:20 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider)
|
|
|
|
.rejectArray();
|
|
|
|
|
2024-01-08 08:10:50 +01:00
|
|
|
input_display_list = [ 0, 1, 3, 4 ];
|
|
|
|
|
2024-07-15 05:54:28 +02:00
|
|
|
static onValueUpdate = function(index = 3) { global.__FRAME_LABEL_SCALE = getInputData(3); }
|
2023-10-04 05:52:20 +02:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
static step = function() {
|
2024-07-15 05:54:28 +02:00
|
|
|
previewable = true;
|
|
|
|
|
|
|
|
var sz = getInputData(0);
|
|
|
|
w = sz[0];
|
|
|
|
h = sz[1];
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
color = getInputData(1);
|
|
|
|
alpha = _color_get_alpha(color);
|
|
|
|
|
|
|
|
scale = getInputData(3);
|
|
|
|
lcolor = getInputData(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
static drawNodeBase = function(xx, yy, _s, _panel) {
|
|
|
|
var px0 = 3;
|
|
|
|
var py0 = 3;
|
|
|
|
var px1 = -3 + _panel.w;
|
|
|
|
var py1 = -0 + _panel.h - _panel.toolbar_height;
|
|
|
|
|
|
|
|
var _yy = yy - name_height;
|
|
|
|
|
|
|
|
var x0 = xx;
|
|
|
|
var y0 = _yy;
|
|
|
|
var x1 = xx + w * _s;
|
|
|
|
var y1 = _yy + name_height + h * _s;
|
|
|
|
|
|
|
|
draw_x0 = max(x0, px0);
|
|
|
|
draw_x1 = min(x1, px1);
|
|
|
|
draw_y0 = max(y0, py0);
|
|
|
|
draw_y1 = min(y1, py1);
|
|
|
|
|
|
|
|
var _h = max(draw_y1 - draw_y0, name_height);
|
|
|
|
|
|
|
|
if(y0 > 0) draw_y1 = draw_y0 + _h;
|
|
|
|
else draw_y0 = draw_y1 - _h;
|
|
|
|
|
|
|
|
if(draw_x1 - draw_x0 < 4) return;
|
|
|
|
|
2024-07-15 05:54:28 +02:00
|
|
|
draw_sprite_stretched_ext(bg_spr, 0, x0, y0, x1 - x0, y1 - y0, color, alpha);
|
2024-07-12 10:35:01 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
static drawNodeFG = function(_x, _y, _mx, _my, _s, _dparam, _panel) {
|
|
|
|
|
|
|
|
if(draw_x1 - draw_x0 < 4) return;
|
|
|
|
|
2024-07-15 05:54:28 +02:00
|
|
|
var _w = draw_x1 - draw_x0;
|
|
|
|
var _h = draw_y1 - draw_y0;
|
|
|
|
var txt = renamed? display_name : name;
|
2024-07-12 10:35:01 +02:00
|
|
|
|
2024-07-15 05:54:28 +02:00
|
|
|
draw_sprite_stretched_ext(bg_spr, 1, draw_x0, draw_y0, _w, _h, color, alpha * .50);
|
2024-07-12 10:35:01 +02:00
|
|
|
|
2024-07-15 05:54:28 +02:00
|
|
|
if(WIDGET_CURRENT == tb_name) {
|
|
|
|
var nh = 24;
|
2024-08-06 06:28:00 +02:00
|
|
|
draw_sprite_stretched_ext(bg_spr, 2, draw_x0, draw_y0, _w, nh, color, alpha * .75);
|
2024-07-15 05:54:28 +02:00
|
|
|
|
|
|
|
tb_name.setFocusHover(PANEL_GRAPH.pFOCUS, PANEL_GRAPH.pHOVER);
|
|
|
|
tb_name.draw(draw_x0, draw_y0, _w, nh, txt, [ _mx, _my ]);
|
|
|
|
|
|
|
|
} else {
|
2024-08-06 06:28:00 +02:00
|
|
|
draw_sprite_stretched_ext(bg_spr, 2, draw_x0, draw_y0, _w, name_height, color, alpha * .75);
|
2024-07-15 05:54:28 +02:00
|
|
|
|
|
|
|
draw_set_text(f_p2, fa_center, fa_bottom, COLORS._main_text);
|
2024-07-25 11:43:51 +02:00
|
|
|
draw_text_cut((draw_x0 + draw_x1) / 2, draw_y0 + name_height + 1, txt, _w - 4);
|
2024-07-29 10:08:08 +02:00
|
|
|
// draw_text_ext_add((draw_x0 + draw_x1) / 2, draw_y0 + name_height + 1, txt, -1, _w - 4);
|
|
|
|
// name_height = max(18, string_height_ext(txt, -1, _w - 4));
|
2024-07-15 05:54:28 +02:00
|
|
|
|
|
|
|
if(point_in_rectangle(_mx, _my, draw_x0, draw_y0, draw_x0 + _w, draw_y0 + name_height)) {
|
|
|
|
if(PANEL_GRAPH.pFOCUS && DOUBLE_CLICK)
|
2024-07-29 10:08:08 +02:00
|
|
|
tb_name.activate(txt);
|
2024-07-15 05:54:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_sprite_stretched_add(bg_spr, 1, draw_x0, draw_y0, _w, _h, c_white, .20);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
if(active_draw_index > -1) {
|
2024-08-06 06:28:00 +02:00
|
|
|
draw_sprite_stretched_ext(bg_spr, 1, draw_x0, draw_y0, _w, _h, COLORS._main_accent, 1);
|
2024-07-12 10:35:01 +02:00
|
|
|
active_draw_index = -1;
|
|
|
|
}
|
2023-10-04 05:52:20 +02:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
drawBadge(_x, _y, _s);
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
static drawNodeBG = function(_x, _y, _mx, _my, _s, _dparam, _panel) {
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(size_dragging) {
|
|
|
|
w = size_dragging_w + (mouse_mx - size_dragging_mx) / _s;
|
|
|
|
h = size_dragging_h + (mouse_my - size_dragging_my) / _s;
|
2024-07-12 10:35:01 +02:00
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
if(!key_mod_press(CTRL)) {
|
2024-07-12 10:35:01 +02:00
|
|
|
w = value_snap(w, 16);
|
|
|
|
h = value_snap(h, 16);
|
2023-03-05 07:16:44 +01:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
size_dragging = false;
|
2024-08-08 06:57:51 +02:00
|
|
|
inputs[0].setValue([ w, h ]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var xx = x * _s + _x;
|
|
|
|
var yy = y * _s + _y;
|
2024-07-12 10:35:01 +02:00
|
|
|
drawNodeBase(xx, yy, _s, _panel);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
var x1 = xx + w * _s;
|
|
|
|
var y1 = yy + h * _s;
|
|
|
|
var x0 = x1 - 16;
|
|
|
|
var y0 = y1 - 16;
|
2023-03-05 07:16:44 +01:00
|
|
|
var ics = 0.5;
|
2024-07-29 06:35:10 +02:00
|
|
|
var shf = 8 + 8 * ics;
|
2023-03-05 07:16:44 +01:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
if(w * _s < 32 || h * _s < 32) return point_in_rectangle(_mx, _my, xx, yy, x1, y1);
|
2023-03-05 07:16:44 +01:00
|
|
|
|
|
|
|
if(point_in_rectangle(_mx, _my, xx, yy, x1, y1) || size_dragging)
|
2024-07-29 10:25:29 +02:00
|
|
|
draw_sprite_ext_add(THEME.node_resize, 0, x1 - shf, y1 - shf, ics, ics, 0, c_white, 0.15);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
if(!name_hover && point_in_rectangle(_mx, _my, x0, y0, x1, y1)) {
|
2024-07-29 10:25:29 +02:00
|
|
|
draw_sprite_ext_add(THEME.node_resize, 0, x1 - shf, y1 - shf, ics, ics, 0, c_white, 0.30);
|
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)) {
|
2024-07-12 10:35:01 +02:00
|
|
|
size_dragging = true;
|
|
|
|
size_dragging_w = w;
|
|
|
|
size_dragging_h = h;
|
2022-01-13 05:24:03 +01:00
|
|
|
size_dragging_mx = mouse_mx;
|
|
|
|
size_dragging_my = mouse_my;
|
|
|
|
}
|
|
|
|
}
|
2023-11-16 02:49:52 +01:00
|
|
|
|
|
|
|
return point_in_rectangle(_mx, _my, xx, yy, x1, y1);
|
2024-07-12 10:35:01 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
static pointIn = function(_x, _y, _mx, _my, _s) {
|
2023-03-05 07:16:44 +01:00
|
|
|
var xx = x * _s + _x;
|
|
|
|
var yy = y * _s + _y;
|
2024-07-12 10:35:01 +02:00
|
|
|
var y0 = yy - name_height;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2024-07-12 10:35:01 +02:00
|
|
|
var hover = point_in_rectangle(_mx, _my, xx, y0, xx + w * _s, yy);
|
2022-01-13 05:24:03 +01:00
|
|
|
name_hover = hover;
|
|
|
|
|
|
|
|
return hover;
|
2024-07-12 10:35:01 +02:00
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|