Skip to content

Commit aeb7242

Browse files
committed
Fix an issue where tweaks mode wont run if there are semi-transparent colors in the tab because of a regex issue.
1 parent 80a5b12 commit aeb7242

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

java/src/processing/mode/java/tweak/Handle.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,26 @@ public Handle(String t, String n, int vi, String v, int ti, int l, int sc,
8585
textFormat = "0x%x";
8686

8787
} else if ("webcolor".equals(type)) {
88-
Long val = Long.parseLong(strValue.substring(1, strValue.length()), 16);
88+
Long val;
89+
String prefix;
90+
if (strValue.length() == 7) {
91+
val = Long.parseLong(strValue.substring(1, strValue.length()), 16);
92+
prefix = "";
93+
} else {
94+
String valStr = strValue.substring(
95+
strValue.length() - 6,
96+
strValue.length()
97+
);
98+
val = Long.parseLong(valStr, 16);
99+
prefix = strValue.substring(
100+
1,
101+
strValue.length() - 6
102+
);
103+
}
89104
val = val | 0xff000000;
90105
value = newValue = val.intValue();
91106
strNewValue = strValue;
92-
textFormat = "#%06x";
93-
107+
textFormat = "#" + prefix + "%06x";
94108
} else if ("float".equals(type)) {
95109
value = newValue = Float.parseFloat(strValue);
96110
strNewValue = strValue;
@@ -267,7 +281,19 @@ public void sendNewValue() {
267281
} else if ("hex".equals(type)) {
268282
tweakClient.sendInt(index, newValue.intValue());
269283
} else if ("webcolor".equals(type)) {
270-
tweakClient.sendInt(index, newValue.intValue());
284+
// If full opaque color, don't spend the cycles on string processing
285+
// which does appear to matter at high frame rates. Otherwise take the
286+
// hit and parse back from string value with transparency.
287+
if (strNewValue.length() == 7) {
288+
tweakClient.sendInt(index, newValue.intValue());
289+
} else {
290+
long target = Long.parseLong(
291+
strNewValue.substring(1, strNewValue.length()),
292+
16
293+
);
294+
tweakClient.sendInt(index, (int) target);
295+
}
296+
271297
} else if ("float".equals(type)) {
272298
tweakClient.sendFloat(index, newValue.floatValue());
273299
}

java/src/processing/mode/java/tweak/SketchParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private void addAllHexNumbers() {
270270
* list of all hexadecimal numbers in the sketch
271271
*/
272272
private void addAllWebColorNumbers() {
273-
Pattern p = Pattern.compile("#[A-Fa-f0-9]{6}");
273+
Pattern p = Pattern.compile("#([A-Fa-f0-9]{2})?[A-Fa-f0-9]{6}");
274274
for (int i=0; i<codeTabs.length; i++)
275275
{
276276
String c = codeTabs[i];

0 commit comments

Comments
 (0)