2
0

ui_base.ts 56 KB

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