diff --git a/Sources/arm/Context.hx b/Sources/arm/Context.hx index 43ab1876..a33141f8 100644 --- a/Sources/arm/Context.hx +++ b/Sources/arm/Context.hx @@ -163,6 +163,8 @@ class Context { public static var brushRadius = 0.5; public static var brushRadiusHandle = new Handle({value: 0.5}); + public static var brushDecalMaskRadius = 0.5; + public static var brushDecalMaskRadiusHandle = new Handle({value: 0.5}); public static var brushScaleX = 1.0; public static var brushScaleXHandle = new Handle({value: 1.0}); public static var brushBlending = BlendMix; diff --git a/Sources/arm/Operator.hx b/Sources/arm/Operator.hx index 57c555a1..8960b4af 100644 --- a/Sources/arm/Operator.hx +++ b/Sources/arm/Operator.hx @@ -32,7 +32,7 @@ class Operator { // Mouse (type == ShortcutDown ? mouse.down(s) : mouse.started(s)) : // Keyboard - (type == ShortcutRepeat ? kb.repeat(s) : type == ShortcutDown ? kb.down(s) : kb.started(s)); + (type == ShortcutRepeat ? kb.repeat(s) : type == ShortcutDown ? kb.down(s) : type == ShortcutReleased ? kb.released(s) : kb.started(s)); return flag && key; } } @@ -41,4 +41,5 @@ class Operator { var ShortcutStarted = 0; var ShortcutRepeat = 1; var ShortcutDown = 2; + var ShortcutReleased = 3; } diff --git a/Sources/arm/render/RenderPathPaint.hx b/Sources/arm/render/RenderPathPaint.hx index 77295431..6e838c31 100644 --- a/Sources/arm/render/RenderPathPaint.hx +++ b/Sources/arm/render/RenderPathPaint.hx @@ -379,7 +379,8 @@ class RenderPathPaint { mx = (Context.lockStartedX - iron.App.x()) / iron.App.w(); my = 1.0 - (Context.lockStartedY - iron.App.y()) / iron.App.h(); } - drawCursor(mx, my, Context.brushNodesRadius * Context.brushRadius / 3.4); + var radius = decalMask ? Context.brushDecalMaskRadius : Context.brushRadius; + drawCursor(mx, my, Context.brushNodesRadius * radius / 3.4); // if (Context.brushLazyRadius > 0 && (Context.tool == ToolBrush || Context.tool == ToolEraser)) { // var _brushRadius = Context.brushRadius; diff --git a/Sources/arm/render/Uniforms.hx b/Sources/arm/render/Uniforms.hx index 09f6c983..f0acac24 100644 --- a/Sources/arm/render/Uniforms.hx +++ b/Sources/arm/render/Uniforms.hx @@ -29,9 +29,23 @@ class Uniforms { public static function linkFloat(object: Object, mat: MaterialData, link: String): Null { switch (link) { case "_brushRadius": { - var val = radiusUniform(); - var decalMask = Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutDown); - return decalMask ? val * 2 : val; + var decal = Context.tool == ToolDecal || Context.tool == ToolText; + var decalMask = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutDown); + var radius = decalMask ? Context.brushDecalMaskRadius * 2.0 : Context.brushRadius; + var val = (radius * Context.brushNodesRadius) / 15.0; + var pen = Input.getPen(); + if (Config.raw.pressure_radius && pen.down()) { + val *= pen.pressure * Config.raw.pressure_sensitivity; + } + var scale2d = (900 / App.h()) * Config.raw.window_scale; + + if (Config.raw.brush_3d && !decal) { + val *= Context.paint2d ? 0.55 * scale2d : 2; + } + else { + val *= scale2d; // Projection ratio + } + return val; } case "_brushScaleX": { return 1 / Context.brushScaleX; @@ -86,23 +100,6 @@ class Uniforms { return null; } - static function radiusUniform(): Float { - var val = (Context.brushRadius * Context.brushNodesRadius) / 15.0; - var pen = Input.getPen(); - if (Config.raw.pressure_radius && pen.down()) { - val *= pen.pressure * Config.raw.pressure_sensitivity; - } - var scale2d = (900 / App.h()) * Config.raw.window_scale; - var decal = Context.tool == ToolDecal || Context.tool == ToolText; - if (Config.raw.brush_3d && !decal) { - val *= Context.paint2d ? 0.55 * scale2d : 2; - } - else { - val *= scale2d; // Projection ratio - } - return val; - } - public static function linkVec2(object: Object, mat: MaterialData, link: String): iron.math.Vec4 { switch (link) { case "_sub": { @@ -205,8 +202,12 @@ class Uniforms { return vec; } case "_decalMask": { + var decal = Context.tool == ToolDecal || Context.tool == ToolText; var decalMask = Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutDown); - vec.set(Context.decalX, Context.decalY, decalMask ? 1 : 0, radiusUniform()); + var val = (Context.brushRadius * Context.brushNodesRadius) / 15.0; + var scale2d = (900 / App.h()) * Config.raw.window_scale; + val *= scale2d; // Projection ratio + vec.set(Context.decalX, Context.decalY, decalMask ? 1 : 0, val); return vec; } } diff --git a/Sources/arm/ui/UIHeader.hx b/Sources/arm/ui/UIHeader.hx index 4ef77994..b80a1145 100644 --- a/Sources/arm/ui/UIHeader.hx +++ b/Sources/arm/ui/UIHeader.hx @@ -149,7 +149,14 @@ class UIHeader { Context.tool == ToolParticle) { if (Context.tool != ToolFill) { - Context.brushRadius = ui.slider(Context.brushRadiusHandle, tr("Radius"), 0.01, 2.0, true); + var decal = Context.tool == ToolDecal || Context.tool == ToolText; + var decalMask = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutDown); + if (decalMask) { + Context.brushDecalMaskRadius = ui.slider(Context.brushDecalMaskRadiusHandle, tr("Radius"), 0.01, 2.0, true); + } + else { + Context.brushRadius = ui.slider(Context.brushRadiusHandle, tr("Radius"), 0.01, 2.0, true); + } } if (Context.tool == ToolDecal || Context.tool == ToolText) { diff --git a/Sources/arm/ui/UISidebar.hx b/Sources/arm/ui/UISidebar.hx index 4750f48c..3f4b3c8f 100644 --- a/Sources/arm/ui/UISidebar.hx +++ b/Sources/arm/ui/UISidebar.hx @@ -219,11 +219,14 @@ class UISidebar { } var mouse = Input.getMouse(); + var decal = Context.tool == ToolDecal || Context.tool == ToolText; + var decalMask = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutDown); if ((Context.brushCanLock || Context.brushLocked) && mouse.moved) { if (Operator.shortcut(Config.keymap.brush_radius, ShortcutDown) || Operator.shortcut(Config.keymap.brush_opacity, ShortcutDown) || - Operator.shortcut(Config.keymap.brush_angle, ShortcutDown)) { + Operator.shortcut(Config.keymap.brush_angle, ShortcutDown) || + (decalMask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutDown))) { if (Context.brushLocked) { if (Operator.shortcut(Config.keymap.brush_opacity, ShortcutDown)) { Context.brushOpacity += mouse.movementX / 500; @@ -238,6 +241,12 @@ class UISidebar { Context.brushAngleHandle.value = Context.brushAngle; MakeMaterial.parsePaintMaterial(); } + else if (decalMask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutDown)) { + Context.brushDecalMaskRadius += mouse.movementX / 150; + Context.brushDecalMaskRadius = Math.max(0.05, Math.min(4.0, Context.brushDecalMaskRadius)); + Context.brushDecalMaskRadius = Math.round(Context.brushDecalMaskRadius * 100) / 100; + Context.brushDecalMaskRadiusHandle.value = Context.brushDecalMaskRadius; + } else { Context.brushRadius += mouse.movementX / 150; Context.brushRadius = Math.max(0.05, Math.min(4.0, Context.brushRadius)); @@ -256,6 +265,9 @@ class UISidebar { var right = iron.App.w(); if (UIView2D.inst.show) right += UIView2D.inst.ww; + var decal = Context.tool == ToolDecal || Context.tool == ToolText; + var decalMask = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutDown); + // Viewport shortcuts if (mouse.viewX > 0 && mouse.viewX < right && mouse.viewY > 0 && mouse.viewY < iron.App.h() && @@ -295,7 +307,8 @@ class UISidebar { Context.tool == ToolParticle) { if (Operator.shortcut(Config.keymap.brush_radius) || Operator.shortcut(Config.keymap.brush_opacity) || - Operator.shortcut(Config.keymap.brush_angle)) { + Operator.shortcut(Config.keymap.brush_angle) || + (decalMask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius))) { Context.brushCanLock = true; if (!Input.getPen().connected) mouse.lock(); Context.lockStartedX = mouse.x; @@ -313,6 +326,24 @@ class UISidebar { Context.brushRadiusHandle.value = Context.brushRadius; UIHeader.inst.headerHandle.redraws = 2; } + else if (decalMask) { + if (Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius_decrease, ShortcutRepeat)) { + Context.brushDecalMaskRadius -= getRadiusIncrement(); + Context.brushDecalMaskRadius = Math.max(Math.round(Context.brushDecalMaskRadius * 100) / 100, 0.01); + Context.brushDecalMaskRadiusHandle.value = Context.brushDecalMaskRadius; + UIHeader.inst.headerHandle.redraws = 2; + } + else if (Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius_increase, ShortcutRepeat)) { + Context.brushDecalMaskRadius += getRadiusIncrement(); + Context.brushDecalMaskRadius = Math.round(Context.brushDecalMaskRadius * 100) / 100; + Context.brushDecalMaskRadiusHandle.value = Context.brushDecalMaskRadius; + UIHeader.inst.headerHandle.redraws = 2; + } + } + } + + if (decalMask && (Operator.shortcut(Config.keymap.decal_mask, ShortcutStarted) || Operator.shortcut(Config.keymap.decal_mask, ShortcutReleased))) { + UIHeader.inst.headerHandle.redraws = 2; } } @@ -349,7 +380,8 @@ class UISidebar { if (Context.brushLocked && !Operator.shortcut(Config.keymap.brush_radius, ShortcutDown) && !Operator.shortcut(Config.keymap.brush_opacity, ShortcutDown) && - !Operator.shortcut(Config.keymap.brush_angle, ShortcutDown)) { + !Operator.shortcut(Config.keymap.brush_angle, ShortcutDown) && + !(decalMask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutDown))) { mouse.unlock(); Context.brushCanUnlock = true; Context.lastPaintX = -1; @@ -742,7 +774,8 @@ class UISidebar { var psizex = Std.int(256 * ui.SCALE() * (Context.brushRadius * Context.brushNodesRadius * Context.brushScaleX)); var psizey = Std.int(256 * ui.SCALE() * (Context.brushRadius * Context.brushNodesRadius)); var decalAlpha = 0.5; - if (!Operator.shortcut(Config.keymap.decal_mask, ShortcutDown)) { + var decalMask = Operator.shortcut(Config.keymap.decal_mask, ShortcutDown); + if (!decalMask) { Context.decalX = Context.paintVec.x; Context.decalY = Context.paintVec.y; decalAlpha = Context.brushOpacity; @@ -754,7 +787,7 @@ class UISidebar { Context.viewIndex = -1; // Radius being scaled - if (Context.brushLocked) { + if (Context.brushLocked && !decalMask) { decalX += Context.lockStartedX - System.windowWidth() / 2; decalY += Context.lockStartedY - System.windowHeight() / 2; }