From a45f26763308be55cfde1dccc7a60bb36756a6c2 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Wed, 13 Nov 2019 17:45:39 +0100 Subject: [PATCH] UI fixes --- Sources/arm/App.hx | 5 +++++ Sources/arm/ui/BoxPreferences.hx | 7 +++++-- Sources/arm/ui/UIBox.hx | 4 +++- Sources/arm/ui/UIMenu.hx | 28 ++++++++++++++++------------ Sources/arm/ui/UINodes.hx | 2 +- Sources/arm/ui/UITrait.hx | 14 ++++---------- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index b5c0f224..4a2f4de4 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -50,8 +50,10 @@ class App { public static var theme:TTheme; public static var color_wheel:Image; public static var uibox:Zui; + public static var uimenu:Zui; public static var fileArg = ""; public static var saveAndQuit = false; + public static var ELEMENT_H = 28; public function new() { Config.init(); @@ -122,6 +124,8 @@ class App { Nodes.getEnumTexts = getEnumTexts; Nodes.mapEnum = mapEnum; uibox = new Zui({ font: f, scaleFactor: Config.raw.window_scale }); + uimenu = new Zui({ font: f, scaleFactor: Config.raw.window_scale }); + ELEMENT_H = uimenu.t.ELEMENT_H; // File to open passed as argument if (Krom.getArgCount() > 1) { @@ -367,6 +371,7 @@ class App { } if (UIBox.show) UIBox.update(); + if (UIMenu.show) UIMenu.update(); var decal = Context.tool == ToolDecal || Context.tool == ToolText; var isPicker = Context.tool == ToolPicker; diff --git a/Sources/arm/ui/BoxPreferences.hx b/Sources/arm/ui/BoxPreferences.hx index ac1fa000..219cc8ee 100644 --- a/Sources/arm/ui/BoxPreferences.hx +++ b/Sources/arm/ui/BoxPreferences.hx @@ -26,7 +26,7 @@ class BoxPreferences { if (ui.tab(htab, "Interface")) { var hscale = Id.handle({value: Config.raw.window_scale}); - ui.slider(hscale, "UI Scale", 0.5, 4.0, true); + ui.slider(hscale, "UI Scale", 1.0, 4.0, false, 10); if (!hscale.changed && UITrait.inst.hscaleWasChanged) { if (hscale.value == null || Math.isNaN(hscale.value)) hscale.value = 1.0; Config.raw.window_scale = hscale.value; @@ -76,6 +76,7 @@ class BoxPreferences { ui.fill(0, 0, ui._w / ui.SCALE(), ui.t.ELEMENT_H * 2, ui.t.SEPARATOR_COL); ui.text("Restore defaults?", Right, ui.t.HIGHLIGHT_COL); if (ui.button("Confirm", Left)) { + ui.t.ELEMENT_H = App.ELEMENT_H; Config.restore(); setScale(); } @@ -129,8 +130,8 @@ class BoxPreferences { } if (ui.tab(htab, "Pen")) { UITrait.penPressureRadius = ui.check(Id.handle({selected: UITrait.penPressureRadius}), "Brush Radius"); - UITrait.penPressureOpacity = ui.check(Id.handle({selected: UITrait.penPressureOpacity}), "Brush Opacity"); UITrait.penPressureHardness = ui.check(Id.handle({selected: UITrait.penPressureHardness}), "Brush Hardness"); + UITrait.penPressureOpacity = ui.check(Id.handle({selected: UITrait.penPressureOpacity}), "Brush Opacity"); } UITrait.inst.hssgi = Id.handle({selected: Config.raw.rp_ssgi}); @@ -260,6 +261,7 @@ plugin.drawUI = function(ui) { files = File.readDirectory(Path.data() + Path.sep + "plugins"); } + if (Config.raw.plugins == null) Config.raw.plugins = []; var h = Id.handle({selected: false}); for (f in files) { var isJs = f.endsWith(".js"); @@ -322,6 +324,7 @@ plugin.drawUI = function(ui) { UINodes.inst.ui.setScale(scale); UIView2D.inst.ui.setScale(scale); App.uibox.setScale(scale); + App.uimenu.setScale(scale); App.resize(); } } diff --git a/Sources/arm/ui/UIBox.hx b/Sources/arm/ui/UIBox.hx index 858f315d..c0368de7 100644 --- a/Sources/arm/ui/UIBox.hx +++ b/Sources/arm/ui/UIBox.hx @@ -62,10 +62,12 @@ class UIBox { } public static function update() { + if (UIMenu.show) return; var mouse = Input.getMouse(); + var kb = Input.getKeyboard(); var ui = App.uibox; var inUse = ui.comboSelectedHandle != null; - if (ui.inputReleased && !inUse) { + if ((ui.inputReleased || kb.started("escape")) && !inUse && !ui.isTyping) { var appw = System.windowWidth(); var apph = System.windowHeight(); var mw = Std.int(modalW * ui.SCALE()); diff --git a/Sources/arm/ui/UIMenu.hx b/Sources/arm/ui/UIMenu.hx index 6ab1fc9d..ece430a9 100644 --- a/Sources/arm/ui/UIMenu.hx +++ b/Sources/arm/ui/UIMenu.hx @@ -18,13 +18,14 @@ class UIMenu { public static var menuCategory = 0; public static var keepOpen = false; static var showMenuFirst = true; + static var hideMenu = false; static var menuX = 0; static var menuY = 0; static var menuCommands:Zui->Void = null; @:access(zui.Zui) public static function render(g:kha.graphics2.Graphics) { - var ui = App.uibox; + var ui = App.uimenu; var panelx = iron.App.x() - UITrait.inst.toolbarw; var C = Config.raw; @@ -187,10 +188,21 @@ class UIMenu { } } - // Hide menu var first = showMenuFirst; showMenuFirst = false; - if (!first && (ui.changed || ui.inputReleased || ui.inputReleasedR || ui.isEscapeDown)) { + hideMenu = !first && (ui.changed || ui.inputReleased || ui.inputReleasedR || ui.isEscapeDown); + + ui.t.BUTTON_COL = BUTTON_COL; + ui.t.ELEMENT_OFFSET = ELEMENT_OFFSET; + ui.t.ELEMENT_H = ELEMENT_H; + ui.endLayout(); + + g.begin(false); + } + + public static function update() { + var ui = App.uimenu; + if (hideMenu) { if (keepOpen) { keepOpen = false; } @@ -201,22 +213,14 @@ class UIMenu { menuCommands = null; } } - - ui.t.BUTTON_COL = BUTTON_COL; - ui.t.ELEMENT_OFFSET = ELEMENT_OFFSET; - ui.t.ELEMENT_H = ELEMENT_H; - ui.endLayout(); - - g.begin(false); } public static function draw(commands:Zui->Void = null, x = -1, y = -1) { - var uibox = App.uibox; show = true; menuCommands = commands; menuX = x > -1 ? x : Std.int(Input.getMouse().x); menuY = y > -1 ? y : Std.int(Input.getMouse().y); - var menuw = uibox.ELEMENT_W() * 1.7; + var menuw = App.uimenu.ELEMENT_W() * 1.7; if (menuX + menuw > System.windowWidth()) { menuX = Std.int(System.windowWidth() - menuw); } diff --git a/Sources/arm/ui/UINodes.hx b/Sources/arm/ui/UINodes.hx index 835e7db5..9939e3cc 100644 --- a/Sources/arm/ui/UINodes.hx +++ b/Sources/arm/ui/UINodes.hx @@ -408,7 +408,7 @@ class UINodes { var cats = canvasType == 0 ? NodesMaterial.categories : NodesBrush.categories; for (i in 0...cats.length) { - if (ui.button(cats[i], Left) || (ui.isHovered && drawMenu)) { + if ((ui.button(cats[i], Left) && UITrait.inst.ui.comboSelectedHandle == null) || (ui.isHovered && drawMenu)) { addNodeButton = true; menuCategory = i; popupX = wx + ui._x; diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index ce7cb5e7..03543786 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -37,8 +37,8 @@ class UITrait { public static inline var defaultToolbarW = 54; public static inline var defaultHeaderH = 28; public static var penPressureRadius = true; + public static var penPressureHardness = true; public static var penPressureOpacity = false; - public static var penPressureHardness = false; public var windowW = 280; // Panel width public var toolbarw = defaultToolbarW; @@ -420,13 +420,6 @@ class UITrait { for (p in Plugin.plugins) if (p.update != null) p.update(); - var kb = Input.getKeyboard(); - if (!App.uibox.isTyping) { - if (kb.started("escape")) { - UIBox.show = false; - } - } - if (!App.uienabled) return; if (!UINodes.inst.ui.isTyping && !ui.isTyping) { @@ -461,6 +454,7 @@ class UITrait { else if (Operator.shortcut(Config.keymap.file_import_assets)) Project.importAsset(); else if (Operator.shortcut(Config.keymap.edit_prefs)) BoxPreferences.show(); + var kb = Input.getKeyboard(); if (kb.started(Config.keymap.view_distract_free) || (kb.started("escape") && !show && !UIBox.show)) { toggleDistractFree(); @@ -634,11 +628,11 @@ class UITrait { if (Log.messageTimer <= 0) statusHandle.redraws = 2; } + if (!App.uienabled) return; + var mouse = Input.getMouse(); var kb = Input.getKeyboard(); - if (!App.uienabled) return; - var down = Operator.shortcut(Config.keymap.action_paint) || (Operator.shortcut("alt+" + Config.keymap.action_paint) && Context.tool == ToolClone) || Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint) ||