From f97490cdb8155505576e56f2fbe1b31c5e4e7a49 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Mon, 27 Mar 2023 16:45:57 +0200 Subject: [PATCH] Cleanup --- armorpaint/Sources/arm/Enums.hx | 6 +++ armorpaint/Sources/arm/ui/TabBrowser.hx | 2 +- armorpaint/Sources/arm/ui/UIBase.hx | 43 +++++++++++----------- armorpaint/Sources/arm/ui/UIStatus.hx | 8 ++-- base/Sources/arm/io/ImportBlendMaterial.hx | 2 +- base/Sources/arm/io/ImportFont.hx | 2 +- base/Sources/arm/io/ImportTexture.hx | 2 +- 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/armorpaint/Sources/arm/Enums.hx b/armorpaint/Sources/arm/Enums.hx index 7e7dcb22..b943b7b6 100644 --- a/armorpaint/Sources/arm/Enums.hx +++ b/armorpaint/Sources/arm/Enums.hx @@ -31,6 +31,12 @@ package arm; var AreaBrowser = 5; } +@:enum abstract TabArea(Int) from Int to Int { + var TabSidebar0 = 0; + var TabSidebar1 = 1; + var TabStatus = 2; +} + @:enum abstract TextureRes(Int) from Int to Int { var Res128 = 0; var Res256 = 1; diff --git a/armorpaint/Sources/arm/ui/TabBrowser.hx b/armorpaint/Sources/arm/ui/TabBrowser.hx index f25f797a..6d5d3634 100644 --- a/armorpaint/Sources/arm/ui/TabBrowser.hx +++ b/armorpaint/Sources/arm/ui/TabBrowser.hx @@ -16,7 +16,7 @@ class TabBrowser { public static function showDirectory(directory: String) { hpath.text = directory; hsearch.text = ""; - UIBase.inst.htabs[2].position = 0; + UIBase.inst.htabs[TabStatus].position = 0; } @:access(zui.Zui) diff --git a/armorpaint/Sources/arm/ui/UIBase.hx b/armorpaint/Sources/arm/ui/UIBase.hx index 3e93c77d..c1c995c6 100644 --- a/armorpaint/Sources/arm/ui/UIBase.hx +++ b/armorpaint/Sources/arm/ui/UIBase.hx @@ -34,7 +34,6 @@ class UIBase { public var tabx = 0; public var show = true; public var ui: Zui; - // Sidebar0, Sidebar1, Status public var hwnds = [Id.handle(), Id.handle(), Id.handle()]; public var htabs = [Id.handle(), Id.handle(), Id.handle()]; public var hwndTabs = [ @@ -268,11 +267,11 @@ class UIBase { var isTyping = ui.isTyping || UIView2D.inst.ui.isTyping || UINodes.inst.ui.isTyping; if (!isTyping) { if (Operator.shortcut(Config.keymap.select_material, ShortcutDown)) { - hwnds[1].redraws = 2; + hwnds[TabSidebar1].redraws = 2; for (i in 1...10) if (kb.started(i + "")) Context.selectMaterial(i - 1); } else if (Operator.shortcut(Config.keymap.select_layer, ShortcutDown)) { - hwnds[0].redraws = 2; + hwnds[TabSidebar0].redraws = 2; for (i in 1...10) if (kb.started(i + "")) Context.selectLayer(i - 1); } } @@ -454,7 +453,7 @@ class UIBase { else if (Config.raw.layout[LayoutNodesH] > iron.App.h() * 0.95) Config.raw.layout[LayoutNodesH] = Std.int(iron.App.h() * 0.95); } } - else if (borderHandle == hwnds[2]) { + else if (borderHandle == hwnds[TabStatus]) { var my = Std.int(mouse.movementY); if (Config.raw.layout[LayoutStatusH] - my >= UIStatus.defaultStatusH * Config.raw.window_scale && Config.raw.layout[LayoutStatusH] - my < System.windowHeight() * 0.7) { Config.raw.layout[LayoutStatusH] -= my; @@ -468,7 +467,7 @@ class UIBase { } else { var my = Std.int(mouse.movementY); - if (borderHandle == hwnds[1] && borderStarted == SideTop) { + if (borderHandle == hwnds[TabSidebar1] && borderStarted == SideTop) { if (Config.raw.layout[LayoutSidebarH0] + my > 32 && Config.raw.layout[LayoutSidebarH1] - my > 32) { Config.raw.layout[LayoutSidebarH0] += my; Config.raw.layout[LayoutSidebarH1] -= my; @@ -624,7 +623,7 @@ class UIBase { if (Console.messageTimer > 0) { Console.messageTimer -= Time.delta; - if (Console.messageTimer <= 0) hwnds[2].redraws = 2; + if (Console.messageTimer <= 0) hwnds[TabStatus].redraws = 2; } if (!App.uiEnabled) return; @@ -842,7 +841,7 @@ class UIBase { g2.pipeline = null; g2.end(); } - hwnds[0].redraws = 2; + hwnds[TabSidebar0].redraws = 2; } if (Context.raw.layerPreviewDirty && !Context.raw.layer.isGroup()) { Context.raw.layerPreviewDirty = false; @@ -859,7 +858,7 @@ class UIBase { g2.drawScaledImage(source, 0, 0, target.width, target.height); g2.pipeline = null; g2.end(); - hwnds[0].redraws = 2; + hwnds[TabSidebar0].redraws = 2; } var undoPressed = Operator.shortcut(Config.keymap.edit_undo); @@ -901,11 +900,11 @@ class UIBase { UIStatus.inst.renderUI(g); tabx = System.windowWidth() - Config.raw.layout[LayoutSidebarW]; - if (ui.window(hwnds[0], tabx, 0, Config.raw.layout[LayoutSidebarW], Config.raw.layout[LayoutSidebarH0])) { - for (draw in hwndTabs[0]) draw(htabs[0]); + if (ui.window(hwnds[TabSidebar0], tabx, 0, Config.raw.layout[LayoutSidebarW], Config.raw.layout[LayoutSidebarH0])) { + for (draw in hwndTabs[TabSidebar0]) draw(htabs[TabSidebar0]); } - if (ui.window(hwnds[1], tabx, Config.raw.layout[LayoutSidebarH0], Config.raw.layout[LayoutSidebarW], Config.raw.layout[LayoutSidebarH1])) { - for (draw in hwndTabs[1]) draw(htabs[1]); + if (ui.window(hwnds[TabSidebar1], tabx, Config.raw.layout[LayoutSidebarH0], Config.raw.layout[LayoutSidebarW], Config.raw.layout[LayoutSidebarH1])) { + for (draw in hwndTabs[TabSidebar1]) draw(htabs[TabSidebar1]); } if (Config.raw.layout[LayoutSidebarW] == 0) { @@ -917,14 +916,14 @@ class UIBase { } } } - else if (htabs[0].changed && (htabs[0].position == Context.raw.lastHtab0Position)) { + else if (htabs[TabSidebar0].changed && htabs[TabSidebar0].position == Context.raw.lastHtab0Position) { if (Time.time() - Context.raw.selectTime < 0.25) { Context.raw.maximizedSidebarWidth = Config.raw.layout[LayoutSidebarW]; Config.raw.layout[LayoutSidebarW] = 0; } Context.raw.selectTime = Time.time(); } - Context.raw.lastHtab0Position = htabs[0].position; + Context.raw.lastHtab0Position = htabs[TabSidebar0].position; ui.end(); g.begin(false); @@ -1129,16 +1128,16 @@ class UIBase { function onBorderHover(handle: Handle, side: Int) { if (!App.uiEnabled) return; - if (handle != hwnds[0] && - handle != hwnds[1] && - handle != hwnds[2] && + if (handle != hwnds[TabSidebar0] && + handle != hwnds[TabSidebar1] && + handle != hwnds[TabStatus] && handle != UINodes.inst.hwnd && handle != UIView2D.inst.hwnd) return; // Scalable handles if (handle == UINodes.inst.hwnd && side != SideLeft && side != SideTop) return; if (handle == UINodes.inst.hwnd && side == SideTop && !UIView2D.inst.show) return; if (handle == UIView2D.inst.hwnd && side != SideLeft) return; - if (handle == hwnds[0] && side == SideTop) return; - if (handle == hwnds[2] && side != SideTop) return; + if (handle == hwnds[TabSidebar0] && side == SideTop) return; + if (handle == hwnds[TabStatus] && side != SideTop) return; if (side == SideRight) return; // UI is snapped to the right side side == SideLeft || side == SideRight ? @@ -1178,10 +1177,10 @@ class UIBase { public function tagUIRedraw() { UIHeader.inst.headerHandle.redraws = 2; UIToolbar.inst.toolbarHandle.redraws = 2; - hwnds[2].redraws = 2; + hwnds[TabStatus].redraws = 2; UIMenubar.inst.workspaceHandle.redraws = 2; UIMenubar.inst.menuHandle.redraws = 2; - hwnds[0].redraws = 2; - hwnds[1].redraws = 2; + hwnds[TabSidebar0].redraws = 2; + hwnds[TabSidebar1].redraws = 2; } } diff --git a/armorpaint/Sources/arm/ui/UIStatus.hx b/armorpaint/Sources/arm/ui/UIStatus.hx index acdad4d7..d294e9ef 100644 --- a/armorpaint/Sources/arm/ui/UIStatus.hx +++ b/armorpaint/Sources/arm/ui/UIStatus.hx @@ -18,7 +18,7 @@ class UIStatus { var ui = UIBase.inst.ui; var statush = Config.raw.layout[LayoutStatusH]; - if (ui.window(UIBase.inst.hwnds[2], iron.App.x(), System.windowHeight() - statush, System.windowWidth() - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW], statush)) { + if (ui.window(UIBase.inst.hwnds[TabStatus], iron.App.x(), System.windowHeight() - statush, System.windowWidth() - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW], statush)) { ui._y += 2; // Border @@ -26,13 +26,13 @@ class UIStatus { ui.g.fillRect(0, 0, 1, ui._windowH); ui.g.fillRect(ui._windowW - 1, 0, 1, ui._windowH); - for (draw in UIBase.inst.hwndTabs[2]) draw(UIBase.inst.htabs[2]); + for (draw in UIBase.inst.hwndTabs[TabStatus]) draw(UIBase.inst.htabs[TabStatus]); var minimized = statush <= defaultStatusH * Config.raw.window_scale; - if (UIBase.inst.htabs[2].changed && (UIBase.inst.htabs[2].position == Context.raw.lastStatusPosition || minimized)) { + if (UIBase.inst.htabs[TabStatus].changed && (UIBase.inst.htabs[TabStatus].position == Context.raw.lastStatusPosition || minimized)) { UIBase.inst.toggleBrowser(); } - Context.raw.lastStatusPosition = UIBase.inst.htabs[2].position; + Context.raw.lastStatusPosition = UIBase.inst.htabs[TabStatus].position; } } } diff --git a/base/Sources/arm/io/ImportBlendMaterial.hx b/base/Sources/arm/io/ImportBlendMaterial.hx index 33380d42..ea01f5cf 100644 --- a/base/Sources/arm/io/ImportBlendMaterial.hx +++ b/base/Sources/arm/io/ImportBlendMaterial.hx @@ -263,7 +263,7 @@ class ImportBlendMaterial { } iron.App.notifyOnInit(_init); - UIBase.inst.hwnds[1].redraws = 2; + UIBase.inst.hwnds[TabSidebar1].redraws = 2; Data.deleteBlob(path); }); } diff --git a/base/Sources/arm/io/ImportFont.hx b/base/Sources/arm/io/ImportFont.hx index 29f96320..7d617f32 100644 --- a/base/Sources/arm/io/ImportFont.hx +++ b/base/Sources/arm/io/ImportFont.hx @@ -37,7 +37,7 @@ class ImportFont { } iron.App.notifyOnInit(_init); - UIBase.inst.hwnds[2].redraws = 2; + UIBase.inst.hwnds[TabStatus].redraws = 2; }); } } diff --git a/base/Sources/arm/io/ImportTexture.hx b/base/Sources/arm/io/ImportTexture.hx index 65398af3..24abf0c5 100644 --- a/base/Sources/arm/io/ImportTexture.hx +++ b/base/Sources/arm/io/ImportTexture.hx @@ -46,7 +46,7 @@ class ImportTexture { if (Context.raw.texture == null) Context.raw.texture = asset; Project.assetNames.push(name); Project.assetMap.set(asset.id, image); - UIBase.inst.hwnds[2].redraws = 2; + UIBase.inst.hwnds[TabStatus].redraws = 2; Console.info(tr("Texture imported:") + " " + name); // Set as envmap