- [Gradient] Fix freeze when resize the panel is too small.

This commit is contained in:
Tanasart 2024-07-29 16:15:56 +07:00
parent 24e33606f5
commit a344f1643f
3 changed files with 134 additions and 142 deletions

View file

@ -141,7 +141,7 @@ function gradientObject(color = c_black) constructor {
surface_set_target(surf);
DRAW_CLEAR
var _gh = aa? _h - ui(8) : _h;
draw_sprite_stretched_ext(THEME.gradient_mask, 0, 0, 0, _w, _gh, c_white, _a)
draw_sprite_stretched_ext(THEME.ui_panel_bg, 4, 0, 0, _w, _gh, c_white, _a)
if(len) {
BLEND_MULTIPLY
@ -159,7 +159,7 @@ function gradientObject(color = c_black) constructor {
}
if(aa) {
draw_sprite_stretched_ext(THEME.gradient_mask, 0, 0, _h - ui(6), _w, ui(6), c_white, _a)
draw_sprite_stretched_ext(THEME.ui_panel_bg, 4, 0, _h - ui(6), _w, ui(6), c_white, _a)
BLEND_MULTIPLY

View file

@ -1,31 +1,24 @@
function Panel_Gradient() : PanelContent() constructor {
title = __txt("Gradients");
showHeader = false;
title_height = 64;
padding = 20;
padding = 8;
w = ui(320);
h = ui(480);
function onResize() {
PANEL_PADDING
sp_gradient.resize(w - ui(padding + padding), h - ui(title_height + padding));
}
function onResize() { sp_gradient.resize(w - ui(padding + padding), h - ui(padding + padding)); }
sp_gradient = new scrollPane(w - ui(padding + padding), h - ui(title_height + padding), function(_y, _m) {
sp_gradient = new scrollPane(w - ui(padding + padding), h - ui(padding + padding), function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var ww = sp_gradient.surface_w;
var hh = 0;
var amo = array_length(GRADIENTS);
var col = floor(ww / ui(160));
var col = max(1, floor(ww / ui(160)));
var row = ceil(amo / col);
var pd = ui(6);
var gw = (ww + ui(8)) / col;
var gh = ui(16);
var hg = ui(24 + 8) + gh;
var hg = ui(26);
var yy = _y;
for(var i = 0; i < row; i++) {
@ -33,30 +26,36 @@ function Panel_Gradient() : PanelContent() constructor {
var ind = i * col + j;
if(ind >= amo) break;
var xx = j * gw;
var gww = gw - ui(8);
var xx = j * gw;
var preset = GRADIENTS[ind];
var isHover = pHOVER && point_in_rectangle(_m[0], _m[1], xx, max(0, yy), xx + gw - ui(8), min(sp_gradient.h, yy + hg));
draw_sprite_stretched(THEME.ui_panel_bg, 3, xx, yy, gw - ui(8), hg);
var isHover = pHOVER && point_in_rectangle(_m[0], _m[1], xx, max(0, yy), xx + gww, min(sp_gradient.h, yy + hg));
draw_sprite_stretched(THEME.ui_panel_bg, 3, xx, yy, gww, hg);
preset.gradient.draw(xx, yy, gww, hg);
draw_set_text(f_p2, fa_left, fa_center, c_white);
if(_color_get_light(preset.gradient.keys[0].value) > 0.5) {
draw_set_color(c_black);
draw_text(xx + pd, yy + hg / 2, preset.name);
} else
draw_text_add(xx + pd, yy + hg / 2, preset.name);
draw_sprite_stretched_add(THEME.ui_panel_fg, 1, xx, yy, gww, hg, c_white, 0.3);
if(isHover) {
sp_gradient.hover_content = true;
draw_sprite_stretched_ext(THEME.node_active, 1, xx, yy, gw - ui(8), hg, COLORS._main_accent, 1);
draw_sprite_stretched_ext(THEME.ui_panel_fg, 1, xx, yy, gww, hg, COLORS._main_accent, 1);
}
draw_set_text(f_p2, fa_left, fa_top, COLORS._main_text_sub);
draw_text(xx + ui(10), yy + ui(2), preset.name);
preset.gradient.draw(xx + ui(10), yy + ui(24), gw - ui(28), gh);
if(isHover && mouse_press(mb_left, pFOCUS)) {
DRAGGING = {
type: "Gradient",
data: preset.gradient
}
MESSAGE = DRAGGING;
DRAGGING = { type: "Gradient", data: preset.gradient }
MESSAGE = DRAGGING;
}
}
yy += hg + ui(8);
hh += hg + ui(8);
yy += hg + ui(6);
hh += hg + ui(6);
}
return hh;
@ -64,23 +63,21 @@ function Panel_Gradient() : PanelContent() constructor {
function drawContent(panel) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
PANEL_PADDING
PANEL_TITLE
var px = ui(padding);
var py = ui(title_height);
var py = ui(padding);
var pw = w - ui(padding + padding);
var ph = h - ui(title_height + padding);
var ph = h - ui(padding + padding);
draw_sprite_stretched(THEME.ui_panel_bg, 1, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
sp_gradient.setFocusHover(pFOCUS, pHOVER);
sp_gradient.draw(px, py, mx - px, my - py);
var bx = w - ui(32 + 16);
var by = title_height / 2 - ui(16 + !in_dialog * 2);
// var bx = w - ui(32 + 16);
// var by = padding / 2 - ui(16 + !in_dialog * 2);
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txt("Refresh"), THEME.refresh_icon, 1, COLORS._main_icon) == 2)
__initGradient();
// if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, __txt("Refresh"), THEME.refresh_icon, 1, COLORS._main_icon) == 2)
// __initGradient();
}
}

View file

@ -1,8 +1,6 @@
function Panel_Tunnels() : PanelContent() constructor {
title = __txt("Tunnels");
showHeader = false;
title_height = 64;
padding = 20;
title = __txt("Tunnels");
padding = 8;
#region data
w = ui(320);
@ -37,6 +35,7 @@ function Panel_Tunnels() : PanelContent() constructor {
search_string = string(str);
searchNodes();
});
tb_search.align = fa_left;
tb_search.auto_update = true;
tb_search.boxColor = COLORS._main_icon_light;
@ -54,125 +53,121 @@ function Panel_Tunnels() : PanelContent() constructor {
}
#endregion
function onResize() {
PANEL_PADDING
sc_tunnel.resize(w - ui(padding + padding), h - ui(title_height + padding + 40));
}
function onResize() { sc_tunnel.resize(w - ui(padding + padding), h - ui(padding + padding) - ui(28)); }
sc_tunnel = new scrollPane(w - ui(padding + padding), h - ui(padding + padding) - ui(28), function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var _h = 0;
var ww = sc_tunnel.surface_w;
var hg = ui(36);
var i = 0;
#region content
sc_tunnel = new scrollPane(w - ui(padding + padding), h - ui(title_height + padding + 40), function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var _h = 0;
var ww = sc_tunnel.surface_w;
var hg = ui(36);
var i = 0;
var arr = search_string == ""? tunnel_ins : search_res;
tunnel_hover = noone;
for( var i = 0, n = array_length(arr); i < n; i++ ) {
var node = arr[i];
var arr = search_string == ""? tunnel_ins : search_res;
tunnel_hover = noone;
for( var i = 0, n = array_length(arr); i < n; i++ ) {
var node = arr[i];
if(point_in_rectangle(_m[0], _m[1], 0, _y, ww, _y + hg)) {
sc_tunnel.hover_content = true;
var cc = merge_color(COLORS._main_icon_light, COLORS._main_icon, 0.25);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _y, ww, hg, cc, 1);
tunnel_hover = node;
if(mouse_press(mb_left, sc_tunnel.active) && _m[0] < ww - ui(32 + 32 * 2))
tunnel_select = tunnel_select == node? noone : node;
} else
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _y, ww, hg, COLORS._main_icon_light, 1);
if(point_in_rectangle(_m[0], _m[1], 0, _y, ww, _y + hg)) {
sc_tunnel.hover_content = true;
var cc = merge_color(COLORS._main_icon_light, COLORS._main_icon, 0.25);
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _y, ww, hg, cc, 1);
tunnel_hover = node;
var key = node.inputs[| 0].getValue(0);
var bw = ui(28);
var bh = ui(28);
var bx = ww - ui(4) - bw;
var by = _y + (hg - bh) / 2;
if(mouse_press(mb_left, sc_tunnel.active) && _m[0] < ww - ui(32 + 32 * 2))
tunnel_select = tunnel_select == node? noone : node;
} else
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _y, ww, hg, COLORS._main_icon_light, 1);
draw_sprite_stretched_add(THEME.ui_panel_fg, 0, 0, _y, ww, hg, c_white, .3);
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, sc_tunnel.active, sc_tunnel.hover, __txtx("panel_node_goto", "Go to node"), THEME.node_goto) == 2)
graphFocusNode(node);
bx -= ui(32);
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, sc_tunnel.active, sc_tunnel.hover, __txtx("panel_tunnel_create_tunnel", "Create tunnel out"), THEME.tunnel) == 2) {
var _node = nodeBuild("Node_Tunnel_Out", build_x, build_y);
_node.inputs[| 0].setValue(key);
if(in_dialog) instance_destroy();
}
bx -= ui(32);
draw_sprite_ui(THEME.tunnel, 1, ui(4 + 16), _y + hg / 2);
draw_set_text(f_p0, fa_left, fa_center, key == ""? COLORS._main_text_sub : COLORS._main_text);
draw_text(ui(4 + 32 + 4), _y + hg / 2, key == ""? $"[{__txtx("panel_tunnel_no_key", "No key")}]" : key);
_y += hg + ui(4);
_h += hg + ui(4);
if(tunnel_select == node) {
var amo = ds_map_size(TUNNELS_OUT);
var k = ds_map_find_first(TUNNELS_OUT);
var key = node.inputs[| 0].getValue(0);
var bw = ui(28);
var bh = ui(28);
var bx = ww - ui(4) - bw;
var by = _y + (hg - bh) / 2;
repeat(amo) {
var _k = k;
k = ds_map_find_next(TUNNELS_OUT, k);
var out = TUNNELS_OUT[? _k];
if(out != key || !ds_map_exists(PROJECT.nodeMap, _k))
continue;
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, sc_tunnel.active, sc_tunnel.hover, __txtx("panel_node_goto", "Go to node"), THEME.node_goto) == 2)
graphFocusNode(node);
bx -= ui(32);
if(buttonInstant(THEME.button_hide, bx, by, bw, bh, _m, sc_tunnel.active, sc_tunnel.hover, __txtx("panel_tunnel_create_tunnel", "Create tunnel out"), THEME.tunnel) == 2) {
var _node = nodeBuild("Node_Tunnel_Out", build_x, build_y);
_node.inputs[| 0].setValue(key);
var _node = PROJECT.nodeMap[? _k];
draw_sprite_ui(THEME.tunnel, 0, ui(32), _y + ui(10), 0.75, 0.75, 0, COLORS._main_icon);
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text_sub);
draw_text(ui(32 + 16), _y + ui(10), _node.renamed? _node.display_name : _node.name);
if(point_in_rectangle(_m[0], _m[1], 0, _y, ww, _y + ui(20)))
tunnel_hover = _node;
_y += ui(20);
_h += ui(20);
}
_y += ui(8);
_h += ui(8);
}
if(in_dialog) instance_destroy();
}
bx -= ui(32);
return _h;
})
#endregion
draw_sprite_ui(THEME.tunnel, 1, ui(4 + 16), _y + hg / 2);
draw_set_text(f_p0, fa_left, fa_center, key == ""? COLORS._main_text_sub : COLORS._main_text);
draw_text(ui(4 + 32 + 4), _y + hg / 2, key == ""? $"[{__txtx("panel_tunnel_no_key", "No key")}]" : key);
_y += hg + ui(4);
_h += hg + ui(4);
if(tunnel_select == node) {
var amo = ds_map_size(TUNNELS_OUT);
var k = ds_map_find_first(TUNNELS_OUT);
repeat(amo) {
var _k = k;
k = ds_map_find_next(TUNNELS_OUT, k);
var out = TUNNELS_OUT[? _k];
if(out != key || !ds_map_exists(PROJECT.nodeMap, _k))
continue;
var _node = PROJECT.nodeMap[? _k];
draw_sprite_ui(THEME.tunnel, 0, ui(32), _y + ui(10), 0.75, 0.75, 0, COLORS._main_icon);
draw_set_text(f_p1, fa_left, fa_center, COLORS._main_text_sub);
draw_text(ui(32 + 16), _y + ui(10), _node.renamed? _node.display_name : _node.name);
if(point_in_rectangle(_m[0], _m[1], 0, _y, ww, _y + ui(20)))
tunnel_hover = _node;
_y += ui(20);
_h += ui(20);
}
_y += ui(8);
_h += ui(8);
}
}
return _h;
});
function drawContent(panel) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
PANEL_PADDING
PANEL_TITLE
scanNodes();
var px = ui(padding);
var py = ui(title_height);
var py = ui(padding);
var pw = w - ui(padding + padding);
var ph = h - ui(title_height + padding);
var ph = h - ui(padding + padding) - ui(28);
draw_sprite_stretched(THEME.ui_panel_bg, 1, px - ui(8), py - ui(8), pw + ui(16), ph + ui(16));
if(pFOCUS) WIDGET_CURRENT = tb_search;
tb_search.draw(px, py, pw, ui(32), search_string, [mx, my]);
if(search_string == "")
tb_search.sprite_index = 1;
if(search_string == "") tb_search.sprite_index = 1;
sc_tunnel.setFocusHover(pFOCUS, pHOVER);
sc_tunnel.draw(px, py + ui(40), mx - px, my - (py + ui(40)));
var bx = w - ui(32 + 16);
var by = title_height / 2 - ui(16 + !in_dialog * 2);
var txt = __txtx("panel_tunnel_create_tunnel", "Create tunnel");
if(buttonInstant(THEME.button_hide, bx, by, ui(32), ui(32), [mx, my], pFOCUS, pHOVER, txt, THEME.tunnel, 1, c_white) == 2) {
var _add_h = ui(24);
var _bx = 0;
var _by = h - _add_h;
var _ww = w;
var _hov = pHOVER && point_in_rectangle(mx, my, _bx, _by, _bx + _ww, _by + _add_h);
draw_sprite_stretched_ext(THEME.timeline_node, 0, _bx, _by, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .3 + _hov * .1);
draw_sprite_stretched_ext(THEME.timeline_node, 1, _bx, _by, _ww, _add_h, _hov? COLORS._main_value_positive : COLORS._main_icon, .6 + _hov * .25);
draw_set_text(f_p2, fa_center, fa_center, _hov? COLORS._main_value_positive : COLORS._main_icon);
draw_text_add(_ww / 2, _by + _add_h / 2, __txtx("panel_tunnel_create_tunnel", "Create tunnel"));
if(mouse_press(mb_left, pFOCUS && _hov))
nodeBuild("Node_Tunnel_In", build_x, build_y);
instance_destroy();
}
}
}