Pixel-Composer/scripts/draw_tooltip/draw_tooltip.gml

318 lines
9.1 KiB
Text
Raw Normal View History

2024-09-12 05:27:42 +02:00
#macro __mouse_tx (PREFERENCES.multi_window? mouse_raw_x : mouse_mxs)
#macro __mouse_ty (PREFERENCES.multi_window? mouse_raw_y : mouse_mys)
#macro __win_tw (PREFERENCES.multi_window? display_get_width() : WIN_W)
#macro __win_th (PREFERENCES.multi_window? display_get_height() : WIN_H)
2024-08-27 05:30:03 +02:00
function draw_tooltip_text(txt) {
2024-06-03 09:34:59 +02:00
txt = array_to_string(txt);
if(string_length(txt) > 1024)
txt = string_copy(txt, 1, 1024) + "...";
2024-08-27 05:30:03 +02:00
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text);
2023-01-25 06:49:00 +01:00
2024-06-03 09:34:59 +02:00
var tw = min(max(320, WIN_W * 0.4), string_width(txt));
2023-02-21 04:48:50 +01:00
var th = string_height_ext(txt, -1, tw);
2023-01-25 06:49:00 +01:00
var pd = ui(8);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (tw + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (th + pd * 2));
2023-01-25 06:49:00 +01:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, tw + pd * 2, th + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, tw + pd * 2, th + pd * 2);
draw_text_line(mx + pd, my + pd, txt, -1, tw);
2024-08-27 05:30:03 +02:00
}
2023-01-25 06:49:00 +01:00
2024-08-27 05:30:03 +02:00
function draw_tooltip_color(clr) {
2023-01-25 06:49:00 +01:00
if(is_array(clr)) {
draw_tooltip_palette(clr);
return;
}
var ww = ui(32);
var hh = ui(32);
var pd = ui(4);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (ww + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (hh + pd * 2));
2023-01-25 06:49:00 +01:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, ww + pd * 2, hh + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, ww + pd * 2, hh + pd * 2);
2023-01-25 06:49:00 +01:00
draw_sprite_stretched_ext(THEME.s_box_r2, 0, mx + pd, my + pd, ww, hh, clr, 1);
draw_sprite_stretched_add(THEME.s_box_r2, 1, mx + pd, my + pd, ww, hh, c_white, 0.3);
2024-08-27 05:30:03 +02:00
}
2023-01-25 06:49:00 +01:00
2024-08-27 05:30:03 +02:00
function draw_tooltip_palette(clr) {
2023-12-10 02:48:10 +01:00
if(array_empty(clr)) return;
var ph = ui(32);
if(!is_array(clr[0])) clr = [ clr ];
var pal_len = 0;
for( var i = 0, n = array_length(clr); i < n; i++ )
pal_len = max(pal_len, array_length(clr[i]));
var ww = min(ui(160), ui(32) * pal_len);
var hh = array_length(clr) * ph;
var pd = ui(4);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (ww + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (hh + pd * 2));
2023-01-25 06:49:00 +01:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, ww + pd * 2, hh + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, ww + pd * 2, hh + pd * 2);
2023-01-25 06:49:00 +01:00
var _y = my + pd;
2023-12-10 02:48:10 +01:00
for( var i = 0, n = array_length(clr); i < n; i++ ) {
drawPalette(clr[i], mx + pd, _y, ui(ww), ph);
2023-12-10 02:48:10 +01:00
_y += ph;
}
draw_sprite_stretched_add(THEME.s_box_r2, 1, mx + pd, my + pd, ww, hh, c_white, 0.3);
2024-08-27 05:30:03 +02:00
}
2023-01-25 06:49:00 +01:00
2024-08-27 05:30:03 +02:00
function draw_tooltip_gradient(clr) {
2023-12-10 02:48:10 +01:00
var gh = ui(32);
if(!is_array(clr)) clr = [ clr ];
2023-03-07 14:29:47 +01:00
var ww = ui(160);
2023-12-10 02:48:10 +01:00
var hh = array_length(clr) * gh;
2023-03-02 07:59:14 +01:00
var pd = ui(4);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (ww + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (hh + pd * 2));
2023-03-02 07:59:14 +01:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, ww + pd * 2, hh + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, ww + pd * 2, hh + pd * 2);
2023-03-02 07:59:14 +01:00
var _y = my + pd;
2023-12-10 02:48:10 +01:00
for( var i = 0, n = array_length(clr); i < n; i++ ) {
clr[i].draw(mx + pd, _y, ui(ww), gh);
2023-12-10 02:48:10 +01:00
_y += gh;
}
2024-08-27 05:30:03 +02:00
}
2023-03-02 07:59:14 +01:00
2024-08-27 05:30:03 +02:00
function draw_tooltip_surface_array(surf) {
2023-10-12 07:07:24 +02:00
if(!is_array(surf) || array_empty(surf)) return;
2023-10-06 11:51:11 +02:00
if(is_instanceof(surf[0], SurfaceAtlas)) {
draw_tooltip_atlas(surf);
return;
}
2023-02-14 13:44:46 +01:00
var amo = array_length(surf);
var col = ceil(sqrt(amo));
var row = ceil(amo / col);
var nn = min(ui(64), ui(320) / col);
var sw = nn;
var sh = nn;
var ww = sw * col;
var hh = sh * row;
var pd = ui(4);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (ww + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (hh + pd * 2));
2023-02-14 13:44:46 +01:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, ww + pd * 2, hh + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, ww + pd * 2, hh + pd * 2);
2023-02-14 13:44:46 +01:00
for( var ind = 0; ind < amo; ind++ ) {
if(!is_surface(surf[ind])) continue;
var i = floor(ind / col);
2023-02-20 10:16:31 +01:00
var j = safe_mod(ind, col);
2023-02-14 13:44:46 +01:00
2023-09-08 21:37:36 +02:00
var sw = surface_get_width_safe(surf[ind]);
var sh = surface_get_height_safe(surf[ind]);
2023-02-14 13:44:46 +01:00
var ss = nn / max(sw, sh);
var cx = mx + pd + j * nn + nn / 2;
var cy = my + pd + i * nn + nn / 2;
2023-02-14 13:44:46 +01:00
2023-03-19 09:17:39 +01:00
draw_surface_ext_safe(surf[ind], cx - sw * ss / 2, cy - sh * ss / 2, ss, ss, 0, c_white, 1);
2023-02-14 13:44:46 +01:00
draw_set_color(COLORS._main_icon);
draw_rectangle(cx - sw * ss / 2, cy - sh * ss / 2, cx + sw * ss / 2 - 1, cy + sh * ss / 2 - 1, true);
}
2024-08-27 05:30:03 +02:00
}
2023-02-14 13:44:46 +01:00
2024-08-27 05:30:03 +02:00
function draw_tooltip_surface(surf) {
2023-02-14 13:44:46 +01:00
if(is_array(surf)) {
draw_tooltip_surface_array(array_spread(surf))
return;
}
2023-10-06 11:51:11 +02:00
if(is_instanceof(surf, SurfaceAtlas)) {
draw_tooltip_atlas(surf);
return;
}
2023-01-25 06:49:00 +01:00
if(!is_surface(surf)) return;
2023-09-08 21:37:36 +02:00
var sw = surface_get_width_safe(surf);
var sh = surface_get_height_safe(surf);
2023-01-25 06:49:00 +01:00
var ss = min(ui(128) / sw, ui(128) / sh);
var ww = sw * ss;
var hh = sh * ss;
var pd = ui(4);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (ww + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (hh + pd * 2));
2023-01-25 06:49:00 +01:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, ww + pd * 2, hh + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, ww + pd * 2, hh + pd * 2);
2023-01-25 06:49:00 +01:00
draw_surface_ext_safe(surf, mx + pd, my + pd, ss, ss);
2024-08-27 05:30:03 +02:00
}
2023-05-28 20:00:51 +02:00
2024-08-27 05:30:03 +02:00
function draw_tooltip_sprite(spr) {
if(!sprite_exists(spr)) return;
2024-05-16 09:42:34 +02:00
var ox = sprite_get_xoffset(spr);
var oy = sprite_get_yoffset(spr);
var sw = sprite_get_width(spr);
var sh = sprite_get_height(spr);
var sn = sprite_get_number(spr);
2024-05-16 15:28:45 +02:00
var ss = min(max(1, min(ui(64) / sw, ui(64) / sh)), ui(320) / sw, ui(320) / sh);
var ww = sw * ss * sn + 2 * (sn - 1);
2024-05-16 15:28:45 +02:00
var hh = sh * ss + ui(16);
var pd = ui(4);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (ww + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (hh + pd * 2));
draw_sprite_stretched(THEME.textbox, 3, mx, my, ww + pd * 2, hh + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, ww + pd * 2, hh + pd * 2);
var sx = mx + pd + ox * ss;
var sy = my + pd + oy * ss;
for( var i = 0; i < sn; i++ )
draw_sprite_ext(spr, i, sx + i * (sw * ss + 2), sy, ss, ss, 0, c_white, 1);
2024-05-16 15:28:45 +02:00
draw_set_text(f_p3, fa_center, fa_bottom, COLORS._main_text_sub);
draw_text(mx + (ww + pd * 2) / 2, my + hh + pd * 2 - ui(4), $"{sw} x {sh} px");
2024-08-27 05:30:03 +02:00
}
2024-08-27 05:30:03 +02:00
function draw_tooltip_atlas(atlas) {
2023-05-28 20:00:51 +02:00
if(!is_array(atlas)) atlas = [ atlas ];
var amo = array_length(atlas);
var ww = ui(160);
var hh = amo * ui(48 + 8) - ui(8);
2023-07-30 19:56:53 +02:00
if(amo && is_array(atlas[0])) return;
var pd = ui(4);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (ww + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (hh + pd * 2));
2023-05-28 20:00:51 +02:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, ww + pd * 2, hh + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, ww + pd * 2, hh + pd * 2);
2023-05-28 20:00:51 +02:00
var sx = mx + pd;
var sy = my + pd;
2023-05-28 20:00:51 +02:00
for( var i = 0; i < amo; i++ ) {
var _y = sy + i * ui(48 + 8);
2024-05-20 05:16:05 +02:00
var atl = atlas[i];
if(!is_instanceof(atl, SurfaceAtlas)) continue;
2023-05-28 20:00:51 +02:00
2024-05-20 05:16:05 +02:00
var surf = atl.getSurface();
2023-05-28 20:00:51 +02:00
if(!is_surface(surf)) continue;
2023-09-08 21:37:36 +02:00
var sw = surface_get_width_safe(surf);
var sh = surface_get_height_safe(surf);
2023-05-28 20:00:51 +02:00
var ss = min(ui(48) / sw, ui(48) / sh);
draw_surface_ext_safe(surf, sx, _y, ss, ss);
draw_set_color(COLORS._main_icon);
draw_rectangle(sx, _y, sx + ui(48), _y + ui(48), 1);
draw_set_text(f_p3, fa_left, fa_top, COLORS._main_text_sub);
draw_text_add(sx + ui( 56), _y + ui( 0), __txt("Position"));
draw_text_add(sx + ui( 56), _y + ui(16), __txt("Rotation"));
draw_text_add(sx + ui( 56), _y + ui(32), __txt("Scale"));
2023-05-28 20:00:51 +02:00
draw_set_text(f_p3, fa_right, fa_top, COLORS._main_text);
2023-10-06 11:51:11 +02:00
draw_text_add(sx + ui(160), _y + ui( 0), $"{atl.x}, {atl.y}");
2023-05-28 20:00:51 +02:00
draw_text_add(sx + ui(160), _y + ui(16), atl.rotation);
2023-10-06 11:51:11 +02:00
draw_text_add(sx + ui(160), _y + ui(32), $"{atl.sx}, {atl.sy}");
2023-05-28 20:00:51 +02:00
}
2024-08-27 05:30:03 +02:00
}
2023-06-24 22:12:35 +02:00
2024-08-27 05:30:03 +02:00
function draw_tooltip_buffer(buff) {
2023-07-29 10:10:48 +02:00
var txt = buffer_get_string(buff, false, 400);
2023-07-21 12:40:20 +02:00
var len = string_length(txt);
if(len > 400) txt = string_copy(txt, 1, 400);
draw_set_text(f_code, fa_left, fa_top, COLORS._main_text);
var tw = min(string_width(" ") * 40, string_width(txt));
var th = string_height_ext(txt, -1, tw);
if(len > 400)
th += string_height(" ");
var pd = ui(8);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (tw + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (th + pd * 2));
2023-07-21 12:40:20 +02:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, tw + pd * 2, th + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, tw + pd * 2, th + pd * 2);
draw_text_line(mx + pd, my + pd, txt, -1, tw);
2023-07-21 12:40:20 +02:00
if(len > 400) {
draw_set_text(f_code, fa_left, fa_bottom, COLORS._main_text_sub);
draw_text(mx + pd, my + th + pd, $"...({buffer_get_size(buff)} bytes)");
2023-07-21 12:40:20 +02:00
}
2024-08-27 05:30:03 +02:00
}
2024-06-19 11:32:41 +02:00
2024-08-27 05:30:03 +02:00
function draw_tooltip_curve(curve) {
2024-06-19 11:32:41 +02:00
var ww = ui(160);
var hh = ui(160);
var pd = ui(8);
2024-09-12 05:27:42 +02:00
var mx = min(__mouse_tx + ui(16), __win_tw - (ww + pd * 2));
var my = min(__mouse_ty + ui(16), __win_th - (hh + pd * 2));
2024-06-19 11:32:41 +02:00
draw_sprite_stretched(THEME.textbox, 3, mx, my, ww + pd * 2, hh + pd * 2);
draw_sprite_stretched(THEME.textbox, 0, mx, my, ww + pd * 2, hh + pd * 2);
var x0 = mx + pd;
var x1 = x0 + ww;
var y0 = my + pd;
var y1 = y0 + hh;
var st = 0.1;
draw_set_color(COLORS.widget_curve_line);
draw_set_alpha(0.15);
for( var i = st; i < 1; i += st ) {
var _y0 = y0 + hh * (1 - i);
draw_line(x0, _y0, x1, _y0);
var _x0 = x0 + ww * i;
draw_line(_x0, y0, _x0, y1);
}
draw_set_alpha(1);
draw_set_color(COLORS._main_accent);
draw_curve(x0, y0, ww, hh, curve);
draw_set_color(COLORS.widget_curve_outline);
draw_rectangle(x0, y0, x1, y1, true);
2024-08-27 05:30:03 +02:00
}