diff --git a/scripts/draw_text_function/draw_text_function.gml b/scripts/draw_text_function/draw_text_function.gml index 381bae89d..2cbc46f31 100644 --- a/scripts/draw_text_function/draw_text_function.gml +++ b/scripts/draw_text_function/draw_text_function.gml @@ -21,3 +21,10 @@ function draw_text_ext_add(_x, _y, _text, _sep, _w) { draw_text_ext(_x, _y, _text, _sep, _w); BLEND_NORMAL; } + +function draw_text_bbox(bbox, text) { + var ss = min(bbox.w / string_width(text), bbox.h / string_height(text)); + ss = max(0.5, ss); + + draw_text_cut(bbox.xc, bbox.yc, text, bbox.w, ss); +} \ No newline at end of file diff --git a/scripts/node_data/node_data.gml b/scripts/node_data/node_data.gml index 2b1fa6d73..f17b8ebc9 100644 --- a/scripts/node_data/node_data.gml +++ b/scripts/node_data/node_data.gml @@ -401,14 +401,14 @@ function Node(_x, _y, _group = PANEL_GRAPH.getCurrentContext()) : __Node_Base(_x var y0 = yy + 20 * draw_name + draw_padding * _s; var y1 = yy + (h - draw_padding) * _s; - return { x0: x0, + return { x0 : x0, x1 : x1, - y0: y0, + y0 : y0, y1 : y1, - xc: (x0 + x1) / 2, - yc: (y0 + y1) / 2, - w: x1 - x0, - h: y1 - y0 + xc : (x0 + x1) / 2, + yc : (y0 + y1) / 2, + w : x1 - x0, + h : y1 - y0 }; } diff --git a/scripts/node_string/node_string.gml b/scripts/node_string/node_string.gml index 7f691adfb..8557ab6d7 100644 --- a/scripts/node_string/node_string.gml +++ b/scripts/node_string/node_string.gml @@ -12,10 +12,10 @@ function Node_String(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co } static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { - draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); - var str = inputs[| 0].getValue(); + var str = inputs[| 0].getValue(); var bbox = drawGetBbox(xx, yy, _s); - var ss = string_scale(str, bbox.w, bbox.h); - draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); + + draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); + draw_text_bbox(bbox, str); } } \ No newline at end of file diff --git a/scripts/node_string_get_char/node_string_get_char.gml b/scripts/node_string_get_char/node_string_get_char.gml index 318e407e5..423d7e15f 100644 --- a/scripts/node_string_get_char/node_string_get_char.gml +++ b/scripts/node_string_get_char/node_string_get_char.gml @@ -17,10 +17,10 @@ function Node_String_Get_Char(_x, _y, _group = noone) : Node_Processor(_x, _y, _ } static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { - draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); var str = inputs[| 0].getValue(); var bbox = drawGetBbox(xx, yy, _s); - var ss = string_scale(str, bbox.w, bbox.h); - draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); + + draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); + draw_text_bbox(bbox, str); } } \ No newline at end of file diff --git a/scripts/node_string_join/node_string_join.gml b/scripts/node_string_join/node_string_join.gml index ac9c2bbd3..4977da700 100644 --- a/scripts/node_string_join/node_string_join.gml +++ b/scripts/node_string_join/node_string_join.gml @@ -25,10 +25,10 @@ function Node_String_Join(_x, _y, _group = noone) : Node(_x, _y, _group) constru } static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { - draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); var str = outputs[| 0].getValue(); var bbox = drawGetBbox(xx, yy, _s); - var ss = string_scale(str, bbox.w, bbox.h); - draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); + + draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); + draw_text_bbox(bbox, str); } } \ No newline at end of file diff --git a/scripts/node_string_length/node_string_length.gml b/scripts/node_string_length/node_string_length.gml index bc6062933..6f96231b7 100644 --- a/scripts/node_string_length/node_string_length.gml +++ b/scripts/node_string_length/node_string_length.gml @@ -20,10 +20,10 @@ function Node_String_Length(_x, _y, _group = noone) : Node_Processor(_x, _y, _gr } static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { - draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); var str = outputs[| 0].getValue(); var bbox = drawGetBbox(xx, yy, _s); - var ss = string_scale(str, bbox.w, bbox.h); - draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); + + draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); + draw_text_bbox(bbox, str); } } \ No newline at end of file diff --git a/scripts/node_string_merge/node_string_merge.gml b/scripts/node_string_merge/node_string_merge.gml index 754e5a732..04bf915ea 100644 --- a/scripts/node_string_merge/node_string_merge.gml +++ b/scripts/node_string_merge/node_string_merge.gml @@ -15,10 +15,10 @@ function Node_String_Merge(_x, _y, _group = noone) : Node_Processor(_x, _y, _gro } static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { - draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); var str = inputs[| 0].getValue(); var bbox = drawGetBbox(xx, yy, _s); - var ss = string_scale(str, bbox.w, bbox.h); - draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); + + draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); + draw_text_bbox(bbox, str); } } \ No newline at end of file diff --git a/scripts/node_string_regex_search/node_string_regex_search.gml b/scripts/node_string_regex_search/node_string_regex_search.gml index b465b85cc..f11b4632a 100644 --- a/scripts/node_string_regex_search/node_string_regex_search.gml +++ b/scripts/node_string_regex_search/node_string_regex_search.gml @@ -27,13 +27,9 @@ function Node_String_Regex_Search(_x, _y, _group = noone) : Node_Processor(_x, _ static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { var str = outputs[| 0].getValue(); - - if(is_array(str) && array_length(str)) - str = str[0]; + var bbox = drawGetBbox(xx, yy, _s); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); - var bbox = drawGetBbox(xx, yy, _s); - var ss = string_scale(str, bbox.w, bbox.h); - draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); + draw_text_bbox(bbox, str); } } \ No newline at end of file diff --git a/scripts/node_string_trim/node_string_trim.gml b/scripts/node_string_trim/node_string_trim.gml index 0b72ca969..9b31b9819 100644 --- a/scripts/node_string_trim/node_string_trim.gml +++ b/scripts/node_string_trim/node_string_trim.gml @@ -69,15 +69,9 @@ function Node_String_Trim(_x, _y, _group = noone) : Node_Processor(_x, _y, _grou static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { var str = outputs[| 0].getValue(); - var hed = inputs[| 1].getValue(); - var tal = inputs[| 2].getValue(); - - if(is_array(str) && array_length(str)) - str = str[0]; + var bbox = drawGetBbox(xx, yy, _s); draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text); - var bbox = drawGetBbox(xx, yy, _s); - var ss = string_scale(str, bbox.w, bbox.h); - draw_text_transformed(bbox.xc, bbox.yc, str, ss, ss, 0); + draw_text_bbox(bbox, str); } } \ No newline at end of file diff --git a/scripts/string_cut/string_cut.gml b/scripts/string_cut/string_cut.gml index f56a15c9a..2e3dd2cd7 100644 --- a/scripts/string_cut/string_cut.gml +++ b/scripts/string_cut/string_cut.gml @@ -3,25 +3,26 @@ function draw_text_cut(x, y, str, w, scale = 1) { } function string_cut(str, w, tail = "...", scale = 1) { - var ww = 0; - var ind = 1; - var ss = ""; - var tw = string_width(tail); + var ww = 0; + var ind = 1; + var ss = ""; + var _str = str; + var tw = string_width(tail) * scale; if(string_width(str) <= w) return str; - while(ind <= string_length(str)) { - var ch = string_char_at(str, ind); - var _w = string_width(ch) * scale; - - if(ww + _w + tw >= w) { - ss += tail; - break; - } else - ss += ch; + var amo = string_length(str); + for( var i = 1; i <= amo; i++ ) { + var ch = string_char_at(str, 1); + str = string_copy(str, 2, string_length(str) - 1); + var _w = string_width(ch) * scale; ww += _w; - ind++; + var _tl = string_width(str) * scale; + + if(ww + tw > w) + return ww + _tl <= w? _str : ss + tail; + ss += ch; } return ss;