This commit is contained in:
luboslenco
2025-10-15 18:39:55 +02:00
parent 231fda884a
commit 5405d47fcf
242 changed files with 14647 additions and 15144 deletions
+91 -96
View File
@@ -1,35 +1,34 @@
type draw_cloud_icon_data_t = {
f: string;
image: gpu_texture_t;
f: string; image : gpu_texture_t;
};
let ui_files_default_path: string =
///if arm_windows
"C:\\Users"
///elseif arm_android
"/storage/emulated/0/Download"
///elseif arm_macos
"/Users"
///else
"/"
///end
;
/// if arm_windows
"C:\\Users"
/// elseif arm_android
"/storage/emulated/0/Download"
/// elseif arm_macos
"/Users"
/// else
"/"
/// end
;
let ui_files_filename: string;
let ui_files_path: string = ui_files_default_path;
let ui_files_last_path: string = "";
let ui_files_last_search: string = "";
let ui_files_files: string[] = null;
let ui_files_path: string = ui_files_default_path;
let ui_files_last_path: string = "";
let ui_files_last_search: string = "";
let ui_files_files: string[] = null;
let ui_files_icon_map: map_t<string, gpu_texture_t> = null;
let ui_files_icon_file_map: map_t<string, string> = null;
let ui_files_selected: i32 = -1;
let ui_files_show_extensions: bool = false;
let ui_files_offline: bool = false;
let ui_files_icon_file_map: map_t<string, string> = null;
let ui_files_selected: i32 = -1;
let ui_files_show_extensions: bool = false;
let ui_files_offline: bool = false;
let _ui_files_file_browser_handle: ui_handle_t;
let _ui_files_file_browser_f: string;
function ui_files_show(filters: string, is_save: bool, open_multiple: bool, files_done: (s: string)=>void) {
function ui_files_show(filters: string, is_save: bool, open_multiple: bool, files_done: (s: string) => void) {
if (is_save) {
ui_files_path = iron_save_dialog(filters, "");
if (ui_files_path != null) {
@@ -37,9 +36,9 @@ function ui_files_show(filters: string, is_save: bool, open_multiple: bool, file
while (string_index_of(ui_files_path, sep2) >= 0) {
ui_files_path = string_replace_all(ui_files_path, sep2, path_sep);
}
ui_files_path = string_replace_all(ui_files_path, "\r", "");
ui_files_path = string_replace_all(ui_files_path, "\r", "");
ui_files_filename = substring(ui_files_path, string_last_index_of(ui_files_path, path_sep) + 1, ui_files_path.length);
ui_files_path = substring(ui_files_path, 0, string_last_index_of(ui_files_path, path_sep));
ui_files_path = substring(ui_files_path, 0, string_last_index_of(ui_files_path, path_sep));
files_done(ui_files_path);
}
}
@@ -52,7 +51,7 @@ function ui_files_show(filters: string, is_save: bool, open_multiple: bool, file
while (string_index_of(path, sep2) >= 0) {
path = string_replace_all(path, sep2, path_sep);
}
path = string_replace_all(path, "\r", "");
path = string_replace_all(path, "\r", "");
ui_files_filename = substring(path, string_last_index_of(path, path_sep) + 1, path.length);
files_done(path);
}
@@ -66,37 +65,38 @@ function ui_files_release_keys() {
// File dialog may prevent firing key up events
keyboard_up_listener(key_code_t.SHIFT);
keyboard_up_listener(key_code_t.CONTROL);
///if arm_macos
/// if arm_macos
keyboard_up_listener(key_code_t.META);
///end
/// end
}
function make_draw_cloud_icon_data(f: string, image: gpu_texture_t): draw_cloud_icon_data_t {
let data: draw_cloud_icon_data_t = { f: f, image: image };
let data: draw_cloud_icon_data_t = {f : f, image : image};
return data;
}
function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, search: string = "", refresh: bool = false, context_menu: (s: string)=>void = null): string {
function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, search: string = "", refresh: bool = false,
context_menu: (s: string) => void = null): string {
let icons: gpu_texture_t = resource_get("icons.k");
let folder: rect_t = resource_tile50(icons, 2, 1);
let file: rect_t = resource_tile50(icons, 3, 1);
let is_cloud: bool = starts_with(handle.text, "cloud");
let folder: rect_t = resource_tile50(icons, 2, 1);
let file: rect_t = resource_tile50(icons, 3, 1);
let is_cloud: bool = starts_with(handle.text, "cloud");
if (is_cloud && file_cloud == null) {
file_init_cloud(function () {
file_init_cloud(function() {
ui_base_hwnds[tab_area_t.STATUS].redraws = 3;
tab_browser_refresh = true;
tab_browser_refresh = true;
});
}
if (is_cloud && file_read_directory("cloud").length == 0) {
return handle.text;
}
///if arm_ios
/// if arm_ios
let document_directory: string = iron_save_dialog("", "");
document_directory = substring(document_directory, 0, document_directory.length - 8); // Strip /"untitled"
///end
document_directory = substring(document_directory, 0, document_directory.length - 8); // Strip /"untitled"
/// end
if (handle.text == "") {
handle.text = ui_files_default_path;
@@ -106,11 +106,11 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
ui_files_files = [];
let dir_path: string = handle.text;
///if arm_ios
/// if arm_ios
if (!is_cloud) {
dir_path = document_directory + dir_path;
}
///end
/// end
let files_all: string[] = file_read_directory(dir_path);
for (let i: i32 = 0; i < files_all.length; ++i) {
@@ -130,12 +130,12 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
array_push(ui_files_files, f);
}
}
ui_files_last_path = handle.text;
ui_files_last_path = handle.text;
ui_files_last_search = search;
handle.changed = false;
handle.changed = false;
let slotw: i32 = math_floor(70 * UI_SCALE());
let num: i32 = math_floor(ui._w / slotw);
let num: i32 = math_floor(ui._w / slotw);
if (num == 0) {
return handle.text;
}
@@ -161,19 +161,20 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
}
let f: string = ui_files_files[i];
let _x: f32 = ui._x;
let _x: f32 = ui._x;
let rect: rect_t = string_index_of(f, ".") > 0 ? file : folder;
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 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._x += off;
let uix: f32 = ui._x;
let uiy: f32 = ui._y;
let state: ui_state_t = ui_state_t.IDLE;
let generic: bool = true;
let uix: f32 = ui._x;
let uiy: f32 = ui._y;
let state: ui_state_t = ui_state_t.IDLE;
let generic: bool = true;
let icon: gpu_texture_t = null;
if (is_cloud && !ui_files_offline) {
@@ -188,26 +189,26 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
let dot: i32 = string_last_index_of(f, ".");
if (dot > -1) {
let files_all: string[] = file_read_directory(handle.text);
let icon_file: string = substring(f, 0, dot) + "_icon.jpg";
let icon_file: string = substring(f, 0, dot) + "_icon.jpg";
if (array_index_of(files_all, icon_file) >= 0) {
let rt: render_target_t = map_get(render_path_render_targets, "empty_black");
let rt: render_target_t = map_get(render_path_render_targets, "empty_black");
let empty: gpu_texture_t = rt._image;
map_set(ui_files_icon_map, handle.text + path_sep + f, empty);
_ui_files_file_browser_handle = handle;
map_set(ui_files_icon_file_map, icon_file, f);
file_cache_cloud(handle.text + path_sep + icon_file, function (abs: string) {
file_cache_cloud(handle.text + path_sep + icon_file, function(abs: string) {
if (abs != null) {
let image: gpu_texture_t = data_get_image(abs);
///if arm_windows
/// if arm_windows
abs = string_replace_all(abs, "\\", "/");
///end
let icon_file: string = substring(abs, string_last_index_of(abs, "/") + 1, abs.length);
let f: string = map_get(ui_files_icon_file_map, icon_file);
/// end
let icon_file: string = substring(abs, string_last_index_of(abs, "/") + 1, abs.length);
let f: string = map_get(ui_files_icon_file_map, icon_file);
let data: draw_cloud_icon_data_t = make_draw_cloud_icon_data(f, image);
sys_notify_on_next_frame(function (data: draw_cloud_icon_data_t) {
sys_notify_on_next_frame(function(data: draw_cloud_icon_data_t) {
let icon: gpu_texture_t = gpu_create_render_target(data.image.width, data.image.height);
if (ends_with(data.f, ".arm")) { // Used for material sphere alpha cutout
draw_begin(icon);
@@ -235,10 +236,10 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
if (icon != null) {
let w: i32 = 50;
if (i == ui_files_selected) {
ui_fill(-2, -2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(-2, w + 2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
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);
ui_fill(-2, -2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(-2, w + 2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
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());
if (ui.is_hovered) {
@@ -253,27 +254,27 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
ui_files_icon_map = map_create();
}
let key: string = handle.text + path_sep + f;
icon = map_get(ui_files_icon_map, key);
icon = map_get(ui_files_icon_map, key);
if (map_get(ui_files_icon_map, key) == null) {
let blob_path: string = key;
///if arm_ios
/// if arm_ios
blob_path = document_directory + blob_path;
///end
/// end
let buffer: buffer_t = iron_load_blob(blob_path);
let buffer: buffer_t = iron_load_blob(blob_path);
let raw: project_format_t = armpack_decode(buffer);
if (raw.material_icons != null) {
let bytes_icon: any = raw.material_icons[0];
icon = gpu_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256);
icon = gpu_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256);
}
else if (raw.mesh_icons != null) {
let bytes_icon: any = raw.mesh_icons[0];
icon = gpu_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256);
icon = gpu_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256);
}
else if (raw.brush_icons != null) {
let bytes_icon: any = raw.brush_icons[0];
icon = gpu_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256);
icon = gpu_create_texture_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256);
}
map_set(ui_files_icon_map, key, icon);
@@ -281,10 +282,10 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
if (icon != null) {
let w: i32 = 50;
if (i == ui_files_selected) {
ui_fill(-2, -2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(-2, w + 2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
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);
ui_fill(-2, -2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(-2, w + 2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
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());
if (ui.is_hovered) {
@@ -301,31 +302,27 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
ui_files_icon_map = map_create();
}
let shandle: string = handle.text + path_sep + f;
///if arm_ios
/// if arm_ios
shandle = document_directory + shandle;
///end
/// end
icon = map_get(ui_files_icon_map, shandle);
if (icon == null) {
let rt: render_target_t = map_get(render_path_render_targets, "empty_black");
let rt: render_target_t = map_get(render_path_render_targets, "empty_black");
let empty: gpu_texture_t = rt._image;
map_set(ui_files_icon_map, shandle, empty);
let image: gpu_texture_t = data_get_image(shandle);
let args: ui_files_make_icon_t = {
image: image,
shandle: shandle,
w: w
};
let args: ui_files_make_icon_t = {image : image, shandle : shandle, w : w};
sys_notify_on_next_frame(ui_files_make_icon, args);
}
if (icon != null) {
if (i == ui_files_selected) {
ui_fill(-2, -2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(-2, w + 2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
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);
ui_fill(-2, -2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
ui_fill(-2, w + 2, w + 4, 2, ui.ops.theme.HIGHLIGHT_COL);
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());
state = ui_image(icon, 0xffffffff, icon.height * UI_SCALE());
generic = false;
}
}
@@ -342,12 +339,12 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
if (drag_files) {
base_drag_off_x = -(mouse_x - uix - ui._window_x - 3);
base_drag_off_y = -(mouse_y - uiy - ui._window_y + 1);
base_drag_file = handle.text;
///if arm_ios
base_drag_file = handle.text;
/// if arm_ios
if (!is_cloud) {
base_drag_file = document_directory + base_drag_file;
}
///end
/// end
if (char_at(base_drag_file, base_drag_file.length - 1) != path_sep) {
base_drag_file += path_sep;
}
@@ -357,9 +354,9 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
ui_files_selected = i;
if (sys_time() - context_raw.select_time < 0.2) {
base_drag_file = null;
base_drag_file = null;
base_drag_file_icon = null;
base_is_dragging = false;
base_is_dragging = false;
handle.changed = ui.changed = true;
if (char_at(handle.text, handle.text.length - 1) != path_sep) {
handle.text += path_sep;
@@ -413,11 +410,11 @@ function ui_files_file_browser(handle: ui_handle_t, drag_files: bool = false, se
}
function ui_files_make_icon(args: ui_files_make_icon_t) {
let w: i32 = args.w;
let w: i32 = args.w;
let image: gpu_texture_t = args.image;
let sw: i32 = image.width > image.height ? w : math_floor(1.0 * image.width / image.height * w);
let sh: i32 = image.width > image.height ? math_floor(1.0 * image.height / image.width * w) : w;
let icon: gpu_texture_t = gpu_create_render_target(sw, sh);
let sw: i32 = image.width > image.height ? w : math_floor(1.0 * image.width / image.height * w);
let sh: i32 = image.width > image.height ? math_floor(1.0 * image.height / image.width * w) : w;
let icon: gpu_texture_t = gpu_create_render_target(sw, sh);
draw_begin(icon, true, 0xffffffff);
draw_set_pipeline(pipes_copy_rgb);
draw_scaled_image(image, 0, 0, sw, sh);
@@ -449,7 +446,5 @@ function ui_files_go_up(handle: ui_handle_t) {
}
type ui_files_make_icon_t = {
image: gpu_texture_t;
shandle: string;
w: i32;
image: gpu_texture_t; shandle : string; w : i32;
};