Files
armorpaint/paint/sources/tab_fonts.ts
T

172 lines
4.9 KiB
TypeScript
Raw Normal View History

2024-03-14 15:31:22 +01:00
2024-04-07 09:52:45 +02:00
let _tab_fonts_draw_i: i32;
2024-09-03 15:52:05 +02:00
function tab_fonts_draw(htab: ui_handle_t) {
2024-03-14 15:31:22 +01:00
let statush: i32 = config_raw.layout[layout_size_t.STATUS_H];
2025-09-16 15:03:51 +02:00
if (ui_tab(htab, tr("Fonts")) && statush > ui_statusbar_default_h * UI_SCALE()) {
2024-03-14 15:31:22 +01:00
2024-09-03 15:52:05 +02:00
ui_begin_sticky();
2024-03-14 15:31:22 +01:00
if (config_raw.touch_ui) {
2024-04-25 22:04:43 +02:00
let row: f32[] = [1 / 4, 1 / 4];
2024-09-03 15:52:05 +02:00
ui_row(row);
2024-03-14 15:31:22 +01:00
}
else {
2024-04-25 22:04:43 +02:00
let row: f32[] = [1 / 14, 1 / 14];
2024-09-03 15:52:05 +02:00
ui_row(row);
2024-03-14 15:31:22 +01:00
}
2024-09-03 15:52:05 +02:00
if (ui_button(tr("Import"))) {
2024-03-20 16:13:54 +01:00
project_import_asset("ttf,ttc,otf");
}
if (ui.is_hovered) {
2024-09-03 15:52:05 +02:00
ui_tooltip(tr("Import font file"));
2024-03-20 16:13:54 +01:00
}
2024-03-14 15:31:22 +01:00
2024-09-03 15:52:05 +02:00
if (ui_button(tr("2D View"))) {
2024-03-14 15:31:22 +01:00
ui_base_show_2d_view(view_2d_type_t.FONT);
}
2024-09-03 15:52:05 +02:00
ui_end_sticky();
ui_separator(3, false);
2024-03-14 15:31:22 +01:00
2025-07-18 23:37:51 +02:00
let statusw: i32 = iron_window_width() - ui_toolbar_w(true) - config_raw.layout[layout_size_t.SIDEBAR_W];
2025-08-15 22:04:07 +02:00
let slotw: i32 = math_floor(51 * UI_SCALE());
2024-03-14 15:31:22 +01:00
let num: i32 = math_floor(statusw / slotw);
2024-11-22 19:45:06 +01:00
if (num == 0) {
return;
}
2024-03-14 15:31:22 +01:00
for (let row: i32 = 0; row < math_floor(math_ceil(project_fonts.length / num)); ++row) {
let mult: i32 = config_raw.show_asset_names ? 2 : 1;
let ar: f32[] = [];
2024-03-20 16:13:54 +01:00
for (let i: i32 = 0; i < num * mult; ++i) {
array_push(ar, 1 / num);
}
2024-09-03 15:52:05 +02:00
ui_row(ar);
2024-03-14 15:31:22 +01:00
ui._x += 2;
2025-08-15 22:04:07 +02:00
let off: f32 = config_raw.show_asset_names ? UI_ELEMENT_OFFSET() * 10.0 : 6;
2024-03-20 16:13:54 +01:00
if (row > 0) {
ui._y += off;
}
2024-03-14 15:31:22 +01:00
for (let j: i32 = 0; j < num; ++j) {
2025-08-15 22:04:07 +02:00
let imgw: i32 = math_floor(50 * UI_SCALE());
2024-03-14 15:31:22 +01:00
let i: i32 = j + row * num;
if (i >= project_fonts.length) {
2025-08-15 22:04:07 +02:00
ui_end_element_of_size(imgw);
2024-03-20 16:13:54 +01:00
if (config_raw.show_asset_names) {
2025-08-15 22:04:07 +02:00
ui_end_element_of_size(0);
2024-03-20 16:13:54 +01:00
}
2024-03-14 15:31:22 +01:00
continue;
}
2025-06-19 19:55:16 +02:00
let img: gpu_texture_t = project_fonts[i].image;
2024-03-14 15:31:22 +01:00
if (context_raw.font == project_fonts[i]) {
2024-09-03 15:52:05 +02:00
// ui_fill(1, -2, img.width + 3, img.height + 3, ui.ops.theme.HIGHLIGHT_COL); // TODO
2024-03-14 15:31:22 +01:00
let off: i32 = row % 2 == 1 ? 1 : 0;
let w: i32 = 50;
2024-03-20 16:13:54 +01:00
if (config_raw.window_scale > 1) {
w += math_floor(config_raw.window_scale * 2);
}
2024-09-03 15:52:05 +02:00
ui_fill(-1, -2, w + 3, 2, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(-1, w - off, w + 3, 2 + off, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(-1, -2, 2, w + 3, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(w + 1, -2, 2, w + 4, ui.ops.theme.HIGHLIGHT_COL);
2024-03-14 15:31:22 +01:00
}
let uix: f32 = ui._x;
2025-08-15 22:04:07 +02:00
let tile: i32 = UI_SCALE() > 1 ? 100 : 50;
2024-09-03 15:52:05 +02:00
let state: ui_state_t = ui_state_t.IDLE;
2024-03-14 15:31:22 +01:00
if (project_fonts[i].preview_ready) {
2025-03-03 22:50:40 +01:00
// draw_set_pipeline(pipe); // L8
2025-03-18 12:14:21 +01:00
// gpu_set_int(channel_location, 1);
2025-08-04 19:34:53 +02:00
state = ui_image(img);
2025-03-03 22:50:40 +01:00
// draw_set_pipeline(null);
2024-03-14 15:31:22 +01:00
}
else {
2025-08-04 19:34:53 +02:00
state = ui_sub_image(resource_get("icons.k"), -1, -1.0, tile * 6, tile, tile, tile);
2024-03-14 15:31:22 +01:00
}
2024-09-03 15:52:05 +02:00
if (state == ui_state_t.STARTED) {
2024-03-14 15:31:22 +01:00
if (context_raw.font != project_fonts[i]) {
2024-04-07 09:52:45 +02:00
_tab_fonts_draw_i = i;
2025-08-16 20:43:45 +02:00
sys_notify_on_next_frame(function () {
2024-04-07 09:52:45 +02:00
let i: i32 = _tab_fonts_draw_i;
2024-03-14 15:31:22 +01:00
context_select_font(i);
2024-04-07 09:52:45 +02:00
});
2024-03-14 15:31:22 +01:00
}
2025-09-26 17:42:01 +02:00
if (sys_time() - context_raw.select_time < 0.2) {
2024-03-20 16:13:54 +01:00
ui_base_show_2d_view(view_2d_type_t.FONT);
}
2025-03-11 10:02:47 +01:00
context_raw.select_time = sys_time();
2024-03-14 15:31:22 +01:00
}
if (ui.is_hovered && ui.input_released_r) {
context_select_font(i);
2024-04-07 09:52:45 +02:00
_tab_fonts_draw_i = i;
2025-08-15 22:59:45 +02:00
ui_menu_draw(function () {
2024-04-07 09:52:45 +02:00
let i: i32 = _tab_fonts_draw_i;
2025-02-26 08:47:09 +01:00
if (project_fonts.length > 1 && ui_menu_button(tr("Delete"), "delete") && project_fonts[i].file != "") {
2024-03-14 15:31:22 +01:00
tab_fonts_delete_font(project_fonts[i]);
}
2024-09-11 16:32:12 +02:00
});
2024-03-14 15:31:22 +01:00
}
if (ui.is_hovered) {
if (img == null) {
2024-04-07 09:52:45 +02:00
_tab_fonts_draw_i = i;
2025-08-16 20:43:45 +02:00
sys_notify_on_next_frame(function () {
2024-04-07 09:52:45 +02:00
let i: i32 = _tab_fonts_draw_i;
2024-03-20 16:13:54 +01:00
let _font: slot_font_t = context_raw.font;
2024-03-14 15:31:22 +01:00
context_raw.font = project_fonts[i];
util_render_make_font_preview();
context_raw.font = _font;
});
}
else {
2025-03-10 22:13:30 +01:00
ui_tooltip_image(img);
2024-09-03 15:52:05 +02:00
ui_tooltip(project_fonts[i].name);
2024-03-14 15:31:22 +01:00
}
}
if (config_raw.show_asset_names) {
ui._x = uix;
ui._y += slotw * 0.9;
2024-09-03 15:52:05 +02:00
ui_text(project_fonts[i].name, ui_align_t.CENTER);
2024-03-20 16:13:54 +01:00
if (ui.is_hovered) {
2024-09-03 15:52:05 +02:00
ui_tooltip(project_fonts[i].name);
2024-03-20 16:13:54 +01:00
}
2024-03-14 15:31:22 +01:00
ui._y -= slotw * 0.9;
if (i == project_fonts.length - 1) {
2025-08-15 22:04:07 +02:00
ui._y += j == num - 1 ? imgw : imgw + UI_ELEMENT_H() + UI_ELEMENT_OFFSET();
2024-03-14 15:31:22 +01:00
}
}
}
ui._y += 6;
}
let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w &&
2024-03-20 16:13:54 +01:00
ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h;
2024-03-14 15:31:22 +01:00
if (in_focus && ui.is_delete_down && project_fonts.length > 1 && context_raw.font.file != "") {
ui.is_delete_down = false;
tab_fonts_delete_font(context_raw.font);
}
}
}
2024-03-20 16:13:54 +01:00
function tab_fonts_delete_font(font: slot_font_t) {
2025-08-16 20:43:45 +02:00
sys_notify_on_next_frame(function (font: slot_font_t) {
2024-04-07 09:52:45 +02:00
let i: i32 = array_index_of(project_fonts, font);
2024-03-14 15:31:22 +01:00
context_select_font(i == project_fonts.length - 1 ? i - 1 : i + 1);
data_delete_font(project_fonts[i].file);
2024-03-20 16:13:54 +01:00
array_splice(project_fonts, i, 1);
2024-04-07 09:52:45 +02:00
}, font);
2024-03-14 15:31:22 +01:00
ui_base_hwnds[2].redraws = 2;
}