C#: Fix Color.ToHtml()

(cherry picked from commit 57fe284fe6)
This commit is contained in:
Ignacio Etcheverry 2019-08-04 05:04:39 +02:00 committed by Rémi Verschelde
parent 53b44aacad
commit b6bcd09d7c
1 changed files with 16 additions and 11 deletions

View File

@ -378,7 +378,7 @@ namespace Godot
return c; return c;
} }
public string ToHtml(bool include_alpha = true) public string ToHtml(bool includeAlpha = true)
{ {
var txt = string.Empty; var txt = string.Empty;
@ -386,7 +386,7 @@ namespace Godot
txt += ToHex32(g); txt += ToHex32(g);
txt += ToHex32(b); txt += ToHex32(b);
if (include_alpha) if (includeAlpha)
txt = ToHex32(a) + txt; txt = ToHex32(a) + txt;
return txt; return txt;
@ -468,13 +468,13 @@ namespace Godot
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
char[] c = { (char)0, (char)0 }; char c;
int lv = v & 0xF; int lv = v & 0xF;
if (lv < 10) if (lv < 10)
c[0] = (char)('0' + lv); c = (char)('0' + lv);
else else
c[0] = (char)('a' + lv - 10); c = (char)('a' + lv - 10);
v >>= 4; v >>= 4;
ret = c + ret; ret = c + ret;
@ -493,12 +493,17 @@ namespace Godot
bool alpha; bool alpha;
if (color.Length == 8) switch (color.Length)
alpha = true; {
else if (color.Length == 6) case 8:
alpha = false; alpha = true;
else break;
return false; case 6:
alpha = false;
break;
default:
return false;
}
if (alpha) if (alpha)
{ {