aboutsummaryrefslogtreecommitdiff
path: root/chuck/OSCGraphicsText.ck
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-10-03 13:06:07 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-10-03 13:06:07 +0200
commit20001cbed6f01461a936ce00e6da51ca1aa4c926 (patch)
treead40829a58be4e5283c8ac9c18353b1ec836e197 /chuck/OSCGraphicsText.ck
parentb224aef050b4f75b6325cb3b46b70e31d9116fa2 (diff)
downloadosc-graphics-20001cbed6f01461a936ce00e6da51ca1aa4c926.tar.gz
ChucK text layer wrapper
Diffstat (limited to 'chuck/OSCGraphicsText.ck')
-rw-r--r--chuck/OSCGraphicsText.ck72
1 files changed, 72 insertions, 0 deletions
diff --git a/chuck/OSCGraphicsText.ck b/chuck/OSCGraphicsText.ck
new file mode 100644
index 0000000..59f12ea
--- /dev/null
+++ b/chuck/OSCGraphicsText.ck
@@ -0,0 +1,72 @@
+public class OSCGraphicsText extends OSCGraphicsLayer {
+ class ColorPort extends OSCGraphicsPort {
+ OSCGraphicsText @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;
+ }
+
+ fun string
+ text(string text)
+ {
+ osc_send.startMsg("/layer/"+name+"/text", "s");
+ text => osc_send.addString;
+
+ return text;
+ }
+
+ static int STYLE_BOLD;
+ static int STYLE_ITALIC;
+ static int STYLE_UNDERLINE;
+
+ fun int
+ style(int flags)
+ {
+ string style;
+
+ if (flags & STYLE_BOLD)
+ style +=> "b";
+ if (flags & STYLE_ITALIC)
+ style +=> "i";
+ if (flags & STYLE_UNDERLINE)
+ style +=> "u";
+
+ osc_send.startMsg("/layer/"+name+"/style", "s");
+ style => osc_send.addString;
+
+ return flags;
+ }
+}
+/* static initialization */
+(1 << 1) => OSCGraphicsText.STYLE_BOLD;
+(1 << 2) => OSCGraphicsText.STYLE_ITALIC;
+(1 << 3) => OSCGraphicsText.STYLE_UNDERLINE;