Pixel-Composer/scripts/tooltip_hotkey/tooltip_hotkey.gml

38 lines
1.3 KiB
Text
Raw Normal View History

2024-05-11 04:56:08 +02:00
function tooltipHotkey(text, context = "", name = "") constructor {
2024-04-03 10:01:26 +02:00
self.text = text;
2024-04-05 05:50:03 +02:00
self.hotkey = find_hotkey(context, name);
keyStr = hotkey? key_get_name(hotkey.key, hotkey.modi) : "";
2024-04-03 10:01:26 +02:00
2024-05-11 04:56:08 +02:00
static setKey = function(key) { keyStr = key; return self; }
2024-04-03 10:01:26 +02:00
static drawTooltip = function() {
2024-04-05 05:50:03 +02:00
draw_set_font(f_p0);
var _w1 = string_width(text);
draw_set_font(f_p1);
var _w2 = string_width(keyStr);
2024-05-19 07:55:09 +02:00
var tw = min(WIN_W - ui(32), _w1 + ui(24) + _w2);
2024-04-05 05:50:03 +02:00
var th = string_height_ext(text, -1, tw);
var mx = min(mouse_mx + ui(16), WIN_W - (tw + ui(16)));
var my = min(mouse_my + ui(16), WIN_H - (th + ui(16)));
draw_sprite_stretched(THEME.textbox, 3, mx, my, tw + ui(16), th + ui(16));
draw_sprite_stretched(THEME.textbox, 0, mx, my, tw + ui(16), th + ui(16));
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text);
draw_set_color(COLORS._main_text);
draw_text_line(mx + ui(8), my + ui(8), text, -1, tw);
2024-04-03 10:01:26 +02:00
2024-04-05 05:50:03 +02:00
draw_set_text(f_p1, fa_right, fa_center, COLORS._main_text_sub);
2024-05-19 07:55:09 +02:00
var _tw = string_width( keyStr);
var _th = string_height(keyStr);
var _hx = mx + tw + ui(6);
var _hy = my + th / 2 + ui(10);
draw_sprite_stretched_ext(THEME.ui_panel_fg, 1, _hx - _tw - ui(4), _hy - _th / 2 - ui(3), _tw + ui(8), _th + ui(3), COLORS._main_text_sub, 0.5);
draw_text(_hx, _hy, keyStr);
2024-04-03 10:01:26 +02:00
}
}