base.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. let base_ui_enabled: bool = true;
  2. let base_is_dragging: bool = false;
  3. let base_is_resizing: bool = false;
  4. let base_drag_asset: asset_t = null;
  5. let base_drag_swatch: swatch_color_t = null;
  6. let base_drag_file: string = null;
  7. let base_drag_file_icon: gpu_texture_t = null;
  8. let base_drag_tint: i32 = 0xffffffff;
  9. let base_drag_size: i32 = -1;
  10. let base_drag_rect: rect_t = null;
  11. let base_drag_off_x: f32 = 0.0;
  12. let base_drag_off_y: f32 = 0.0;
  13. let base_drag_start: f32 = 0.0;
  14. let base_drop_x: f32 = 0.0;
  15. let base_drop_y: f32 = 0.0;
  16. let base_font: draw_font_t = null;
  17. let base_theme: ui_theme_t;
  18. let base_color_wheel: gpu_texture_t;
  19. let base_color_wheel_gradient: gpu_texture_t;
  20. let base_default_element_w: i32 = 100;
  21. let base_default_element_h: i32 = 28;
  22. let base_default_font_size: i32 = 13;
  23. let base_res_handle: ui_handle_t = ui_handle_create();
  24. let base_bits_handle: ui_handle_t = ui_handle_create();
  25. let base_drop_paths: string[] = [];
  26. let base_appx: i32 = 0;
  27. let base_appy: i32 = 0;
  28. let base_last_window_width: i32 = 0;
  29. let base_last_window_height: i32 = 0;
  30. let base_drag_material: slot_material_t = null;
  31. let base_drag_layer: slot_layer_t = null;
  32. let base_default_fov: f32 = 0.69;
  33. let _base_material_count: i32;
  34. function base_init() {
  35. base_last_window_width = iron_window_width();
  36. base_last_window_height = iron_window_height();
  37. sys_notify_on_drop_files(function (drop_path: string) {
  38. ///if arm_linux
  39. drop_path = uri_decode(drop_path);
  40. ///end
  41. drop_path = trim_end(drop_path);
  42. array_push(base_drop_paths, drop_path);
  43. });
  44. sys_notify_on_app_state(
  45. function () { // Foreground
  46. context_raw.foreground_event = true;
  47. context_raw.last_paint_x = -1;
  48. context_raw.last_paint_y = -1;
  49. },
  50. function () {}, // Resume
  51. function () {}, // Pause
  52. function () { // Background
  53. // Release keys after alt-tab / win-tab
  54. keyboard_up_listener(key_code_t.ALT);
  55. keyboard_up_listener(key_code_t.WIN);
  56. },
  57. function () { // Shutdown
  58. ///if (arm_android || arm_ios)
  59. project_save();
  60. ///end
  61. config_save();
  62. }
  63. );
  64. iron_set_save_and_quit_callback(base_save_and_quit_callback);
  65. let font: draw_font_t = data_get_font("font.ttf");
  66. let image_color_wheel: gpu_texture_t = data_get_image("color_wheel.k");
  67. let image_color_wheel_gradient: gpu_texture_t = data_get_image("color_wheel_gradient.k");
  68. base_font = font;
  69. config_load_theme(config_raw.theme, false);
  70. base_default_element_w = base_theme.ELEMENT_W;
  71. base_default_element_h = base_theme.ELEMENT_H;
  72. base_default_font_size = base_theme.FONT_SIZE;
  73. translator_load_translations(config_raw.locale);
  74. ui_files_filename = tr("untitled");
  75. ///if (arm_android || arm_ios)
  76. sys_title_set(tr("untitled"));
  77. ///end
  78. // Baked font for fast startup
  79. if (config_raw.locale == "en") {
  80. draw_font_13(base_font);
  81. }
  82. else {
  83. draw_font_init(base_font);
  84. }
  85. base_color_wheel = image_color_wheel;
  86. base_color_wheel_gradient = image_color_wheel_gradient;
  87. ui_nodes_enum_texts = base_enum_texts;
  88. // Init plugins
  89. if (config_raw.plugins != null) {
  90. for (let i: i32 = 0; i < config_raw.plugins.length; ++i) {
  91. let plugin: string = config_raw.plugins[i];
  92. plugin_start(plugin);
  93. }
  94. }
  95. args_parse();
  96. camera_init();
  97. ui_base_init();
  98. ui_viewnodes_init();
  99. ui_view2d_init();
  100. base_ext_init();
  101. sys_notify_on_update(base_update);
  102. sys_notify_on_render(ui_view2d_render);
  103. sys_notify_on_update(ui_view2d_update);
  104. sys_notify_on_render(ui_base_render_cursor);
  105. sys_notify_on_update(ui_nodes_update);
  106. sys_notify_on_render(ui_nodes_render);
  107. sys_notify_on_update(ui_base_update);
  108. sys_notify_on_render(ui_base_render);
  109. sys_notify_on_update(camera_update);
  110. sys_notify_on_render(base_render);
  111. base_appx = ui_toolbar_w(true);
  112. base_appy = 0;
  113. if (config_raw.layout[layout_size_t.HEADER] == 1) {
  114. base_appy = ui_header_h * 2;
  115. }
  116. let cam: camera_object_t = scene_camera;
  117. cam.data.fov = math_floor(cam.data.fov * 100) / 100;
  118. camera_object_build_proj(cam);
  119. args_run();
  120. let has_projects: bool = config_raw.recent_projects.length > 0;
  121. if (config_raw.splash_screen && has_projects) {
  122. box_projects_show();
  123. }
  124. }
  125. function base_save_and_quit_callback(save: bool) {
  126. base_save_window_rect();
  127. if (save) {
  128. project_save(true);
  129. }
  130. else {
  131. iron_stop();
  132. }
  133. }
  134. function base_w(): i32 {
  135. // Drawing material preview
  136. if (context_raw.material_preview) {
  137. return util_render_material_preview_size;
  138. }
  139. // Drawing decal preview
  140. if (context_raw.decal_preview) {
  141. return util_render_decal_preview_size;
  142. }
  143. let res: i32 = 0;
  144. if (config_raw.layout == null) {
  145. let sidebarw: i32 = ui_base_default_sidebar_w;
  146. res = iron_window_width() - sidebarw - ui_toolbar_default_w;
  147. }
  148. else if (ui_nodes_show || ui_view2d_show) {
  149. res = iron_window_width() - config_raw.layout[layout_size_t.SIDEBAR_W] - config_raw.layout[layout_size_t.NODES_W] - ui_toolbar_w(true);
  150. }
  151. else if (ui_base_show) {
  152. res = iron_window_width() - config_raw.layout[layout_size_t.SIDEBAR_W] - ui_toolbar_w(true);
  153. }
  154. else { // Distract free
  155. res = iron_window_width();
  156. }
  157. if (context_raw.view_index > -1) {
  158. res = math_floor(res / 2);
  159. }
  160. if (context_raw.paint2d_view) {
  161. res = ui_view2d_ww;
  162. }
  163. return res > 0 ? res : 1; // App was minimized, force render path resize
  164. }
  165. function base_h(): i32 {
  166. // Drawing material preview
  167. if (context_raw.material_preview) {
  168. return util_render_material_preview_size;
  169. }
  170. // Drawing decal preview
  171. if (context_raw.decal_preview) {
  172. return util_render_decal_preview_size;
  173. }
  174. let res: i32 = iron_window_height();
  175. if (config_raw.layout == null) {
  176. res -= ui_header_default_h * 2 + ui_status_default_status_h;
  177. ///if (arm_android || arm_ios)
  178. res += ui_header_h;
  179. ///end
  180. }
  181. else if (ui_base_show && res > 0) {
  182. let statush: i32 = config_raw.layout[layout_size_t.STATUS_H];
  183. res -= math_floor(ui_header_default_h * 2 * config_raw.window_scale) + statush;
  184. if (config_raw.layout[layout_size_t.HEADER] == 0) {
  185. res += ui_header_h * 2;
  186. }
  187. }
  188. return res > 0 ? res : 1; // App was minimized, force render path resize
  189. }
  190. function base_x(): i32 {
  191. return context_raw.view_index == 1 ? base_appx + base_w() : base_appx;
  192. }
  193. function base_y(): i32 {
  194. return base_appy;
  195. }
  196. function base_on_resize() {
  197. if (iron_window_width() == 0 || iron_window_height() == 0) {
  198. return;
  199. }
  200. let ratio_w: f32 = iron_window_width() / base_last_window_width;
  201. base_last_window_width = iron_window_width();
  202. let ratio_h: f32 = iron_window_height() / base_last_window_height;
  203. base_last_window_height = iron_window_height();
  204. config_raw.layout[layout_size_t.NODES_W] = math_floor(config_raw.layout[layout_size_t.NODES_W] * ratio_w);
  205. config_raw.layout[layout_size_t.SIDEBAR_H0] = math_floor(config_raw.layout[layout_size_t.SIDEBAR_H0] * ratio_h);
  206. config_raw.layout[layout_size_t.SIDEBAR_H1] = iron_window_height() - config_raw.layout[layout_size_t.SIDEBAR_H0];
  207. base_resize();
  208. base_save_window_rect();
  209. }
  210. function base_save_window_rect() {
  211. config_raw.window_w = iron_window_width();
  212. config_raw.window_h = iron_window_height();
  213. config_raw.window_x = iron_window_x();
  214. config_raw.window_y = iron_window_y();
  215. config_save();
  216. }
  217. function base_resize() {
  218. if (iron_window_width() == 0 || iron_window_height() == 0) {
  219. return;
  220. }
  221. let cam: camera_object_t = scene_camera;
  222. if (cam.data.ortho != null) {
  223. cam.data.ortho[2] = -2 * (sys_h() / sys_w());
  224. cam.data.ortho[3] = 2 * (sys_h() / sys_w());
  225. }
  226. camera_object_build_proj(cam);
  227. render_path_base_taa_frame = 0;
  228. if (context_raw.camera_type == camera_type_t.ORTHOGRAPHIC) {
  229. viewport_update_camera_type(context_raw.camera_type);
  230. }
  231. context_raw.ddirty = 2;
  232. if (ui_base_show) {
  233. base_appx = ui_toolbar_w(true);
  234. base_appy = 0;
  235. if (config_raw.layout[layout_size_t.HEADER] == 1) {
  236. base_appy = ui_header_h * 2;
  237. }
  238. }
  239. else {
  240. base_appx = 0;
  241. base_appy = 0;
  242. }
  243. ui_nodes_grid_redraw = true;
  244. ui_view2d_grid_redraw = true;
  245. base_redraw_ui();
  246. }
  247. function base_redraw_ui() {
  248. ui_header_handle.redraws = 2;
  249. ui_base_hwnds[tab_area_t.STATUS].redraws = 2;
  250. ui_menubar_menu_handle.redraws = 2;
  251. ui_menubar_workspace_handle.redraws = 2;
  252. ui_nodes_hwnd.redraws = 2;
  253. ui_box_hwnd.redraws = 2;
  254. ui_view2d_hwnd.redraws = 2;
  255. // Redraw viewport
  256. if (context_raw.ddirty < 0) {
  257. context_raw.ddirty = 0;
  258. }
  259. ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2;
  260. ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2;
  261. ui_toolbar_handle.redraws = 2;
  262. if (context_raw.split_view) {
  263. context_raw.ddirty = 1;
  264. }
  265. }
  266. function base_update() {
  267. if (mouse_movement_x != 0 || mouse_movement_y != 0) {
  268. iron_mouse_set_cursor(cursor_t.ARROW);
  269. }
  270. let has_drag: bool = base_drag_asset != null ||
  271. base_drag_material != null ||
  272. base_drag_layer != null ||
  273. base_drag_file != null ||
  274. base_drag_swatch != null;
  275. if (config_raw.touch_ui) {
  276. // Touch and hold to activate dragging
  277. if (base_drag_start < 0.2) {
  278. if (has_drag && mouse_down()) {
  279. base_drag_start += sys_real_delta();
  280. }
  281. else {
  282. base_drag_start = 0;
  283. }
  284. has_drag = false;
  285. }
  286. if (mouse_released()) {
  287. base_drag_start = 0;
  288. }
  289. let moved: bool = math_abs(mouse_movement_x) > 1 && math_abs(mouse_movement_y) > 1;
  290. if ((mouse_released() || moved) && !has_drag) {
  291. base_drag_asset = null;
  292. base_drag_swatch = null;
  293. base_drag_file = null;
  294. base_drag_file_icon = null;
  295. base_is_dragging = false;
  296. base_drag_material = null;
  297. base_drag_layer = null;
  298. }
  299. // Disable touch scrolling while dragging is active
  300. ui_touch_scroll = !base_is_dragging;
  301. }
  302. if (has_drag && (mouse_movement_x != 0 || mouse_movement_y != 0)) {
  303. base_is_dragging = true;
  304. }
  305. if (mouse_released() && has_drag) {
  306. if (base_drag_asset != null) {
  307. // Create image texture
  308. if (context_in_nodes()) {
  309. ui_nodes_accept_asset_drag(array_index_of(project_assets, base_drag_asset));
  310. }
  311. else if (context_in_viewport()) {
  312. if (ends_with(to_lower_case(base_drag_asset.file), ".hdr")) {
  313. let image: gpu_texture_t = project_get_image(base_drag_asset);
  314. import_envmap_run(base_drag_asset.file, image);
  315. }
  316. }
  317. // Create mask
  318. else if (context_in_layers() || context_in_2d_view()) {
  319. layers_create_image_mask(base_drag_asset);
  320. }
  321. base_drag_asset = null;
  322. }
  323. else if (base_drag_swatch != null) {
  324. // Create RGB node
  325. if (context_in_nodes()) {
  326. ui_nodes_accept_swatch_drag(base_drag_swatch);
  327. }
  328. else if (context_in_swatches()) {
  329. tab_swatches_accept_swatch_drag(base_drag_swatch);
  330. }
  331. else if (context_in_materials()) {
  332. tab_materials_accept_swatch_drag(base_drag_swatch);
  333. }
  334. else if (context_in_viewport()) {
  335. let color: i32 = base_drag_swatch.base;
  336. color = color_set_ab(color, base_drag_swatch.opacity * 255);
  337. layers_create_color_layer(color, base_drag_swatch.occlusion, base_drag_swatch.roughness, base_drag_swatch.metallic);
  338. }
  339. else if (context_in_layers() && tab_layers_can_drop_new_layer(context_raw.drag_dest)) {
  340. let color: i32 = base_drag_swatch.base;
  341. color = color_set_ab(color, base_drag_swatch.opacity * 255);
  342. layers_create_color_layer(color, base_drag_swatch.occlusion, base_drag_swatch.roughness, base_drag_swatch.metallic, context_raw.drag_dest);
  343. }
  344. base_drag_swatch = null;
  345. }
  346. else if (base_drag_file != null) {
  347. if (!context_in_browser()) {
  348. base_drop_x = mouse_x;
  349. base_drop_y = mouse_y;
  350. ///if is_paint
  351. _base_material_count = project_materials.length;
  352. import_asset_run(base_drag_file, base_drop_x, base_drop_y, true, true, function () {
  353. // Asset was material
  354. if (project_materials.length > _base_material_count) {
  355. base_drag_material = context_raw.material;
  356. base_material_dropped();
  357. }
  358. });
  359. ///end
  360. ///if is_lab
  361. import_asset_run(base_drag_file, base_drop_x, base_drop_y);
  362. ///end
  363. }
  364. base_drag_file = null;
  365. base_drag_file_icon = null;
  366. }
  367. else if (base_drag_material != null) {
  368. base_material_dropped();
  369. }
  370. else if (base_drag_layer != null) {
  371. if (context_in_nodes()) {
  372. ui_nodes_accept_layer_drag(array_index_of(project_layers, base_drag_layer));
  373. }
  374. else if (context_in_layers() && base_is_dragging) {
  375. slot_layer_move(base_drag_layer, context_raw.drag_dest);
  376. make_material_parse_mesh_material();
  377. }
  378. base_drag_layer = null;
  379. }
  380. iron_mouse_set_cursor(cursor_t.ARROW);
  381. base_is_dragging = false;
  382. }
  383. if (context_raw.color_picker_callback != null && (mouse_released() || mouse_released("right"))) {
  384. context_raw.color_picker_callback = null;
  385. context_select_tool(context_raw.color_picker_previous_tool);
  386. }
  387. base_handle_drop_paths();
  388. if (context_raw.ddirty < 0) {
  389. context_raw.ddirty = 0;
  390. }
  391. base_ext_update();
  392. compass_update();
  393. }
  394. function base_material_dropped() {
  395. // Material drag and dropped onto viewport or layers tab
  396. if (context_in_viewport()) {
  397. let uv_type: uv_type_t = keyboard_down("control") ? uv_type_t.PROJECT : uv_type_t.UVMAP;
  398. let decal_mat: mat4_t = uv_type == uv_type_t.PROJECT ? util_render_get_decal_mat() : mat4_nan();
  399. layers_create_fill_layer(uv_type, decal_mat);
  400. }
  401. if (context_in_layers() && tab_layers_can_drop_new_layer(context_raw.drag_dest)) {
  402. let uv_type: uv_type_t = keyboard_down("control") ? uv_type_t.PROJECT : uv_type_t.UVMAP;
  403. let decal_mat: mat4_t = uv_type == uv_type_t.PROJECT ? util_render_get_decal_mat() : mat4_nan();
  404. layers_create_fill_layer(uv_type, decal_mat, context_raw.drag_dest);
  405. }
  406. else if (context_in_nodes()) {
  407. ui_nodes_accept_material_drag(array_index_of(project_materials, base_drag_material));
  408. }
  409. base_drag_material = null;
  410. }
  411. function base_handle_drop_paths() {
  412. if (base_drop_paths.length > 0) {
  413. let wait: bool = false;
  414. ///if (arm_linux || arm_macos)
  415. wait = !mouse_moved; // Mouse coords not updated during drag
  416. ///end
  417. if (!wait) {
  418. base_drop_x = mouse_x;
  419. base_drop_y = mouse_y;
  420. let drop_path: string = array_shift(base_drop_paths);
  421. import_asset_run(drop_path, base_drop_x, base_drop_y);
  422. }
  423. }
  424. }
  425. function base_get_drag_background(): rect_t {
  426. let icons: gpu_texture_t = resource_get("icons.k");
  427. if (base_drag_layer != null && !slot_layer_is_group(base_drag_layer) && base_drag_layer.fill_layer == null) {
  428. return resource_tile50(icons, 4, 1);
  429. }
  430. return null;
  431. }
  432. function base_get_drag_image(): gpu_texture_t {
  433. base_drag_tint = 0xffffffff;
  434. base_drag_size = -1;
  435. base_drag_rect = null;
  436. if (base_drag_asset != null) {
  437. return project_get_image(base_drag_asset);
  438. }
  439. if (base_drag_swatch != null) {
  440. base_drag_tint = base_drag_swatch.base;
  441. base_drag_size = 26;
  442. return tab_swatches_empty_get();
  443. }
  444. if (base_drag_file != null) {
  445. if (base_drag_file_icon != null) {
  446. return base_drag_file_icon;
  447. }
  448. let icons: gpu_texture_t = resource_get("icons.k");
  449. base_drag_rect = string_index_of(base_drag_file, ".") > 0 ? resource_tile50(icons, 3, 1) : resource_tile50(icons, 2, 1);
  450. base_drag_tint = ui.ops.theme.HIGHLIGHT_COL;
  451. return icons;
  452. }
  453. if (base_drag_material != null) {
  454. return base_drag_material.image_icon;
  455. }
  456. if (base_drag_layer != null && slot_layer_is_group(base_drag_layer)) {
  457. let icons: gpu_texture_t = resource_get("icons.k");
  458. let folder_closed: rect_t = resource_tile50(icons, 2, 1);
  459. let folder_open: rect_t = resource_tile50(icons, 8, 1);
  460. base_drag_rect = base_drag_layer.show_panel ? folder_open : folder_closed;
  461. base_drag_tint = ui.ops.theme.LABEL_COL - 0x00202020;
  462. return icons;
  463. }
  464. if (base_drag_layer != null && slot_layer_is_mask(base_drag_layer) && base_drag_layer.fill_layer == null) {
  465. tab_layers_make_mask_preview_rgba32(base_drag_layer);
  466. return context_raw.mask_preview_rgba32;
  467. }
  468. if (base_drag_layer != null) {
  469. return base_drag_layer.fill_layer != null ? base_drag_layer.fill_layer.image_icon : base_drag_layer.texpaint_preview;
  470. }
  471. return null;
  472. }
  473. function base_render() {
  474. base_ext_render();
  475. if (context_raw.frame == 2) {
  476. make_material_parse_mesh_material();
  477. make_material_parse_paint_material();
  478. context_raw.ddirty = 0;
  479. // Default workspace
  480. if (config_raw.workspace != 0) {
  481. ui_header_worktab.position = config_raw.workspace;
  482. ui_menubar_workspace_handle.redraws = 2;
  483. ui_header_worktab.changed = true;
  484. }
  485. // Default camera controls
  486. context_raw.camera_controls = config_raw.camera_controls;
  487. }
  488. else if (context_raw.frame == 3) {
  489. context_raw.ddirty = 3;
  490. }
  491. context_raw.frame++;
  492. if (base_is_dragging) {
  493. iron_mouse_set_cursor(cursor_t.HAND);
  494. let img: gpu_texture_t = base_get_drag_image();
  495. let scale_factor: f32 = UI_SCALE();
  496. let size: f32 = (base_drag_size == -1 ? 50 : base_drag_size) * scale_factor;
  497. let ratio: f32 = size / img.width;
  498. let h: f32 = img.height * ratio;
  499. let inv: i32 = 0;
  500. draw_begin();
  501. draw_set_color(base_drag_tint);
  502. let bg_rect: rect_t = base_get_drag_background();
  503. if (bg_rect != null) {
  504. draw_scaled_sub_image(resource_get("icons.k"), bg_rect.x, bg_rect.y, bg_rect.w, bg_rect.h, mouse_x + base_drag_off_x, mouse_y + base_drag_off_y + inv, size, h - inv * 2);
  505. }
  506. base_drag_rect == null ?
  507. draw_scaled_image(img, mouse_x + base_drag_off_x, mouse_y + base_drag_off_y + inv, size, h - inv * 2) :
  508. draw_scaled_sub_image(img, base_drag_rect.x, base_drag_rect.y, base_drag_rect.w, base_drag_rect.h, mouse_x + base_drag_off_x, mouse_y + base_drag_off_y + inv, size, h - inv * 2);
  509. draw_set_color(0xffffffff);
  510. draw_end();
  511. }
  512. let using_menu: bool = ui_menu_show && mouse_y > ui_header_h;
  513. base_ui_enabled = !ui_box_show && !using_menu && !base_is_combo_selected();
  514. if (ui_box_show) {
  515. ui_box_render();
  516. }
  517. if (ui_menu_show) {
  518. ui_menu_render();
  519. }
  520. // Save last pos for continuos paint
  521. context_raw.last_paint_vec_x = context_raw.paint_vec.x;
  522. context_raw.last_paint_vec_y = context_raw.paint_vec.y;
  523. ///if (arm_android || arm_ios)
  524. // No mouse move events for touch, re-init last paint position on touch start
  525. if (!mouse_down()) {
  526. context_raw.last_paint_x = -1;
  527. context_raw.last_paint_y = -1;
  528. }
  529. ///end
  530. }
  531. function base_enum_texts(node_type: string): string[] {
  532. if (node_type == "TEX_IMAGE") {
  533. if (project_asset_names.length > 0) {
  534. return project_asset_names;
  535. }
  536. else {
  537. let empty: string[] = [""];
  538. return empty;
  539. }
  540. }
  541. if (node_type == "LAYER" || node_type == "LAYER_MASK") {
  542. let layer_names: string[] = [];
  543. for (let i: i32 = 0; i < project_layers.length; ++i) {
  544. let l: slot_layer_t = project_layers[i];
  545. array_push(layer_names, l.name);
  546. }
  547. return layer_names;
  548. }
  549. if (node_type == "MATERIAL") {
  550. let material_names: string[] = [];
  551. for (let i: i32 = 0; i < project_materials.length; ++i) {
  552. let m: slot_material_t = project_materials[i];
  553. array_push(material_names, m.canvas.name);
  554. }
  555. return material_names;
  556. }
  557. if (node_type == "image_texture_node") {
  558. if (project_asset_names.length > 0) {
  559. return project_asset_names;
  560. }
  561. else {
  562. let empty: string[] = [""];
  563. return empty;
  564. }
  565. }
  566. return null;
  567. }
  568. function base_get_asset_index(file_name: string): i32 {
  569. let i: i32 = array_index_of(project_asset_names, file_name);
  570. return i >= 0 ? i : 0;
  571. }
  572. function base_toggle_fullscreen() {
  573. if (iron_window_get_mode() == window_mode_t.WINDOWED) {
  574. config_raw.window_w = iron_window_width();
  575. config_raw.window_h = iron_window_height();
  576. config_raw.window_x = iron_window_x();
  577. config_raw.window_y = iron_window_y();
  578. iron_set_window_mode(window_mode_t.FULLSCREEN);
  579. }
  580. else {
  581. iron_set_window_mode(window_mode_t.WINDOWED);
  582. iron_window_resize(config_raw.window_w, config_raw.window_h);
  583. iron_window_move(config_raw.window_x, config_raw.window_y);
  584. }
  585. }
  586. function base_is_scrolling(): bool {
  587. return ui.is_scrolling;
  588. }
  589. function base_is_combo_selected(): bool {
  590. return ui.combo_selected_handle != null;
  591. }
  592. function base_is_decal_layer(): bool {
  593. ///if is_lab
  594. return false;
  595. ///end
  596. let is_painting: bool = context_raw.tool != tool_type_t.MATERIAL && context_raw.tool != tool_type_t.BAKE;
  597. return is_painting && context_raw.layer.fill_layer != null && context_raw.layer.uv_type == uv_type_t.PROJECT;
  598. }
  599. function base_redraw_status() {
  600. ui_base_hwnds[tab_area_t.STATUS].redraws = 2;
  601. }
  602. function base_redraw_console() {
  603. let statush: i32 = config_raw.layout[layout_size_t.STATUS_H];
  604. if (ui != null && statush > ui_status_default_status_h * UI_SCALE()) {
  605. ui_base_hwnds[tab_area_t.STATUS].redraws = 2;
  606. }
  607. }
  608. function base_init_undo_layers() {
  609. if (history_undo_layers == null) {
  610. history_undo_layers = [];
  611. for (let i: i32 = 0; i < config_raw.undo_steps; ++i) {
  612. let len: i32 = history_undo_layers.length;
  613. let ext: string = "_undo" + len;
  614. let l: slot_layer_t = slot_layer_create(ext);
  615. array_push(history_undo_layers, l);
  616. }
  617. }
  618. }
  619. function base_init_layout() {
  620. let raw: config_t = config_raw;
  621. let show2d: bool = (ui_nodes_show || ui_view2d_show) && raw.layout != null;
  622. let new_layout: i32[] = [];
  623. array_push(new_layout, math_floor(ui_base_default_sidebar_w * raw.window_scale)); // LayoutSidebarW
  624. array_push(new_layout, math_floor(iron_window_height() / 2)); // LayoutSidebarH0
  625. array_push(new_layout, math_floor(iron_window_height() / 2)); // LayoutSidebarH1
  626. ///if arm_ios
  627. array_push(new_layout, show2d ? math_floor((sys_w() + raw.layout[layout_size_t.NODES_W]) * 0.473) : math_floor(sys_w() * 0.473)); // LayoutNodesW
  628. ///elseif arm_android
  629. array_push(new_layout, show2d ? math_floor((sys_w() + raw.layout[layout_size_t.NODES_W]) * 0.473) : math_floor(sys_w() * 0.473));
  630. ///else
  631. array_push(new_layout, show2d ? math_floor((sys_w() + raw.layout[layout_size_t.NODES_W]) * 0.515) : math_floor(sys_w() * 0.515)); // Align with ui header controls
  632. ///end
  633. array_push(new_layout, math_floor(sys_h() / 2)); // LayoutNodesH
  634. array_push(new_layout, math_floor(ui_status_default_status_h * raw.window_scale)); // LayoutStatusH
  635. ///if (arm_android || arm_ios)
  636. array_push(new_layout, 0); // LayoutHeader
  637. ///else
  638. array_push(new_layout, 1);
  639. ///end
  640. raw.layout_tabs = [
  641. 0,
  642. 0,
  643. 0
  644. ];
  645. raw.layout = new_layout;
  646. }
  647. function base_init_config() {
  648. let raw: config_t = config_raw;
  649. raw.recent_projects = [];
  650. raw.bookmarks = [];
  651. raw.plugins = [];
  652. ///if (arm_android || arm_ios)
  653. raw.keymap = "touch.json";
  654. ///else
  655. raw.keymap = "default.json";
  656. ///end
  657. raw.theme = "default.json";
  658. raw.server = "https://armorpaint.fra1.digitaloceanspaces.com";
  659. raw.undo_steps = 4;
  660. raw.pressure_radius = true;
  661. raw.pressure_sensitivity = 3.0;
  662. raw.camera_zoom_speed = 1.0;
  663. raw.camera_pan_speed = 1.0;
  664. raw.camera_rotation_speed = 1.0;
  665. raw.zoom_direction = zoom_direction_t.VERTICAL;
  666. raw.displace_strength = 0.0;
  667. raw.wrap_mouse = false;
  668. raw.workspace = space_type_t.SPACE3D;
  669. raw.camera_controls = camera_controls_t.ORBIT;
  670. raw.layer_res = texture_res_t.RES2048;
  671. ///if (arm_android || arm_ios)
  672. raw.touch_ui = true;
  673. raw.splash_screen = true;
  674. ///else
  675. raw.touch_ui = false;
  676. raw.splash_screen = false;
  677. ///end
  678. raw.node_preview = true;
  679. raw.pressure_hardness = true;
  680. raw.pressure_angle = false;
  681. raw.pressure_opacity = false;
  682. ///if (arm_android || arm_ios)
  683. raw.material_live = false;
  684. ///else
  685. raw.material_live = true;
  686. ///end
  687. raw.brush_3d = true;
  688. raw.brush_depth_reject = true;
  689. raw.brush_angle_reject = true;
  690. raw.brush_live = false;
  691. raw.show_asset_names = false;
  692. raw.dilate = dilate_type_t.INSTANT;
  693. raw.dilate_radius = 2;
  694. raw.gpu_inference = true;
  695. raw.blender = "";
  696. raw.scene_atlas_res = texture_res_t.RES8192;
  697. raw.pathtrace_mode = pathtrace_mode_t.FAST;
  698. raw.grid_snap = false;
  699. base_ext_init_config(raw);
  700. }