From 47f1147ba5cb211190dd33c89175cf2ff11bb0d0 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Fri, 15 Aug 2025 22:04:07 +0200 Subject: [PATCH] ui cleanup --- base/sources/iron.h | 1 + base/sources/iron_ui.c | 64 ++++----- base/sources/iron_ui.h | 5 +- base/sources/ts/base.ts | 36 +---- base/sources/ts/box_export.ts | 2 +- base/sources/ts/box_preferences.ts | 21 +-- base/sources/ts/box_projects.ts | 26 ++-- base/sources/ts/config.ts | 5 +- base/sources/ts/console.ts | 4 +- base/sources/ts/iron/iron.ts | 77 ++--------- base/sources/ts/nodes_material.ts | 12 +- base/sources/ts/project.ts | 2 +- base/sources/ts/tab_browser.ts | 4 +- base/sources/ts/tab_brushes.ts | 16 +-- base/sources/ts/tab_console.ts | 4 +- base/sources/ts/tab_fonts.ts | 16 +-- base/sources/ts/tab_history.ts | 2 +- base/sources/ts/tab_layers.ts | 70 +++++----- base/sources/ts/tab_materials.ts | 22 +-- base/sources/ts/tab_meshes.ts | 16 +-- base/sources/ts/tab_scripts.ts | 2 +- base/sources/ts/tab_swatches.ts | 8 +- base/sources/ts/tab_textures.ts | 14 +- base/sources/ts/translator.ts | 9 +- base/sources/ts/ui_base.ts | 50 +++---- base/sources/ts/ui_box.ts | 16 +-- base/sources/ts/ui_files.ts | 18 +-- base/sources/ts/ui_header.ts | 2 +- base/sources/ts/ui_menu.ts | 15 ++- base/sources/ts/ui_menubar.ts | 12 +- base/sources/ts/ui_nodes.ts | 206 ++++++++++++++--------------- base/sources/ts/ui_toolbar.ts | 12 +- base/sources/ts/ui_view2d.ts | 76 +++++------ lab/sources/ui_nodes_ext.ts | 2 +- paint/sources/ui_header_ext.ts | 10 +- 35 files changed, 370 insertions(+), 487 deletions(-) diff --git a/base/sources/iron.h b/base/sources/iron.h index bcee9724..48e563f1 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -430,6 +430,7 @@ void _update(void *data) { #endif iron_update(); + ui_end_frame(); gpu_present(); } diff --git a/base/sources/iron_ui.c b/base/sources/iron_ui.c index 686d1e2a..2a19eec5 100644 --- a/base/sources/iron_ui.c +++ b/base/sources/iron_ui.c @@ -602,7 +602,7 @@ char *ui_lower_case(char *dest, char *src) { return dest; } -void ui_draw_tooltip_text(bool bind_global_g) { +void ui_draw_tooltip_text() { int line_count = ui_line_count(current->tooltip_text); float tooltip_w = 0.0; for (int i = 0; i < line_count; ++i) { @@ -612,7 +612,7 @@ void ui_draw_tooltip_text(bool bind_global_g) { } } current->tooltip_x = fmin(current->tooltip_x, iron_window_width() - tooltip_w - 20); - if (bind_global_g) draw_begin(NULL, false, 0); + draw_begin(NULL, false, 0); float font_height = draw_font_height(current->ops->font, current->font_size); float off = 0; if (current->tooltip_img != NULL) { @@ -636,10 +636,10 @@ void ui_draw_tooltip_text(bool bind_global_g) { for (int i = 0; i < line_count; ++i) { draw_string(ui_extract_line(current->tooltip_text, i), current->tooltip_x + 5, current->tooltip_y + off + i * current->font_size); } - if (bind_global_g) draw_end(); + draw_end(); } -void ui_draw_tooltip_image(bool bind_global_g) { +void ui_draw_tooltip_image() { float w = current->tooltip_img->width; if (current->tooltip_img_max_width != 0 && w > current->tooltip_img_max_width) { w = current->tooltip_img_max_width; @@ -647,24 +647,20 @@ void ui_draw_tooltip_image(bool bind_global_g) { float h = current->tooltip_img->height * (w / current->tooltip_img->width); current->tooltip_x = fmin(current->tooltip_x, iron_window_width() - w - 20); current->tooltip_y = fmin(current->tooltip_y, iron_window_height() - h - 20); - if (bind_global_g) { - draw_begin(NULL, false, 0); - } + draw_begin(NULL, false, 0); draw_set_color(0xff000000); draw_filled_rect(current->tooltip_x, current->tooltip_y, w, h); draw_set_color(0xffffffff); current->tooltip_invert_y ? draw_scaled_image(current->tooltip_img, current->tooltip_x, current->tooltip_y + h, w, -h) : draw_scaled_image(current->tooltip_img, current->tooltip_x, current->tooltip_y, w, h); - if (bind_global_g) draw_end(); + draw_end(); } -void ui_draw_tooltip(bool bind_global_g) { +void ui_draw_tooltip() { static char temp[1024]; if (current->slider_tooltip) { - if (bind_global_g) { - draw_begin(NULL, false, 0); - } + draw_begin(NULL, false, 0); draw_set_font(current->ops->font, current->font_size * 2); sprintf(temp, "%f", round(current->scroll_handle->value * 100.0) / 100.0); string_strip_trailing_zeros(temp); @@ -676,12 +672,10 @@ void ui_draw_tooltip(bool bind_global_g) { draw_filled_rect(x - x_off, current->slider_tooltip_y - y_off, x_off * 2.0, y_off); draw_set_color(theme->TEXT_COL); draw_string(text, x - x_off, current->slider_tooltip_y - y_off); - if (bind_global_g) draw_end(); + draw_end(); } if (ui_touch_tooltip && current->text_selected_handle != NULL) { - if (bind_global_g) { - draw_begin(NULL, false, 0); - } + draw_begin(NULL, false, 0); draw_set_font(current->ops->font, current->font_size * 2.0); float x_off = draw_string_width(current->ops->font, current->font_size * 2.0, current->text_selected) / 2.0; float y_off = draw_font_height(current->ops->font, current->font_size * 2.0) / 2.0; @@ -691,7 +685,7 @@ void ui_draw_tooltip(bool bind_global_g) { draw_filled_rect(x - x_off, y - y_off, x_off * 2.0, y_off * 2.0); draw_set_color(theme->TEXT_COL); draw_string(current->text_selected, x - x_off, y - y_off); - if (bind_global_g) draw_end(); + draw_end(); } if (current->tooltip_text[0] != '\0' || current->tooltip_img != NULL) { @@ -706,24 +700,22 @@ void ui_draw_tooltip(bool bind_global_g) { } if (!current->tooltip_wait && iron_time() - current->tooltip_time > UI_TOOLTIP_DELAY()) { if (current->tooltip_img != NULL) { - ui_draw_tooltip_image(bind_global_g); + ui_draw_tooltip_image(); } if (current->tooltip_text[0] != '\0') { - ui_draw_tooltip_text(bind_global_g); + ui_draw_tooltip_text(); } } } else current->tooltip_shown = false; } -void ui_draw_combo(bool begin /*= true*/) { +void ui_draw_combo() { if (current->combo_selected_handle == NULL) { return; } draw_set_color(theme->SEPARATOR_COL); - if (begin) { - draw_begin(NULL, false, 0); - } + draw_begin(NULL, false, 0); float combo_h = (current->combo_selected_texts->length + (current->combo_selected_label != NULL ? 1 : 0) + (current->combo_search_bar ? 1 : 0)) * UI_ELEMENT_H(); float dist_top = current->combo_selected_y - combo_h - UI_ELEMENT_H() - current->window_border_top; @@ -892,10 +884,14 @@ void ui_draw_combo(bool begin /*= true*/) { ui_combo_first = false; } current->input_enabled = current->combo_selected_handle == NULL; - ui_end_region(false); - if (begin) { - draw_end(); - } + ui_end_region(); + draw_end(); +} + +void ui_end_frame() { + ui_draw_combo(); // Handle active combo + ui_draw_tooltip(); + ui_end_input(); } void ui_bake_elements() { @@ -978,13 +974,8 @@ void ui_begin_region(ui_t *ui, int x, int y, int w) { current->_h = 0; } -void ui_end_region(bool last) { - ui_draw_tooltip(false); +void ui_end_region() { current->tab_pressed_handle = NULL; - if (last) { - ui_draw_combo(false); // Handle active combo - ui_end_input(); - } } void ui_set_cursor_to_input(int align) { @@ -2281,16 +2272,11 @@ void ui_tooltip_image(gpu_texture_t *image, int max_width) { current->tooltip_y = current->_y + current->_window_y; } -void ui_end(bool last) { +void ui_end() { if (!current->window_ended) { ui_end_window(); } - ui_draw_combo(true); // Handle active combo - ui_draw_tooltip(true); current->tab_pressed_handle = NULL; - if (last) { - ui_end_input(); - } } void ui_set_input_position(ui_t *ui, int x, int y) { diff --git a/base/sources/iron_ui.h b/base/sources/iron_ui.h index 505bd6e7..9322c599 100644 --- a/base/sources/iron_ui.h +++ b/base/sources/iron_ui.h @@ -274,7 +274,7 @@ void ui_begin(ui_t *ui); void ui_begin_sticky(); void ui_end_sticky(); void ui_begin_region(ui_t *ui, int x, int y, int w); -void ui_end_region(bool last); +void ui_end_region(); bool ui_window(ui_handle_t *handle, int x, int y, int w, int h, bool drag); // Returns true if redraw is needed bool ui_button(char *text, int align, char *label); int ui_text(char *text, int align, int bg); @@ -297,7 +297,7 @@ void ui_row7(); void ui_separator(int h, bool fill); void ui_tooltip(char *text); void ui_tooltip_image(gpu_texture_t *image, int max_width); -void ui_end(bool last); +void ui_end(); void ui_end_window(); char *ui_hovered_tab_name(); void ui_set_hovered_tab_name(char *name); @@ -337,6 +337,7 @@ bool ui_is_visible(float elem_h); void ui_end_element(); void ui_end_element_of_size(float element_size); void ui_end_input(); +void ui_end_frame(); void ui_fade_color(float alpha); void ui_draw_string(char *text, float x_offset, float y_offset, int align, bool truncation); void ui_draw_shadow(float x, float y, float w, float h); diff --git a/base/sources/ts/base.ts b/base/sources/ts/base.ts index c1d95c2c..7f2ec46b 100644 --- a/base/sources/ts/base.ts +++ b/base/sources/ts/base.ts @@ -18,8 +18,6 @@ let base_font: draw_font_t = null; let base_theme: ui_theme_t; let base_color_wheel: gpu_texture_t; let base_color_wheel_gradient: gpu_texture_t; -let base_ui_box: ui_t; -let base_ui_menu: ui_t; let base_default_element_w: i32 = 100; let base_default_element_h: i32 = 28; let base_default_font_size: i32 = 13; @@ -96,15 +94,6 @@ function base_init() { base_color_wheel = image_color_wheel; base_color_wheel_gradient = image_color_wheel_gradient; ui_nodes_enum_texts = base_enum_texts; - let ops: ui_options_t = { - theme: base_theme, - font: font, - scale_factor: config_raw.window_scale, - color_wheel: base_color_wheel, - black_white_gradient: base_color_wheel_gradient - }; - base_ui_box = ui_create(ops); - base_ui_menu = ui_create(ops); // Init plugins if (config_raw.plugins != null) { @@ -573,7 +562,7 @@ function base_render() { if (base_is_dragging) { iron_set_mouse_cursor(1); // Hand let img: gpu_texture_t = base_get_drag_image(); - let scale_factor: f32 = ui_SCALE(ui_base_ui); + let scale_factor: f32 = UI_SCALE(); let size: f32 = (base_drag_size == -1 ? 50 : base_drag_size) * scale_factor; let ratio: f32 = size / img.width; let h: f32 = img.height * ratio; @@ -679,28 +668,11 @@ function base_toggle_fullscreen() { } function base_is_scrolling(): bool { - for (let i: i32 = 0; i < base_get_uis().length; ++i) { - let ui: ui_t = base_get_uis()[i]; - if (ui.is_scrolling) { - return true; - } - } - return false; + return ui_base_ui.is_scrolling; } function base_is_combo_selected(): bool { - for (let i: i32 = 0; i < base_get_uis().length; ++i) { - let ui: ui_t = base_get_uis()[i]; - if (ui.combo_selected_handle != null) { - return true; - } - } - return false; -} - -function base_get_uis(): ui_t[] { - let uis: ui_t[] = [base_ui_box, base_ui_menu, ui_base_ui, ui_nodes_ui, ui_view2d_ui]; - return uis; + return ui_base_ui.combo_selected_handle != null; } function base_is_decal_layer(): bool { @@ -718,7 +690,7 @@ function base_redraw_status() { function base_redraw_console() { let statush: i32 = config_raw.layout[layout_size_t.STATUS_H]; - if (ui_base_ui != null && statush > ui_status_default_status_h * ui_SCALE(ui_base_ui)) { + if (ui_base_ui != null && statush > ui_status_default_status_h * UI_SCALE()) { ui_base_hwnds[tab_area_t.STATUS].redraws = 2; } } diff --git a/base/sources/ts/box_export.ts b/base/sources/ts/box_export.ts index 09a768c4..46a34e98 100644 --- a/base/sources/ts/box_export.ts +++ b/base/sources/ts/box_export.ts @@ -155,7 +155,7 @@ function box_export_tab_export_textures(ui: ui_t, title: string, bake_material: let layers_destination_combo: string[] = [tr("Disk"), tr("Packed")]; context_raw.layers_destination = ui_combo(layers_destination_handle, layers_destination_combo, tr("Destination"), true); - _ui_end_element(); + ui_end_element(); ui_row2(); if (ui_button(tr("Cancel"))) { diff --git a/base/sources/ts/box_preferences.ts b/base/sources/ts/box_preferences.ts index 8d954307..f9b564f9 100644 --- a/base/sources/ts/box_preferences.ts +++ b/base/sources/ts/box_preferences.ts @@ -9,7 +9,6 @@ let box_preferences_themes: string[] = null; let _box_preferences_f: string; let _box_preferences_h: ui_handle_t; let _box_preferences_i: i32; -let _box_preferences_ui: ui_t; function box_preferences_show() { ui_box_show_custom(function (ui: ui_t) { @@ -131,7 +130,7 @@ function box_preferences_show() { config_raw.grid_snap = ui_check(h_grid_snap, tr("Grid Snap")); ui_nodes_grid_snap = config_raw.grid_snap; - _ui_end_element(); + ui_end_element(); ui_row2(); if (ui_button(tr("Restore")) && !ui_menu_show) { @@ -155,12 +154,11 @@ function box_preferences_show() { }, ui); } if (ui_menu_button(tr("Import..."))) { - _box_preferences_ui = ui; ui_files_show("json", false, false, function (path: string) { let b: buffer_t = data_get_blob(path); let raw: config_t = json_parse(sys_buffer_to_string(b)); sys_notify_on_init(function (raw: config_t) { - _box_preferences_ui.ops.theme.ELEMENT_H = base_default_element_h; + ui_base_ui.ops.theme.ELEMENT_H = base_default_element_h; config_import_from(raw); box_preferences_set_scale(); make_material_parse_mesh_material(); @@ -265,7 +263,7 @@ function box_preferences_show() { _box_preferences_i = i; ui_menu_draw(function (ui: ui_t) { ui.changed = false; - let color: i32 = ui_color_wheel(_box_preferences_h, false, -1, 11 * ui.ops.theme.ELEMENT_H * ui_SCALE(ui), true); + let color: i32 = ui_color_wheel(_box_preferences_h, false, -1, 11 * ui.ops.theme.ELEMENT_H * UI_SCALE(), true); let u32_theme: u32_ptr = base_theme; DEREFERENCE(u32_theme + _box_preferences_i) = color; if (ui.changed) { @@ -308,10 +306,7 @@ function box_preferences_show() { } if (ui.changed) { - for (let i: i32 = 0; i < base_get_uis().length; ++i) { - let ui: ui_t = base_get_uis()[i]; - ui.elements_baked = false; - } + ui_base_ui.elements_baked = false; } } ui.input_enabled = true; @@ -538,7 +533,7 @@ function box_preferences_show() { config_raw.pressure_angle = ui_check(h_pressure_angle, tr("Brush Angle")); ///end - _ui_end_element(); + ui_end_element(); let row: f32[] = [0.5]; ui_row(row); if (ui_button(tr("Help"))) { @@ -889,15 +884,11 @@ function box_preferences_get_preset_index(): i32 { function box_preferences_set_scale() { let scale: f32 = config_raw.window_scale; - _ui_set_scale(ui_base_ui, scale); + ui_set_scale(scale); ui_header_h = math_floor(ui_header_default_h * scale); config_raw.layout[layout_size_t.STATUS_H] = math_floor(ui_status_default_status_h * scale); ui_menubar_w = math_floor(ui_menubar_default_w * scale); ui_base_set_icon_scale(); - _ui_set_scale(ui_nodes_ui, scale); - _ui_set_scale(ui_view2d_ui, scale); - _ui_set_scale(base_ui_box, scale); - _ui_set_scale(base_ui_menu, scale); base_resize(); config_raw.layout[layout_size_t.SIDEBAR_W] = math_floor(ui_base_default_sidebar_w * scale); } diff --git a/base/sources/ts/box_projects.ts b/base/sources/ts/box_projects.ts index 4763e536..b2dff2c2 100644 --- a/base/sources/ts/box_projects.ts +++ b/base/sources/ts/box_projects.ts @@ -68,7 +68,7 @@ function box_projects_tab(ui: ui_t) { ui_end_sticky(); ui_separator(3, false); - let slotw: i32 = math_floor(150 * ui_SCALE(ui)); + let slotw: i32 = math_floor(150 * UI_SCALE()); let num: i32 = math_floor(iron_window_width() / slotw); if (num == 0) { return; @@ -85,18 +85,18 @@ function box_projects_tab(ui: ui_t) { ui_row(ar); ui._x += 2; - let off: f32 = show_asset_names ? ui_ELEMENT_OFFSET(ui) * 16.0 : 6; + let off: f32 = show_asset_names ? UI_ELEMENT_OFFSET() * 16.0 : 6; if (row > 0) { ui._y += off; } for (let j: i32 = 0; j < num; ++j) { - let imgw: i32 = math_floor(128 * ui_SCALE(ui)); + let imgw: i32 = math_floor(128 * UI_SCALE()); let i: i32 = j + row * num; if (i >= recent_projects.length) { - _ui_end_element(imgw); + ui_end_element_of_size(imgw); if (show_asset_names) { - _ui_end_element(0); + ui_end_element_of_size(0); } continue; } @@ -124,7 +124,7 @@ function box_projects_tab(ui: ui_t) { if (icon != null) { ui_fill(0, 0, 128, 128, ui.ops.theme.SEPARATOR_COL); - let state: i32 = ui_image(icon, 0xffffffff, 128 * ui_SCALE(ui)); + let state: i32 = ui_image(icon, 0xffffffff, 128 * UI_SCALE()); if (state == ui_state_t.RELEASED) { let _uix: i32 = ui._x; ui._x = uix; @@ -168,14 +168,14 @@ function box_projects_tab(ui: ui_t) { } ui._y -= slotw * 0.9; if (i == recent_projects.length - 1) { - ui._y += j == num - 1 ? imgw : imgw + ui_ELEMENT_H(ui) + ui_ELEMENT_OFFSET(ui); + ui._y += j == num - 1 ? imgw : imgw + UI_ELEMENT_H() + UI_ELEMENT_OFFSET(); } } } else { - _ui_end_element(0); + ui_end_element_of_size(0); if (show_asset_names) { - _ui_end_element(0); + ui_end_element_of_size(0); } ui._x = uix; } @@ -230,7 +230,7 @@ function box_projects_recent_tab(ui: ui_t) { } ui.enabled = true; - _ui_end_element(); + ui_end_element(); if (ui_button(tr("New Project..."), ui_align_t.LEFT)) { project_new_box(); } @@ -243,7 +243,7 @@ function box_projects_recent_tab(ui: ui_t) { function box_projects_draw_badge(ui: ui_t) { let img: gpu_texture_t = data_get_image("badge.k"); ui_image(img); - _ui_end_element(); + ui_end_element(); } function box_projects_get_started_tab(ui: ui_t) { @@ -261,8 +261,8 @@ function box_projects_get_started_tab(ui: ui_t) { } function box_projects_align_to_fullscreen() { - ui_box_modalw = math_floor(iron_window_width() / ui_SCALE(base_ui_box)); - ui_box_modalh = math_floor(iron_window_height() / ui_SCALE(base_ui_box)); + ui_box_modalw = math_floor(iron_window_width() / UI_SCALE()); + ui_box_modalh = math_floor(iron_window_height() / UI_SCALE()); let appw: i32 = iron_window_width(); let apph: i32 = iron_window_height(); let mw: i32 = appw; diff --git a/base/sources/ts/config.ts b/base/sources/ts/config.ts index d4c485f2..49062f58 100644 --- a/base/sources/ts/config.ts +++ b/base/sources/ts/config.ts @@ -330,10 +330,7 @@ function config_load_theme(theme: string, tag_redraw: bool = true) { base_theme.FILL_WINDOW_BG = true; if (tag_redraw) { - for (let i: i32 = 0; i < base_get_uis().length; ++i) { - let ui: ui_t = base_get_uis()[i]; - ui.ops.theme = base_theme; - } + ui_base_ui.ops.theme = base_theme; ui_base_tag_ui_redraw(); } diff --git a/base/sources/ts/console.ts b/base/sources/ts/console.ts index d51516a9..07f5651a 100644 --- a/base/sources/ts/console.ts +++ b/base/sources/ts/console.ts @@ -9,7 +9,7 @@ function console_draw_toast(s: string) { draw_begin(); draw_set_color(0x55000000); draw_filled_rect(0, 0, iron_window_width(), iron_window_height()); - let scale: f32 = ui_SCALE(base_get_uis()[0]); + let scale: f32 = UI_SCALE(); let x: f32 = iron_window_width() / 2; let y: f32 = iron_window_height() - 200 * scale; draw_filled_rect(x - 200 * scale, y, 400 * scale, 80 * scale); @@ -47,11 +47,11 @@ function console_progress(s: string) { console_progress_text = s; // Pass one frame to immediately show the message - ui_end_input(); draw_end(); sys_render(); draw_begin(); gpu_present(); + ui_end_input(); } function console_info(s: string) { diff --git a/base/sources/ts/iron/iron.ts b/base/sources/ts/iron/iron.ts index 7ba97c77..42c70d85 100644 --- a/base/sources/ts/iron/iron.ts +++ b/base/sources/ts/iron/iron.ts @@ -713,7 +713,7 @@ declare function ui_separator(h: i32 = 4, fill: bool = true): void; declare function ui_text_area(handle: ui_handle_t, align: ui_align_t = ui_align_t.LEFT, editable: bool = true, label: string = "", word_wrap: bool = false): string; declare function ui_begin(ui: ui_t): void; declare function ui_end_window(): void; -declare function ui_end_region(last: bool = true): void; +declare function ui_end_region(): void; declare function ui_float_input(handle: ui_handle_t, label: string = "", align: ui_align_t = ui_align_t.LEFT, precision: f32 = 1000.0): f32; declare function ui_get_current(): ui_t; declare function ui_remove_node(n: ui_node_t, canvas: ui_node_canvas_t): void; @@ -738,7 +738,6 @@ declare function ui_begin_menu(): void; declare function ui_end_menu(): void; declare function _ui_menu_button(s: string): bool; declare function ui_begin_region(ui: ui_t, x: i32, y: i32, w: i32): void; -declare function ui_end_region(last: bool): void; declare function ui_inline_radio(handle: ui_handle_t, texts: string[], align: i32): i32; declare function ui_end_input(): void; declare function ui_panel(handle: ui_handle_t, text: string, is_tree: bool, filled: bool): bool; @@ -939,79 +938,31 @@ enum ui_state_t { HOVERED, } -declare function UI_OUTPUTS_H(sockets_count: i32, length: i32 = -1): f32; declare function ui_tooltip_image(image: gpu_texture_t, max_width: i32 = 0); declare function ui_image(image: gpu_texture_t, tint: i32 = 0xffffffff, h: f32 = -1.0): ui_state_t; declare function ui_sub_image(image: gpu_texture_t, tint: i32 = 0xffffffff, h: f32 = -1.0, sx: i32 = 0, sy: i32 = 0, sw: i32 = 0, sh: i32 = 0): ui_state_t; declare function ui_window(handle: ui_handle_t, x: i32, y: i32, w: i32, h: i32, drag: bool = false): bool; -declare function ui_end(last: bool = true); - -let ui_children: map_t = map_create(); -let ui_nodes_custom_buttons: map_tvoid> = map_create(); - -function ui_SCALE(ui: ui_t): f32 { - let current: ui_t = ui_get_current(); - ui_set_current(ui); - let f: f32 = UI_SCALE(); - ui_set_current(current); - return f; -} - -function ui_ELEMENT_OFFSET(ui: ui_t): f32 { - let current: ui_t = ui_get_current(); - ui_set_current(ui); - let f: f32 = UI_ELEMENT_OFFSET(); - ui_set_current(current); - return f; -} - -function ui_ELEMENT_W(ui: ui_t): f32 { - let current: ui_t = ui_get_current(); - ui_set_current(ui); - let f: f32 = UI_ELEMENT_W(); - ui_set_current(current); - return f; -} - -function ui_ELEMENT_H(ui: ui_t): f32 { - let current: ui_t = ui_get_current(); - ui_set_current(ui); - let f: f32 = UI_ELEMENT_H(); - ui_set_current(current); - return f; -} +declare function ui_end(); +declare function ui_set_scale(factor: f32); +declare function ui_end_element(): void; +declare function ui_end_element_of_size(element_size: f32); +declare function UI_SCALE(): f32; +declare function UI_ELEMENT_OFFSET(): f32; +declare function UI_ELEMENT_W(): f32; +declare function UI_ELEMENT_H(): f32; +declare function UI_OUTPUTS_H(sockets_count: i32, length: i32 = -1): f32; function ui_MENUBAR_H(ui: ui_t): f32 { - let button_offset_y: f32 = (ui.ops.theme.ELEMENT_H * ui_SCALE(ui) - ui.ops.theme.BUTTON_H * ui_SCALE(ui)) / 2; - return ui.ops.theme.BUTTON_H * ui_SCALE(ui) * 1.1 + 2 + button_offset_y; + let button_offset_y: f32 = (ui.ops.theme.ELEMENT_H * UI_SCALE() - ui.ops.theme.BUTTON_H * UI_SCALE()) / 2; + return ui.ops.theme.BUTTON_H * UI_SCALE() * 1.1 + 2 + button_offset_y; } function ui_nodes_INPUT_Y(canvas: ui_node_canvas_t, sockets: ui_node_socket_t[], pos: i32): f32 { return UI_INPUT_Y(canvas, sockets.buffer, sockets.length, pos); } -function _ui_set_scale(ui: ui_t, factor: f32) { - let current: ui_t = ui_get_current(); - ui_set_current(ui); - ui_set_scale(factor); - ui_set_current(current); -} - -function _ui_end_element(element_size: f32 = -1.0) { - if (element_size < 0) { - ui_end_element(); - } - else { - ui_end_element_of_size(element_size); - } -} - -function _ui_end_input(ui: ui_t) { - let current: ui_t = ui_get_current(); - ui_set_current(ui); - ui_end_input(); - ui_set_current(current); -} +let ui_children: map_t = map_create(); +let ui_nodes_custom_buttons: map_tvoid> = map_create(); function ui_handle(s: string): ui_handle_t { let h: ui_handle_t = map_get(ui_children, s); diff --git a/base/sources/ts/nodes_material.ts b/base/sources/ts/nodes_material.ts index 25aa90f5..c26c1d88 100644 --- a/base/sources/ts/nodes_material.ts +++ b/base/sources/ts/nodes_material.ts @@ -3985,7 +3985,7 @@ function nodes_material_init() { } function nodes_material_vector_curves_button(node_id: i32) { - let ui: ui_t = ui_nodes_ui; + let ui: ui_t = ui_base_ui; let nodes: ui_nodes_t = ui_nodes_get_nodes(); let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); @@ -4053,7 +4053,7 @@ function nodes_material_vector_curves_button(node_id: i32) { } function nodes_material_color_ramp_button(node_id: i32) { - let ui: ui_t = ui_nodes_ui; + let ui: ui_t = ui_base_ui; let nodes: ui_nodes_t = ui_nodes_get_nodes(); let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); @@ -4120,7 +4120,7 @@ function nodes_material_color_ramp_button(node_id: i32) { let rx: f32 = nx + ui._w - ui_p(37); let ry: f32 = ny - ui_p(5); nodes._input_started = ui.input_started = false; - ui_nodes_rgba_popup(chandle, vals.buffer + i * 5, math_floor(rx), math_floor(ry + ui_ELEMENT_H(ui))); + ui_nodes_rgba_popup(chandle, vals.buffer + i * 5, math_floor(rx), math_floor(ry + UI_ELEMENT_H())); } vals[i * 5 + 0] = color_get_rb(chandle.color) / 255; vals[i * 5 + 1] = color_get_gb(chandle.color) / 255; @@ -4128,7 +4128,7 @@ function nodes_material_color_ramp_button(node_id: i32) { } function nodes_material_new_group_button(node_id: i32) { - let ui: ui_t = ui_nodes_ui; + let ui: ui_t = ui_base_ui; let nodes: ui_nodes_t = ui_nodes_get_nodes(); let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); @@ -4213,7 +4213,7 @@ function nodes_material_new_group_button(node_id: i32) { } function nodes_material_group_input_button(node_id: i32) { - let ui: ui_t = ui_nodes_ui; + let ui: ui_t = ui_base_ui; let nodes: ui_nodes_t = ui_nodes_get_nodes(); let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); @@ -4221,7 +4221,7 @@ function nodes_material_group_input_button(node_id: i32) { } function nodes_material_group_output_button(node_id: i32) { - let ui: ui_t = ui_nodes_ui; + let ui: ui_t = ui_base_ui; let nodes: ui_nodes_t = ui_nodes_get_nodes(); let node: ui_node_t = ui_get_node(ui_nodes_get_canvas(true).nodes, node_id); diff --git a/base/sources/ts/project.ts b/base/sources/ts/project.ts index fb95ff78..f8f9c394 100644 --- a/base/sources/ts/project.ts +++ b/base/sources/ts/project.ts @@ -128,7 +128,7 @@ function project_new_box() { let project_aspect_ratio_combo: string[] = ["1:1", "2:1", "1:2"]; context_raw.project_aspect_ratio = ui_combo(h_project_aspect_ratio, project_aspect_ratio_combo, tr("Aspect Ratio"), true); - _ui_end_element(); + ui_end_element(); ui_row2(); if (ui_button(tr("Cancel"))) { ui_box_hide(); diff --git a/base/sources/ts/tab_browser.ts b/base/sources/ts/tab_browser.ts index bd9d7836..412c0b44 100644 --- a/base/sources/ts/tab_browser.ts +++ b/base/sources/ts/tab_browser.ts @@ -15,13 +15,13 @@ function tab_browser_show_directory(directory: string) { function tab_browser_draw(htab: ui_handle_t) { let ui: ui_t = ui_base_ui; let statush: i32 = config_raw.layout[layout_size_t.STATUS_H]; - if (ui_tab(htab, tr("Browser")) && statush > ui_status_default_status_h * ui_SCALE(ui)) { + if (ui_tab(htab, tr("Browser")) && statush > ui_status_default_status_h * UI_SCALE()) { if (config_raw.bookmarks == null) { config_raw.bookmarks = []; } - let bookmarks_w: i32 = math_floor(100 * ui_SCALE(ui)); + let bookmarks_w: i32 = math_floor(100 * UI_SCALE()); if (tab_browser_hpath.text == "" && config_raw.bookmarks.length > 0) { // Init to first bookmark tab_browser_hpath.text = config_raw.bookmarks[0]; diff --git a/base/sources/ts/tab_brushes.ts b/base/sources/ts/tab_brushes.ts index 24d0d82d..1dde5baa 100644 --- a/base/sources/ts/tab_brushes.ts +++ b/base/sources/ts/tab_brushes.ts @@ -22,7 +22,7 @@ function tab_brushes_draw(htab: ui_handle_t) { ui_end_sticky(); ui_separator(3, false); - let slotw: i32 = math_floor(51 * ui_SCALE(ui)); + let slotw: i32 = math_floor(51 * UI_SCALE()); let num: i32 = math_floor(config_raw.layout[layout_size_t.SIDEBAR_W] / slotw); if (num == 0) { return; @@ -37,22 +37,22 @@ function tab_brushes_draw(htab: ui_handle_t) { ui_row(ar); ui._x += 2; - let off: f32 = config_raw.show_asset_names ? ui_ELEMENT_OFFSET(ui) * 10.0 : 6; + let off: f32 = config_raw.show_asset_names ? UI_ELEMENT_OFFSET() * 10.0 : 6; if (row > 0) { ui._y += off; } for (let j: i32 = 0; j < num; ++j) { - let imgw: i32 = math_floor(50 * ui_SCALE(ui)); + let imgw: i32 = math_floor(50 * UI_SCALE()); let i: i32 = j + row * num; if (i >= project_brushes.length) { - _ui_end_element(imgw); + ui_end_element_of_size(imgw); if (config_raw.show_asset_names) { - _ui_end_element(0); + ui_end_element_of_size(0); } continue; } - let img: gpu_texture_t = ui_SCALE(ui) > 1 ? project_brushes[i].image : project_brushes[i].image_icon; + let img: gpu_texture_t = UI_SCALE() > 1 ? project_brushes[i].image : project_brushes[i].image_icon; let img_full: gpu_texture_t = project_brushes[i].image; if (context_raw.brush == project_brushes[i]) { @@ -70,7 +70,7 @@ function tab_brushes_draw(htab: ui_handle_t) { let uix: f32 = ui._x; //let uiy: f32 = ui._y; - let tile: i32 = ui_SCALE(ui) > 1 ? 100 : 50; + let tile: i32 = UI_SCALE() > 1 ? 100 : 50; let state: ui_state_t = project_brushes[i].preview_ready ? ui_image(img) : ui_sub_image(resource_get("icons.k"), -1, -1.0, tile * 5, tile, tile, tile); if (state == ui_state_t.STARTED) { if (context_raw.brush != project_brushes[i]) { @@ -147,7 +147,7 @@ function tab_brushes_draw(htab: ui_handle_t) { } ui._y -= slotw * 0.9; if (i == project_brushes.length - 1) { - ui._y += j == num - 1 ? imgw : imgw + ui_ELEMENT_H(ui) + ui_ELEMENT_OFFSET(ui); + ui._y += j == num - 1 ? imgw : imgw + UI_ELEMENT_H() + UI_ELEMENT_OFFSET(); } } } diff --git a/base/sources/ts/tab_console.ts b/base/sources/ts/tab_console.ts index 187481da..d7e95571 100644 --- a/base/sources/ts/tab_console.ts +++ b/base/sources/ts/tab_console.ts @@ -6,7 +6,7 @@ function tab_console_draw(htab: ui_handle_t) { let color: i32 = console_message_timer > 0 ? console_message_color : -1; let statush: i32 = config_raw.layout[layout_size_t.STATUS_H]; - if (ui_tab(htab, title, false, color) && statush > ui_status_default_status_h * ui_SCALE(ui)) { + if (ui_tab(htab, title, false, color) && statush > ui_status_default_status_h * UI_SCALE()) { ui_begin_sticky(); ///if (arm_windows || arm_linux || arm_macos) // Copy @@ -59,7 +59,7 @@ function tab_console_draw(htab: ui_handle_t) { let _font_size: i32 = ui.font_size; let f: draw_font_t = data_get_font("font_mono.ttf"); ui_set_font(ui, f); - ui.font_size = math_floor(15 * ui_SCALE(ui)); + ui.font_size = math_floor(15 * UI_SCALE()); for (let i: i32 = 0; i < console_last_traces.length; ++i) { let t: string = console_last_traces[i]; ui_text(t); diff --git a/base/sources/ts/tab_fonts.ts b/base/sources/ts/tab_fonts.ts index ec8544be..affb3e71 100644 --- a/base/sources/ts/tab_fonts.ts +++ b/base/sources/ts/tab_fonts.ts @@ -4,7 +4,7 @@ let _tab_fonts_draw_i: i32; function tab_fonts_draw(htab: ui_handle_t) { let ui: ui_t = ui_base_ui; let statush: i32 = config_raw.layout[layout_size_t.STATUS_H]; - if (ui_tab(htab, tr("Fonts")) && statush > ui_status_default_status_h * ui_SCALE(ui)) { + if (ui_tab(htab, tr("Fonts")) && statush > ui_status_default_status_h * UI_SCALE()) { ui_begin_sticky(); if (config_raw.touch_ui) { @@ -30,7 +30,7 @@ function tab_fonts_draw(htab: ui_handle_t) { ui_separator(3, false); let statusw: i32 = iron_window_width() - ui_toolbar_w(true) - config_raw.layout[layout_size_t.SIDEBAR_W]; - let slotw: i32 = math_floor(51 * ui_SCALE(ui)); + let slotw: i32 = math_floor(51 * UI_SCALE()); let num: i32 = math_floor(statusw / slotw); if (num == 0) { return; @@ -45,18 +45,18 @@ function tab_fonts_draw(htab: ui_handle_t) { ui_row(ar); ui._x += 2; - let off: f32 = config_raw.show_asset_names ? ui_ELEMENT_OFFSET(ui) * 10.0 : 6; + let off: f32 = config_raw.show_asset_names ? UI_ELEMENT_OFFSET() * 10.0 : 6; if (row > 0) { ui._y += off; } for (let j: i32 = 0; j < num; ++j) { - let imgw: i32 = math_floor(50 * ui_SCALE(ui)); + let imgw: i32 = math_floor(50 * UI_SCALE()); let i: i32 = j + row * num; if (i >= project_fonts.length) { - _ui_end_element(imgw); + ui_end_element_of_size(imgw); if (config_raw.show_asset_names) { - _ui_end_element(0); + ui_end_element_of_size(0); } continue; } @@ -76,7 +76,7 @@ function tab_fonts_draw(htab: ui_handle_t) { } let uix: f32 = ui._x; - let tile: i32 = ui_SCALE(ui) > 1 ? 100 : 50; + let tile: i32 = UI_SCALE() > 1 ? 100 : 50; let state: ui_state_t = ui_state_t.IDLE; if (project_fonts[i].preview_ready) { // draw_set_pipeline(pipe); // L8 @@ -143,7 +143,7 @@ function tab_fonts_draw(htab: ui_handle_t) { } ui._y -= slotw * 0.9; if (i == project_fonts.length - 1) { - ui._y += j == num - 1 ? imgw : imgw + ui_ELEMENT_H(ui) + ui_ELEMENT_OFFSET(ui); + ui._y += j == num - 1 ? imgw : imgw + UI_ELEMENT_H() + UI_ELEMENT_OFFSET(); } } } diff --git a/base/sources/ts/tab_history.ts b/base/sources/ts/tab_history.ts index ecd8dadb..a60b4d6b 100644 --- a/base/sources/ts/tab_history.ts +++ b/base/sources/ts/tab_history.ts @@ -19,7 +19,7 @@ function tab_history_draw(htab: ui_handle_t) { history_undo(); } } - ui_fill(0, 0, (ui._window_w / ui_SCALE(ui) - 2), 1 * ui_SCALE(ui), ui.ops.theme.SEPARATOR_COL); + ui_fill(0, 0, (ui._window_w / UI_SCALE() - 2), 1 * UI_SCALE(), ui.ops.theme.SEPARATOR_COL); } } } diff --git a/base/sources/ts/tab_layers.ts b/base/sources/ts/tab_layers.ts index 7e2a4517..563b6a14 100644 --- a/base/sources/ts/tab_layers.ts +++ b/base/sources/ts/tab_layers.ts @@ -15,7 +15,7 @@ function tab_layers_draw_mini(htab: ui_handle_t) { ui_set_hovered_tab_name(tr("Layers")); let _ELEMENT_H: i32 = ui.ops.theme.ELEMENT_H; - ui.ops.theme.ELEMENT_H = math_floor(ui_base_sidebar_mini_w / 2 / ui_SCALE(ui)); + ui.ops.theme.ELEMENT_H = math_floor(ui_base_sidebar_mini_w / 2 / UI_SCALE()); ui_begin_sticky(); ui_separator(5); @@ -79,7 +79,7 @@ function tab_layers_highlight_odd_lines() { let full_h: i32 = ui._window_h - ui_base_hwnds[0].scroll_offset; for (let i: i32 = 0; i < math_floor(full_h / step); ++i) { if (i % 2 == 0) { - ui_fill(0, i * step, (ui._w / ui_SCALE(ui) - 2), step, ui.ops.theme.WINDOW_BG_COL - 0x00040404); + ui_fill(0, i * step, (ui._w / UI_SCALE() - 2), step, ui.ops.theme.WINDOW_BG_COL - 0x00040404); } } } @@ -270,7 +270,7 @@ function tab_layers_draw_layer_slot(l: slot_layer_t, i: i32, mini: bool) { } let step: i32 = ui.ops.theme.ELEMENT_H; - let checkw: f32 = (ui._window_w / 100 * 8) / ui_SCALE(ui); + let checkw: f32 = (ui._window_w / 100 * 8) / UI_SCALE(); // Highlight drag destination let absy: f32 = ui._window_y + ui._y; @@ -285,14 +285,14 @@ function tab_layers_draw_layer_slot(l: slot_layer_t, i: i32, mini: bool) { let nested_group: bool = slot_layer_is_group(base_drag_layer) && to_group; if (!nested_group) { if (slot_layer_can_move(context_raw.layer, context_raw.drag_dest)) { - ui_fill(checkw, step * 2, (ui._window_w / ui_SCALE(ui) - 2) - checkw, 2 * ui_SCALE(ui), ui.ops.theme.HIGHLIGHT_COL); + ui_fill(checkw, step * 2, (ui._window_w / UI_SCALE() - 2) - checkw, 2 * UI_SCALE(), ui.ops.theme.HIGHLIGHT_COL); } } } else if (i == project_layers.length - 1 && mouse_y < absy + step) { context_raw.drag_dest = project_layers.length - 1; if (slot_layer_can_move(context_raw.layer, context_raw.drag_dest)) { - ui_fill(checkw, 0, (ui._window_w / ui_SCALE(ui) - 2) - checkw, 2 * ui_SCALE(ui), ui.ops.theme.HIGHLIGHT_COL); + ui_fill(checkw, 0, (ui._window_w / UI_SCALE() - 2) - checkw, 2 * UI_SCALE(), ui.ops.theme.HIGHLIGHT_COL); } } } @@ -300,13 +300,13 @@ function tab_layers_draw_layer_slot(l: slot_layer_t, i: i32, mini: bool) { if (mouse_y > absy + step && mouse_y < absy + step * 3) { context_raw.drag_dest = i; if (tab_layers_can_drop_new_layer(i)) { - ui_fill(checkw, 2 * step, (ui._window_w / ui_SCALE(ui) - 2) - checkw, 2 * ui_SCALE(ui), ui.ops.theme.HIGHLIGHT_COL); + ui_fill(checkw, 2 * step, (ui._window_w / UI_SCALE() - 2) - checkw, 2 * UI_SCALE(), ui.ops.theme.HIGHLIGHT_COL); } } else if (i == project_layers.length - 1 && mouse_y < absy + step) { context_raw.drag_dest = project_layers.length; if (tab_layers_can_drop_new_layer(project_layers.length)) { - ui_fill(checkw, 0, (ui._window_w / ui_SCALE(ui) - 2) - checkw, 2 * ui_SCALE(ui), ui.ops.theme.HIGHLIGHT_COL); + ui_fill(checkw, 0, (ui._window_w / UI_SCALE() - 2) - checkw, 2 * UI_SCALE(), ui.ops.theme.HIGHLIGHT_COL); } } } @@ -329,10 +329,10 @@ function tab_layers_draw_layer_slot_mini(l: slot_layer_t, i: i32) { let uiy: f32 = ui._y; let state: ui_state_t = tab_layers_draw_layer_icon(l, i, uix, uiy, true); tab_layers_handle_layer_icon_state(l, i, state, uix, uiy); - _ui_end_element(); + ui_end_element(); - ui._y += ui_ELEMENT_H(ui); - ui._y -= ui_ELEMENT_OFFSET(ui); + ui._y += UI_ELEMENT_H(); + ui._y -= UI_ELEMENT_OFFSET(); } function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { @@ -354,7 +354,7 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { // Draw eye icon let icons: gpu_texture_t = resource_get("icons.k"); let r: rect_t = resource_tile18(icons, l.visible ? 0 : 1, 0); - let center: f32 = (step / 2) * ui_SCALE(ui); + let center: f32 = (step / 2) * UI_SCALE(); ui._x += 2; ui._y += 3; ui._y += center; @@ -376,8 +376,8 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { ui._x += 2; ui._y += 3; if (l.parent != null) { - ui._x += 10 * ui_SCALE(ui); - if (l.parent.parent != null) ui._x += 10 * ui_SCALE(ui); + ui._x += 10 * UI_SCALE(); + if (l.parent.parent != null) ui._x += 10 * UI_SCALE(); } let state: ui_state_t = tab_layers_draw_layer_icon(l, i, uix, uiy, false); @@ -386,7 +386,7 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { ui._y -= 3; if (config_raw.touch_ui) { - ui._x += 12 * ui_SCALE(ui); + ui._x += 12 * UI_SCALE(); } tab_layers_handle_layer_icon_state(l, i, state, uix, uiy); @@ -403,7 +403,7 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { else { if (ui.enabled && ui.input_enabled && ui.combo_selected_handle == null && ui.input_x > ui._window_x + ui._x && ui.input_x < ui._window_x + uiw && - ui.input_y > ui._window_y + ui._y - center && ui.input_y < ui._window_y + ui._y - center + (step * ui_SCALE(ui)) * 2) { + ui.input_y > ui._window_y + ui._y - center && ui.input_y < ui._window_y + ui._y - center + (step * UI_SCALE()) * 2) { if (ui.input_started) { context_set_layer(l); tab_layers_set_drag_layer(context_raw.layer, -(mouse_x - uix - ui._window_x - 3), -(mouse_y - uiy - ui._window_y + 1)); @@ -436,12 +436,12 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { ui._y -= center; if (l.parent != null) { - ui._x -= 10 * ui_SCALE(ui); - if (l.parent.parent != null) ui._x -= 10 * ui_SCALE(ui); + ui._x -= 10 * UI_SCALE(); + if (l.parent.parent != null) ui._x -= 10 * UI_SCALE(); } if (slot_layer_is_group(l)) { - _ui_end_element(); + ui_end_element(); } else { if (slot_layer_is_mask(l)) { @@ -464,27 +464,27 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { } if (slot_layer_is_group(l) || slot_layer_is_mask(l)) { - ui._y -= ui_ELEMENT_OFFSET(ui); - _ui_end_element(); + ui._y -= UI_ELEMENT_OFFSET(); + ui_end_element(); } else { - ui._y -= ui_ELEMENT_OFFSET(ui); + ui._y -= UI_ELEMENT_OFFSET(); let row: f32[] = [8 / 100, 16 / 100, 36 / 100, 30 / 100, 10 / 100]; ui_row(row); - _ui_end_element(); - _ui_end_element(); - _ui_end_element(); + ui_end_element(); + ui_end_element(); + ui_end_element(); if (config_raw.touch_ui) { - ui._x += 12 * ui_SCALE(ui); + ui._x += 12 * UI_SCALE(); } tab_layers_combo_object(ui, l); - _ui_end_element(); + ui_end_element(); } - ui._y -= ui_ELEMENT_OFFSET(ui); + ui._y -= UI_ELEMENT_OFFSET(); } function tab_layers_combo_object(ui: ui_t, l: slot_layer_t, label: bool = false): ui_handle_t { @@ -564,15 +564,15 @@ function tab_layers_draw_layer_highlight(l: slot_layer_t, mini: bool) { let step: i32 = ui.ops.theme.ELEMENT_H; // Separator line - ui_fill(0, 0, (ui._w / ui_SCALE(ui) - 2), 1 * ui_SCALE(ui), ui.ops.theme.SEPARATOR_COL); + ui_fill(0, 0, (ui._w / UI_SCALE() - 2), 1 * UI_SCALE(), ui.ops.theme.SEPARATOR_COL); // Highlight selected if (context_raw.layer == l) { if (mini) { - ui_rect(1, -step * 2, ui._w / ui_SCALE(ui) - 1, step * 2 + (mini ? -1 : 1), ui.ops.theme.HIGHLIGHT_COL, 3); + ui_rect(1, -step * 2, ui._w / UI_SCALE() - 1, step * 2 + (mini ? -1 : 1), ui.ops.theme.HIGHLIGHT_COL, 3); } else { - ui_rect(1, -step * 2 - 1, ui._w / ui_SCALE(ui) - 2, step * 2 + (mini ? -2 : 1), ui.ops.theme.HIGHLIGHT_COL, 2); + ui_rect(1, -step * 2 - 1, ui._w / UI_SCALE() - 2, step * 2 + (mini ? -2 : 1), ui.ops.theme.HIGHLIGHT_COL, 2); } } } @@ -628,10 +628,10 @@ function tab_layers_handle_layer_icon_state(l: slot_layer_t, i: i32, state: ui_s function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, mini: bool): ui_state_t { let ui: ui_t = ui_base_ui; let icons: gpu_texture_t = resource_get("icons.k"); - let icon_h: i32 = (ui_ELEMENT_H(ui) - (mini ? 2 : 3)) * 2; + let icon_h: i32 = (UI_ELEMENT_H() - (mini ? 2 : 3)) * 2; - if (mini && ui_SCALE(ui) > 1) { - ui._x -= 1 * ui_SCALE(ui); + if (mini && UI_SCALE() > 1) { + ui._x -= 1 * UI_SCALE(); } if (l.parent != null) { @@ -671,7 +671,7 @@ function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, } // Draw layer numbers when selecting a layer via keyboard shortcut - let is_typing: bool = ui.is_typing || ui_view2d_ui.is_typing || ui_nodes_ui.is_typing; + let is_typing: bool = ui.is_typing; if (!is_typing) { if (i < 9 && operator_shortcut(map_get(config_keymap, "select_layer"), shortcut_type_t.DOWN)) { let number: string = i32_to_string(i + 1) ; @@ -891,7 +891,7 @@ function tab_layers_draw_layer_context_menu(l: slot_layer_t, mini: bool) { } ui._y = _y; ui_draw_string(tr("Res"), -1, 0, ui_align_t.RIGHT, true); - _ui_end_element(); + ui_end_element(); ui_menu_align(ui); ///if (arm_android || arm_ios) diff --git a/base/sources/ts/tab_materials.ts b/base/sources/ts/tab_materials.ts index fb3367d0..feddca9e 100644 --- a/base/sources/ts/tab_materials.ts +++ b/base/sources/ts/tab_materials.ts @@ -50,7 +50,7 @@ function tab_materials_button_nodes() { function tab_materials_draw_slots(mini: bool) { let ui: ui_t = ui_base_ui; - let slotw: i32 = math_floor(51 * ui_SCALE(ui)); + let slotw: i32 = math_floor(51 * UI_SCALE()); let num: i32 = math_floor(config_raw.layout[layout_size_t.SIDEBAR_W] / slotw); if (num == 0) { return; @@ -65,28 +65,28 @@ function tab_materials_draw_slots(mini: bool) { ui_row(ar); ui._x += 2; - let off: f32 = config_raw.show_asset_names ? ui_ELEMENT_OFFSET(ui) * 10.0 : 6; + let off: f32 = config_raw.show_asset_names ? UI_ELEMENT_OFFSET() * 10.0 : 6; if (row > 0) { ui._y += off; } for (let j: i32 = 0; j < num; ++j) { - let imgw: i32 = math_floor(50 * ui_SCALE(ui)); + let imgw: i32 = math_floor(50 * UI_SCALE()); let i: i32 = j + row * num; if (i >= project_materials.length) { - _ui_end_element(imgw); + ui_end_element_of_size(imgw); if (config_raw.show_asset_names) { - _ui_end_element(0); + ui_end_element_of_size(0); } continue; } - let img: gpu_texture_t = ui_SCALE(ui) > 1 ? project_materials[i].image : project_materials[i].image_icon; + let img: gpu_texture_t = UI_SCALE() > 1 ? project_materials[i].image : project_materials[i].image_icon; let img_full: gpu_texture_t = project_materials[i].image; // Highligh selected if (context_raw.material == project_materials[i]) { if (mini) { - let w: f32 = ui._w / ui_SCALE(ui); + let w: f32 = ui._w / UI_SCALE(); ui_rect(0, -2, w - 2, w - 4, ui.ops.theme.HIGHLIGHT_COL, 3); } else { @@ -105,14 +105,14 @@ function tab_materials_draw_slots(mini: bool) { // Draw material icon let uix: f32 = ui._x; let uiy: f32 = ui._y; - let tile: i32 = ui_SCALE(ui) > 1 ? 100 : 50; - let imgh: f32 = mini ? ui_base_default_sidebar_mini_w * 0.85 * ui_SCALE(ui) : -1.0; + let tile: i32 = UI_SCALE() > 1 ? 100 : 50; + let imgh: f32 = mini ? ui_base_default_sidebar_mini_w * 0.85 * UI_SCALE() : -1.0; let state: ui_state_t = project_materials[i].preview_ready ? ui_image(img, 0xffffffff, imgh) : ui_sub_image(resource_get("icons.k"), 0xffffffff, -1.0, tile, tile, tile, tile); // Draw material numbers when selecting a material via keyboard shortcut - let is_typing: bool = ui.is_typing || ui_view2d_ui.is_typing || ui_nodes_ui.is_typing; + let is_typing: bool = ui.is_typing; if (!is_typing) { if (i < 9 && operator_shortcut(map_get(config_keymap, "select_material"), shortcut_type_t.DOWN)) { let number: string = i32_to_string(i + 1); @@ -284,7 +284,7 @@ function tab_materials_draw_slots(mini: bool) { } ui._y -= slotw * 0.9; if (i == project_materials.length - 1) { - ui._y += j == num - 1 ? imgw : imgw + ui_ELEMENT_H(ui) + ui_ELEMENT_OFFSET(ui); + ui._y += j == num - 1 ? imgw : imgw + UI_ELEMENT_H() + UI_ELEMENT_OFFSET(); } } } diff --git a/base/sources/ts/tab_meshes.ts b/base/sources/ts/tab_meshes.ts index 7b18d77d..82520326 100644 --- a/base/sources/ts/tab_meshes.ts +++ b/base/sources/ts/tab_meshes.ts @@ -4,7 +4,7 @@ let _tab_meshes_draw_i: i32; function tab_meshes_draw(htab: ui_handle_t) { let ui: ui_t = ui_base_ui; let statush: i32 = config_raw.layout[layout_size_t.STATUS_H]; - if (ui_tab(htab, tr("Meshes")) && statush > ui_status_default_status_h * ui_SCALE(ui)) { + if (ui_tab(htab, tr("Meshes")) && statush > ui_status_default_status_h * UI_SCALE()) { ui_begin_sticky(); @@ -331,7 +331,7 @@ function tab_meshes_draw(htab: ui_handle_t) { let _font_size: i32 = ui.font_size; let fmono: draw_font_t = data_get_font("font_mono.ttf"); ui_set_font(ui, fmono); - ui.font_size = math_floor(15 * ui_SCALE(ui)); + ui.font_size = math_floor(15 * UI_SCALE()); ui_text_area_coloring = tab_scripts_get_text_coloring(); ui_text_area(hscript); ui_text_area_coloring = null; @@ -455,14 +455,14 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: // Highlight every other line if (tab_scene_line_counter % 2 == 0) { draw_set_color(ui.ops.theme.SEPARATOR_COL); - draw_filled_rect(0, ui._y, ui._window_w, ui_ELEMENT_H(ui)); + draw_filled_rect(0, ui._y, ui._window_w, UI_ELEMENT_H()); draw_set_color(0xffffffff); } // Highlight selected line if (current_object == context_raw.selected_object) { draw_set_color(0xff205d9c); - draw_filled_rect(0, ui._y, ui._window_w, ui_ELEMENT_H(ui)); + draw_filled_rect(0, ui._y, ui._window_w, UI_ELEMENT_H()); draw_set_color(0xffffffff); } @@ -481,7 +481,7 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: // Draw line that shows parent relations draw_set_color(ui.ops.theme.BUTTON_COL); - draw_line(ui._x - 10, ui._y + ui_ELEMENT_H(ui) / 2, ui._x, ui._y + ui_ELEMENT_H(ui) / 2); + draw_line(ui._x - 10, ui._y + UI_ELEMENT_H() / 2, ui._x, ui._y + UI_ELEMENT_H() / 2); draw_set_color(0xffffffff); ui_text(current_object.name); @@ -490,7 +490,7 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: tab_scene_line_counter++; // Undo applied offset for row drawing caused by end_element() - ui._y -= ui_ELEMENT_OFFSET(ui); + ui._y -= UI_ELEMENT_OFFSET(); if (ui.is_released) { tab_scene_select_object(current_object.ext); @@ -520,7 +520,7 @@ function tab_scene_draw_list(ui: ui_t, list_handle: ui_handle_t, current_object: // Draw line that shows parent relations draw_set_color(ui.ops.theme.BUTTON_COL); - draw_line(ui._x + 14, current_y, ui._x + 14, ui._y - ui_ELEMENT_H(ui) / 2); + draw_line(ui._x + 14, current_y, ui._x + 14, ui._y - UI_ELEMENT_H() / 2); draw_set_color(0xffffffff); } } @@ -577,7 +577,7 @@ function tab_scene_draw(htab: ui_handle_t) { ui_end_sticky(); { - ui._y -= ui_ELEMENT_OFFSET(ui); + ui._y -= UI_ELEMENT_OFFSET(); tab_scene_line_counter = 0; diff --git a/base/sources/ts/tab_scripts.ts b/base/sources/ts/tab_scripts.ts index 39eec552..c868a45e 100644 --- a/base/sources/ts/tab_scripts.ts +++ b/base/sources/ts/tab_scripts.ts @@ -55,7 +55,7 @@ function tab_scripts_draw(htab: ui_handle_t) { let _font_size: i32 = ui.font_size; let f: draw_font_t = data_get_font("font_mono.ttf"); ui_set_font(ui, f); - ui.font_size = math_floor(15 * ui_SCALE(ui)); + ui.font_size = math_floor(15 * UI_SCALE()); ui_text_area_line_numbers = true; ui_text_area_scroll_past_end = true; ui_text_area_coloring = tab_scripts_get_text_coloring(); diff --git a/base/sources/ts/tab_swatches.ts b/base/sources/ts/tab_swatches.ts index 4ff9ddd5..86fe6a78 100644 --- a/base/sources/ts/tab_swatches.ts +++ b/base/sources/ts/tab_swatches.ts @@ -22,7 +22,7 @@ function tab_swatches_empty_get(): gpu_texture_t { function tab_swatches_draw(htab: ui_handle_t) { let ui: ui_t = ui_base_ui; let statush: i32 = config_raw.layout[layout_size_t.STATUS_H]; - if (ui_tab(htab, tr("Swatches")) && statush > ui_status_default_status_h * ui_SCALE(ui)) { + if (ui_tab(htab, tr("Swatches")) && statush > ui_status_default_status_h * UI_SCALE()) { ui_begin_sticky(); if (config_raw.touch_ui) { @@ -80,7 +80,7 @@ function tab_swatches_draw(htab: ui_handle_t) { ui_end_sticky(); ui_separator(3, false); - let slotw: i32 = math_floor(26 * ui_SCALE(ui)); + let slotw: i32 = math_floor(26 * UI_SCALE()); let num: i32 = math_floor(ui._w / (slotw + 3)); if (num == 0) { return; @@ -104,7 +104,7 @@ function tab_swatches_draw(htab: ui_handle_t) { for (let j: i32 = 0; j < num; ++j) { let i: i32 = j + row * num; if (i >= project_raw.swatches.length) { - _ui_end_element(slotw); + ui_end_element_of_size(slotw); continue; } @@ -144,7 +144,7 @@ function tab_swatches_draw(htab: ui_handle_t) { let h: ui_handle_t = ui_handle(__ID__); h.color = context_raw.swatch.base; - context_raw.swatch.base = ui_color_wheel(h, false, -1, 11 * ui.ops.theme.ELEMENT_H * ui_SCALE(ui), true, function () { + context_raw.swatch.base = ui_color_wheel(h, false, -1, 11 * ui.ops.theme.ELEMENT_H * UI_SCALE(), true, function () { context_raw.color_picker_previous_tool = context_raw.tool; context_select_tool(tool_type_t.PICKER); diff --git a/base/sources/ts/tab_textures.ts b/base/sources/ts/tab_textures.ts index b7c05c2d..52328f8e 100644 --- a/base/sources/ts/tab_textures.ts +++ b/base/sources/ts/tab_textures.ts @@ -8,7 +8,7 @@ let _tab_textures_draw_is_packed: bool; function tab_textures_draw(htab: ui_handle_t) { let ui: ui_t = ui_base_ui; let statush: i32 = config_raw.layout[layout_size_t.STATUS_H]; - if (ui_tab(htab, tr("Textures")) && statush > ui_status_default_status_h * ui_SCALE(ui)) { + if (ui_tab(htab, tr("Textures")) && statush > ui_status_default_status_h * UI_SCALE()) { ui_begin_sticky(); @@ -46,7 +46,7 @@ function tab_textures_draw(htab: ui_handle_t) { let statusw: i32 = iron_window_width(); ///end - let slotw: i32 = math_floor(52 * ui_SCALE(ui)); + let slotw: i32 = math_floor(52 * UI_SCALE()); let num: i32 = math_floor(statusw / slotw); if (num == 0) { return; @@ -61,18 +61,18 @@ function tab_textures_draw(htab: ui_handle_t) { ui_row(ar); ui._x += 2; - let off: f32 = config_raw.show_asset_names ? ui_ELEMENT_OFFSET(ui) * 10.0 : 6; + let off: f32 = config_raw.show_asset_names ? UI_ELEMENT_OFFSET() * 10.0 : 6; if (row > 0) { ui._y += off; } for (let j: i32 = 0; j < num; ++j) { - let imgw: i32 = math_floor(50 * ui_SCALE(ui)); + let imgw: i32 = math_floor(50 * UI_SCALE()); let i: i32 = j + row * num; if (i >= project_assets.length) { - _ui_end_element(imgw); + ui_end_element_of_size(imgw); if (config_raw.show_asset_names) { - _ui_end_element(0); + ui_end_element_of_size(0); } continue; } @@ -213,7 +213,7 @@ function tab_textures_draw(htab: ui_handle_t) { } ui._y -= slotw * 0.9; if (i == project_assets.length - 1) { - ui._y += j == num - 1 ? imgw : imgw + ui_ELEMENT_H(ui) + ui_ELEMENT_OFFSET(ui); + ui._y += j == num - 1 ? imgw : imgw + UI_ELEMENT_H() + UI_ELEMENT_OFFSET(); } } } diff --git a/base/sources/ts/translator.ts b/base/sources/ts/translator.ts index 5154386e..da5a2108 100644 --- a/base/sources/ts/translator.ts +++ b/base/sources/ts/translator.ts @@ -166,12 +166,9 @@ function translator_init_font(cjk: bool, font_path: string, font_scale: f32) { // Scale up the font size and elements width a bit base_theme.FONT_SIZE = math_floor(base_default_font_size * font_scale); base_theme.ELEMENT_W = math_floor(base_default_element_w * (config_raw.locale != "en" ? 1.4 : 1.0)); - let uis: ui_t[] = base_get_uis(); - for (let i: i32 = 0; i < uis.length; ++i) { - let ui: ui_t = uis[i]; - ui_set_font(ui, f); - _ui_set_scale(ui, ui_SCALE(ui)); - } + + ui_set_font(ui_base_ui, f); + ui_set_scale(UI_SCALE()); }); } diff --git a/base/sources/ts/ui_base.ts b/base/sources/ts/ui_base.ts index 001b6129..7d8b2972 100644 --- a/base/sources/ts/ui_base.ts +++ b/base/sources/ts/ui_base.ts @@ -4,8 +4,8 @@ type tab_draw_t = { }; type tab_draw_array_t = tab_draw_t[]; -let ui_base_show: bool = true; let ui_base_ui: ui_t; +let ui_base_show: bool = true; let ui_base_border_started: i32 = 0; let ui_base_border_handle: ui_handle_t = null; let ui_base_action_paint_remap: string = ""; @@ -181,7 +181,7 @@ function ui_base_init() { resource_load(resources); - if (ui_SCALE(ui_base_ui) > 1) { + if (UI_SCALE() > 1) { ui_base_set_icon_scale(); } @@ -217,7 +217,7 @@ function ui_base_update() { return; } - if (!ui_nodes_ui.is_typing && !ui_base_ui.is_typing) { + if (!ui_base_ui.is_typing) { if (operator_shortcut(map_get(config_keymap, "toggle_node_editor"))) { ///if is_paint ui_nodes_canvas_type == canvas_type_t.MATERIAL ? ui_base_show_material_nodes() : ui_base_show_brush_nodes(); @@ -356,7 +356,7 @@ function ui_base_update() { } ///end - let is_typing: bool = ui_base_ui.is_typing || ui_view2d_ui.is_typing || ui_nodes_ui.is_typing; + let is_typing: bool = ui_base_ui.is_typing; ///if is_paint if (!is_typing) { @@ -563,7 +563,7 @@ function ui_base_update() { viewport_zoom(-0.2); } else if (operator_shortcut(map_get(config_keymap, "viewport_mode"))) { - base_ui_menu.is_key_pressed = false; + ui_base_ui.is_key_pressed = false; ui_menu_draw(function (ui: ui_t) { let mode_handle: ui_handle_t = ui_handle(__ID__); mode_handle.position = context_raw.viewport_mode; @@ -762,7 +762,7 @@ function ui_base_update() { } function ui_base_view_top() { - let is_typing: bool = ui_base_ui.is_typing || ui_view2d_ui.is_typing || ui_nodes_ui.is_typing; + let is_typing: bool = ui_base_ui.is_typing; if (context_in_paint_area() && !is_typing) { if (mouse_view_x() < sys_w()) { @@ -775,7 +775,7 @@ function ui_base_operator_search() { _ui_base_operator_search_first = true; ui_menu_draw(function (ui: ui_t) { - ui_menu_h = ui_ELEMENT_H(ui) * 8; + ui_menu_h = UI_ELEMENT_H() * 8; let search_handle: ui_handle_t = ui_handle(__ID__); let search: string = ui_text_input(search_handle, "", ui_align_t.LEFT, true, true); ui.changed = false; @@ -862,7 +862,7 @@ function ui_base_update_ui() { } } - ui_base_sidebar_mini_w = math_floor(ui_base_default_sidebar_mini_w * ui_SCALE(ui_base_ui)); + ui_base_sidebar_mini_w = math_floor(ui_base_default_sidebar_mini_w * UI_SCALE()); if (!base_ui_enabled) { return; @@ -1150,7 +1150,7 @@ function ui_base_render() { if (!ui_base_show && config_raw.touch_ui) { ui_base_ui.input_enabled = true; ui_begin(ui_base_ui); - if (ui_window(ui_handle(__ID__), 0, 0, 150, math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui) + 1))) { + if (ui_window(ui_handle(__ID__), 0, 0, 150, math_floor(UI_ELEMENT_H() + UI_ELEMENT_OFFSET() + 1))) { if (ui_button(tr("Close"))) { ui_base_toggle_distract_free(); } @@ -1191,12 +1191,14 @@ function ui_base_render() { ///end ui_end(); + + ui_base_ui.input_enabled = true; } function ui_base_draw_sidebar() { // Tabs let mini: bool = config_raw.layout[layout_size_t.SIDEBAR_W] <= ui_base_sidebar_mini_w; - let expand_button_offset: i32 = config_raw.touch_ui ? math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui)) : 0; + let expand_button_offset: i32 = config_raw.touch_ui ? math_floor(UI_ELEMENT_H() + UI_ELEMENT_OFFSET()) : 0; ui_base_tabx = iron_window_width() - config_raw.layout[layout_size_t.SIDEBAR_W]; let _SCROLL_W: i32 = ui_base_ui.ops.theme.SCROLL_W; @@ -1223,7 +1225,7 @@ function ui_base_draw_sidebar() { // Collapse / expand button for mini sidebar if (config_raw.touch_ui) { let width: i32 = config_raw.layout[layout_size_t.SIDEBAR_W]; - let height: i32 = math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui)); + let height: i32 = math_floor(UI_ELEMENT_H() + UI_ELEMENT_OFFSET()); if (ui_window(ui_handle(__ID__), iron_window_width() - width, iron_window_height() - height, width, height + 1)) { ui_base_ui._w = width; let _BUTTON_H: i32 = ui_base_ui.ops.theme.BUTTON_H; @@ -1232,7 +1234,7 @@ function ui_base_draw_sidebar() { ui_base_ui.ops.theme.BUTTON_COL = ui_base_ui.ops.theme.WINDOW_BG_COL; if (ui_button(mini ? "<<" : ">>")) { config_raw.layout[layout_size_t.SIDEBAR_W] = mini ? ui_base_default_sidebar_full_w : ui_base_default_sidebar_mini_w; - config_raw.layout[layout_size_t.SIDEBAR_W] = math_floor(config_raw.layout[layout_size_t.SIDEBAR_W] * ui_SCALE(ui_base_ui)); + config_raw.layout[layout_size_t.SIDEBAR_W] = math_floor(config_raw.layout[layout_size_t.SIDEBAR_W] * UI_SCALE()); } ui_base_ui.ops.theme.BUTTON_H = _BUTTON_H; ui_base_ui.ops.theme.BUTTON_COL = _BUTTON_COL; @@ -1241,8 +1243,8 @@ function ui_base_draw_sidebar() { // Expand button if (config_raw.layout[layout_size_t.SIDEBAR_W] == 0) { - let width: i32 = math_floor(draw_string_width(ui_base_ui.ops.font, ui_base_ui.font_size, "<<") + 25 * ui_SCALE(ui_base_ui)); - if (ui_window(ui_base_hminimized, iron_window_width() - width, 0, width, math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui) + 1))) { + let width: i32 = math_floor(draw_string_width(ui_base_ui.ops.font, ui_base_ui.font_size, "<<") + 25 * UI_SCALE()); + if (ui_window(ui_base_hminimized, iron_window_width() - width, 0, width, math_floor(UI_ELEMENT_H() + UI_ELEMENT_OFFSET() + 1))) { ui_base_ui._w = width; let _BUTTON_H: i32 = ui_base_ui.ops.theme.BUTTON_H; let _BUTTON_COL: i32 = ui_base_ui.ops.theme.BUTTON_COL; @@ -1337,7 +1339,7 @@ function ui_base_render_cursor() { } let cursor_img: gpu_texture_t = resource_get("cursor.k"); - let psize: i32 = math_floor(182 * (context_raw.brush_radius * context_raw.brush_nodes_radius) * ui_SCALE(ui_base_ui)); + let psize: i32 = math_floor(182 * (context_raw.brush_radius * context_raw.brush_nodes_radius) * UI_SCALE()); // Clone source cursor if (context_raw.tool == tool_type_t.CLONE && !keyboard_down("alt") && (mouse_down() || pen_down())) { @@ -1365,8 +1367,8 @@ function ui_base_render_cursor() { } if (!config_raw.brush_live) { - let psizex: i32 = math_floor(256 * ui_SCALE(ui_base_ui) * (context_raw.brush_radius * context_raw.brush_nodes_radius * context_raw.brush_scale_x)); - let psizey: i32 = math_floor(256 * ui_SCALE(ui_base_ui) * (context_raw.brush_radius * context_raw.brush_nodes_radius)); + let psizex: i32 = math_floor(256 * UI_SCALE() * (context_raw.brush_radius * context_raw.brush_nodes_radius * context_raw.brush_scale_x)); + let psizey: i32 = math_floor(256 * UI_SCALE() * (context_raw.brush_radius * context_raw.brush_nodes_radius)); context_raw.view_index = context_raw.view_index_last; let decalx: f32 = base_x() + context_raw.decal_x * base_w() - psizex / 2; @@ -1390,7 +1392,7 @@ function ui_base_render_cursor() { (decal_mask && !config_raw.brush_3d) || (decal_mask && context_in_2d_view())) { if (decal_mask) { - psize = math_floor(cursor_img.width * (context_raw.brush_decal_mask_radius * context_raw.brush_nodes_radius) * ui_SCALE(ui_base_ui)); + psize = math_floor(cursor_img.width * (context_raw.brush_decal_mask_radius * context_raw.brush_nodes_radius) * UI_SCALE()); } if (config_raw.brush_3d && context_in_2d_view()) { psize = math_floor(psize * ui_view2d_pan_scale); @@ -1421,7 +1423,7 @@ function ui_base_render_cursor() { function ui_base_show_material_nodes() { // Clear input state as ui receives input events even when not drawn - _ui_end_input(ui_nodes_ui); + ui_end_input(); ///if is_paint ui_nodes_show = !ui_nodes_show || ui_nodes_canvas_type != canvas_type_t.MATERIAL; @@ -1436,7 +1438,7 @@ function ui_base_show_material_nodes() { function ui_base_show_brush_nodes() { // Clear input state as ui receives input events even when not drawn - _ui_end_input(ui_nodes_ui); + ui_end_input(); ui_nodes_show = !ui_nodes_show || ui_nodes_canvas_type != canvas_type_t.BRUSH; ui_nodes_canvas_type = canvas_type_t.BRUSH; base_resize(); @@ -1444,7 +1446,7 @@ function ui_base_show_brush_nodes() { function ui_base_show_2d_view(type: view_2d_type_t) { // Clear input state as ui receives input events even when not drawn - _ui_end_input(ui_view2d_ui); + ui_end_input(); if (ui_view2d_type != type) { ui_view2d_show = true; } @@ -1463,7 +1465,7 @@ function ui_base_toggle_browser() { } function ui_base_set_icon_scale() { - if (ui_SCALE(ui_base_ui) > 1) { + if (UI_SCALE() > 1) { let res: string[] = ["icons2x.k"]; resource_load(res); map_set(resource_bundled, "icons.k", resource_get("icons2x.k")); @@ -1475,7 +1477,9 @@ function ui_base_set_icon_scale() { } function ui_base_on_border_hover(handle: ui_handle_t, side: i32) { - if (!base_ui_enabled) return; + if (!base_ui_enabled) { + return; + } if (handle != ui_base_hwnds[tab_area_t.SIDEBAR0] && handle != ui_base_hwnds[tab_area_t.SIDEBAR1] && diff --git a/base/sources/ts/ui_box.ts b/base/sources/ts/ui_box.ts index 4e6cbeba..6b7f6245 100644 --- a/base/sources/ts/ui_box.ts +++ b/base/sources/ts/ui_box.ts @@ -24,14 +24,14 @@ function ui_box_init() { function ui_box_render() { if (!ui_menu_show) { - let ui: ui_t = base_ui_box; + let ui: ui_t = ui_base_ui; let in_use: bool = ui.combo_selected_handle != null; let is_escape: bool = keyboard_started("escape"); if (ui_box_draws > 2 && (ui.input_released || is_escape) && !in_use && !ui.is_typing) { let appw: i32 = iron_window_width(); let apph: i32 = iron_window_height(); - let mw: i32 = math_floor(ui_box_modalw * ui_SCALE(ui)); - let mh: i32 = math_floor(ui_box_modalh * ui_SCALE(ui)); + let mw: i32 = math_floor(ui_box_modalw * UI_SCALE()); + let mh: i32 = math_floor(ui_box_modalh * UI_SCALE()); let left: f32 = (appw / 2 - mw / 2) + ui_box_hwnd.drag_x; let right: f32 = (appw / 2 + mw / 2) + ui_box_hwnd.drag_x; let top: f32 = (apph / 2 - mh / 2) + ui_box_hwnd.drag_y; @@ -55,11 +55,11 @@ function ui_box_render() { draw_end(); } - let ui: ui_t = base_ui_box; + let ui: ui_t = ui_base_ui; let appw: i32 = iron_window_width(); let apph: i32 = iron_window_height(); - let mw: i32 = math_floor(ui_box_modalw * ui_SCALE(ui)); - let mh: i32 = math_floor(ui_box_modalh * ui_SCALE(ui)); + let mw: i32 = math_floor(ui_box_modalw * UI_SCALE()); + let mh: i32 = math_floor(ui_box_modalh * UI_SCALE()); if (mw > appw) { mw = appw; } @@ -83,7 +83,7 @@ function ui_box_render() { else { ui_text(ui_box_text); } - _ui_end_element(); + ui_end_element(); ///if (arm_windows || arm_linux || arm_macos) if (ui_box_copyable) { @@ -98,7 +98,7 @@ function ui_box_render() { ui_row(row); ///end - _ui_end_element(); + ui_end_element(); ///if (arm_windows || arm_linux || arm_macos) if (ui_box_copyable && ui_button(tr("Copy"))) { diff --git a/base/sources/ts/ui_files.ts b/base/sources/ts/ui_files.ts index 04523775..ce3f1165 100644 --- a/base/sources/ts/ui_files.ts +++ b/base/sources/ts/ui_files.ts @@ -133,7 +133,7 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = ui_files_last_search = search; handle.changed = false; - let slotw: i32 = math_floor(70 * ui_SCALE(ui)); + let slotw: i32 = math_floor(70 * UI_SCALE()); let num: i32 = math_floor(ui._w / slotw); if (num == 0) { return handle.text; @@ -148,14 +148,14 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = } ui_row(ar); if (row > 0) { - ui._y += ui_ELEMENT_OFFSET(ui) * 14.0; + ui._y += UI_ELEMENT_OFFSET() * 14.0; } for (let j: i32 = 0; j < num; ++j) { let i: i32 = j + row * num; if (i >= ui_files_files.length) { - _ui_end_element(slotw); - _ui_end_element(slotw); + ui_end_element_of_size(slotw); + ui_end_element_of_size(slotw); continue; } @@ -166,7 +166,7 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = let col: i32 = rect == file ? ui.ops.theme.LABEL_COL : ui.ops.theme.LABEL_COL - 0x00202020; if (ui_files_selected == i) col = ui.ops.theme.HIGHLIGHT_COL; - let off: f32 = ui._w / 2 - 25 * ui_SCALE(ui); + let off: f32 = ui._w / 2 - 25 * UI_SCALE(); ui._x += off; let uix: f32 = ui._x; @@ -240,7 +240,7 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = ui_fill(-2, 0, 2, w + 4, ui.ops.theme.HIGHLIGHT_COL); ui_fill(w + 2 , -2, 2, w + 6, ui.ops.theme.HIGHLIGHT_COL); } - state = ui_image(icon, 0xffffffff, w * ui_SCALE(ui)); + state = ui_image(icon, 0xffffffff, w * UI_SCALE()); if (ui.is_hovered) { ui_tooltip_image(icon); ui_tooltip(f); @@ -293,7 +293,7 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = ui_fill(-2, 0, 2, w + 4, ui.ops.theme.HIGHLIGHT_COL); ui_fill(w + 2 , -2, 2, w + 6, ui.ops.theme.HIGHLIGHT_COL); } - state = ui_image(icon, 0xffffffff, w * ui_SCALE(ui)); + state = ui_image(icon, 0xffffffff, w * UI_SCALE()); if (ui.is_hovered) { ui_tooltip_image(icon); ui_tooltip(f); @@ -329,13 +329,13 @@ function ui_files_file_browser(ui: ui_t, handle: ui_handle_t, drag_files: bool = ui_fill(-2, 0, 2, w + 4, ui.ops.theme.HIGHLIGHT_COL); ui_fill(w + 2 , -2, 2, w + 6, ui.ops.theme.HIGHLIGHT_COL); } - state = ui_image(icon, 0xffffffff, icon.height * ui_SCALE(ui)); + state = ui_image(icon, 0xffffffff, icon.height * UI_SCALE()); generic = false; } } if (generic) { - state = ui_sub_image(icons, col, 50 * ui_SCALE(ui), rect.x, rect.y, rect.w, rect.h); + state = ui_sub_image(icons, col, 50 * UI_SCALE(), rect.x, rect.y, rect.w, rect.h); } if (ui.is_hovered && ui.input_released_r && context_menu != null) { diff --git a/base/sources/ts/ui_header.ts b/base/sources/ts/ui_header.ts index 67e7316b..2161e680 100644 --- a/base/sources/ts/ui_header.ts +++ b/base/sources/ts/ui_header.ts @@ -16,7 +16,7 @@ function ui_header_render_ui() { else { ui_header_h = ui_header_default_h; } - ui_header_h = math_floor(ui_header_h * ui_SCALE(ui)); + ui_header_h = math_floor(ui_header_h * UI_SCALE()); if (config_raw.layout[layout_size_t.HEADER] == 0) { return; diff --git a/base/sources/ts/ui_menu.ts b/base/sources/ts/ui_menu.ts index d274db01..4bd81a0f 100644 --- a/base/sources/ts/ui_menu.ts +++ b/base/sources/ts/ui_menu.ts @@ -12,10 +12,10 @@ let ui_menu_hide_flag: bool = false; let _ui_menu_render_msg: string; function ui_menu_render() { - let ui: ui_t = base_ui_menu; + let ui: ui_t = ui_base_ui; let menu_w: i32 = ui_menu_commands != null ? - math_floor(base_default_element_w * ui_SCALE(base_ui_menu) * 2.3) : - math_floor(ui_ELEMENT_W(ui) * 2.3); + math_floor(base_default_element_w * UI_SCALE() * 2.3) : + math_floor(UI_ELEMENT_W() * 2.3); let _FILL_BUTTON_BG: i32 = ui.ops.theme.FILL_BUTTON_BG; ui.ops.theme.FILL_BUTTON_BG = false; @@ -55,6 +55,7 @@ function ui_menu_render() { if (ui_menu_show_first) { ui_menu_show_first = false; + ui_menu_keep_open = true; ui_menu_h = ui._y - ui_menu_y; ui_menu_x += iron_window_width() * 2; ui_menu_y += iron_window_height() * 2; @@ -89,7 +90,7 @@ function ui_menu_draw(commands: (ui: ui_t)=>void = null, x: i32 = -1, y: i32 = - function ui_menu_fit_to_screen() { // Prevent the menu going out of screen - let menu_w: f32 = base_default_element_w * ui_SCALE(base_ui_menu) * 2.3; + let menu_w: f32 = base_default_element_w * UI_SCALE() * 2.3; if (ui_menu_x + menu_w > iron_window_width()) { if (ui_menu_x - menu_w > 0) { ui_menu_x = math_floor(ui_menu_x - menu_w); @@ -112,10 +113,10 @@ function ui_menu_fit_to_screen() { function ui_menu_separator(ui: ui_t) { ui._y++; if (config_raw.touch_ui) { - ui_fill(0, 0, ui._w / ui_SCALE(ui), 1, ui.ops.theme.BUTTON_COL); + ui_fill(0, 0, ui._w / UI_SCALE(), 1, ui.ops.theme.BUTTON_COL); } else { - ui_fill(26, 0, ui._w / ui_SCALE(ui) - 26, 1, ui.ops.theme.BUTTON_COL); + ui_fill(26, 0, ui._w / UI_SCALE() - 26, 1, ui.ops.theme.BUTTON_COL); } } @@ -130,7 +131,7 @@ function ui_menu_align(ui: ui_t) { if (!config_raw.touch_ui) { let row: f32[] = [12 / 100, 88 / 100]; ui_row(row); - _ui_end_element(); + ui_end_element(); } } diff --git a/base/sources/ts/ui_menubar.ts b/base/sources/ts/ui_menubar.ts index 0b1013f9..270f8b8f 100644 --- a/base/sources/ts/ui_menubar.ts +++ b/base/sources/ts/ui_menubar.ts @@ -62,7 +62,7 @@ function ui_menubar_render_ui() { box_export_show_textures(); } ///end - let size: i32 = math_floor(ui._w / ui_SCALE(ui)); + let size: i32 = math_floor(ui._w / UI_SCALE()); if (ui_menu_show && ui_menubar_category == menubar_category_t.VIEWPORT) { ui_fill(0, -6, size, size - 4, ui.ops.theme.HIGHLIGHT_COL); } @@ -696,7 +696,7 @@ function ui_menubar_draw_category_items(ui: ui_t) { let img: gpu_texture_t = data_get_image("badge.k"); ui_image(img); - _ui_end_element(); + ui_end_element(); let h: ui_handle_t = ui_handle(__ID__); if (h.init) { @@ -711,7 +711,7 @@ function ui_menubar_draw_category_items(ui: ui_t) { iron_copy_to_clipboard(_ui_menu_render_msg); } ///else - _ui_end_element(); + ui_end_element(); ///end if (ui_button(tr("Contributors"))) { @@ -739,10 +739,10 @@ function ui_menubar_show_menu(ui: ui_t, category: i32) { ui_menu_x = math_floor(ui._x - ui._w); ui_menu_y = math_floor(ui_MENUBAR_H(ui)); if (config_raw.touch_ui) { - let menu_w: i32 = math_floor(base_default_element_w * ui_SCALE(base_ui_menu) * 2.0); + let menu_w: i32 = math_floor(base_default_element_w * UI_SCALE() * 2.0); ui_menu_x -= math_floor((menu_w - ui._w) / 2) + math_floor(ui_header_h / 2); - ui_menu_x += math_floor(2 * ui_SCALE(base_ui_menu)); - ui_menu_y -= math_floor(2 * ui_SCALE(base_ui_menu)); + ui_menu_x += math_floor(2 * UI_SCALE()); + ui_menu_y -= math_floor(2 * UI_SCALE()); ui_menu_keep_open = true; } } diff --git a/base/sources/ts/ui_nodes.ts b/base/sources/ts/ui_nodes.ts index 671bd691..f01a3c5d 100644 --- a/base/sources/ts/ui_nodes.ts +++ b/base/sources/ts/ui_nodes.ts @@ -11,7 +11,6 @@ let ui_nodes_wy: i32; let ui_nodes_ww: i32; let ui_nodes_wh: i32; -let ui_nodes_ui: ui_t; let ui_nodes_canvas_type: canvas_type_t = canvas_type_t.MATERIAL; let ui_nodes_show_menu: bool = false; let ui_nodes_show_menu_first: bool = true; @@ -66,16 +65,7 @@ function ui_viewnodes_init() { ui_nodes_grid_snap = config_raw.grid_snap; nodes_material_init(); - let scale: f32 = config_raw.window_scale; - let ops: ui_options_t = { - theme: base_theme, - font: base_font, - color_wheel: base_color_wheel, - black_white_gradient: base_color_wheel_gradient, - scale_factor: scale - }; - ui_nodes_ui = ui_create(ops); - ui_nodes_ui.scroll_enabled = false; + // ui_base_ui.scroll_enabled = false; } function ui_viewnodes_on_link_drag(link_drag_id: i32, is_new_link: bool) { @@ -88,8 +78,8 @@ function ui_viewnodes_on_link_drag(link_drag_id: i32, is_new_link: bool) { let link_drag: ui_node_link_t = ui_get_link(links, link_drag_id); let nodes: ui_node_t[] = ui_nodes_get_canvas(true).nodes; let node: ui_node_t = ui_get_node(nodes, link_drag.from_id > -1 ? link_drag.from_id : link_drag.to_id); - let link_x: i32 = ui_nodes_ui._window_x + UI_NODE_X(node); - let link_y: i32 = ui_nodes_ui._window_y + UI_NODE_Y(node); + let link_x: i32 = ui_base_ui._window_x + UI_NODE_X(node); + let link_y: i32 = ui_base_ui._window_y + UI_NODE_Y(node); if (link_drag.from_id > -1) { link_x += UI_NODE_W(node); link_y += UI_OUTPUT_Y(node.outputs.length, link_drag.from_socket); @@ -155,7 +145,7 @@ function ui_viewnodes_on_socket_released(socket_id: i32) { let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true); let socket: ui_node_socket_t = ui_get_socket(canvas.nodes, socket_id); let node: ui_node_t = ui_get_node(canvas.nodes, socket.node_id); - if (ui_nodes_ui.input_released_r) { + if (ui_base_ui.input_released_r) { if (node.type == "GROUP_INPUT" || node.type == "GROUP_OUTPUT") { _ui_nodes_on_socket_released_socket = socket; @@ -275,10 +265,10 @@ function ui_viewnodes_on_socket_released(socket_id: i32) { } function ui_viewnodes_on_canvas_released() { - if (ui_nodes_ui.input_released_r && + if (ui_base_ui.input_released_r && context_in_nodes() && - math_abs(ui_nodes_ui.input_x - ui_nodes_ui.input_started_x) < 2 && - math_abs(ui_nodes_ui.input_y - ui_nodes_ui.input_started_y) < 2) { + math_abs(ui_base_ui.input_x - ui_base_ui.input_started_x) < 2 && + math_abs(ui_base_ui.input_y - ui_base_ui.input_started_y) < 2) { // Node selection let nodes: ui_nodes_t = ui_nodes_get_nodes(); @@ -287,8 +277,8 @@ function ui_viewnodes_on_canvas_released() { for (let i: i32 = 0; i < canvas.nodes.length; ++i) { let node: ui_node_t = canvas.nodes[i]; if (ui_input_in_rect( - ui_nodes_ui._window_x + UI_NODE_X(node), - ui_nodes_ui._window_y + UI_NODE_Y(node), + ui_base_ui._window_x + UI_NODE_X(node), + ui_base_ui._window_y + UI_NODE_Y(node), UI_NODE_W(node), UI_NODE_H(canvas, node))) { selected = node; @@ -346,7 +336,7 @@ function ui_viewnodes_on_canvas_released() { if (ui_menu_button(tr("Delete"), "delete")) { sys_notify_on_next_frame(function () { ui_nodes_hwnd.redraws = 2; - ui_nodes_ui.is_delete_down = true; + ui_base_ui.is_delete_down = true; ui_nodes_is_node_menu_op = true; }); } @@ -380,12 +370,12 @@ function ui_viewnodes_on_canvas_released() { } } - if (ui_nodes_ui.input_released) { + if (ui_base_ui.input_released) { let nodes: ui_nodes_t = ui_nodes_get_nodes(); let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true); for (let i: i32 = 0; i < canvas.nodes.length; ++i) { let node: ui_node_t = canvas.nodes[i]; - if (ui_input_in_rect(ui_nodes_ui._window_x + UI_NODE_X(node), ui_nodes_ui._window_y + UI_NODE_Y(node), UI_NODE_W(node), UI_NODE_H(canvas, node))) { + if (ui_input_in_rect(ui_base_ui._window_x + UI_NODE_X(node), ui_base_ui._window_y + UI_NODE_Y(node), UI_NODE_W(node), UI_NODE_H(canvas, node))) { if (nodes.nodes_selected_id.length > 0 && node.id == nodes.nodes_selected_id[0]) { ui_view2d_hwnd.redraws = 2; if (sys_time() - context_raw.select_time < 0.25) ui_base_show_2d_view(view_2d_type_t.NODE); @@ -398,7 +388,7 @@ function ui_viewnodes_on_canvas_released() { } function ui_viewnodes_on_canvas_control(): ui_canvas_control_t { - let control: ui_canvas_control_t = ui_nodes_get_canvas_control(ui_nodes_ui, ui_nodes_controls_down); + let control: ui_canvas_control_t = ui_nodes_get_canvas_control(ui_base_ui, ui_nodes_controls_down); ui_nodes_controls_down = control.controls_down; return control; } @@ -567,34 +557,34 @@ function ui_nodes_update() { if (mx < ui_nodes_wx || mx > ui_nodes_wx + ww || my < ui_nodes_wy) { return; } - if (ui_nodes_ui.is_typing || !ui_nodes_ui.input_enabled) { + if (ui_base_ui.is_typing || !ui_base_ui.input_enabled) { return; } let nodes: ui_nodes_t = ui_nodes_get_nodes(); - if (nodes.nodes_selected_id.length > 0 && ui_nodes_ui.is_key_pressed) { - if (ui_nodes_ui.key_code == key_code_t.LEFT) { + if (nodes.nodes_selected_id.length > 0 && ui_base_ui.is_key_pressed) { + if (ui_base_ui.key_code == key_code_t.LEFT) { for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) { let n: i32 = nodes.nodes_selected_id[i]; let _nodes: ui_node_t[] = ui_nodes_get_canvas(true).nodes; ui_get_node(_nodes, n).x -= 1; } } - else if (ui_nodes_ui.key_code == key_code_t.RIGHT) { + else if (ui_base_ui.key_code == key_code_t.RIGHT) { for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) { let n: i32 = nodes.nodes_selected_id[i]; let _nodes: ui_node_t[] = ui_nodes_get_canvas(true).nodes; ui_get_node(_nodes, n).x += 1; } } - if (ui_nodes_ui.key_code == key_code_t.UP) { + if (ui_base_ui.key_code == key_code_t.UP) { for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) { let n: i32 = nodes.nodes_selected_id[i]; let _nodes: ui_node_t[] = ui_nodes_get_canvas(true).nodes; ui_get_node(_nodes, n).y -= 1; } } - else if (ui_nodes_ui.key_code == key_code_t.DOWN) { + else if (ui_base_ui.key_code == key_code_t.DOWN) { for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) { let n: i32 = nodes.nodes_selected_id[i]; let _nodes: ui_node_t[] = ui_nodes_get_canvas(true).nodes; @@ -608,8 +598,8 @@ function ui_nodes_update() { ui_nodes_node_search(); } if (ui_nodes_node_search_spawn != null) { - ui_nodes_ui.input_x = mouse_x; // Fix inputDX after popup removal - ui_nodes_ui.input_y = mouse_y; + ui_base_ui.input_x = mouse_x; // Fix inputDX after popup removal + ui_base_ui.input_y = mouse_y; ui_nodes_node_search_spawn = null; } @@ -630,7 +620,7 @@ function ui_nodes_node_search(x: i32 = -1, y: i32 = -1, done: ()=>void = null) { _ui_nodes_node_search_done = done; ui_menu_draw(function (ui: ui_t) { - ui_menu_h = ui_ELEMENT_H(ui) * 8; + ui_menu_h = UI_ELEMENT_H() * 8; let search_handle: ui_handle_t = ui_handle(__ID__); let search: string = to_lower_case(ui_text_input(search_handle, "", ui_align_t.LEFT, true, true)); ui.changed = false; @@ -730,7 +720,7 @@ function ui_nodes_draw_grid(zoom: f32): gpu_texture_t { let wh: i32 = sys_h(); let step: f32 = ui_nodes_grid_cell_w * zoom; - let mult: i32 = 5 * ui_SCALE(ui_nodes_ui); + let mult: i32 = 5 * UI_SCALE(); let w: i32 = math_floor(ww + step * mult); let h: i32 = math_floor(wh + step * mult); if (w < 1) { @@ -741,9 +731,9 @@ function ui_nodes_draw_grid(zoom: f32): gpu_texture_t { } let grid: gpu_texture_t = gpu_create_render_target(w, h); - draw_begin(grid, true, ui_nodes_ui.ops.theme.SEPARATOR_COL); + draw_begin(grid, true, ui_base_ui.ops.theme.SEPARATOR_COL); - let sep_col: i32 = ui_nodes_ui.ops.theme.SEPARATOR_COL; + let sep_col: i32 = ui_base_ui.ops.theme.SEPARATOR_COL; let line_primary: i32 = sep_col - 0x00050505; if (line_primary < 0xff000000) { line_primary = sep_col + 0x00050505; @@ -859,13 +849,13 @@ function ui_nodes_render() { array_remove(c.links, ui_get_link(c.links, nodes.link_drag_id)); nodes.link_drag_id = -1; } - ui_nodes_release_link = ui_nodes_ui.input_released; + ui_nodes_release_link = ui_base_ui.input_released; if (!ui_nodes_show || iron_window_width() == 0 || iron_window_height() == 0) { return; } - ui_nodes_ui.input_enabled = base_ui_enabled; + ui_base_ui.input_enabled = base_ui_enabled; if (ui_nodes_grid_redraw) { if (ui_nodes_grid != null) { @@ -883,7 +873,7 @@ function ui_nodes_render() { ///end // Start with UI - ui_begin(ui_nodes_ui); + ui_begin(ui_base_ui); // Make window ui_nodes_ww = config_raw.layout[layout_size_t.NODES_W]; @@ -904,7 +894,7 @@ function ui_nodes_render() { } ///end - let ew: i32 = math_floor(ui_ELEMENT_W(ui_nodes_ui) * 0.7); + let ew: i32 = math_floor(UI_ELEMENT_W() * 0.7); ui_nodes_wh = sys_h(); if (config_raw.layout[layout_size_t.HEADER] == 1) { ui_nodes_wh += ui_header_h * 2; @@ -954,21 +944,21 @@ function ui_nodes_render() { draw_image(ui_nodes_grid, x, y); // Undo - if (ui_nodes_ui.input_started || ui_nodes_ui.is_key_pressed) { + if (ui_base_ui.input_started || ui_base_ui.is_key_pressed) { ui_nodes_last_canvas = util_clone_canvas(ui_nodes_get_canvas(true)); } // Nodes - let _input_enabled: bool = ui_nodes_ui.input_enabled; - ui_nodes_ui.input_enabled = _input_enabled && !ui_nodes_show_menu; + let _input_enabled: bool = ui_base_ui.input_enabled; + ui_base_ui.input_enabled = _input_enabled && !ui_nodes_show_menu; ///if is_paint - ui_nodes_ui.window_border_right = config_raw.layout[layout_size_t.SIDEBAR_W]; + ui_base_ui.window_border_right = config_raw.layout[layout_size_t.SIDEBAR_W]; ///end - ui_nodes_ui.window_border_top = ui_header_h * 2; - ui_nodes_ui.window_border_bottom = config_raw.layout[layout_size_t.STATUS_H]; + ui_base_ui.window_border_top = ui_header_h * 2; + ui_base_ui.window_border_bottom = config_raw.layout[layout_size_t.STATUS_H]; ui_node_canvas(nodes, c); - ui_nodes_ui.input_enabled = _input_enabled; + ui_base_ui.input_enabled = _input_enabled; if (nodes.color_picker_callback != null) { context_raw.color_picker_previous_tool = context_raw.tool; @@ -1037,23 +1027,23 @@ function ui_nodes_render() { ui_is_copy = false; ui_is_cut = false; ui_is_paste = false; - ui_nodes_ui.is_delete_down = false; + ui_base_ui.is_delete_down = false; } // Recompile material on change - if (ui_nodes_ui.changed) { + if (ui_base_ui.changed) { ///if is_paint - ui_nodes_recompile_mat = (ui_nodes_ui.input_dx != 0 || ui_nodes_ui.input_dy != 0 || !ui_nodes_uichanged_last) && config_raw.material_live; // Instant preview + ui_nodes_recompile_mat = (ui_base_ui.input_dx != 0 || ui_base_ui.input_dy != 0 || !ui_nodes_uichanged_last) && config_raw.material_live; // Instant preview ///end ///if is_lab - ui_nodes_recompile_mat = (ui_nodes_ui.input_dx != 0 || ui_nodes_ui.input_dy != 0 || !ui_nodes_uichanged_last); // Instant preview + ui_nodes_recompile_mat = (ui_base_ui.input_dx != 0 || ui_base_ui.input_dy != 0 || !ui_nodes_uichanged_last); // Instant preview ///end } else if (ui_nodes_uichanged_last) { ui_nodes_canvas_changed(); ui_nodes_push_undo(ui_nodes_last_canvas); } - ui_nodes_uichanged_last = ui_nodes_ui.changed; + ui_nodes_uichanged_last = ui_base_ui.changed; // Node previews if (config_raw.node_preview && nodes.nodes_selected_id.length > 0) { @@ -1097,10 +1087,10 @@ function ui_nodes_render() { ///end if (img != null) { - let tw: f32 = 128 * ui_SCALE(ui_nodes_ui); + let tw: f32 = 128 * UI_SCALE(); let th: f32 = tw * (img.height / img.width); - let tx: f32 = ui_nodes_ww - tw - 8 * ui_SCALE(ui_nodes_ui); - let ty: f32 = ui_nodes_wh - th - 8 * ui_SCALE(ui_nodes_ui); + let tx: f32 = ui_nodes_ww - tw - 8 * UI_SCALE(); + let ty: f32 = ui_nodes_wh - th - 8 * UI_SCALE(); let invert_y: bool = false; @@ -1125,24 +1115,24 @@ function ui_nodes_render() { } // Menu - draw_set_color(ui_nodes_ui.ops.theme.SEPARATOR_COL); - draw_filled_rect(0, ui_ELEMENT_H(ui_nodes_ui), ui_nodes_ww, ui_ELEMENT_H(ui_nodes_ui) + ui_ELEMENT_OFFSET(ui_nodes_ui) * 2); + draw_set_color(ui_base_ui.ops.theme.SEPARATOR_COL); + draw_filled_rect(0, UI_ELEMENT_H(), ui_nodes_ww, UI_ELEMENT_H() + UI_ELEMENT_OFFSET() * 2); draw_set_color(0xffffffff); - let start_y: i32 = ui_ELEMENT_H(ui_nodes_ui) + ui_ELEMENT_OFFSET(ui_nodes_ui); - ui_nodes_ui._x = 0; - ui_nodes_ui._y = 2 + start_y; - ui_nodes_ui._w = ew; + let start_y: i32 = UI_ELEMENT_H() + UI_ELEMENT_OFFSET(); + ui_base_ui._x = 0; + ui_base_ui._y = 2 + start_y; + ui_base_ui._w = ew; ///if is_paint // Editable canvas name let h: ui_handle_t = ui_handle(__ID__); h.text = c.name; - ui_nodes_ui._w = math_floor(math_min(draw_string_width(ui_nodes_ui.ops.font, ui_nodes_ui.font_size, h.text) + 15 * ui_SCALE(ui_nodes_ui), 100 * ui_SCALE(ui_nodes_ui))); + ui_base_ui._w = math_floor(math_min(draw_string_width(ui_base_ui.ops.font, ui_base_ui.font_size, h.text) + 15 * UI_SCALE(), 100 * UI_SCALE())); let new_name: string = ui_text_input(h, ""); - ui_nodes_ui._x += ui_nodes_ui._w + 3; - ui_nodes_ui._y = 2 + start_y; - ui_nodes_ui._w = ew; + ui_base_ui._x += ui_base_ui._w + 3; + ui_base_ui._y = 2 + start_y; + ui_base_ui._w = ew; if (h.changed) { // Check whether renaming is possible and update group links if (ui_nodes_group_stack.length > 0) { @@ -1188,12 +1178,12 @@ function ui_nodes_render() { // let type: i32 = ui_combo(type_handle, type_combo, tr("Type"), true); ///if is_lab - ui_nodes_ui.window_border_top = 0; + ui_base_ui.window_border_top = 0; ui_nodes_ext_draw_buttons(ew, start_y); ///end - let _BUTTON_COL: i32 = ui_nodes_ui.ops.theme.BUTTON_COL; - ui_nodes_ui.ops.theme.BUTTON_COL = ui_nodes_ui.ops.theme.SEPARATOR_COL; + let _BUTTON_COL: i32 = ui_base_ui.ops.theme.BUTTON_COL; + ui_base_ui.ops.theme.BUTTON_COL = ui_base_ui.ops.theme.SEPARATOR_COL; ///if is_paint let cats: string[] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_categories : nodes_brush_categories; @@ -1203,48 +1193,48 @@ function ui_nodes_render() { ///end for (let i: i32 = 0; i < cats.length; ++i) { - if ((_ui_menu_button(tr(cats[i]))) || (ui_nodes_ui.is_hovered && ui_nodes_show_menu)) { + if ((_ui_menu_button(tr(cats[i]))) || (ui_base_ui.is_hovered && ui_nodes_show_menu)) { ui_nodes_show_menu = true; ui_nodes_menu_category = i; - ui_nodes_popup_x = ui_nodes_wx + ui_nodes_ui._x; - ui_nodes_popup_y = ui_nodes_wy + ui_nodes_ui._y; + ui_nodes_popup_x = ui_nodes_wx + ui_base_ui._x; + ui_nodes_popup_y = ui_nodes_wy + ui_base_ui._y; if (config_raw.touch_ui) { ui_nodes_show_menu_first = true; let menuw: i32 = math_floor(ew * 2.3); ui_nodes_popup_x -= menuw / 2; - ui_nodes_popup_x += ui_nodes_ui._w / 2; + ui_nodes_popup_x += ui_base_ui._w / 2; } } - ui_nodes_ui._x += ui_nodes_ui._w + 3; - ui_nodes_ui._y = 2 + start_y; + ui_base_ui._x += ui_base_ui._w + 3; + ui_base_ui._y = 2 + start_y; } if (config_raw.touch_ui) { - let _w: i32 = ui_nodes_ui._w; - ui_nodes_ui._w = math_floor(36 * ui_SCALE(ui_nodes_ui)); - ui_nodes_ui._y = 4 * ui_SCALE(ui_nodes_ui) + start_y; - if (ui_menubar_icon_button(ui_nodes_ui, 2, 3)) { - ui_nodes_node_search(math_floor(ui_nodes_ui._window_x + ui_nodes_ui._x), math_floor(ui_nodes_ui._window_y + ui_nodes_ui._y)); + let _w: i32 = ui_base_ui._w; + ui_base_ui._w = math_floor(36 * UI_SCALE()); + ui_base_ui._y = 4 * UI_SCALE() + start_y; + if (ui_menubar_icon_button(ui_base_ui, 2, 3)) { + ui_nodes_node_search(math_floor(ui_base_ui._window_x + ui_base_ui._x), math_floor(ui_base_ui._window_y + ui_base_ui._y)); } - ui_nodes_ui._w = _w; + ui_base_ui._w = _w; } else { if (_ui_menu_button(tr("Search"))) { - ui_nodes_node_search_x = ui_nodes_ui._window_x + ui_nodes_ui._x; - ui_nodes_node_search_y = ui_nodes_ui._window_y + ui_nodes_ui._y; + ui_nodes_node_search_x = ui_base_ui._window_x + ui_base_ui._x; + ui_nodes_node_search_y = ui_base_ui._window_y + ui_base_ui._y; // Allow for node menu to be closed first sys_notify_on_init(function() { ui_nodes_node_search(math_floor(ui_nodes_node_search_x), math_floor(ui_nodes_node_search_y)); }); } } - if (ui_nodes_ui.is_hovered) { + if (ui_base_ui.is_hovered) { ui_tooltip(tr("Search for nodes") + " (" + map_get(config_keymap, "node_search") + ")"); } - ui_nodes_ui._x += ui_nodes_ui._w + 3; - ui_nodes_ui._y = 2 + start_y; + ui_base_ui._x += ui_base_ui._w + 3; + ui_base_ui._y = 2 + start_y; - ui_nodes_ui.ops.theme.BUTTON_COL = _BUTTON_COL; + ui_base_ui.ops.theme.BUTTON_COL = _BUTTON_COL; // Close node group if (ui_nodes_group_stack.length > 0 && _ui_menu_button(tr("Close"))) { @@ -1252,7 +1242,7 @@ function ui_nodes_render() { } } - ui_end(!ui_nodes_show_menu); + ui_end(); if (ui_nodes_show_menu) { ///if is_paint @@ -1279,20 +1269,20 @@ function ui_nodes_render() { let py: i32 = ui_nodes_popup_y; let menuw: i32 = math_floor(ew * 2.3); draw_begin(null); - ui_begin_region(ui_nodes_ui, math_floor(ui_nodes_popup_x), math_floor(py), menuw); - let _FILL_BUTTON_BG: i32 = ui_nodes_ui.ops.theme.FILL_BUTTON_BG; - ui_nodes_ui.ops.theme.FILL_BUTTON_BG = false; - let _ELEMENT_OFFSET: i32 = ui_nodes_ui.ops.theme.ELEMENT_OFFSET; - ui_nodes_ui.ops.theme.ELEMENT_OFFSET = 0; - let _ELEMENT_H: i32 = ui_nodes_ui.ops.theme.ELEMENT_H; - ui_nodes_ui.ops.theme.ELEMENT_H = config_raw.touch_ui ? (28 + 2) : 28; + ui_begin_region(ui_base_ui, math_floor(ui_nodes_popup_x), math_floor(py), menuw); + let _FILL_BUTTON_BG: i32 = ui_base_ui.ops.theme.FILL_BUTTON_BG; + ui_base_ui.ops.theme.FILL_BUTTON_BG = false; + let _ELEMENT_OFFSET: i32 = ui_base_ui.ops.theme.ELEMENT_OFFSET; + ui_base_ui.ops.theme.ELEMENT_OFFSET = 0; + let _ELEMENT_H: i32 = ui_base_ui.ops.theme.ELEMENT_H; + ui_base_ui.ops.theme.ELEMENT_H = config_raw.touch_ui ? (28 + 2) : 28; - ui_menu_h = category.length * ui_ELEMENT_H(ui_nodes_ui); + ui_menu_h = category.length * UI_ELEMENT_H(); if (is_group_category) { - ui_menu_h += project_material_groups.length * ui_ELEMENT_H(ui_nodes_ui); + ui_menu_h += project_material_groups.length * UI_ELEMENT_H(); } - ui_menu_start(ui_nodes_ui); + ui_menu_start(ui_base_ui); for (let i: i32 = 0; i < category.length; ++i) { let n: ui_node_t = category[i]; @@ -1309,15 +1299,15 @@ function ui_nodes_render() { ///end } // Next column - if (ui_nodes_ui._y - ui_nodes_wy + ui_ELEMENT_H(ui_nodes_ui) / 2 > ui_nodes_wh) { - ui_nodes_ui._x += menuw; - ui_nodes_ui._y = py; + if (ui_base_ui._y - ui_nodes_wy + UI_ELEMENT_H() / 2 > ui_nodes_wh) { + ui_base_ui._x += menuw; + ui_base_ui._y = py; } } if (is_group_category) { for (let i: i32 = 0; i < project_material_groups.length; ++i) { let g: node_group_t = project_material_groups[i]; - ui_nodes_ui.enabled = ui_nodes_can_place_group(g.canvas.name); + ui_base_ui.enabled = ui_nodes_can_place_group(g.canvas.name); let row: f32[] = [5 / 6, 1 / 6]; ui_row(row); if (ui_button(config_button_spacing + g.canvas.name, ui_align_t.LEFT)) { @@ -1331,24 +1321,24 @@ function ui_nodes_render() { } ///if is_paint - ui_nodes_ui.enabled = !project_is_material_group_in_use(g); + ui_base_ui.enabled = !project_is_material_group_in_use(g); if (ui_button("x", ui_align_t.CENTER)) { history_delete_material_group(g); array_remove(project_material_groups, g); } ///end - ui_nodes_ui.enabled = true; + ui_base_ui.enabled = true; } } - ui_nodes_hide_menu = ui_nodes_ui.combo_selected_handle == null && !ui_nodes_show_menu_first && (ui_nodes_ui.changed || ui_nodes_ui.input_released || ui_nodes_ui.input_released_r || ui_nodes_ui.is_escape_down); + ui_nodes_hide_menu = ui_base_ui.combo_selected_handle == null && !ui_nodes_show_menu_first && (ui_base_ui.changed || ui_base_ui.input_released || ui_base_ui.input_released_r || ui_base_ui.is_escape_down); ui_nodes_show_menu_first = false; - ui_nodes_ui.ops.theme.FILL_BUTTON_BG = _FILL_BUTTON_BG; - ui_nodes_ui.ops.theme.ELEMENT_OFFSET = _ELEMENT_OFFSET; - ui_nodes_ui.ops.theme.ELEMENT_H = _ELEMENT_H; - ui_menu_end(ui_nodes_ui); + ui_base_ui.ops.theme.FILL_BUTTON_BG = _FILL_BUTTON_BG; + ui_base_ui.ops.theme.ELEMENT_OFFSET = _ELEMENT_OFFSET; + ui_base_ui.ops.theme.ELEMENT_H = _ELEMENT_H; + ui_menu_end(ui_base_ui); ui_end_region(); draw_end(); } @@ -1357,6 +1347,8 @@ function ui_nodes_render() { ui_nodes_show_menu = false; ui_nodes_show_menu_first = true; } + + ui_base_ui.input_enabled = true; } function ui_nodes_contains_node_group_recursive(group: node_group_t, group_name: string): bool { diff --git a/base/sources/ts/ui_toolbar.ts b/base/sources/ts/ui_toolbar.ts index f6fc107b..9844b41e 100644 --- a/base/sources/ts/ui_toolbar.ts +++ b/base/sources/ts/ui_toolbar.ts @@ -56,7 +56,7 @@ function ui_toolbar_draw_tool(i: i32, ui: ui_t, img: gpu_texture_t, icon_accent: ///if is_paint if (i == tool_type_t.COLORID && context_raw.colorid_picked) { let rt: render_target_t = map_get(render_path_render_targets, "texpaint_colorid"); - draw_scaled_sub_image(rt._image, 0, 0, 1, 1, 0, _y + 1.5 * ui_SCALE(ui), 5 * ui_SCALE(ui), 34 * ui_SCALE(ui)); + draw_scaled_sub_image(rt._image, 0, 0, 1, 1, 0, _y + 1.5 * UI_SCALE(), 5 * UI_SCALE(), 34 * UI_SCALE()); } ///end @@ -85,7 +85,7 @@ function ui_toolbar_w(screen_size_request: bool = false): i32 { function ui_toolbar_x(): i32 { let ui: ui_t = ui_base_ui; - return 5 * ui_SCALE(ui); + return 5 * UI_SCALE(); } function ui_toolbar_render_ui() { @@ -103,7 +103,7 @@ function ui_toolbar_render_ui() { } if (ui_window(ui_toolbar_handle, x, y, ui_toolbar_w(), h)) { - ui._y -= 4 * ui_SCALE(ui); + ui._y -= 4 * UI_SCALE(); ui.image_scroll_align = false; let img: gpu_texture_t = resource_get("icons.k"); @@ -129,7 +129,7 @@ function ui_toolbar_render_ui() { ui.ops.theme.BUTTON_H = ui.ops.theme.ELEMENT_H; ui.ops.theme.BUTTON_COL = ui.ops.theme.WINDOW_BG_COL; let font_height: i32 = draw_font_height(ui.ops.font, ui.font_size); - ui.font_offset_y = (ui_ELEMENT_H(ui) - font_height) / 2; + ui.font_offset_y = (UI_ELEMENT_H() - font_height) / 2; let _w: i32 = ui._w; ui._w = ui_toolbar_w(); @@ -146,7 +146,7 @@ function ui_toolbar_render_ui() { if (ui.is_hovered) { ui_tooltip(tr("Toggle header")); } - ui._y -= 4 * ui_SCALE(ui); + ui._y -= 4 * UI_SCALE(); let vars_brush: map_t = map_create(); map_set(vars_brush, "key", map_get(config_keymap, "brush_ruler")); @@ -237,7 +237,7 @@ function ui_toolbar_tool_properties_menu() { if (ui_button(tr("Pin to Header"), ui_align_t.LEFT)) { config_raw.layout[layout_size_t.HEADER] = 1; } - }, math_floor(ui._x + ui._w + 2), math_floor(ui._y - 6 * ui_SCALE(ui))); + }, math_floor(ui._x + ui._w + 2), math_floor(ui._y - 6 * UI_SCALE())); } function ui_toolbar_draw_highlight() { diff --git a/base/sources/ts/ui_view2d.ts b/base/sources/ts/ui_view2d.ts index ff8ab06b..7a36c581 100644 --- a/base/sources/ts/ui_view2d.ts +++ b/base/sources/ts/ui_view2d.ts @@ -15,7 +15,6 @@ let ui_view2d_wx: i32; let ui_view2d_wy: i32; let ui_view2d_ww: i32; let ui_view2d_wh: i32; -let ui_view2d_ui: ui_t; let ui_view2d_hwnd: ui_handle_t = ui_handle_create(); let ui_view2d_pan_x: f32 = 0.0; let ui_view2d_pan_y: f32 = 0.0; @@ -50,16 +49,7 @@ function ui_view2d_init() { ui_view2d_channel_loc = pipes_get_constant_location("int"); ///end - let scale: f32 = config_raw.window_scale; - let ops: ui_options_t = { - theme: base_theme, - font: base_font, - color_wheel: base_color_wheel, - black_white_gradient: base_color_wheel_gradient, - scale_factor: scale - }; - ui_view2d_ui = ui_create(ops); - ui_view2d_ui.scroll_enabled = false; + // ui_base_ui.scroll_enabled = false; } function ui_view2d_render() { @@ -115,7 +105,7 @@ function ui_view2d_render() { } ///end - ui_begin(ui_view2d_ui); + ui_begin(ui_base_ui); let headerh: i32 = config_raw.layout[layout_size_t.HEADER] == 1 ? ui_header_h * 2 : ui_header_h; let apph: i32 = iron_window_height() - config_raw.layout[layout_size_t.STATUS_H] + headerh; @@ -250,10 +240,10 @@ function ui_view2d_render() { } // Texture and node preview color picking - if ((context_in_2d_view(view_2d_type_t.ASSET) || context_in_2d_view(view_2d_type_t.NODE)) && context_raw.tool == tool_type_t.PICKER && ui_view2d_ui.input_down) { + if ((context_in_2d_view(view_2d_type_t.ASSET) || context_in_2d_view(view_2d_type_t.NODE)) && context_raw.tool == tool_type_t.PICKER && ui_base_ui.input_down) { _ui_view2d_render_tex = tex; - _ui_view2d_render_x = ui_view2d_ui.input_x - tx - ui_view2d_wx;; - _ui_view2d_render_y = ui_view2d_ui.input_y - ty - ui_view2d_wy; + _ui_view2d_render_x = ui_base_ui.input_x - tx - ui_view2d_wx;; + _ui_view2d_render_y = ui_base_ui.input_y - ty - ui_view2d_wy; _ui_view2d_render_tw = tw; _ui_view2d_render_th = th; @@ -291,15 +281,15 @@ function ui_view2d_render() { ///end // Menu - let ew: i32 = math_floor(ui_ELEMENT_W(ui_view2d_ui)); - draw_set_color(ui_view2d_ui.ops.theme.SEPARATOR_COL); - draw_filled_rect(0, ui_ELEMENT_H(ui_view2d_ui), ui_view2d_ww, ui_ELEMENT_H(ui_view2d_ui) + ui_ELEMENT_OFFSET(ui_view2d_ui) * 2); + let ew: i32 = math_floor(UI_ELEMENT_W()); + draw_set_color(ui_base_ui.ops.theme.SEPARATOR_COL); + draw_filled_rect(0, UI_ELEMENT_H(), ui_view2d_ww, UI_ELEMENT_H() + UI_ELEMENT_OFFSET() * 2); draw_set_color(0xffffffff); - let start_y: f32 = ui_ELEMENT_H(ui_view2d_ui) + ui_ELEMENT_OFFSET(ui_view2d_ui); - ui_view2d_ui._x = 2; - ui_view2d_ui._y = 2 + start_y; - ui_view2d_ui._w = ew; + let start_y: f32 = UI_ELEMENT_H() + UI_ELEMENT_OFFSET(); + ui_base_ui._x = 2; + ui_base_ui._y = 2 + start_y; + ui_base_ui._w = ew; // Editable layer name let h: ui_handle_t = ui_handle(__ID__); @@ -310,7 +300,7 @@ function ui_view2d_render() { let text: string = h.text; ///end - ui_view2d_ui._w = math_floor(math_min(draw_string_width(ui_view2d_ui.ops.font, ui_view2d_ui.font_size, text) + 15 * ui_SCALE(ui_view2d_ui), 100 * ui_SCALE(ui_view2d_ui))); + ui_base_ui._w = math_floor(math_min(draw_string_width(ui_base_ui.ops.font, ui_base_ui.font_size, text) + 15 * UI_SCALE(), 100 * UI_SCALE())); if (ui_view2d_type == view_2d_type_t.ASSET) { let asset: asset_t = context_raw.texture; @@ -340,7 +330,7 @@ function ui_view2d_render() { else if (ui_view2d_type == view_2d_type_t.LAYER) { h.text = l.name; l.name = ui_text_input(h, ""); - ui_view2d_text_input_hover = ui_view2d_ui.is_hovered; + ui_view2d_text_input_hover = ui_base_ui.is_hovered; } else if (ui_view2d_type == view_2d_type_t.FONT) { h.text = context_raw.font.name; @@ -351,9 +341,9 @@ function ui_view2d_render() { if (h.changed) { ui_base_hwnds[0].redraws = 2; } - ui_view2d_ui._x += ui_view2d_ui._w + 3; - ui_view2d_ui._y = 2 + start_y; - ui_view2d_ui._w = ew; + ui_base_ui._x += ui_base_ui._w + 3; + ui_base_ui._y = 2 + start_y; + ui_base_ui._w = ew; ///if is_paint if (ui_view2d_type == view_2d_type_t.LAYER) { @@ -363,8 +353,8 @@ function ui_view2d_render() { } let layer_mode_combo: string[] = [tr("Visible"), tr("Selected")]; ui_view2d_layer_mode = ui_combo(h_layer_mode, layer_mode_combo, tr("Layers")); - ui_view2d_ui._x += ew + 3; - ui_view2d_ui._y = 2 + start_y; + ui_base_ui._x += ew + 3; + ui_base_ui._y = 2 + start_y; if (!slot_layer_is_mask(context_raw.layer)) { let h_tex_type: ui_handle_t = ui_handle(__ID__); @@ -381,18 +371,18 @@ function ui_view2d_render() { tr("Height"), ]; ui_view2d_tex_type = ui_combo(h_tex_type, tex_type_combo, tr("Texture")); - ui_view2d_ui._x += ew + 3; - ui_view2d_ui._y = 2 + start_y; + ui_base_ui._x += ew + 3; + ui_base_ui._y = 2 + start_y; } - ui_view2d_ui._w = math_floor(ew * 0.7 + 3); + ui_base_ui._w = math_floor(ew * 0.7 + 3); let h_uvmap_show: ui_handle_t = ui_handle(__ID__); if (h_uvmap_show.init) { h_uvmap_show.selected = ui_view2d_uvmap_show; } ui_view2d_uvmap_show = ui_check(h_uvmap_show, tr("UV Map")); - ui_view2d_ui._x += ew * 0.7 + 3; - ui_view2d_ui._y = 2 + start_y; + ui_base_ui._x += ew * 0.7 + 3; + ui_base_ui._y = 2 + start_y; } ///end @@ -401,8 +391,8 @@ function ui_view2d_render() { h_tiled_show.selected = ui_view2d_tiled_show; } ui_view2d_tiled_show = ui_check(h_tiled_show, tr("Tiled")); - ui_view2d_ui._x += ew * 0.7 + 3; - ui_view2d_ui._y = 2 + start_y; + ui_base_ui._x += ew * 0.7 + 3; + ui_base_ui._y = 2 + start_y; if (ui_view2d_type == view_2d_type_t.ASSET && tex != null) { // Texture resolution ui_text(tex.width + "x" + tex.height); @@ -412,7 +402,7 @@ function ui_view2d_render() { ///if is_paint if (context_raw.tool == tool_type_t.PICKER && (ui_view2d_type == view_2d_type_t.LAYER || ui_view2d_type == view_2d_type_t.ASSET)) { let cursor_img: gpu_texture_t = resource_get("cursor.k"); - let hsize: f32 = 16 * ui_SCALE(ui_view2d_ui); + let hsize: f32 = 16 * UI_SCALE(); let size: f32 = hsize * 2; draw_scaled_image(cursor_img, tx + tw * context_raw.uvx_picked - hsize, ty + th * context_raw.uvy_picked - hsize, size, size); } @@ -422,7 +412,7 @@ function ui_view2d_render() { } function ui_view2d_update() { - let headerh: f32 = ui_ELEMENT_H(ui_view2d_ui) * 1.4; + let headerh: f32 = UI_ELEMENT_H() * 1.4; ///if is_paint context_raw.paint2d = false; @@ -435,13 +425,13 @@ function ui_view2d_update() { mouse_y < ui_view2d_wy + headerh || mouse_y > ui_view2d_wy + ui_view2d_wh) { if (ui_view2d_controls_down) { - let control: ui_canvas_control_t = ui_nodes_get_canvas_control(ui_view2d_ui, ui_view2d_controls_down); + let control: ui_canvas_control_t = ui_nodes_get_canvas_control(ui_base_ui, ui_view2d_controls_down); ui_view2d_controls_down = control.controls_down; } return; } - let control: ui_canvas_control_t = ui_nodes_get_canvas_control(ui_view2d_ui, ui_view2d_controls_down); + let control: ui_canvas_control_t = ui_nodes_get_canvas_control(ui_base_ui, ui_view2d_controls_down); ui_view2d_pan_x += control.pan_x; ui_view2d_pan_y += control.pan_y; ui_view2d_controls_down = control.controls_down; @@ -460,8 +450,8 @@ function ui_view2d_update() { if (ui_touch_scroll) { // Zoom to finger location - ui_view2d_pan_x -= (ui_view2d_ui.input_x - ui_view2d_ui._window_x - ui_view2d_ui._window_w / 2) * control.zoom; - ui_view2d_pan_y -= (ui_view2d_ui.input_y - ui_view2d_ui._window_y - ui_view2d_ui._window_h / 2) * control.zoom; + ui_view2d_pan_x -= (ui_base_ui.input_x - ui_base_ui._window_x - ui_base_ui._window_w / 2) * control.zoom; + ui_view2d_pan_y -= (ui_base_ui.input_y - ui_base_ui._window_y - ui_base_ui._window_h / 2) * control.zoom; } ui_view2d_grid_redraw = true; } @@ -484,7 +474,7 @@ function ui_view2d_update() { } ///end - if (ui_view2d_ui.is_typing) { + if (ui_base_ui.is_typing) { return; } diff --git a/lab/sources/ui_nodes_ext.ts b/lab/sources/ui_nodes_ext.ts index 296bf745..27e7381b 100644 --- a/lab/sources/ui_nodes_ext.ts +++ b/lab/sources/ui_nodes_ext.ts @@ -6,7 +6,7 @@ function ui_nodes_ext_delay_idle_sleep() { } function ui_nodes_ext_draw_buttons(ew: f32, start_y: f32) { - let ui: ui_t = ui_nodes_ui; + let ui: ui_t = ui_base_ui; if (ui_button(tr("Run"))) { // sys_notify_on_init(function() { ui_nodes_ext_run(); diff --git a/paint/sources/ui_header_ext.ts b/paint/sources/ui_header_ext.ts index 7b8a8ec6..5bee1733 100644 --- a/paint/sources/ui_header_ext.ts +++ b/paint/sources/ui_header_ext.ts @@ -104,9 +104,9 @@ function ui_header_draw_tool_properties(ui: ui_t) { if (ui.is_hovered && ui.input_released) { _ui_header_draw_tool_properties_h = h; ui_menu_draw(function (ui: ui_t) { - ui_fill(0, 0, ui._w / ui_SCALE(ui), ui.ops.theme.ELEMENT_H * 9, ui.ops.theme.SEPARATOR_COL); + ui_fill(0, 0, ui._w / UI_SCALE(), ui.ops.theme.ELEMENT_H * 9, ui.ops.theme.SEPARATOR_COL); ui.changed = false; - ui_color_wheel(_ui_header_draw_tool_properties_h, false, -1, 10 * ui.ops.theme.ELEMENT_H * ui_SCALE(ui), false); + ui_color_wheel(_ui_header_draw_tool_properties_h, false, -1, 10 * ui.ops.theme.ELEMENT_H * UI_SCALE(), false); if (ui.changed) { ui_menu_keep_open = true; } @@ -242,9 +242,9 @@ function ui_header_draw_tool_properties(ui: ui_t) { if (progress > 1.0) progress = 1.0; // Progress bar draw_set_color(ui.ops.theme.SEPARATOR_COL); - ui_draw_rect(true, ui._x + 1, ui._y, ui._w - 2, ui_ELEMENT_H(ui)); + ui_draw_rect(true, ui._x + 1, ui._y, ui._w - 2, UI_ELEMENT_H()); draw_set_color(ui.ops.theme.HIGHLIGHT_COL); - ui_draw_rect(true, ui._x + 1, ui._y, (ui._w - 2) * progress, ui_ELEMENT_H(ui)); + ui_draw_rect(true, ui._x + 1, ui._y, (ui._w - 2) * progress, UI_ELEMENT_H()); draw_set_color(0xffffffff); ui_text(tr("Samples") + ": " + render_path_raytrace_bake_current_sample); ui_text(tr("Rays/pixel") + ": " + render_path_raytrace_bake_rays_pix); @@ -449,7 +449,7 @@ function ui_header_draw_tool_properties(ui: ui_t) { } else { let _w: i32 = ui._w; - let sc: f32 = ui_SCALE(ui); + let sc: f32 = UI_SCALE(); let touch_header: bool = (config_raw.touch_ui && config_raw.layout[layout_size_t.HEADER] == 1); if (touch_header) { ui._x -= 4 * sc;