base.ts 24 KB

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