From 3c10a586d3665d82c9380dc1d369fbe44f7983da Mon Sep 17 00:00:00 2001 From: luboslenco Date: Fri, 3 Jul 2020 17:22:42 +0200 Subject: [PATCH] Improve paint vector handling --- Sources/arm/App.hx | 43 +++++++++++++++++++++++++++++++ Sources/arm/render/Uniforms.hx | 13 ++++++---- Sources/arm/ui/UISidebar.hx | 46 ---------------------------------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index 2c3541b8..12ff7ce9 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -463,6 +463,27 @@ class App { static function render(g: kha.graphics2.Graphics) { if (System.windowWidth() == 0 || System.windowHeight() == 0) return; + if (Context.frame == 2) { + RenderUtil.makeMaterialPreview(); + UISidebar.inst.hwnd1.redraws = 2; + MaterialParser.parseMeshMaterial(); + MaterialParser.parsePaintMaterial(); + Context.ddirty = 0; + History.reset(); + if (History.undoLayers == null) { + History.undoLayers = []; + for (i in 0...Config.raw.undo_steps) { + var l = new LayerSlot("_undo" + History.undoLayers.length); + l.createMask(0, false); + History.undoLayers.push(l); + } + } + } + else if (Context.frame == 3) { + Context.ddirty = 1; + } + Context.frame++; + var mouse = Input.getMouse(); if (isDragging) { Krom.setMouseCursor(1); // Hand @@ -488,6 +509,28 @@ class App { uiEnabled = !UIBox.show && !usingMenu; if (UIBox.show) UIBox.render(g); if (UIMenu.show) UIMenu.render(g); + + // Save last pos for continuos paint + if (mouse.down()) { + Context.lastPaintVecX = Context.paintVec.x; + Context.lastPaintVecY = Context.paintVec.y; + } + else { + if (Context.splitView) { + Context.viewIndex = Input.getMouse().viewX > arm.App.w() / 2 ? 1 : 0; + } + + Context.lastPaintVecX = mouse.viewX / iron.App.w(); + Context.lastPaintVecY = mouse.viewY / iron.App.h(); + + Context.viewIndex = -1; + + #if (krom_android || krom_ios) + // No mouse move events for touch, re-init last paint position on touch start + Context.lastPaintX = -1; + Context.lastPaintY = -1; + #end + } } public static function enumTexts(nodeType: String): Array { diff --git a/Sources/arm/render/Uniforms.hx b/Sources/arm/render/Uniforms.hx index 80d0e628..50a158da 100644 --- a/Sources/arm/render/Uniforms.hx +++ b/Sources/arm/render/Uniforms.hx @@ -284,17 +284,20 @@ class Uniforms { #if arm_painter if (link == "_brushDirection") { v = iron.object.Uniforms.helpVec; - if (Context.lastPaintVecX != Context.paintVec.x) Context.prevPaintVecX = Context.lastPaintVecX; - if (Context.lastPaintVecY != Context.paintVec.y) Context.prevPaintVecY = Context.lastPaintVecY; + // Discard first paint for directional brush + var allowPaint = Context.prevPaintVecX != Context.lastPaintVecX && + Context.prevPaintVecY != Context.lastPaintVecY && + Context.prevPaintVecX > 0 && + Context.prevPaintVecY > 0; var x = Context.paintVec.x; var y = Context.paintVec.y; var lastx = Context.prevPaintVecX; var lasty = Context.prevPaintVecY; if (Context.paint2d) { x -= 1.0; lastx -= 1.0; } var angle = Math.atan2(-y + lasty, x - lastx) - Math.PI / 2; - // Discard first paint for directional brush - var allowPaint = (Context.prevPaintVecX > 0 && Context.prevPaintVecY > 0) ? 1 : 0; - v.set(Math.cos(angle), Math.sin(angle), allowPaint); + v.set(Math.cos(angle), Math.sin(angle), allowPaint ? 1 : 0); + Context.prevPaintVecX = Context.lastPaintVecX; + Context.prevPaintVecY = Context.lastPaintVecY; return v; } #end diff --git a/Sources/arm/ui/UISidebar.hx b/Sources/arm/ui/UISidebar.hx index 7e81885a..6b3fb1d2 100644 --- a/Sources/arm/ui/UISidebar.hx +++ b/Sources/arm/ui/UISidebar.hx @@ -129,52 +129,6 @@ class UISidebar { world.envmap = Context.showEnvmap ? Context.savedEnvmap : Context.emptyEnvmap; Context.ddirty = 1; - // Save last pos for continuos paint - iron.App.notifyOnRender(function(g: kha.graphics4.Graphics) { // - if (Context.frame == 2) { - RenderUtil.makeMaterialPreview(); - hwnd1.redraws = 2; - MaterialParser.parseMeshMaterial(); - MaterialParser.parsePaintMaterial(); - Context.ddirty = 0; - History.reset(); - if (History.undoLayers == null) { - History.undoLayers = []; - for (i in 0...Config.raw.undo_steps) { - var l = new LayerSlot("_undo" + History.undoLayers.length); - l.createMask(0, false); - History.undoLayers.push(l); - } - } - } - else if (Context.frame == 3) { - Context.ddirty = 1; - } - Context.frame++; - - var mouse = Input.getMouse(); - if (mouse.down()) { // - Context.lastPaintVecX = Context.paintVec.x; // - Context.lastPaintVecY = Context.paintVec.y; // - } // - else { - if (Context.splitView) { - Context.viewIndex = Input.getMouse().viewX > arm.App.w() / 2 ? 1 : 0; - } - - Context.lastPaintVecX = mouse.viewX / iron.App.w(); - Context.lastPaintVecY = mouse.viewY / iron.App.h(); - - Context.viewIndex = -1; - - #if (krom_android || krom_ios) - // No mouse move events for touch, re-init last paint position on touch start - Context.lastPaintX = -1; - Context.lastPaintY = -1; - #end - } - }); // - var scale = Config.raw.window_scale; ui = new Zui( { theme: App.theme, font: App.font, scaleFactor: scale, color_wheel: App.colorWheel } ); Zui.onBorderHover = onBorderHover;