aboutsummaryrefslogtreecommitdiff
path: root/chuck
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-09-17 02:42:51 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-09-17 02:42:51 +0200
commit88fa6b98d6a4a705c692997d83844c88d05f9922 (patch)
tree26285aaa153136cf9f42b7d0657240bec1e8aadf /chuck
parent3b7b682ca322d62f03c812f22623a43dc25b0074 (diff)
downloadosc-graphics-88fa6b98d6a4a705c692997d83844c88d05f9922.tar.gz
allow setting box color
Diffstat (limited to 'chuck')
-rw-r--r--chuck/OSCGraphics.ck12
-rw-r--r--chuck/OSCGraphicsBox.ck35
2 files changed, 41 insertions, 6 deletions
diff --git a/chuck/OSCGraphics.ck b/chuck/OSCGraphics.ck
index 626c92d..6c8dd9f 100644
--- a/chuck/OSCGraphics.ck
+++ b/chuck/OSCGraphics.ck
@@ -87,14 +87,14 @@ public class OSCGraphics {
return box;
}
fun static OSCGraphicsBox @
- newBox(int pos, int geo[], int color[], float opacity)
+ newBox(int pos, int geo[], float opacity, int color[])
{
OSCGraphicsBox box;
- box.init(osc_send, "box", "iiif", pos, "__box_"+free_id, geo);
+ box.init(osc_send, "box", "fiii", pos, "__box_"+free_id, geo);
+ opacity => osc_send.addFloat;
for (0 => int i; i < 3; i++)
color[i] => osc_send.addInt;
- opacity => osc_send.addFloat;
free_id++;
return box;
@@ -102,17 +102,17 @@ public class OSCGraphics {
fun static OSCGraphicsBox @
newBox(int pos, int geo[], int color[])
{
- return newBox(pos, geo, color, 1.);
+ return newBox(pos, geo, 1., color);
}
fun static OSCGraphicsBox @
newBox(int pos, int color[])
{
- return newBox(pos, null, color, 1.);
+ return newBox(pos, null, 1., color);
}
fun static OSCGraphicsBox @
newBox(int color[])
{
- return newBox(-1, null, color, 1.);
+ return newBox(-1, null, 1., color);
}
}
diff --git a/chuck/OSCGraphicsBox.ck b/chuck/OSCGraphicsBox.ck
index 489bcf5..3899994 100644
--- a/chuck/OSCGraphicsBox.ck
+++ b/chuck/OSCGraphicsBox.ck
@@ -1,2 +1,37 @@
public class OSCGraphicsBox extends OSCGraphicsLayer {
+ class ColorPort extends OSCGraphicsPort {
+ OSCGraphicsBox @layer;
+
+ int color[];
+ int index;
+
+ fun void
+ tick(float in, float prev)
+ {
+ in $ int => color[index];
+
+ /* optimize: avoid sending unnecessary messages */
+ if (color[index] != (prev $ int))
+ color => layer.color;
+ }
+ }
+ fun OSCGraphicsPort @
+ getColorPort(int color[], int index)
+ {
+ ColorPort p;
+ this @=> p.layer;
+ color @=> p.color;
+ index => p.index;
+
+ return p;
+ }
+ fun int[]
+ color(int color[])
+ {
+ osc_send.startMsg("/layer/"+name+"/color", "iii");
+ for (0 => int i; i < 3; i++)
+ color[i] => osc_send.addInt;
+
+ return color;
+ }
}