From 0b98385d8de025577df92de4ade5a80a5e6516cd Mon Sep 17 00:00:00 2001 From: MathemanFlo Date: Tue, 15 Mar 2022 21:26:18 +0100 Subject: [PATCH 1/5] Fix pbr swatches --- Sources/arm/ui/TabSwatches.hx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sources/arm/ui/TabSwatches.hx b/Sources/arm/ui/TabSwatches.hx index adf9c217..a3835e5e 100644 --- a/Sources/arm/ui/TabSwatches.hx +++ b/Sources/arm/ui/TabSwatches.hx @@ -137,15 +137,20 @@ class TabSwatches { Project.raw.swatches[i].base = color.base; }; }); - var hopacity = Id.handle({ value: Context.swatch.opacity }); + var hopacity = Id.handle(); + hopacity.value = Context.swatch.opacity; Context.swatch.opacity = ui.slider(hopacity, "Opacity", 0, 1, true); - var hocclusion = Id.handle({ value: Context.swatch.occlusion }); + var hocclusion = Id.handle(); + hocclusion.value = Context.swatch.occlusion; Context.swatch.occlusion = ui.slider(hocclusion, "Occlusion", 0, 1, true); - var hroughness = Id.handle({ value: Context.swatch.roughness }); + var hroughness = Id.handle(); + hroughness.value = Context.swatch.roughness; Context.swatch.roughness = ui.slider(hroughness, "Roughness", 0, 1, true); - var hmetallic = Id.handle({ value: Context.swatch.metallic }); + var hmetallic = Id.handle(); + hmetallic.value = Context.swatch.metallic; Context.swatch.metallic = ui.slider(hmetallic, "Metallic", 0, 1, true); - var hheight = Id.handle({ value: Context.swatch.height }); + var hheight = Id.handle(); + hheight.value = Context.swatch.height; Context.swatch.height = ui.slider(hheight, "Height", 0, 1, true); if (ui.changed || ui.isTyping) UIMenu.keepOpen = true; From 683b813e475fbe305ad12d72db49b8c1bd3bfb09 Mon Sep 17 00:00:00 2001 From: MathemanFlo Date: Tue, 15 Mar 2022 22:04:28 +0100 Subject: [PATCH 2/5] Release color picker on right click --- Sources/arm/App.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index ffb32055..dd57cb85 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -461,7 +461,7 @@ class App { Krom.setMouseCursor(0); // Arrow isDragging = false; } - if (Context.colorPickerCallback != null && mouse.released()) { + if (Context.colorPickerCallback != null && (mouse.released() || mouse.released("right"))) { Context.colorPickerCallback = null; } From 0d5a205f487bedd0a554c5675390657af28e4939 Mon Sep 17 00:00:00 2001 From: MathemanFlo Date: Tue, 15 Mar 2022 22:05:42 +0100 Subject: [PATCH 3/5] Make color picker pbr swatch ready --- Sources/arm/ui/TabSwatches.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/arm/ui/TabSwatches.hx b/Sources/arm/ui/TabSwatches.hx index a3835e5e..abaa20e0 100644 --- a/Sources/arm/ui/TabSwatches.hx +++ b/Sources/arm/ui/TabSwatches.hx @@ -134,7 +134,7 @@ class TabSwatches { Context.swatch.base = zui.Ext.colorWheel(ui, h, false, null, 11 * ui.t.ELEMENT_H * ui.SCALE(), true, function () { Context.selectTool(ToolPicker); Context.colorPickerCallback = function (color: TSwatchColor) { - Project.raw.swatches[i].base = color.base; + Project.raw.swatches[i] = Project.cloneSwatch(color); }; }); var hopacity = Id.handle(); From 3c0bae578b736e0d03f5a6947e33dc9584bba806 Mon Sep 17 00:00:00 2001 From: MathemanFlo Date: Tue, 15 Mar 2022 22:06:38 +0100 Subject: [PATCH 4/5] Show color picker icon --- Sources/arm/ui/UISidebar.hx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sources/arm/ui/UISidebar.hx b/Sources/arm/ui/UISidebar.hx index 62124480..ff52efd5 100644 --- a/Sources/arm/ui/UISidebar.hx +++ b/Sources/arm/ui/UISidebar.hx @@ -815,7 +815,7 @@ class UISidebar { } // Show picked material next to cursor - if (Context.tool == ToolPicker && Context.pickerSelectMaterial) { + if (Context.tool == ToolPicker && Context.pickerSelectMaterial && Context.colorPickerCallback == null) { var img = Context.material.imageIcon; #if kha_opengl g.drawScaledImage(img, mx + 10, my + 10 + img.height, img.width, -img.height); @@ -823,6 +823,12 @@ class UISidebar { g.drawImage(img, mx + 10, my + 10); #end } + if (Context.tool == ToolPicker && Context.colorPickerCallback != null) { + var img = Res.get("icons.k"); + var rect = Res.tile50(img, ToolPicker, 0); + + g.drawSubImage(img, mx + 10, my + 10, rect.x, rect.y, rect.w, rect.h); + } var cursorImg = Res.get("cursor.k"); var psize = Std.int(cursorImg.width * (Context.brushRadius * Context.brushNodesRadius) * ui.SCALE()); From 67a4c21c4c667c992edd2aaa953c3b740bb5825d Mon Sep 17 00:00:00 2001 From: MathemanFlo Date: Tue, 15 Mar 2022 22:17:23 +0100 Subject: [PATCH 5/5] Restore previous tool after color picking --- Sources/arm/App.hx | 1 + Sources/arm/Context.hx | 1 + Sources/arm/ui/TabSwatches.hx | 1 + Sources/arm/ui/UINodes.hx | 1 + 4 files changed, 4 insertions(+) diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index dd57cb85..2b9a5ebc 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -463,6 +463,7 @@ class App { } if (Context.colorPickerCallback != null && (mouse.released() || mouse.released("right"))) { Context.colorPickerCallback = null; + Context.selectTool(Context.colorPickerPreviousTool); } handleDropPaths(); diff --git a/Sources/arm/Context.hx b/Sources/arm/Context.hx index f2a1ea7b..dd6c8e5e 100644 --- a/Sources/arm/Context.hx +++ b/Sources/arm/Context.hx @@ -66,6 +66,7 @@ class Context { public static var swatch: TSwatchColor; public static var pickedColor: TSwatchColor = Project.makeSwatch(); public static var colorPickerCallback: TSwatchColor->Void = null; + public static var colorPickerPreviousTool = ToolBrush; public static var materialIdPicked = 0; public static var uvxPicked = 0.0; public static var uvyPicked = 0.0; diff --git a/Sources/arm/ui/TabSwatches.hx b/Sources/arm/ui/TabSwatches.hx index abaa20e0..a211b7ad 100644 --- a/Sources/arm/ui/TabSwatches.hx +++ b/Sources/arm/ui/TabSwatches.hx @@ -132,6 +132,7 @@ class TabSwatches { h.color = Context.swatch.base; Context.swatch.base = zui.Ext.colorWheel(ui, h, false, null, 11 * ui.t.ELEMENT_H * ui.SCALE(), true, function () { + Context.colorPickerPreviousTool = Context.tool; Context.selectTool(ToolPicker); Context.colorPickerCallback = function (color: TSwatchColor) { Project.raw.swatches[i] = Project.cloneSwatch(color); diff --git a/Sources/arm/ui/UINodes.hx b/Sources/arm/ui/UINodes.hx index 0c8d6d15..d5a5ec2b 100644 --- a/Sources/arm/ui/UINodes.hx +++ b/Sources/arm/ui/UINodes.hx @@ -683,6 +683,7 @@ class UINodes { } if (nodes.colorPickerCallback != null) { + Context.colorPickerPreviousTool = Context.tool; Context.selectTool(ToolPicker); var tmp = nodes.colorPickerCallback; Context.colorPickerCallback = function(color: TSwatchColor) {