From a0c0db0f5a6b50bf7faa12930b39e483042ce9fa Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 24 Apr 2020 16:56:53 +0200 Subject: [PATCH] [csharp] Fixed ColorTimeline and TwoColorTimeline result colors not being clamped. Closes #1664. --- spine-csharp/src/Animation.cs | 11 +++++++++++ spine-csharp/src/Slot.cs | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/spine-csharp/src/Animation.cs b/spine-csharp/src/Animation.cs index e6d172aad..8fff49ba0 100644 --- a/spine-csharp/src/Animation.cs +++ b/spine-csharp/src/Animation.cs @@ -725,6 +725,7 @@ namespace Spine { slot.g += (slotData.g - slot.g) * alpha; slot.b += (slotData.b - slot.b) * alpha; slot.a += (slotData.a - slot.a) * alpha; + slot.ClampColor(); return; } return; @@ -758,6 +759,7 @@ namespace Spine { slot.g = g; slot.b = b; slot.a = a; + slot.ClampColor(); } else { float br, bg, bb, ba; if (blend == MixBlend.Setup) { @@ -775,6 +777,7 @@ namespace Spine { slot.g = bg + ((g - bg) * alpha); slot.b = bb + ((b - bb) * alpha); slot.a = ba + ((a - ba) * alpha); + slot.ClampColor(); } } } @@ -839,18 +842,22 @@ namespace Spine { slot.g = slotData.g; slot.b = slotData.b; slot.a = slotData.a; + slot.ClampColor(); slot.r2 = slotData.r2; slot.g2 = slotData.g2; slot.b2 = slotData.b2; + slot.ClampSecondColor(); return; case MixBlend.First: slot.r += (slot.r - slotData.r) * alpha; slot.g += (slot.g - slotData.g) * alpha; slot.b += (slot.b - slotData.b) * alpha; slot.a += (slot.a - slotData.a) * alpha; + slot.ClampColor(); slot.r2 += (slot.r2 - slotData.r2) * alpha; slot.g2 += (slot.g2 - slotData.g2) * alpha; slot.b2 += (slot.b2 - slotData.b2) * alpha; + slot.ClampSecondColor(); return; } return; @@ -893,9 +900,11 @@ namespace Spine { slot.g = g; slot.b = b; slot.a = a; + slot.ClampColor(); slot.r2 = r2; slot.g2 = g2; slot.b2 = b2; + slot.ClampSecondColor(); } else { float br, bg, bb, ba, br2, bg2, bb2; if (blend == MixBlend.Setup) { @@ -919,9 +928,11 @@ namespace Spine { slot.g = bg + ((g - bg) * alpha); slot.b = bb + ((b - bb) * alpha); slot.a = ba + ((a - ba) * alpha); + slot.ClampColor(); slot.r2 = br2 + ((r2 - br2) * alpha); slot.g2 = bg2 + ((g2 - bg2) * alpha); slot.b2 = bb2 + ((b2 - bb2) * alpha); + slot.ClampSecondColor(); } } diff --git a/spine-csharp/src/Slot.cs b/spine-csharp/src/Slot.cs index 1c1c1fb34..c7e45a886 100644 --- a/spine-csharp/src/Slot.cs +++ b/spine-csharp/src/Slot.cs @@ -106,6 +106,13 @@ namespace Spine { /// color tinting. public float A { get { return a; } set { a = value; } } + public void ClampColor() { + r = MathUtils.Clamp(r, 0, 1); + g = MathUtils.Clamp(g, 0, 1); + b = MathUtils.Clamp(b, 0, 1); + a = MathUtils.Clamp(a, 0, 1); + } + /// The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used. /// public float R2 { get { return r2; } set { r2 = value; } } @@ -118,6 +125,12 @@ namespace Spine { /// Whether R2 G2 B2 are used to tint the slot's attachment for two color tinting. False if two color tinting is not used. public bool HasSecondColor { get { return data.hasSecondColor; } set { data.hasSecondColor = value; } } + public void ClampSecondColor () { + r2 = MathUtils.Clamp(r2, 0, 1); + g2 = MathUtils.Clamp(g2, 0, 1); + b2 = MathUtils.Clamp(b2, 0, 1); + } + public Attachment Attachment { /// The current attachment for the slot, or null if the slot has no attachment. get { return attachment; }