ui_base.ts 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  1. type tab_draw_t = {
  2. f: (h: ui_handle_t)=>void;
  3. };
  4. type tab_draw_array_t = tab_draw_t[];
  5. let ui_base_show: bool = true;
  6. let ui_base_ui: ui_t;
  7. let ui_base_border_started: i32 = 0;
  8. let ui_base_border_handle: ui_handle_t = null;
  9. let ui_base_action_paint_remap: string = "";
  10. let ui_base_operator_search_offset: i32 = 0;
  11. let ui_base_undo_tap_time: f32 = 0.0;
  12. let ui_base_redo_tap_time: f32 = 0.0;
  13. let ui_base_hwnds: ui_handle_t[] = ui_base_init_hwnds();
  14. let ui_base_htabs: ui_handle_t[] = ui_base_init_htabs();
  15. let ui_base_hwnd_tabs: tab_draw_array_t[] = ui_base_init_hwnd_tabs();
  16. let ui_base_viewport_col: i32;
  17. ///if is_lab
  18. let ui_base_default_sidebar_mini_w: i32 = 0;
  19. let ui_base_default_sidebar_full_w: i32 = 0;
  20. ///else
  21. let ui_base_default_sidebar_mini_w: i32 = 56;
  22. let ui_base_default_sidebar_full_w: i32 = 280;
  23. ///end
  24. ///if (arm_android || arm_ios)
  25. let ui_base_default_sidebar_w: i32 = ui_base_default_sidebar_mini_w;
  26. ///else
  27. let ui_base_default_sidebar_w: i32 = ui_base_default_sidebar_full_w;
  28. ///end
  29. let ui_base_tabx: i32 = 0;
  30. let ui_base_hminimized: ui_handle_t = ui_handle_create();
  31. let ui_base_sidebar_mini_w: i32 = ui_base_default_sidebar_mini_w;
  32. let _ui_base_operator_search_first: bool;
  33. function ui_base_init_hwnds(): ui_handle_t[] {
  34. let hwnds: ui_handle_t[] = [ui_handle_create(), ui_handle_create(), ui_handle_create()];
  35. return hwnds;
  36. }
  37. function ui_base_init_htabs(): ui_handle_t[] {
  38. let htabs: ui_handle_t[] = [ui_handle_create(), ui_handle_create(), ui_handle_create()];
  39. return htabs;
  40. }
  41. function _draw_callback_create(f: (h: ui_handle_t)=>void): tab_draw_t {
  42. let cb: tab_draw_t = { f: f };
  43. return cb;
  44. }
  45. function ui_base_init_hwnd_tabs(): tab_draw_array_t[] {
  46. return ui_base_ext_init_hwnd_tabs();
  47. }
  48. function ui_base_init() {
  49. ///if (is_paint || is_sculpt)
  50. ui_toolbar_init();
  51. ui_toolbar_w = math_floor(ui_toolbar_default_w * config_raw.window_scale);
  52. context_raw.text_tool_text = tr("Text");
  53. ///end
  54. ui_header_init();
  55. ui_status_init();
  56. ui_menubar_init();
  57. ui_header_h = math_floor(ui_header_default_h * config_raw.window_scale);
  58. ui_menubar_w = math_floor(ui_menubar_default_w * config_raw.window_scale);
  59. ///if (is_paint || is_sculpt)
  60. if (project_materials == null) {
  61. project_materials = [];
  62. let m: material_data_t = data_get_material("Scene", "Material");
  63. array_push(project_materials, slot_material_create(m));
  64. context_raw.material = project_materials[0];
  65. }
  66. if (project_brushes == null) {
  67. project_brushes = [];
  68. array_push(project_brushes, slot_brush_create());
  69. context_raw.brush = project_brushes[0];
  70. make_material_parse_brush();
  71. }
  72. if (project_fonts == null) {
  73. project_fonts = [];
  74. array_push(project_fonts, slot_font_create("default.ttf", base_font));
  75. context_raw.font = project_fonts[0];
  76. }
  77. if (project_layers == null) {
  78. project_layers = [];
  79. array_push(project_layers, slot_layer_create());
  80. context_raw.layer = project_layers[0];
  81. }
  82. ///end
  83. ///if is_lab
  84. if (project_material_data == null) {
  85. let m: material_data_t = data_get_material("Scene", "Material");
  86. project_material_data = m;
  87. }
  88. if (project_default_canvas == null) { // Synchronous
  89. let b: buffer_t = data_get_blob("default_brush.arm");
  90. project_default_canvas = b;
  91. }
  92. project_nodes = ui_nodes_create();
  93. project_canvas = armpack_decode(project_default_canvas);
  94. project_canvas.name = "Brush 1";
  95. brush_output_node_parse_inputs();
  96. parser_logic_parse(project_canvas);
  97. ///end
  98. if (project_raw.swatches == null) {
  99. project_set_default_swatches();
  100. context_raw.swatch = project_raw.swatches[0];
  101. }
  102. if (context_raw.empty_envmap == null) {
  103. ui_base_make_empty_envmap(base_theme.VIEWPORT_COL);
  104. }
  105. if (context_raw.preview_envmap == null) {
  106. let b: u8_array_t = u8_array_create(4);
  107. b[0] = 0;
  108. b[1] = 0;
  109. b[2] = 0;
  110. b[3] = 255;
  111. context_raw.preview_envmap = image_from_bytes(b, 1, 1);
  112. }
  113. let world: world_data_t = scene_world;
  114. if (context_raw.saved_envmap == null) {
  115. // raw.saved_envmap = world._envmap;
  116. context_raw.default_irradiance = world._.irradiance;
  117. context_raw.default_radiance = world._.radiance;
  118. context_raw.default_radiance_mipmaps = world._.radiance_mipmaps;
  119. }
  120. world._.envmap = context_raw.show_envmap ? context_raw.saved_envmap : context_raw.empty_envmap;
  121. context_raw.ddirty = 1;
  122. history_reset();
  123. let scale: f32 = config_raw.window_scale;
  124. let ops: ui_options_t = {
  125. theme: base_theme,
  126. font: base_font,
  127. scale_factor: scale,
  128. color_wheel: base_color_wheel.texture_,
  129. black_white_gradient: base_color_wheel_gradient.texture_
  130. };
  131. ui_base_ui = ui_create(ops);
  132. ui_on_border_hover = ui_base_on_border_hover;
  133. ui_on_text_hover = ui_base_on_text_hover;
  134. ui_on_deselect_text = ui_base_on_deselect_text;
  135. ui_on_tab_drop = ui_base_on_tab_drop;
  136. ///if (is_paint || is_sculpt)
  137. let resources: string[] = ["cursor.k", "icons.k"];
  138. ///end
  139. ///if is_lab
  140. let resources: string[] = ["cursor.k", "icons.k", "placeholder.k"];
  141. ///end
  142. ///if (is_paint || is_sculpt)
  143. context_raw.gizmo = scene_get_child(".Gizmo");
  144. context_raw.gizmo_translate_x = object_get_child(context_raw.gizmo, ".TranslateX");
  145. context_raw.gizmo_translate_y = object_get_child(context_raw.gizmo, ".TranslateY");
  146. context_raw.gizmo_translate_z = object_get_child(context_raw.gizmo, ".TranslateZ");
  147. context_raw.gizmo_scale_x = object_get_child(context_raw.gizmo, ".ScaleX");
  148. context_raw.gizmo_scale_y = object_get_child(context_raw.gizmo, ".ScaleY");
  149. context_raw.gizmo_scale_z = object_get_child(context_raw.gizmo, ".ScaleZ");
  150. context_raw.gizmo_rotate_x = object_get_child(context_raw.gizmo, ".RotateX");
  151. context_raw.gizmo_rotate_y = object_get_child(context_raw.gizmo, ".RotateY");
  152. context_raw.gizmo_rotate_z = object_get_child(context_raw.gizmo, ".RotateZ");
  153. ///end
  154. resource_load(resources);
  155. if (ui_SCALE(ui_base_ui) > 1) {
  156. ui_base_set_icon_scale();
  157. }
  158. context_raw.paint_object = scene_get_child(".Cube").ext;
  159. project_paint_objects = [context_raw.paint_object];
  160. if (project_filepath == "") {
  161. app_notify_on_init(layers_init);
  162. }
  163. context_raw.project_objects = [];
  164. for (let i: i32 = 0; i < scene_meshes.length; ++i) {
  165. let m: mesh_object_t = scene_meshes[i];
  166. array_push(context_raw.project_objects, m);
  167. }
  168. operator_register("view_top", ui_base_view_top);
  169. }
  170. function ui_base_update() {
  171. ui_base_update_ui();
  172. operator_update();
  173. let keys: string[] = map_keys(plugin_map);
  174. for (let i: i32 = 0; i < keys.length; ++i) {
  175. let p: plugin_t = map_get(plugin_map, keys[i]);
  176. if (p.on_update != null) {
  177. js_call(p.on_update);
  178. }
  179. }
  180. if (!base_ui_enabled) {
  181. return;
  182. }
  183. if (!ui_nodes_ui.is_typing && !ui_base_ui.is_typing) {
  184. if (operator_shortcut(map_get(config_keymap, "toggle_node_editor"))) {
  185. ///if (is_paint || is_sculpt)
  186. ui_nodes_canvas_type == canvas_type_t.MATERIAL ? ui_base_show_material_nodes() : ui_base_show_brush_nodes();
  187. ///end
  188. ///if is_lab
  189. ui_base_show_material_nodes();
  190. ///end
  191. }
  192. else if (operator_shortcut(map_get(config_keymap, "toggle_browser"))) {
  193. ui_base_toggle_browser();
  194. }
  195. else if (operator_shortcut(map_get(config_keymap, "toggle_2d_view"))) {
  196. ///if (is_paint || is_sculpt)
  197. ui_base_show_2d_view(view_2d_type_t.LAYER);
  198. ///else
  199. ui_base_show_2d_view(view_2d_type_t.ASSET);
  200. ///end
  201. }
  202. }
  203. if (operator_shortcut(map_get(config_keymap, "file_save_as"))) {
  204. project_save_as();
  205. }
  206. else if (operator_shortcut(map_get(config_keymap, "file_save"))) {
  207. project_save();
  208. }
  209. else if (operator_shortcut(map_get(config_keymap, "file_open"))) {
  210. project_open();
  211. }
  212. else if (operator_shortcut(map_get(config_keymap, "file_open_recent"))) {
  213. box_projects_show();
  214. }
  215. else if (operator_shortcut(map_get(config_keymap, "file_reimport_mesh"))) {
  216. project_reimport_mesh();
  217. }
  218. else if (operator_shortcut(map_get(config_keymap, "file_reimport_textures"))) {
  219. project_reimport_textures();
  220. }
  221. else if (operator_shortcut(map_get(config_keymap, "file_new"))) {
  222. project_new_box();
  223. }
  224. else if (operator_shortcut(map_get(config_keymap, "file_export_textures"))) {
  225. if (context_raw.texture_export_path == "") { // First export, ask for path
  226. context_raw.layers_export = export_mode_t.VISIBLE;
  227. box_export_show_textures();
  228. }
  229. else {
  230. app_notify_on_init(function () {
  231. export_texture_run(context_raw.texture_export_path);
  232. });
  233. }
  234. }
  235. else if (operator_shortcut(map_get(config_keymap, "file_export_textures_as"))) {
  236. context_raw.layers_export = export_mode_t.VISIBLE;
  237. box_export_show_textures();
  238. }
  239. else if (operator_shortcut(map_get(config_keymap, "file_import_assets"))) {
  240. project_import_asset();
  241. }
  242. else if (operator_shortcut(map_get(config_keymap, "edit_prefs"))) {
  243. box_preferences_show();
  244. }
  245. if (keyboard_started(map_get(config_keymap, "view_distract_free")) || (keyboard_started("escape") && !ui_base_show && !ui_box_show)) {
  246. ui_base_toggle_distract_free();
  247. }
  248. ///if arm_linux
  249. if (operator_shortcut("alt+enter", shortcut_type_t.STARTED)) {
  250. base_toggle_fullscreen();
  251. }
  252. ///end
  253. ///if (is_paint || is_sculpt)
  254. let decal: bool = context_is_decal();
  255. let decal_mask: bool = context_is_decal_mask();
  256. if ((context_raw.brush_can_lock || context_raw.brush_locked) && mouse_moved) {
  257. if (operator_shortcut(map_get(config_keymap, "brush_radius"), shortcut_type_t.DOWN) ||
  258. operator_shortcut(map_get(config_keymap, "brush_opacity"), shortcut_type_t.DOWN) ||
  259. operator_shortcut(map_get(config_keymap, "brush_angle"), shortcut_type_t.DOWN) ||
  260. (decal_mask && operator_shortcut(map_get(config_keymap, "decal_mask") + "+" + map_get(config_keymap, "brush_radius"), shortcut_type_t.DOWN))) {
  261. if (context_raw.brush_locked) {
  262. if (operator_shortcut(map_get(config_keymap, "brush_opacity"), shortcut_type_t.DOWN)) {
  263. context_raw.brush_opacity += mouse_movement_x / 500;
  264. context_raw.brush_opacity = math_max(0.0, math_min(1.0, context_raw.brush_opacity));
  265. context_raw.brush_opacity = math_round(context_raw.brush_opacity * 100) / 100;
  266. context_raw.brush_opacity_handle.value = context_raw.brush_opacity;
  267. }
  268. else if (operator_shortcut(map_get(config_keymap, "brush_angle"), shortcut_type_t.DOWN)) {
  269. context_raw.brush_angle += mouse_movement_x / 5;
  270. let i: i32 = math_floor(context_raw.brush_angle);
  271. context_raw.brush_angle = i % 360;
  272. if (context_raw.brush_angle < 0) context_raw.brush_angle += 360;
  273. context_raw.brush_angle_handle.value = context_raw.brush_angle;
  274. make_material_parse_paint_material();
  275. }
  276. else if (decal_mask && operator_shortcut(map_get(config_keymap, "decal_mask") + "+" + map_get(config_keymap, "brush_radius"), shortcut_type_t.DOWN)) {
  277. context_raw.brush_decal_mask_radius += mouse_movement_x / 150;
  278. context_raw.brush_decal_mask_radius = math_max(0.01, math_min(4.0, context_raw.brush_decal_mask_radius));
  279. context_raw.brush_decal_mask_radius = math_round(context_raw.brush_decal_mask_radius * 100) / 100;
  280. context_raw.brush_decal_mask_radius_handle.value = context_raw.brush_decal_mask_radius;
  281. }
  282. else {
  283. context_raw.brush_radius += mouse_movement_x / 150;
  284. context_raw.brush_radius = math_max(0.01, math_min(4.0, context_raw.brush_radius));
  285. context_raw.brush_radius = math_round(context_raw.brush_radius * 100) / 100;
  286. context_raw.brush_radius_handle.value = context_raw.brush_radius;
  287. }
  288. ui_header_handle.redraws = 2;
  289. }
  290. else if (context_raw.brush_can_lock) {
  291. context_raw.brush_can_lock = false;
  292. context_raw.brush_locked = true;
  293. }
  294. }
  295. }
  296. ///end
  297. ///if is_lab
  298. if ((context_raw.brush_can_lock || context_raw.brush_locked) && mouse_moved) {
  299. if (operator_shortcut(map_get(config_keymap, "brush_radius"), shortcut_type_t.DOWN)) {
  300. if (context_raw.brush_locked) {
  301. context_raw.brush_radius += mouse_movement_x / 150;
  302. context_raw.brush_radius = math_max(0.01, math_min(4.0, context_raw.brush_radius));
  303. context_raw.brush_radius = math_round(context_raw.brush_radius * 100) / 100;
  304. context_raw.brush_radius_handle.value = context_raw.brush_radius;
  305. ui_header_handle.redraws = 2;
  306. }
  307. else if (context_raw.brush_can_lock) {
  308. context_raw.brush_can_lock = false;
  309. context_raw.brush_locked = true;
  310. }
  311. }
  312. }
  313. ///end
  314. let is_typing: bool = ui_base_ui.is_typing || ui_view2d_ui.is_typing || ui_nodes_ui.is_typing;
  315. ///if (is_paint || is_sculpt)
  316. if (!is_typing) {
  317. if (operator_shortcut(map_get(config_keymap, "select_material"), shortcut_type_t.DOWN)) {
  318. ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2;
  319. for (let i: i32 = 1; i < 10; ++i) {
  320. if (keyboard_started(i + "")) {
  321. context_select_material(i - 1);
  322. }
  323. }
  324. }
  325. else if (operator_shortcut(map_get(config_keymap, "select_layer"), shortcut_type_t.DOWN)) {
  326. ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2;
  327. for (let i: i32 = 1; i < 10; ++i) {
  328. if (keyboard_started(i + "")) {
  329. context_select_layer(i - 1);
  330. }
  331. }
  332. }
  333. }
  334. ///end
  335. // Viewport shortcuts
  336. if (context_in_paint_area() && !is_typing) {
  337. ///if is_paint
  338. if (!mouse_down("right")) { // Fly mode off
  339. if (operator_shortcut(map_get(config_keymap, "tool_brush"))) {
  340. context_select_tool(workspace_tool_t.BRUSH);
  341. }
  342. else if (operator_shortcut(map_get(config_keymap, "tool_eraser"))) {
  343. context_select_tool(workspace_tool_t.ERASER);
  344. }
  345. else if (operator_shortcut(map_get(config_keymap, "tool_fill"))) {
  346. context_select_tool(workspace_tool_t.FILL);
  347. }
  348. else if (operator_shortcut(map_get(config_keymap, "tool_colorid"))) {
  349. context_select_tool(workspace_tool_t.COLORID);
  350. }
  351. else if (operator_shortcut(map_get(config_keymap, "tool_decal"))) {
  352. context_select_tool(workspace_tool_t.DECAL);
  353. }
  354. else if (operator_shortcut(map_get(config_keymap, "tool_text"))) {
  355. context_select_tool(workspace_tool_t.TEXT);
  356. }
  357. else if (operator_shortcut(map_get(config_keymap, "tool_clone"))) {
  358. context_select_tool(workspace_tool_t.CLONE);
  359. }
  360. else if (operator_shortcut(map_get(config_keymap, "tool_blur"))) {
  361. context_select_tool(workspace_tool_t.BLUR);
  362. }
  363. else if (operator_shortcut(map_get(config_keymap, "tool_smudge"))) {
  364. context_select_tool(workspace_tool_t.SMUDGE);
  365. }
  366. else if (operator_shortcut(map_get(config_keymap, "tool_particle"))) {
  367. context_select_tool(workspace_tool_t.PARTICLE);
  368. }
  369. else if (operator_shortcut(map_get(config_keymap, "tool_picker"))) {
  370. context_select_tool(workspace_tool_t.PICKER);
  371. }
  372. else if (operator_shortcut(map_get(config_keymap, "tool_bake"))) {
  373. context_select_tool(workspace_tool_t.BAKE);
  374. }
  375. else if (operator_shortcut(map_get(config_keymap, "tool_gizmo"))) {
  376. context_select_tool(workspace_tool_t.GIZMO);
  377. }
  378. else if (operator_shortcut(map_get(config_keymap, "tool_material"))) {
  379. context_select_tool(workspace_tool_t.MATERIAL);
  380. }
  381. else if (operator_shortcut(map_get(config_keymap, "swap_brush_eraser"))) {
  382. context_select_tool(context_raw.tool == workspace_tool_t.BRUSH ? workspace_tool_t.ERASER : workspace_tool_t.BRUSH);
  383. }
  384. }
  385. // Radius
  386. if (context_raw.tool == workspace_tool_t.BRUSH ||
  387. context_raw.tool == workspace_tool_t.ERASER ||
  388. context_raw.tool == workspace_tool_t.DECAL ||
  389. context_raw.tool == workspace_tool_t.TEXT ||
  390. context_raw.tool == workspace_tool_t.CLONE ||
  391. context_raw.tool == workspace_tool_t.BLUR ||
  392. context_raw.tool == workspace_tool_t.SMUDGE ||
  393. context_raw.tool == workspace_tool_t.PARTICLE) {
  394. if (operator_shortcut(map_get(config_keymap, "brush_radius")) ||
  395. operator_shortcut(map_get(config_keymap, "brush_opacity")) ||
  396. operator_shortcut(map_get(config_keymap, "brush_angle")) ||
  397. (decal_mask && operator_shortcut(map_get(config_keymap, "decal_mask") + "+" + map_get(config_keymap, "brush_radius")))) {
  398. context_raw.brush_can_lock = true;
  399. if (!pen_connected) {
  400. mouse_lock();
  401. }
  402. context_raw.lock_started_x = mouse_x;
  403. context_raw.lock_started_y = mouse_y;
  404. }
  405. else if (operator_shortcut(map_get(config_keymap, "brush_radius_decrease"), shortcut_type_t.REPEAT)) {
  406. context_raw.brush_radius -= ui_base_get_radius_increment();
  407. context_raw.brush_radius = math_max(math_round(context_raw.brush_radius * 100) / 100, 0.01);
  408. context_raw.brush_radius_handle.value = context_raw.brush_radius;
  409. ui_header_handle.redraws = 2;
  410. }
  411. else if (operator_shortcut(map_get(config_keymap, "brush_radius_increase"), shortcut_type_t.REPEAT)) {
  412. context_raw.brush_radius += ui_base_get_radius_increment();
  413. context_raw.brush_radius = math_round(context_raw.brush_radius * 100) / 100;
  414. context_raw.brush_radius_handle.value = context_raw.brush_radius;
  415. ui_header_handle.redraws = 2;
  416. }
  417. else if (decal_mask) {
  418. if (operator_shortcut(map_get(config_keymap, "decal_mask") + "+" + map_get(config_keymap, "brush_radius_decrease"), shortcut_type_t.REPEAT)) {
  419. context_raw.brush_decal_mask_radius -= ui_base_get_radius_increment();
  420. context_raw.brush_decal_mask_radius = math_max(math_round(context_raw.brush_decal_mask_radius * 100) / 100, 0.01);
  421. context_raw.brush_decal_mask_radius_handle.value = context_raw.brush_decal_mask_radius;
  422. ui_header_handle.redraws = 2;
  423. }
  424. else if (operator_shortcut(map_get(config_keymap, "decal_mask") + "+" + map_get(config_keymap, "brush_radius_increase"), shortcut_type_t.REPEAT)) {
  425. context_raw.brush_decal_mask_radius += ui_base_get_radius_increment();
  426. context_raw.brush_decal_mask_radius = math_round(context_raw.brush_decal_mask_radius * 100) / 100;
  427. context_raw.brush_decal_mask_radius_handle.value = context_raw.brush_decal_mask_radius;
  428. ui_header_handle.redraws = 2;
  429. }
  430. }
  431. }
  432. if (decal_mask && (operator_shortcut(map_get(config_keymap, "decal_mask"), shortcut_type_t.STARTED) || operator_shortcut(map_get(config_keymap, "decal_mask"), shortcut_type_t.RELEASED))) {
  433. ui_header_handle.redraws = 2;
  434. }
  435. ///end
  436. ///if is_lab
  437. if (ui_header_worktab.position == space_type_t.SPACE3D) {
  438. // Radius
  439. if (context_raw.tool == workspace_tool_t.ERASER ||
  440. context_raw.tool == workspace_tool_t.CLONE ||
  441. context_raw.tool == workspace_tool_t.BLUR ||
  442. context_raw.tool == workspace_tool_t.SMUDGE) {
  443. if (operator_shortcut(map_get(config_keymap, "brush_radius"))) {
  444. context_raw.brush_can_lock = true;
  445. if (!pen_connected) {
  446. mouse_lock();
  447. }
  448. context_raw.lock_started_x = mouse_x;
  449. context_raw.lock_started_y = mouse_y;
  450. }
  451. else if (operator_shortcut(map_get(config_keymap, "brush_radius_decrease"), shortcut_type_t.REPEAT)) {
  452. context_raw.brush_radius -= ui_base_get_radius_increment();
  453. context_raw.brush_radius = math_max(math_round(context_raw.brush_radius * 100) / 100, 0.01);
  454. context_raw.brush_radius_handle.value = context_raw.brush_radius;
  455. ui_header_handle.redraws = 2;
  456. }
  457. else if (operator_shortcut(map_get(config_keymap, "brush_radius_increase"), shortcut_type_t.REPEAT)) {
  458. context_raw.brush_radius += ui_base_get_radius_increment();
  459. context_raw.brush_radius = math_round(context_raw.brush_radius * 100) / 100;
  460. context_raw.brush_radius_handle.value = context_raw.brush_radius;
  461. ui_header_handle.redraws = 2;
  462. }
  463. }
  464. }
  465. ///end
  466. // Viewpoint
  467. if (mouse_view_x() < app_w()) {
  468. if (operator_shortcut(map_get(config_keymap, "view_reset"))) {
  469. viewport_reset();
  470. viewport_scale_to_bounds();
  471. }
  472. else if (operator_shortcut(map_get(config_keymap, "view_back"))) {
  473. viewport_set_view(0, 1, 0, math_pi() / 2, 0, math_pi());
  474. }
  475. else if (operator_shortcut(map_get(config_keymap, "view_front"))) {
  476. viewport_set_view(0, -1, 0, math_pi() / 2, 0, 0);
  477. }
  478. else if (operator_shortcut(map_get(config_keymap, "view_left"))) {
  479. viewport_set_view(-1, 0, 0, math_pi() / 2, 0, -math_pi() / 2);
  480. }
  481. else if (operator_shortcut(map_get(config_keymap, "view_right"))) {
  482. viewport_set_view(1, 0, 0, math_pi() / 2, 0, math_pi() / 2);
  483. }
  484. else if (operator_shortcut(map_get(config_keymap, "view_bottom"))) {
  485. viewport_set_view(0, 0, -1, math_pi(), 0, math_pi());
  486. }
  487. else if (operator_shortcut(map_get(config_keymap, "view_camera_type"))) {
  488. context_raw.camera_type = context_raw.camera_type == camera_type_t.PERSPECTIVE ? camera_type_t.ORTHOGRAPHIC : camera_type_t.PERSPECTIVE;
  489. context_raw.cam_handle.position = context_raw.camera_type;
  490. viewport_update_camera_type(context_raw.camera_type);
  491. }
  492. else if (operator_shortcut(map_get(config_keymap, "view_orbit_left"), shortcut_type_t.REPEAT)) {
  493. viewport_orbit(-math_pi() / 12, 0);
  494. }
  495. else if (operator_shortcut(map_get(config_keymap, "view_orbit_right"), shortcut_type_t.REPEAT)) {
  496. viewport_orbit(math_pi() / 12, 0);
  497. }
  498. else if (operator_shortcut(map_get(config_keymap, "view_orbit_up"), shortcut_type_t.REPEAT)) {
  499. viewport_orbit(0, -math_pi() / 12);
  500. }
  501. else if (operator_shortcut(map_get(config_keymap, "view_orbit_down"), shortcut_type_t.REPEAT)) {
  502. viewport_orbit(0, math_pi() / 12);
  503. }
  504. else if (operator_shortcut(map_get(config_keymap, "view_orbit_opposite"))) {
  505. viewport_orbit_opposite();
  506. }
  507. else if (operator_shortcut(map_get(config_keymap, "view_zoom_in"), shortcut_type_t.REPEAT)) {
  508. viewport_zoom(0.2);
  509. }
  510. else if (operator_shortcut(map_get(config_keymap, "view_zoom_out"), shortcut_type_t.REPEAT)) {
  511. viewport_zoom(-0.2);
  512. }
  513. else if (operator_shortcut(map_get(config_keymap, "viewport_mode"))) {
  514. base_ui_menu.is_key_pressed = false;
  515. ui_menu_draw(function (ui: ui_t) {
  516. let mode_handle: ui_handle_t = ui_handle(__ID__);
  517. mode_handle.position = context_raw.viewport_mode;
  518. ui_text(tr("Viewport Mode"), ui_align_t.RIGHT);
  519. let modes: string[] = [
  520. tr("Lit"),
  521. tr("Base Color"),
  522. tr("Normal"),
  523. tr("Occlusion"),
  524. tr("Roughness"),
  525. tr("Metallic"),
  526. tr("Opacity"),
  527. tr("Height"),
  528. ///if (is_paint || is_sculpt)
  529. tr("Emission"),
  530. tr("Subsurface"),
  531. tr("TexCoord"),
  532. tr("Object Normal"),
  533. tr("Material ID"),
  534. tr("Object ID"),
  535. tr("Mask")
  536. ///end
  537. ];
  538. let shortcuts: string[] = ["l", "b", "n", "o", "r", "m", "a", "h", "e", "s", "t", "1", "2", "3", "4"];
  539. ///if (arm_direct3d12 || arm_vulkan || arm_metal)
  540. if (iron_raytrace_supported()) {
  541. array_push(modes, tr("Path Traced"));
  542. array_push(shortcuts, "p");
  543. }
  544. ///end
  545. for (let i: i32 = 0; i < modes.length; ++i) {
  546. ui_radio(mode_handle, i, modes[i], shortcuts[i]);
  547. }
  548. let index: i32 = array_index_of(shortcuts, keyboard_key_code(ui.key_code));
  549. if (ui.is_key_pressed && index != -1) {
  550. mode_handle.position = index;
  551. ui.changed = true;
  552. context_set_viewport_mode(mode_handle.position);
  553. }
  554. else if (mode_handle.changed) {
  555. context_set_viewport_mode(mode_handle.position);
  556. ui.changed = true;
  557. }
  558. });
  559. }
  560. }
  561. if (operator_shortcut(map_get(config_keymap, "operator_search"))) {
  562. ui_base_operator_search();
  563. }
  564. }
  565. if (context_raw.brush_can_lock || context_raw.brush_locked) {
  566. if (mouse_moved && context_raw.brush_can_unlock) {
  567. context_raw.brush_locked = false;
  568. context_raw.brush_can_unlock = false;
  569. }
  570. ///if (is_paint || is_sculpt)
  571. let b: bool = (context_raw.brush_can_lock || context_raw.brush_locked) &&
  572. !operator_shortcut(map_get(config_keymap, "brush_radius"), shortcut_type_t.DOWN) &&
  573. !operator_shortcut(map_get(config_keymap, "brush_opacity"), shortcut_type_t.DOWN) &&
  574. !operator_shortcut(map_get(config_keymap, "brush_angle"), shortcut_type_t.DOWN) &&
  575. !(decal_mask && operator_shortcut(map_get(config_keymap, "decal_mask") + "+" + map_get(config_keymap, "brush_radius"), shortcut_type_t.DOWN));
  576. ///end
  577. ///if is_lab
  578. let b: bool = (context_raw.brush_can_lock || context_raw.brush_locked) &&
  579. !operator_shortcut(map_get(config_keymap, "brush_radius"), shortcut_type_t.DOWN);
  580. ///end
  581. if (b) {
  582. mouse_unlock();
  583. context_raw.last_paint_x = -1;
  584. context_raw.last_paint_y = -1;
  585. if (context_raw.brush_can_lock) {
  586. context_raw.brush_can_lock = false;
  587. context_raw.brush_can_unlock = false;
  588. context_raw.brush_locked = false;
  589. }
  590. else {
  591. context_raw.brush_can_unlock = true;
  592. }
  593. }
  594. }
  595. if (ui_base_border_handle != null) {
  596. if (ui_base_border_handle == ui_nodes_hwnd || ui_base_border_handle == ui_view2d_hwnd) {
  597. if (ui_base_border_started == border_side_t.LEFT) {
  598. config_raw.layout[layout_size_t.NODES_W] -= math_floor(mouse_movement_x);
  599. if (config_raw.layout[layout_size_t.NODES_W] < 32) {
  600. config_raw.layout[layout_size_t.NODES_W] = 32;
  601. }
  602. else if (config_raw.layout[layout_size_t.NODES_W] > sys_width() * 0.7) {
  603. config_raw.layout[layout_size_t.NODES_W] = math_floor(sys_width() * 0.7);
  604. }
  605. }
  606. else { // UINodes / UIView2D ratio
  607. config_raw.layout[layout_size_t.NODES_H] -= math_floor(mouse_movement_y);
  608. if (config_raw.layout[layout_size_t.NODES_H] < 32) {
  609. config_raw.layout[layout_size_t.NODES_H] = 32;
  610. }
  611. else if (config_raw.layout[layout_size_t.NODES_H] > app_h() * 0.95) {
  612. config_raw.layout[layout_size_t.NODES_H] = math_floor(app_h() * 0.95);
  613. }
  614. }
  615. }
  616. else if (ui_base_border_handle == ui_base_hwnds[tab_area_t.STATUS]) {
  617. let my: i32 = math_floor(mouse_movement_y);
  618. if (config_raw.layout[layout_size_t.STATUS_H] - my >= ui_status_default_status_h * config_raw.window_scale && config_raw.layout[layout_size_t.STATUS_H] - my < sys_height() * 0.7) {
  619. config_raw.layout[layout_size_t.STATUS_H] -= my;
  620. }
  621. }
  622. else {
  623. if (ui_base_border_started == border_side_t.LEFT) {
  624. config_raw.layout[layout_size_t.SIDEBAR_W] -= math_floor(mouse_movement_x);
  625. if (config_raw.layout[layout_size_t.SIDEBAR_W] < ui_base_sidebar_mini_w) {
  626. config_raw.layout[layout_size_t.SIDEBAR_W] = ui_base_sidebar_mini_w;
  627. }
  628. else if (config_raw.layout[layout_size_t.SIDEBAR_W] > sys_width() - ui_base_sidebar_mini_w) {
  629. config_raw.layout[layout_size_t.SIDEBAR_W] = sys_width() - ui_base_sidebar_mini_w;
  630. }
  631. }
  632. else {
  633. let my: i32 = math_floor(mouse_movement_y);
  634. if (ui_base_border_handle == ui_base_hwnds[tab_area_t.SIDEBAR1] && ui_base_border_started == border_side_t.TOP) {
  635. if (config_raw.layout[layout_size_t.SIDEBAR_H0] + my > 32 && config_raw.layout[layout_size_t.SIDEBAR_H1] - my > 32) {
  636. config_raw.layout[layout_size_t.SIDEBAR_H0] += my;
  637. config_raw.layout[layout_size_t.SIDEBAR_H1] -= my;
  638. }
  639. }
  640. }
  641. }
  642. }
  643. if (!mouse_down()) {
  644. ui_base_border_handle = null;
  645. base_is_resizing = false;
  646. }
  647. ///if arm_physics
  648. if (context_raw.tool == workspace_tool_t.PARTICLE && context_raw.particle_physics && context_in_paint_area() && !context_raw.paint2d) {
  649. util_particle_init_physics();
  650. let world: physics_world_t = physics_world_active;
  651. physics_world_update(world);
  652. context_raw.ddirty = 2;
  653. context_raw.rdirty = 2;
  654. if (mouse_started()) {
  655. if (context_raw.particle_timer != null) {
  656. tween_stop(context_raw.particle_timer);
  657. let timer: tween_anim_t = context_raw.particle_timer;
  658. timer.done(timer.done_data);
  659. context_raw.particle_timer = null;
  660. }
  661. history_push_undo = true;
  662. context_raw.particle_hit_x = context_raw.particle_hit_y = context_raw.particle_hit_z = 0;
  663. let o: object_t = scene_spawn_object(".Sphere");
  664. let md: material_data_t = data_get_material("Scene", ".Gizmo");
  665. let mo: mesh_object_t = o.ext;
  666. mo.base.name = ".Bullet";
  667. mo.materials[0] = md;
  668. mo.base.visible = true;
  669. let camera: camera_object_t = scene_camera;
  670. let ct: transform_t = camera.base.transform;
  671. mo.base.transform.loc = vec4_create(transform_world_x(ct), transform_world_y(ct), transform_world_z(ct));
  672. mo.base.transform.scale = vec4_create(context_raw.brush_radius * 0.2, context_raw.brush_radius * 0.2, context_raw.brush_radius * 0.2);
  673. transform_build_matrix(mo.base.transform);
  674. let body: physics_body_t = physics_body_create();
  675. body.shape = physics_shape_t.SPHERE;
  676. body.mass = 1.0;
  677. physics_body_init(body, mo.base);
  678. let ray: ray_t = raycast_get_ray(mouse_view_x(), mouse_view_y(), camera);
  679. physics_body_apply_impulse(body, vec4_mult(ray.dir, 0.15));
  680. context_raw.particle_timer = tween_timer(5, function (mo: mesh_object_t) {
  681. mesh_object_remove(mo);
  682. }, mo);
  683. }
  684. let pairs: physics_pair_t[] = physics_world_get_contact_pairs(world, context_raw.paint_body);
  685. if (pairs != null) {
  686. for (let i: i32 = 0; i < pairs.length; ++i) {
  687. let p: physics_pair_t = pairs[i];
  688. context_raw.last_particle_hit_x = context_raw.particle_hit_x != 0 ? context_raw.particle_hit_x : p.pos_a_x;
  689. context_raw.last_particle_hit_y = context_raw.particle_hit_y != 0 ? context_raw.particle_hit_y : p.pos_a_y;
  690. context_raw.last_particle_hit_z = context_raw.particle_hit_z != 0 ? context_raw.particle_hit_z : p.pos_a_z;
  691. context_raw.particle_hit_x = p.pos_a_x;
  692. context_raw.particle_hit_y = p.pos_a_y;
  693. context_raw.particle_hit_z = p.pos_a_z;
  694. context_raw.pdirty = 1;
  695. break; // 1 pair for now
  696. }
  697. }
  698. }
  699. ///end
  700. }
  701. function ui_base_view_top() {
  702. let is_typing: bool = ui_base_ui.is_typing || ui_view2d_ui.is_typing || ui_nodes_ui.is_typing;
  703. if (context_in_paint_area() && !is_typing) {
  704. if (mouse_view_x() < app_w()) {
  705. viewport_set_view(0, 0, 1, 0, 0, 0);
  706. }
  707. }
  708. }
  709. function ui_base_operator_search() {
  710. _ui_base_operator_search_first = true;
  711. ui_menu_draw(function (ui: ui_t) {
  712. ui_menu_h = ui_ELEMENT_H(ui) * 8;
  713. let search_handle: ui_handle_t = ui_handle(__ID__);
  714. let search: string = ui_text_input(search_handle, "", ui_align_t.LEFT, true, true);
  715. ui.changed = false;
  716. if (_ui_base_operator_search_first) {
  717. _ui_base_operator_search_first = false;
  718. search_handle.text = "";
  719. ui_start_text_edit(search_handle); // Focus search bar
  720. }
  721. if (search_handle.changed) {
  722. ui_base_operator_search_offset = 0;
  723. }
  724. if (ui.is_key_pressed) { // Move selection
  725. if (ui.key_code == key_code_t.DOWN && ui_base_operator_search_offset < 6) {
  726. ui_base_operator_search_offset++;
  727. }
  728. if (ui.key_code == key_code_t.UP && ui_base_operator_search_offset > 0) {
  729. ui_base_operator_search_offset--;
  730. }
  731. }
  732. let enter: bool = keyboard_down("enter");
  733. let count: i32 = 0;
  734. let BUTTON_COL: i32 = ui.ops.theme.BUTTON_COL;
  735. let keys: string[] = map_keys(config_keymap);
  736. for (let i: i32 = 0; i < keys.length; ++i) {
  737. let n: string = keys[i];
  738. if (string_index_of(n, search) >= 0) {
  739. ui.ops.theme.BUTTON_COL = count == ui_base_operator_search_offset ? ui.ops.theme.HIGHLIGHT_COL : ui.ops.theme.SEPARATOR_COL;
  740. if (ui_button(n, ui_align_t.LEFT, map_get(config_keymap, n)) || (enter && count == ui_base_operator_search_offset)) {
  741. if (enter) {
  742. ui.changed = true;
  743. count = 6; // Trigger break
  744. }
  745. operator_run(n);
  746. }
  747. if (++count > 6) {
  748. break;
  749. }
  750. }
  751. }
  752. if (enter && count == 0) { // Hide popup on enter when command is not found
  753. ui.changed = true;
  754. search_handle.text = "";
  755. }
  756. ui.ops.theme.BUTTON_COL = BUTTON_COL;
  757. });
  758. }
  759. function ui_base_toggle_distract_free() {
  760. ui_base_show = !ui_base_show;
  761. base_resize();
  762. }
  763. function ui_base_get_radius_increment(): f32 {
  764. return 0.1;
  765. }
  766. function ui_base_hit_rect(mx: f32, my: f32, x: i32, y: i32, w: i32, h: i32): bool {
  767. return mx > x && mx < x + w && my > y && my < y + h;
  768. }
  769. function ui_base_get_brush_stencil_rect(): rect_t {
  770. let w: i32 = math_floor(context_raw.brush_stencil_image.width * (base_h() / context_raw.brush_stencil_image.height) * context_raw.brush_stencil_scale);
  771. let h: i32 = math_floor(base_h() * context_raw.brush_stencil_scale);
  772. let x: i32 = math_floor(base_x() + context_raw.brush_stencil_x * base_w());
  773. let y: i32 = math_floor(base_y() + context_raw.brush_stencil_y * base_h());
  774. let r: rect_t = {
  775. w: w,
  776. h: h,
  777. x: x,
  778. y: y
  779. };
  780. return r;
  781. }
  782. function ui_base_update_ui() {
  783. if (console_message_timer > 0) {
  784. console_message_timer -= time_delta();
  785. if (console_message_timer <= 0) {
  786. ui_base_hwnds[tab_area_t.STATUS].redraws = 2;
  787. }
  788. }
  789. ui_base_sidebar_mini_w = math_floor(ui_base_default_sidebar_mini_w * ui_SCALE(ui_base_ui));
  790. if (!base_ui_enabled) {
  791. return;
  792. }
  793. // Same mapping for paint and rotate (predefined in touch keymap)
  794. if (context_in_viewport()) {
  795. if (mouse_started() && map_get(config_keymap, "action_paint") == map_get(config_keymap, "action_rotate")) {
  796. ui_base_action_paint_remap = map_get(config_keymap, "action_paint");
  797. util_render_pick_pos_nor_tex();
  798. let is_mesh: bool = math_abs(context_raw.posx_picked) < 50 && math_abs(context_raw.posy_picked) < 50 && math_abs(context_raw.posz_picked) < 50;
  799. ///if arm_android
  800. // Allow rotating with both pen and touch, because hovering a pen prevents touch input on android
  801. let pen_only: bool = false;
  802. ///else
  803. let pen_only: bool = context_raw.pen_painting_only;
  804. ///end
  805. let is_pen: bool = pen_only && pen_down();
  806. // Mesh picked - disable rotate
  807. // Pen painting only - rotate with touch, paint with pen
  808. if ((is_mesh && !pen_only) || is_pen) {
  809. map_set(config_keymap, "action_rotate", "");
  810. map_set(config_keymap, "action_paint", ui_base_action_paint_remap);
  811. }
  812. // World sphere picked - disable paint
  813. else {
  814. map_set(config_keymap, "action_paint", "");
  815. map_set(config_keymap, "action_rotate", ui_base_action_paint_remap);
  816. }
  817. }
  818. else if (!mouse_down() && ui_base_action_paint_remap != "") {
  819. map_set(config_keymap, "action_rotate", ui_base_action_paint_remap);
  820. map_set(config_keymap, "action_paint", ui_base_action_paint_remap);
  821. ui_base_action_paint_remap = "";
  822. }
  823. }
  824. if (context_raw.brush_stencil_image != null && operator_shortcut(map_get(config_keymap, "stencil_transform"), shortcut_type_t.DOWN)) {
  825. let r: rect_t = ui_base_get_brush_stencil_rect();
  826. if (mouse_started("left")) {
  827. context_raw.brush_stencil_scaling =
  828. ui_base_hit_rect(mouse_x, mouse_y, r.x - 8, r.y - 8, 16, 16) ||
  829. ui_base_hit_rect(mouse_x, mouse_y, r.x - 8, r.h + r.y - 8, 16, 16) ||
  830. ui_base_hit_rect(mouse_x, mouse_y, r.w + r.x - 8, r.y - 8, 16, 16) ||
  831. ui_base_hit_rect(mouse_x, mouse_y, r.w + r.x - 8, r.h + r.y - 8, 16, 16);
  832. let cosa: f32 = math_cos(-context_raw.brush_stencil_angle);
  833. let sina: f32 = math_sin(-context_raw.brush_stencil_angle);
  834. let ox: f32 = 0;
  835. let oy: f32 = -r.h / 2;
  836. let x: f32 = ox * cosa - oy * sina;
  837. let y: f32 = ox * sina + oy * cosa;
  838. x += r.x + r.w / 2;
  839. y += r.y + r.h / 2;
  840. context_raw.brush_stencil_rotating =
  841. ui_base_hit_rect(mouse_x, mouse_y, math_floor(x - 16), math_floor(y - 16), 32, 32);
  842. }
  843. let _scale: f32 = context_raw.brush_stencil_scale;
  844. if (mouse_down("left")) {
  845. if (context_raw.brush_stencil_scaling) {
  846. let mult: i32 = mouse_x > r.x + r.w / 2 ? 1 : -1;
  847. context_raw.brush_stencil_scale += mouse_movement_x / 400 * mult;
  848. }
  849. else if (context_raw.brush_stencil_rotating) {
  850. let gizmo_x: f32 = r.x + r.w / 2;
  851. let gizmo_y: f32 = r.y + r.h / 2;
  852. context_raw.brush_stencil_angle = -math_atan2(mouse_y - gizmo_y, mouse_x - gizmo_x) - math_pi() / 2;
  853. }
  854. else {
  855. context_raw.brush_stencil_x += mouse_movement_x / base_w();
  856. context_raw.brush_stencil_y += mouse_movement_y / base_h();
  857. }
  858. }
  859. else {
  860. context_raw.brush_stencil_scaling = false;
  861. }
  862. if (mouse_wheel_delta != 0) {
  863. context_raw.brush_stencil_scale -= mouse_wheel_delta / 10;
  864. }
  865. // Center after scale
  866. let ratio: f32 = base_h() / context_raw.brush_stencil_image.height;
  867. let old_w: f32 = _scale * context_raw.brush_stencil_image.width * ratio;
  868. let new_w: f32 = context_raw.brush_stencil_scale * context_raw.brush_stencil_image.width * ratio;
  869. let old_h: f32 = _scale * base_h();
  870. let new_h: f32 = context_raw.brush_stencil_scale * base_h();
  871. context_raw.brush_stencil_x += (old_w - new_w) / base_w() / 2;
  872. context_raw.brush_stencil_y += (old_h - new_h) / base_h() / 2;
  873. }
  874. let set_clone_source: bool = context_raw.tool == workspace_tool_t.CLONE && operator_shortcut(map_get(config_keymap, "set_clone_source") + "+" + map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN);
  875. let decal: bool = context_is_decal();
  876. let decal_mask: bool = context_is_decal_mask_paint();
  877. ///if (is_paint || is_sculpt)
  878. let down: bool = operator_shortcut(map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN) ||
  879. decal_mask ||
  880. set_clone_source ||
  881. operator_shortcut(map_get(config_keymap, "brush_ruler") + "+" + map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN) ||
  882. (pen_down() && !keyboard_down("alt"));
  883. ///end
  884. ///if is_lab
  885. let down: bool = operator_shortcut(map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN) ||
  886. set_clone_source ||
  887. operator_shortcut(map_get(config_keymap, "brush_ruler") + "+" + map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN) ||
  888. (pen_down() && !keyboard_down("alt"));
  889. ///end
  890. if (config_raw.touch_ui) {
  891. if (pen_down()) {
  892. context_raw.pen_painting_only = true;
  893. }
  894. else if (context_raw.pen_painting_only) {
  895. down = false;
  896. }
  897. }
  898. ///if arm_physics
  899. if (context_raw.tool == workspace_tool_t.PARTICLE && context_raw.particle_physics) {
  900. down = false;
  901. }
  902. ///end
  903. ///if arm_ios
  904. // No hover on iPad, decals are painted by pen release
  905. if (decal) {
  906. down = pen_released();
  907. if (!context_raw.pen_painting_only) {
  908. down = down || mouse_released();
  909. }
  910. }
  911. ///end
  912. if (down) {
  913. let mx: i32 = mouse_view_x();
  914. let my: i32 = mouse_view_y();
  915. let ww: i32 = app_w();
  916. if (context_raw.paint2d) {
  917. mx -= app_w();
  918. ww = ui_view2d_ww;
  919. }
  920. if (mx < ww &&
  921. mx > app_x() &&
  922. my < app_h() &&
  923. my > app_y()) {
  924. if (set_clone_source) {
  925. context_raw.clone_start_x = mx;
  926. context_raw.clone_start_y = my;
  927. }
  928. else {
  929. if (context_raw.brush_time == 0 &&
  930. !base_is_dragging &&
  931. !base_is_resizing &&
  932. !base_is_combo_selected()) { // Paint started
  933. // Draw line
  934. if (operator_shortcut(map_get(config_keymap, "brush_ruler") + "+" + map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN)) {
  935. context_raw.last_paint_vec_x = context_raw.last_paint_x;
  936. context_raw.last_paint_vec_y = context_raw.last_paint_y;
  937. }
  938. history_push_undo = true;
  939. if (context_raw.tool == workspace_tool_t.CLONE && context_raw.clone_start_x >= 0.0) { // Clone delta
  940. context_raw.clone_delta_x = (context_raw.clone_start_x - mx) / ww;
  941. context_raw.clone_delta_y = (context_raw.clone_start_y - my) / app_h();
  942. context_raw.clone_start_x = -1;
  943. }
  944. else if (context_raw.tool == workspace_tool_t.PARTICLE) {
  945. // Reset particles
  946. ///if arm_particles
  947. let emitter: mesh_object_t = scene_get_child(".ParticleEmitter").ext;
  948. let psys: particle_sys_t = emitter.particle_systems[0];
  949. psys.time = 0;
  950. // psys.time = psys.seed * psys.animtime;
  951. // psys.seed++;
  952. ///end
  953. }
  954. else if (context_raw.tool == workspace_tool_t.FILL && context_raw.fill_type_handle.position == fill_type_t.UV_ISLAND) {
  955. util_uv_uvislandmap_cached = false;
  956. }
  957. }
  958. context_raw.brush_time += time_delta();
  959. if (context_raw.run_brush != null) {
  960. context_raw.run_brush(context_raw.brush_output_node_inst, 0);
  961. }
  962. }
  963. }
  964. }
  965. else if (context_raw.brush_time > 0) { // Brush released
  966. context_raw.brush_time = 0;
  967. context_raw.prev_paint_vec_x = -1;
  968. context_raw.prev_paint_vec_y = -1;
  969. ///if (arm_opengl || arm_direct3d11) // Keep accumulated samples for D3D12
  970. context_raw.ddirty = 3;
  971. ///end
  972. context_raw.brush_blend_dirty = true; // Update brush mask
  973. context_raw.layer_preview_dirty = true; // Update layer preview
  974. // New color id picked, update fill layer
  975. if (context_raw.tool == workspace_tool_t.COLORID && context_raw.layer.fill_layer != null) {
  976. app_notify_on_next_frame(function () {
  977. layers_update_fill_layer();
  978. make_material_parse_paint_material(false);
  979. });
  980. }
  981. }
  982. if (context_raw.layers_preview_dirty) {
  983. context_raw.layers_preview_dirty = false;
  984. context_raw.layer_preview_dirty = false;
  985. context_raw.mask_preview_last = null;
  986. // Update all layer previews
  987. for (let i: i32 = 0; i < project_layers.length; ++i) {
  988. let l: slot_layer_t = project_layers[i];
  989. if (slot_layer_is_group(l)) {
  990. continue;
  991. }
  992. let target: image_t = l.texpaint_preview;
  993. if (target == null) {
  994. continue;
  995. }
  996. let source: image_t = l.texpaint;
  997. g2_begin(target);
  998. g2_clear(0x00000000);
  999. // g2_set_pipeline(l.is_mask() ? pipes_copy8 : pipes_copy);
  1000. g2_set_pipeline(pipes_copy); // texpaint_preview is always RGBA32 for now
  1001. g2_draw_scaled_image(source, 0, 0, target.width, target.height);
  1002. g2_set_pipeline(null);
  1003. g2_end();
  1004. }
  1005. ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2;
  1006. }
  1007. if (context_raw.layer != null && context_raw.layer_preview_dirty && !slot_layer_is_group(context_raw.layer)) {
  1008. context_raw.layer_preview_dirty = false;
  1009. context_raw.mask_preview_last = null;
  1010. // Update layer preview
  1011. let l: slot_layer_t = context_raw.layer;
  1012. let target: image_t = l.texpaint_preview;
  1013. if (target != null) {
  1014. let source: image_t = l.texpaint;
  1015. g2_begin(target);
  1016. g2_clear(0x00000000);
  1017. // g2_set_pipeline(raw.layer.is_mask() ? pipes_copy8 : pipes_copy);
  1018. g2_set_pipeline(pipes_copy); // texpaint_preview is always RGBA32 for now
  1019. g2_draw_scaled_image(source, 0, 0, target.width, target.height);
  1020. g2_set_pipeline(null);
  1021. g2_end();
  1022. ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2;
  1023. }
  1024. }
  1025. let undo_pressed: bool = operator_shortcut(map_get(config_keymap, "edit_undo"));
  1026. let redo_pressed: bool = operator_shortcut(map_get(config_keymap, "edit_redo")) ||
  1027. (keyboard_down("control") && keyboard_started("y"));
  1028. // Two-finger tap to undo, three-finger tap to redo
  1029. if (context_in_viewport() && config_raw.touch_ui) {
  1030. if (mouse_started("middle")) {
  1031. ui_base_redo_tap_time = time_time();
  1032. }
  1033. else if (mouse_started("right")) {
  1034. ui_base_undo_tap_time = time_time();
  1035. }
  1036. else if (mouse_released("middle") && time_time() - ui_base_redo_tap_time < 0.1) {
  1037. ui_base_redo_tap_time = ui_base_undo_tap_time = 0;
  1038. redo_pressed = true;
  1039. }
  1040. else if (mouse_released("right") && time_time() - ui_base_undo_tap_time < 0.1) {
  1041. ui_base_redo_tap_time = ui_base_undo_tap_time = 0;
  1042. undo_pressed = true;
  1043. }
  1044. }
  1045. if (undo_pressed) {
  1046. history_undo();
  1047. }
  1048. else if (redo_pressed) {
  1049. history_redo();
  1050. }
  1051. ///if (is_paint || is_sculpt)
  1052. gizmo_update();
  1053. ///end
  1054. }
  1055. function ui_base_render() {
  1056. if (!ui_base_show && config_raw.touch_ui) {
  1057. ui_base_ui.input_enabled = true;
  1058. g2_end();
  1059. ui_begin(ui_base_ui);
  1060. if (ui_window(ui_handle(__ID__), 0, 0, 150, math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui) + 1))) {
  1061. if (ui_button(tr("Close"))) {
  1062. ui_base_toggle_distract_free();
  1063. }
  1064. }
  1065. ui_end();
  1066. g2_begin(null);
  1067. }
  1068. if (!ui_base_show || sys_width() == 0 || sys_height() == 0) {
  1069. return;
  1070. }
  1071. ui_base_ui.input_enabled = base_ui_enabled;
  1072. // Remember last tab positions
  1073. for (let i: i32 = 0; i < ui_base_htabs.length; ++i) {
  1074. if (ui_base_htabs[i].changed) {
  1075. config_raw.layout_tabs[i] = ui_base_htabs[i].position;
  1076. config_save();
  1077. }
  1078. }
  1079. // Set tab positions
  1080. for (let i: i32 = 0; i < ui_base_htabs.length; ++i) {
  1081. ui_base_htabs[i].position = config_raw.layout_tabs[i];
  1082. }
  1083. g2_end();
  1084. ui_begin(ui_base_ui);
  1085. ///if (is_paint || is_sculpt)
  1086. ui_toolbar_render_ui();
  1087. ///end
  1088. ui_menubar_render_ui();
  1089. ui_header_render_ui();
  1090. ui_status_render_ui();
  1091. ///if (is_paint || is_sculpt)
  1092. ui_base_draw_sidebar();
  1093. ///end
  1094. ui_end();
  1095. g2_begin(null);
  1096. }
  1097. function ui_base_draw_sidebar() {
  1098. // Tabs
  1099. let mini: bool = config_raw.layout[layout_size_t.SIDEBAR_W] <= ui_base_sidebar_mini_w;
  1100. let expand_button_offset: i32 = config_raw.touch_ui ? math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui)) : 0;
  1101. ui_base_tabx = sys_width() - config_raw.layout[layout_size_t.SIDEBAR_W];
  1102. let _SCROLL_W: i32 = ui_base_ui.ops.theme.SCROLL_W;
  1103. if (mini) {
  1104. ui_base_ui.ops.theme.SCROLL_W = ui_base_ui.ops.theme.SCROLL_MINI_W;
  1105. }
  1106. if (ui_window(ui_base_hwnds[tab_area_t.SIDEBAR0], ui_base_tabx, 0, config_raw.layout[layout_size_t.SIDEBAR_W], config_raw.layout[layout_size_t.SIDEBAR_H0])) {
  1107. let tabs: tab_draw_t[] = ui_base_hwnd_tabs[tab_area_t.SIDEBAR0];
  1108. for (let i: i32 = 0; i < (mini ? 1 : tabs.length); ++i) {
  1109. tabs[i].f(ui_base_htabs[tab_area_t.SIDEBAR0]);
  1110. }
  1111. }
  1112. if (ui_window(ui_base_hwnds[tab_area_t.SIDEBAR1], ui_base_tabx, config_raw.layout[layout_size_t.SIDEBAR_H0], config_raw.layout[layout_size_t.SIDEBAR_W], config_raw.layout[layout_size_t.SIDEBAR_H1] - expand_button_offset)) {
  1113. let tabs: tab_draw_t[] = ui_base_hwnd_tabs[tab_area_t.SIDEBAR1];
  1114. for (let i: i32 = 0; i < (mini ? 1 : tabs.length); ++i) {
  1115. tabs[i].f(ui_base_htabs[tab_area_t.SIDEBAR1]);
  1116. }
  1117. }
  1118. ui_end_window();
  1119. ui_base_ui.ops.theme.SCROLL_W = _SCROLL_W;
  1120. // Collapse / expand button for mini sidebar
  1121. if (config_raw.touch_ui) {
  1122. let width: i32 = config_raw.layout[layout_size_t.SIDEBAR_W];
  1123. let height: i32 = math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui));
  1124. if (ui_window(ui_handle(__ID__), sys_width() - width, sys_height() - height, width, height + 1)) {
  1125. ui_base_ui._w = width;
  1126. let _BUTTON_H: i32 = ui_base_ui.ops.theme.BUTTON_H;
  1127. let _BUTTON_COL: i32 = ui_base_ui.ops.theme.BUTTON_COL;
  1128. ui_base_ui.ops.theme.BUTTON_H = ui_base_ui.ops.theme.ELEMENT_H;
  1129. ui_base_ui.ops.theme.BUTTON_COL = ui_base_ui.ops.theme.WINDOW_BG_COL;
  1130. if (ui_button(mini ? "<<" : ">>")) {
  1131. config_raw.layout[layout_size_t.SIDEBAR_W] = mini ? ui_base_default_sidebar_full_w : ui_base_default_sidebar_mini_w;
  1132. config_raw.layout[layout_size_t.SIDEBAR_W] = math_floor(config_raw.layout[layout_size_t.SIDEBAR_W] * ui_SCALE(ui_base_ui));
  1133. }
  1134. ui_base_ui.ops.theme.BUTTON_H = _BUTTON_H;
  1135. ui_base_ui.ops.theme.BUTTON_COL = _BUTTON_COL;
  1136. }
  1137. }
  1138. // Expand button
  1139. if (config_raw.layout[layout_size_t.SIDEBAR_W] == 0) {
  1140. let width: i32 = math_floor(g2_font_width(ui_base_ui.ops.font, ui_base_ui.font_size, "<<") + 25 * ui_SCALE(ui_base_ui));
  1141. if (ui_window(ui_base_hminimized, sys_width() - width, 0, width, math_floor(ui_ELEMENT_H(ui_base_ui) + ui_ELEMENT_OFFSET(ui_base_ui) + 1))) {
  1142. ui_base_ui._w = width;
  1143. let _BUTTON_H: i32 = ui_base_ui.ops.theme.BUTTON_H;
  1144. let _BUTTON_COL: i32 = ui_base_ui.ops.theme.BUTTON_COL;
  1145. ui_base_ui.ops.theme.BUTTON_H = ui_base_ui.ops.theme.ELEMENT_H;
  1146. ui_base_ui.ops.theme.BUTTON_COL = ui_base_ui.ops.theme.SEPARATOR_COL;
  1147. if (ui_button("<<")) {
  1148. config_raw.layout[layout_size_t.SIDEBAR_W] = context_raw.maximized_sidebar_width != 0 ? context_raw.maximized_sidebar_width : math_floor(ui_base_default_sidebar_w * config_raw.window_scale);
  1149. }
  1150. ui_base_ui.ops.theme.BUTTON_H = _BUTTON_H;
  1151. ui_base_ui.ops.theme.BUTTON_COL = _BUTTON_COL;
  1152. }
  1153. }
  1154. else if (ui_base_htabs[tab_area_t.SIDEBAR0].changed && ui_base_htabs[tab_area_t.SIDEBAR0].position == context_raw.last_htab0_pos) {
  1155. if (time_time() - context_raw.select_time < 0.25) {
  1156. context_raw.maximized_sidebar_width = config_raw.layout[layout_size_t.SIDEBAR_W];
  1157. config_raw.layout[layout_size_t.SIDEBAR_W] = 0;
  1158. }
  1159. context_raw.select_time = time_time();
  1160. }
  1161. context_raw.last_htab0_pos = ui_base_htabs[tab_area_t.SIDEBAR0].position;
  1162. }
  1163. function ui_base_render_cursor() {
  1164. if (!base_ui_enabled) {
  1165. return;
  1166. }
  1167. if (context_raw.tool == workspace_tool_t.MATERIAL || context_raw.tool == workspace_tool_t.BAKE) {
  1168. return;
  1169. }
  1170. g2_set_color(0xffffffff);
  1171. context_raw.view_index = context_raw.view_index_last;
  1172. let mx: i32 = base_x() + context_raw.paint_vec.x * base_w();
  1173. let my: i32 = base_y() + context_raw.paint_vec.y * base_h();
  1174. context_raw.view_index = -1;
  1175. // Radius being scaled
  1176. if (context_raw.brush_locked) {
  1177. mx += context_raw.lock_started_x - sys_width() / 2;
  1178. my += context_raw.lock_started_y - sys_height() / 2;
  1179. }
  1180. if (context_raw.brush_stencil_image != null &&
  1181. // @ts-ignore
  1182. context_raw.tool != workspace_tool_t.BAKE &&
  1183. context_raw.tool != workspace_tool_t.PICKER &&
  1184. // @ts-ignore
  1185. context_raw.tool != workspace_tool_t.MATERIAL &&
  1186. context_raw.tool != workspace_tool_t.COLORID) {
  1187. let r: rect_t = ui_base_get_brush_stencil_rect();
  1188. if (!operator_shortcut(map_get(config_keymap, "stencil_hide"), shortcut_type_t.DOWN)) {
  1189. g2_set_color(0x88ffffff);
  1190. let angle: f32 = context_raw.brush_stencil_angle;
  1191. let cx: f32 = r.x + r.w / 2;
  1192. let cy: f32 = r.y + r.h / 2;
  1193. g2_set_transformation(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(-angle)), mat3_translation(-cx, -cy)));
  1194. g2_draw_scaled_image(context_raw.brush_stencil_image, r.x, r.y, r.w, r.h);
  1195. g2_set_transformation(mat3_nan());
  1196. g2_set_color(0xffffffff);
  1197. }
  1198. let transform: bool = operator_shortcut(map_get(config_keymap, "stencil_transform"), shortcut_type_t.DOWN);
  1199. if (transform) {
  1200. // Outline
  1201. g2_draw_rect(r.x, r.y, r.w, r.h);
  1202. // Scale
  1203. g2_draw_rect(r.x - 8, r.y - 8, 16, 16);
  1204. g2_draw_rect(r.x - 8 + r.w, r.y - 8, 16, 16);
  1205. g2_draw_rect(r.x - 8, r.y - 8 + r.h, 16, 16);
  1206. g2_draw_rect(r.x - 8 + r.w, r.y - 8 + r.h, 16, 16);
  1207. // Rotate
  1208. let angle: f32 = context_raw.brush_stencil_angle;
  1209. let cx: f32 = r.x + r.w / 2;
  1210. let cy: f32 = r.y + r.h / 2;
  1211. g2_set_transformation(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(-angle)), mat3_translation(-cx, -cy)));
  1212. g2_fill_circle(r.x + r.w / 2, r.y - 4, 8);
  1213. g2_set_transformation(mat3_nan());
  1214. }
  1215. }
  1216. // Show picked material next to cursor
  1217. if (context_raw.tool == workspace_tool_t.PICKER && context_raw.picker_select_material && context_raw.color_picker_callback == null) {
  1218. let img: image_t = context_raw.material.image_icon;
  1219. ///if arm_opengl
  1220. g2_draw_scaled_image(img, mx + 10, my + 10 + img.height, img.width, -img.height);
  1221. ///else
  1222. g2_draw_image(img, mx + 10, my + 10);
  1223. ///end
  1224. }
  1225. if (context_raw.tool == workspace_tool_t.PICKER && context_raw.color_picker_callback != null) {
  1226. let img: image_t = resource_get("icons.k");
  1227. let rect: rect_t = resource_tile50(img, workspace_tool_t.PICKER, 0);
  1228. g2_draw_sub_image(img, mx + 10, my + 10, rect.x, rect.y, rect.w, rect.h);
  1229. }
  1230. let cursor_img: image_t = resource_get("cursor.k");
  1231. let psize: i32 = math_floor(182 * (context_raw.brush_radius * context_raw.brush_nodes_radius) * ui_SCALE(ui_base_ui));
  1232. // Clone source cursor
  1233. if (context_raw.tool == workspace_tool_t.CLONE && !keyboard_down("alt") && (mouse_down() || pen_down())) {
  1234. g2_set_color(0x66ffffff);
  1235. g2_draw_scaled_image(cursor_img, mx + context_raw.clone_delta_x * app_w() - psize / 2, my + context_raw.clone_delta_y * app_h() - psize / 2, psize, psize);
  1236. g2_set_color(0xffffffff);
  1237. }
  1238. let decal: bool = context_is_decal();
  1239. if (!config_raw.brush_3d || context_in_2d_view() || decal) {
  1240. let decal_mask: bool = context_is_decal_mask();
  1241. if (decal && !context_in_nodes()) {
  1242. let decal_alpha: f32 = 0.5;
  1243. if (!decal_mask) {
  1244. context_raw.decal_x = context_raw.paint_vec.x;
  1245. context_raw.decal_y = context_raw.paint_vec.y;
  1246. decal_alpha = context_raw.brush_opacity;
  1247. // Radius being scaled
  1248. if (context_raw.brush_locked) {
  1249. context_raw.decal_x += (context_raw.lock_started_x - sys_width() / 2) / base_w();
  1250. context_raw.decal_y += (context_raw.lock_started_y - sys_height() / 2) / base_h();
  1251. }
  1252. }
  1253. if (!config_raw.brush_live) {
  1254. 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));
  1255. let psizey: i32 = math_floor(256 * ui_SCALE(ui_base_ui) * (context_raw.brush_radius * context_raw.brush_nodes_radius));
  1256. context_raw.view_index = context_raw.view_index_last;
  1257. let decalx: f32 = base_x() + context_raw.decal_x * base_w() - psizex / 2;
  1258. let decaly: f32 = base_y() + context_raw.decal_y * base_h() - psizey / 2;
  1259. context_raw.view_index = -1;
  1260. g2_set_color(color_from_floats(1, 1, 1, decal_alpha));
  1261. let angle: f32 = (context_raw.brush_angle + context_raw.brush_nodes_angle) * (math_pi() / 180);
  1262. let cx: f32 = decalx + psizex / 2;
  1263. let cy: f32 = decaly + psizey / 2;
  1264. g2_set_transformation(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(angle)), mat3_translation(-cx, -cy)));
  1265. ///if (arm_direct3d11 || arm_direct3d12 || arm_metal || arm_vulkan)
  1266. g2_draw_scaled_image(context_raw.decal_image, decalx, decaly, psizex, psizey);
  1267. ///else
  1268. g2_draw_scaled_image(context_raw.decal_image, decalx, decaly + psizey, psizex, -psizey);
  1269. ///end
  1270. g2_set_transformation(mat3_nan());
  1271. g2_set_color(0xffffffff);
  1272. }
  1273. }
  1274. if (context_raw.tool == workspace_tool_t.BRUSH ||
  1275. context_raw.tool == workspace_tool_t.ERASER ||
  1276. context_raw.tool == workspace_tool_t.CLONE ||
  1277. context_raw.tool == workspace_tool_t.BLUR ||
  1278. context_raw.tool == workspace_tool_t.SMUDGE ||
  1279. context_raw.tool == workspace_tool_t.PARTICLE ||
  1280. (decal_mask && !config_raw.brush_3d) ||
  1281. (decal_mask && context_in_2d_view())) {
  1282. if (decal_mask) {
  1283. psize = math_floor(cursor_img.width * (context_raw.brush_decal_mask_radius * context_raw.brush_nodes_radius) * ui_SCALE(ui_base_ui));
  1284. }
  1285. if (config_raw.brush_3d && context_in_2d_view()) {
  1286. psize = math_floor(psize * ui_view2d_pan_scale);
  1287. }
  1288. g2_draw_scaled_image(cursor_img, mx - psize / 2, my - psize / 2, psize, psize);
  1289. }
  1290. }
  1291. if (context_raw.brush_lazy_radius > 0 && !context_raw.brush_locked &&
  1292. (context_raw.tool == workspace_tool_t.BRUSH ||
  1293. context_raw.tool == workspace_tool_t.ERASER ||
  1294. context_raw.tool == workspace_tool_t.DECAL ||
  1295. context_raw.tool == workspace_tool_t.TEXT ||
  1296. context_raw.tool == workspace_tool_t.CLONE ||
  1297. context_raw.tool == workspace_tool_t.BLUR ||
  1298. context_raw.tool == workspace_tool_t.SMUDGE ||
  1299. context_raw.tool == workspace_tool_t.PARTICLE)) {
  1300. g2_fill_rect(mx - 1, my - 1, 2, 2);
  1301. mx = context_raw.brush_lazy_x * base_w() + base_x();
  1302. my = context_raw.brush_lazy_y * base_h() + base_y();
  1303. let radius: f32 = context_raw.brush_lazy_radius * 180;
  1304. g2_set_color(0xff666666);
  1305. g2_draw_scaled_image(cursor_img, mx - radius / 2, my - radius / 2, radius, radius);
  1306. g2_set_color(0xffffffff);
  1307. }
  1308. }
  1309. function ui_base_show_material_nodes() {
  1310. // Clear input state as ui receives input events even when not drawn
  1311. _ui_end_input(ui_nodes_ui);
  1312. ///if (is_paint || is_sculpt)
  1313. ui_nodes_show = !ui_nodes_show || ui_nodes_canvas_type != canvas_type_t.MATERIAL;
  1314. ui_nodes_canvas_type = canvas_type_t.MATERIAL;
  1315. ///end
  1316. ///if is_lab
  1317. ui_nodes_show = !ui_nodes_show;
  1318. ///end
  1319. base_resize();
  1320. }
  1321. function ui_base_show_brush_nodes() {
  1322. // Clear input state as ui receives input events even when not drawn
  1323. _ui_end_input(ui_nodes_ui);
  1324. ui_nodes_show = !ui_nodes_show || ui_nodes_canvas_type != canvas_type_t.BRUSH;
  1325. ui_nodes_canvas_type = canvas_type_t.BRUSH;
  1326. base_resize();
  1327. }
  1328. function ui_base_show_2d_view(type: view_2d_type_t) {
  1329. // Clear input state as ui receives input events even when not drawn
  1330. _ui_end_input(ui_view2d_ui);
  1331. if (ui_view2d_type != type) {
  1332. ui_view2d_show = true;
  1333. }
  1334. else {
  1335. ui_view2d_show = !ui_view2d_show;
  1336. }
  1337. ui_view2d_type = type;
  1338. ui_view2d_hwnd.redraws = 2;
  1339. base_resize();
  1340. }
  1341. function ui_base_toggle_browser() {
  1342. let minimized: bool = config_raw.layout[layout_size_t.STATUS_H] <= (ui_status_default_status_h * config_raw.window_scale);
  1343. config_raw.layout[layout_size_t.STATUS_H] = minimized ? 240 : ui_status_default_status_h;
  1344. config_raw.layout[layout_size_t.STATUS_H] = math_floor(config_raw.layout[layout_size_t.STATUS_H] * config_raw.window_scale);
  1345. }
  1346. function ui_base_set_icon_scale() {
  1347. if (ui_SCALE(ui_base_ui) > 1) {
  1348. let res: string[] = ["icons2x.k"];
  1349. resource_load(res);
  1350. map_set(resource_bundled, "icons.k", resource_get("icons2x.k"));
  1351. }
  1352. else {
  1353. let res: string[] = ["icons.k"];
  1354. resource_load(res);
  1355. }
  1356. }
  1357. function ui_base_on_border_hover(handle: ui_handle_t, side: i32) {
  1358. if (!base_ui_enabled) return;
  1359. if (handle != ui_base_hwnds[tab_area_t.SIDEBAR0] &&
  1360. handle != ui_base_hwnds[tab_area_t.SIDEBAR1] &&
  1361. handle != ui_base_hwnds[tab_area_t.STATUS] &&
  1362. handle != ui_nodes_hwnd &&
  1363. handle != ui_view2d_hwnd) {
  1364. return; // Scalable handles
  1365. }
  1366. if (handle == ui_view2d_hwnd && side != border_side_t.LEFT) {
  1367. return;
  1368. }
  1369. if (handle == ui_nodes_hwnd && side == border_side_t.TOP && !ui_view2d_show) {
  1370. return;
  1371. }
  1372. if (handle == ui_base_hwnds[tab_area_t.SIDEBAR0] && side == border_side_t.TOP) {
  1373. return;
  1374. }
  1375. if (handle == ui_nodes_hwnd && side != border_side_t.LEFT && side != border_side_t.TOP) {
  1376. return;
  1377. }
  1378. if (handle == ui_base_hwnds[tab_area_t.STATUS] && side != border_side_t.TOP) {
  1379. return;
  1380. }
  1381. if (side == border_side_t.RIGHT) {
  1382. return; // UI is snapped to the right side
  1383. }
  1384. side == border_side_t.LEFT || side == border_side_t.RIGHT ?
  1385. iron_set_mouse_cursor(3) : // Horizontal
  1386. iron_set_mouse_cursor(4); // Vertical
  1387. if (ui_get_current().input_started) {
  1388. ui_base_border_started = side;
  1389. ui_base_border_handle = handle;
  1390. base_is_resizing = true;
  1391. }
  1392. }
  1393. function ui_base_on_text_hover() {
  1394. iron_set_mouse_cursor(2); // I-cursor
  1395. }
  1396. function ui_base_on_deselect_text() {
  1397. ///if arm_ios
  1398. keyboard_up_listener(key_code_t.SHIFT);
  1399. ///end
  1400. }
  1401. function ui_base_on_tab_drop(to: ui_handle_t, to_position: i32, from: ui_handle_t, from_position: i32) {
  1402. let i: i32 = -1;
  1403. let j: i32 = -1;
  1404. for (let k: i32 = 0; k < ui_base_htabs.length; ++k) {
  1405. if (ui_base_htabs[k] == to) {
  1406. i = k;
  1407. }
  1408. if (ui_base_htabs[k] == from) {
  1409. j = k;
  1410. }
  1411. }
  1412. if (i == j && to_position == from_position) {
  1413. return;
  1414. }
  1415. if (i > -1 && j > -1) {
  1416. let tabsi: tab_draw_t[] = ui_base_hwnd_tabs[i];
  1417. let tabsj: tab_draw_t[] = ui_base_hwnd_tabs[j];
  1418. let element: tab_draw_t = tabsj[from_position];
  1419. array_splice(tabsj, from_position, 1);
  1420. array_insert(tabsi, to_position, element);
  1421. ui_base_hwnds[i].redraws = 2;
  1422. ui_base_hwnds[j].redraws = 2;
  1423. }
  1424. }
  1425. function ui_base_tag_ui_redraw() {
  1426. ui_header_handle.redraws = 2;
  1427. ui_base_hwnds[tab_area_t.STATUS].redraws = 2;
  1428. ui_menubar_workspace_handle.redraws = 2;
  1429. ui_menubar_menu_handle.redraws = 2;
  1430. ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2;
  1431. ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2;
  1432. ui_toolbar_handle.redraws = 2;
  1433. }
  1434. function ui_base_make_empty_envmap(col: i32) {
  1435. ui_base_viewport_col = col;
  1436. let b: u8_array_t = u8_array_create(4);
  1437. b[0] = color_get_rb(col);
  1438. b[1] = color_get_gb(col);
  1439. b[2] = color_get_bb(col);
  1440. b[3] = 255;
  1441. context_raw.empty_envmap = image_from_bytes(b, 1, 1);
  1442. }
  1443. function ui_base_set_viewport_col(col: i32) {
  1444. ui_base_make_empty_envmap(col);
  1445. context_raw.ddirty = 2;
  1446. if (!context_raw.show_envmap) {
  1447. scene_world._.envmap = context_raw.empty_envmap;
  1448. }
  1449. }