Skip to content

Commit

Permalink
Closes #720.
Browse files Browse the repository at this point in the history
Fix an issue where tweaks mode wont run if there are semi-transparent
colors in the tab because of a regex issue.
  • Loading branch information
sampottinger committed May 16, 2023
1 parent 80a5b12 commit aeb7242
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
34 changes: 30 additions & 4 deletions java/src/processing/mode/java/tweak/Handle.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,26 @@ public Handle(String t, String n, int vi, String v, int ti, int l, int sc,
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;
Expand Down Expand Up @@ -267,7 +281,19 @@ public void sendNewValue() {
} 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());
}
Expand Down
2 changes: 1 addition & 1 deletion java/src/processing/mode/java/tweak/SketchParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private void addAllHexNumbers() {
* 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];
Expand Down

0 comments on commit aeb7242

Please sign in to comment.