[csharp] Fixed ColorTimeline and TwoColorTimeline result colors not being clamped. Closes #1664.

This commit is contained in:
Harald Csaszar 2020-04-24 16:56:53 +02:00
parent 201f0bd7d5
commit a0c0db0f5a
2 changed files with 24 additions and 0 deletions

View File

@ -725,6 +725,7 @@ namespace Spine {
slot.g += (slotData.g - slot.g) * alpha; slot.g += (slotData.g - slot.g) * alpha;
slot.b += (slotData.b - slot.b) * alpha; slot.b += (slotData.b - slot.b) * alpha;
slot.a += (slotData.a - slot.a) * alpha; slot.a += (slotData.a - slot.a) * alpha;
slot.ClampColor();
return; return;
} }
return; return;
@ -758,6 +759,7 @@ namespace Spine {
slot.g = g; slot.g = g;
slot.b = b; slot.b = b;
slot.a = a; slot.a = a;
slot.ClampColor();
} else { } else {
float br, bg, bb, ba; float br, bg, bb, ba;
if (blend == MixBlend.Setup) { if (blend == MixBlend.Setup) {
@ -775,6 +777,7 @@ namespace Spine {
slot.g = bg + ((g - bg) * alpha); slot.g = bg + ((g - bg) * alpha);
slot.b = bb + ((b - bb) * alpha); slot.b = bb + ((b - bb) * alpha);
slot.a = ba + ((a - ba) * alpha); slot.a = ba + ((a - ba) * alpha);
slot.ClampColor();
} }
} }
} }
@ -839,18 +842,22 @@ namespace Spine {
slot.g = slotData.g; slot.g = slotData.g;
slot.b = slotData.b; slot.b = slotData.b;
slot.a = slotData.a; slot.a = slotData.a;
slot.ClampColor();
slot.r2 = slotData.r2; slot.r2 = slotData.r2;
slot.g2 = slotData.g2; slot.g2 = slotData.g2;
slot.b2 = slotData.b2; slot.b2 = slotData.b2;
slot.ClampSecondColor();
return; return;
case MixBlend.First: case MixBlend.First:
slot.r += (slot.r - slotData.r) * alpha; slot.r += (slot.r - slotData.r) * alpha;
slot.g += (slot.g - slotData.g) * alpha; slot.g += (slot.g - slotData.g) * alpha;
slot.b += (slot.b - slotData.b) * alpha; slot.b += (slot.b - slotData.b) * alpha;
slot.a += (slot.a - slotData.a) * alpha; slot.a += (slot.a - slotData.a) * alpha;
slot.ClampColor();
slot.r2 += (slot.r2 - slotData.r2) * alpha; slot.r2 += (slot.r2 - slotData.r2) * alpha;
slot.g2 += (slot.g2 - slotData.g2) * alpha; slot.g2 += (slot.g2 - slotData.g2) * alpha;
slot.b2 += (slot.b2 - slotData.b2) * alpha; slot.b2 += (slot.b2 - slotData.b2) * alpha;
slot.ClampSecondColor();
return; return;
} }
return; return;
@ -893,9 +900,11 @@ namespace Spine {
slot.g = g; slot.g = g;
slot.b = b; slot.b = b;
slot.a = a; slot.a = a;
slot.ClampColor();
slot.r2 = r2; slot.r2 = r2;
slot.g2 = g2; slot.g2 = g2;
slot.b2 = b2; slot.b2 = b2;
slot.ClampSecondColor();
} else { } else {
float br, bg, bb, ba, br2, bg2, bb2; float br, bg, bb, ba, br2, bg2, bb2;
if (blend == MixBlend.Setup) { if (blend == MixBlend.Setup) {
@ -919,9 +928,11 @@ namespace Spine {
slot.g = bg + ((g - bg) * alpha); slot.g = bg + ((g - bg) * alpha);
slot.b = bb + ((b - bb) * alpha); slot.b = bb + ((b - bb) * alpha);
slot.a = ba + ((a - ba) * alpha); slot.a = ba + ((a - ba) * alpha);
slot.ClampColor();
slot.r2 = br2 + ((r2 - br2) * alpha); slot.r2 = br2 + ((r2 - br2) * alpha);
slot.g2 = bg2 + ((g2 - bg2) * alpha); slot.g2 = bg2 + ((g2 - bg2) * alpha);
slot.b2 = bb2 + ((b2 - bb2) * alpha); slot.b2 = bb2 + ((b2 - bb2) * alpha);
slot.ClampSecondColor();
} }
} }

View File

@ -106,6 +106,13 @@ namespace Spine {
/// color tinting.</summary> /// color tinting.</summary>
public float A { get { return a; } set { a = value; } } 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);
}
/// <summary>The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used.</summary> /// <summary>The dark color used to tint the slot's attachment for two color tinting, ignored if two color tinting is not used.</summary>
/// <seealso cref="HasSecondColor"/> /// <seealso cref="HasSecondColor"/>
public float R2 { get { return r2; } set { r2 = value; } } public float R2 { get { return r2; } set { r2 = value; } }
@ -118,6 +125,12 @@ namespace Spine {
/// <summary>Whether R2 G2 B2 are used to tint the slot's attachment for two color tinting. False if two color tinting is not used.</summary> /// <summary>Whether R2 G2 B2 are used to tint the slot's attachment for two color tinting. False if two color tinting is not used.</summary>
public bool HasSecondColor { get { return data.hasSecondColor; } set { data.hasSecondColor = value; } } 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 { public Attachment Attachment {
/// <summary>The current attachment for the slot, or null if the slot has no attachment.</summary> /// <summary>The current attachment for the slot, or null if the slot has no attachment.</summary>
get { return attachment; } get { return attachment; }