Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 42 additions & 18 deletions Engine/src/mini/font/ColorTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,51 @@ class Range {
Range(int start, String colorStr) {
this.start = start;
this.color = new ColorRGBA();

if (colorStr.length() >= 6) {
color.set(Integer.parseInt(colorStr.subSequence(0, 2).toString(), 16) / 255f,
Integer.parseInt(colorStr.subSequence(2, 4).toString(), 16) / 255f,
Integer.parseInt(colorStr.subSequence(4, 6).toString(), 16) / 255f,
1);
if (baseAlpha != -1) {
color.a = baseAlpha;
} else if (colorStr.length() == 8) {
color.a = Integer.parseInt(colorStr.subSequence(6, 8).toString(), 16) / 255f;
}
readHexColor(colorStr);
return;
}

readColor(colorStr);
}

private void readHexColor(String colorStr) {
color.r = readHexColorValue(colorStr, 0);
color.g = readHexColorValue(colorStr, 1);
color.b = readHexColorValue(colorStr, 2);

if (baseAlpha != -1) {
color.a = baseAlpha;
} else if (colorStr.length() == 8) {
color.a = readHexColorValue(colorStr, 3);
} else {
color.set(Integer.parseInt(Character.toString(colorStr.charAt(0)), 16) / 15f,
Integer.parseInt(Character.toString(colorStr.charAt(1)), 16) / 15f,
Integer.parseInt(Character.toString(colorStr.charAt(2)), 16) / 15f,
1);
if (baseAlpha != -1) {
color.a = baseAlpha;
} else if (colorStr.length() == 4) {
color.a = Integer.parseInt(Character.toString(colorStr.charAt(3)), 16) / 15f;
}
color.a = 1;
}
}

private float readHexColorValue(String colorStr, int index) {
int start = index * 2;
int end = start + 2;
return Integer.parseInt(colorStr.subSequence(start, end).toString(), 16) / 255f;
}

private void readColor(String colorStr) {
color.r = readColorValue(colorStr, 0);
color.g = readColorValue(colorStr, 1);
color.b = readColorValue(colorStr, 2);

if (baseAlpha != -1) {
color.a = baseAlpha;
} else if (colorStr.length() == 4) {
color.a = readColorValue(colorStr, 3);
} else {
color.a = 1;
}
}

private float readColorValue(String colorStr, int index) {
return Integer.parseInt(Character.toString(colorStr.charAt(index)), 16) / 15f;
}
}
}