mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 22:16:17 +01:00
Fix some node draw string extremely small.
This commit is contained in:
parent
99315c5872
commit
a7d56baffa
10 changed files with 48 additions and 50 deletions
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue