Fix an issue where tweaks mode wont run if there are semi-transparent
colors in the tab because of a regex issue.
This commit is contained in:
Sam Pottinger
2023-05-16 11:10:14 -07:00
parent 80a5b124f1
commit aeb72426c1
2 changed files with 31 additions and 5 deletions
@@ -85,12 +85,26 @@ public class Handle {
textFormat = "0x%x";
} else if ("webcolor".equals(type)) {
Long val = Long.parseLong(strValue.substring(1, strValue.length()), 16);
Long val;
String prefix;
if (strValue.length() == 7) {
val = Long.parseLong(strValue.substring(1, strValue.length()), 16);
prefix = "";
} else {
String valStr = strValue.substring(
strValue.length() - 6,
strValue.length()
);
val = Long.parseLong(valStr, 16);
prefix = strValue.substring(
1,
strValue.length() - 6
);
}
val = val | 0xff000000;
value = newValue = val.intValue();
strNewValue = strValue;
textFormat = "#%06x";
textFormat = "#" + prefix + "%06x";
} else if ("float".equals(type)) {
value = newValue = Float.parseFloat(strValue);
strNewValue = strValue;
@@ -267,7 +281,19 @@ public class Handle {
} else if ("hex".equals(type)) {
tweakClient.sendInt(index, newValue.intValue());
} else if ("webcolor".equals(type)) {
tweakClient.sendInt(index, newValue.intValue());
// If full opaque color, don't spend the cycles on string processing
// which does appear to matter at high frame rates. Otherwise take the
// hit and parse back from string value with transparency.
if (strNewValue.length() == 7) {
tweakClient.sendInt(index, newValue.intValue());
} else {
long target = Long.parseLong(
strNewValue.substring(1, strNewValue.length()),
16
);
tweakClient.sendInt(index, (int) target);
}
} else if ("float".equals(type)) {
tweakClient.sendFloat(index, newValue.floatValue());
}
@@ -270,7 +270,7 @@ public class SketchParser {
* list of all hexadecimal numbers in the sketch
*/
private void addAllWebColorNumbers() {
Pattern p = Pattern.compile("#[A-Fa-f0-9]{6}");
Pattern p = Pattern.compile("#([A-Fa-f0-9]{2})?[A-Fa-f0-9]{6}");
for (int i=0; i<codeTabs.length; i++)
{
String c = codeTabs[i];