From 59cfd8bb7fe11a2238bf6dfe9263694fb7937a15 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sat, 14 Mar 2020 23:46:36 +0100 Subject: [PATCH] Improve cursor positioning --- Sources/arm/render/RenderPathPaint.hx | 44 ++++++++++++++++----------- Sources/arm/ui/UITrait.hx | 18 +++++------ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/Sources/arm/render/RenderPathPaint.hx b/Sources/arm/render/RenderPathPaint.hx index d07b6664..92ed977f 100644 --- a/Sources/arm/render/RenderPathPaint.hx +++ b/Sources/arm/render/RenderPathPaint.hx @@ -28,6 +28,7 @@ class RenderPathPaint { static var baking = false; public static var liveLayer: arm.data.LayerSlot = null; public static var liveLayerDrawn = 0; + public static var liveLayerLocked = true; static var _texpaint: RenderTarget; static var _texpaint_mask: RenderTarget; static var _texpaint_nor: RenderTarget; @@ -276,6 +277,7 @@ class RenderPathPaint { path.renderTargets.set("texpaint_nor" + tid, _texpaint_nor); path.renderTargets.set("texpaint_pack" + tid, _texpaint_pack); } + liveLayerLocked = use; } public static function commandsLiveBrush() { @@ -290,6 +292,18 @@ class RenderPathPaint { return; } + if (liveLayerLocked) return; + + // var mouse = Input.getMouse(); + // var mx = mouse.x; + // var my = mouse.y; + // var inViewport = UITrait.inst.paintVec.x < 1 && UITrait.inst.paintVec.x > 0 && + // UITrait.inst.paintVec.y < 1 && UITrait.inst.paintVec.y > 0; + // var in2dView = UIView2D.inst.show && UIView2D.inst.type == View2DLayer && + // mx > UIView2D.inst.wx && mx < UIView2D.inst.wx + UIView2D.inst.ww && + // my > UIView2D.inst.wy && my < UIView2D.inst.wy + UIView2D.inst.wh; + // if (!inViewport && !in2dView) return; + if (liveLayer == null) { liveLayer = new arm.data.LayerSlot("_live"); liveLayer.createMask(0x00000000); @@ -313,31 +327,25 @@ class RenderPathPaint { liveLayerDrawn = 2; - var mx = Input.getMouse().viewX / iron.App.w(); - var my = 1.0 - (Input.getMouse().viewY / iron.App.h()); - if (UITrait.inst.brushLocked) { - mx = (UITrait.inst.lockStartedX - iron.App.x()) / iron.App.w(); - my = 1.0 - (UITrait.inst.lockStartedY - iron.App.y()) / iron.App.h(); - } - UIView2D.inst.hwnd.redraws = 2; var _x = UITrait.inst.paintVec.x; var _y = UITrait.inst.paintVec.y; + if (UITrait.inst.brushLocked) { + UITrait.inst.paintVec.x = (UITrait.inst.lockStartedX - iron.App.x()) / iron.App.w(); + UITrait.inst.paintVec.y = (UITrait.inst.lockStartedY - iron.App.y()) / iron.App.h(); + } var _lastX = UITrait.inst.lastPaintVecX; var _lastY = UITrait.inst.lastPaintVecY; var _pdirty = Context.pdirty; - UITrait.inst.paintVec.x = mx; - UITrait.inst.paintVec.y = 1.0 - my; - UITrait.inst.lastPaintVecX = mx; - UITrait.inst.lastPaintVecY = 1.0 - my; - Context.pdirty = 2; - Context.rdirty = 2; - UITrait.inst.sub = 0; - + UITrait.inst.lastPaintVecX = UITrait.inst.paintVec.x; + UITrait.inst.lastPaintVecY = UITrait.inst.paintVec.y; if (Operator.shortcut(Config.keymap.brush_ruler)) { UITrait.inst.lastPaintVecX = UITrait.inst.lastPaintX; UITrait.inst.lastPaintVecY = UITrait.inst.lastPaintY; } + Context.pdirty = 2; + Context.rdirty = 2; + UITrait.inst.sub = 0; commandsSymmetry(); commandsPaint(); @@ -389,8 +397,8 @@ class RenderPathPaint { g.setTexture(Layers.cursorTex, img); var gbuffer0 = path.renderTargets.get("gbuffer0").image; g.setTextureDepth(Layers.cursorGbufferD, gbuffer0); - var mx = Input.getMouse().viewX / iron.App.w(); - var my = 1.0 - (Input.getMouse().viewY / iron.App.h()); + var mx = UITrait.inst.paintVec.x; + var my = 1.0 - UITrait.inst.paintVec.y; if (UITrait.inst.brushLocked) { mx = (UITrait.inst.lockStartedX - iron.App.x()) / iron.App.w(); my = 1.0 - (UITrait.inst.lockStartedY - iron.App.y()) / iron.App.h(); @@ -517,7 +525,7 @@ class RenderPathPaint { if (liveLayerDrawn > 0) liveLayerDrawn--; if (UITrait.inst.brushLive && Context.pdirty <= 0 && Context.ddirty <= 0 && UITrait.inst.brushTime == 0) { - // Depth is unchnaged, draw before gbuffer gets updated + // Depth is unchanged, draw before gbuffer gets updated commandsLiveBrush(); } } diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index 051967a6..b9b8bfec 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -194,6 +194,8 @@ class UITrait { public var brushRot = 0.0; public var brushHardness = 0.8; public var brushLazy = 0.0; + public var brushLazyX = 0.0; + public var brushLazyY = 0.0; public var brushBias = 1.0; public var brushPaint = UVMap; public var brush3d = true; @@ -307,6 +309,7 @@ class UITrait { Project.brushes.push(new BrushSlot()); Context.brush = Project.brushes[0]; MaterialParser.parseBrush(); + UITrait.inst.parseBrushInputs(); } if (Project.layers == null) { @@ -845,14 +848,8 @@ class UITrait { // Brush if (App.uienabled && worktab.position == SpacePaint) { - var mouse = Input.getMouse(); - var mx = mouse.x; - var my = mouse.y; - var pen = Input.getPen(); - if (pen.down()) { - mx = pen.x; - my = pen.y; - } + var mx = App.x() + paintVec.x * App.w(); + var my = App.y() + paintVec.y * App.h(); // Radius being scaled if (brushLocked) { @@ -885,6 +882,8 @@ class UITrait { var psize = Std.int(cursorImg.width * (brushRadius * brushNodesRadius)); // Clone source cursor + var mouse = Input.getMouse(); + var pen = Input.getPen(); var kb = Input.getKeyboard(); if (Context.tool == ToolClone && !kb.down("alt") && (mouse.down() || pen.down())) { g.color = 0x66ffffff; @@ -918,7 +917,7 @@ class UITrait { Context.tool == ToolBlur || Context.tool == ToolParticle) { if (brushLazy > 0 && (Context.tool == ToolBrush || Context.tool == ToolEraser)) { - var radius = psize + brushLazy; + var radius = psize + brushLazy * 100; g.color = 0x66ffffff; g.drawScaledImage(cursorImg, mx - radius / 2, my - radius / 2, radius, radius); g.color = 0xffffffff; @@ -1182,7 +1181,6 @@ class UITrait { if (Context.tool == ToolBrush || Context.tool == ToolEraser) { brushHardness = ui.slider(Id.handle({value: brushHardness}), "Hardness", 0.0, 1.0, true); - brushLazy = ui.slider(Id.handle({value: brushLazy}), "Lazy", 0.0, 1.0, true); } if (Context.tool != ToolEraser) {