Skip to content
Merged
Show file tree
Hide file tree
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
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