diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-10-03 13:06:07 +0200 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2012-10-03 13:06:07 +0200 |
commit | 20001cbed6f01461a936ce00e6da51ca1aa4c926 (patch) | |
tree | ad40829a58be4e5283c8ac9c18353b1ec836e197 | |
parent | b224aef050b4f75b6325cb3b46b70e31d9116fa2 (diff) | |
download | osc-graphics-20001cbed6f01461a936ce00e6da51ca1aa4c926.tar.gz |
ChucK text layer wrapper
-rw-r--r-- | chuck/Makefile.am | 3 | ||||
-rw-r--r-- | chuck/OSCGraphics.ck | 35 | ||||
-rw-r--r-- | chuck/OSCGraphicsText.ck | 72 | ||||
-rw-r--r-- | chuck/lib.ck.in | 1 |
4 files changed, 110 insertions, 1 deletions
diff --git a/chuck/Makefile.am b/chuck/Makefile.am index 867a89c..43d55fb 100644 --- a/chuck/Makefile.am +++ b/chuck/Makefile.am @@ -1,6 +1,7 @@ dist_chuck_DATA = OSCGraphics.ck OSCGraphicsPort.ck OSCGraphicsLayer.ck \ - OSCGraphicsBox.ck OSCGraphicsImage.ck OSCGraphicsVideo.ck + OSCGraphicsBox.ck OSCGraphicsImage.ck OSCGraphicsVideo.ck \ + OSCGraphicsText.ck nodist_chuck_DATA = lib.ck CLEANFILES = lib.ck diff --git a/chuck/OSCGraphics.ck b/chuck/OSCGraphics.ck index a4e666a..6c2fcec 100644 --- a/chuck/OSCGraphics.ck +++ b/chuck/OSCGraphics.ck @@ -126,6 +126,41 @@ public class OSCGraphics { { return newBox(-1, null, 1., color); } + + fun static OSCGraphicsText @ + getText(string name) + { + OSCGraphicsText text; + osc_send @=> text.osc_send; + name => text.name; + return text; + } + fun static OSCGraphicsText @ + newText(int pos, int geo[], float opacity, int color[], + string txt, string font) + { + OSCGraphicsText text; + + text.init(osc_send, "text", "iiiss", + pos, "__text_"+free_id, geo, opacity); + for (0 => int i; i < 3; i++) + color[i] => osc_send.addInt; + txt => osc_send.addString; + font => osc_send.addString; + + free_id++; + return text; + } + fun static OSCGraphicsText @ + newText(int pos, int geo[], int color[], string txt, string font) + { + return newText(pos, geo, 1., color, txt, font); + } + fun static OSCGraphicsText @ + newText(int geo[], int color[], string txt, string font) + { + return newText(-1, geo, 1., color, txt, font); + } } /* static initialization */ new OscSend @=> OSCGraphics.osc_send; 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; diff --git a/chuck/lib.ck.in b/chuck/lib.ck.in index f4e4c51..0b4aab5 100644 --- a/chuck/lib.ck.in +++ b/chuck/lib.ck.in @@ -3,5 +3,6 @@ "@chuckdir@/OSCGraphicsImage.ck" => Machine.add; "@chuckdir@/OSCGraphicsVideo.ck" => Machine.add; "@chuckdir@/OSCGraphicsBox.ck" => Machine.add; +"@chuckdir@/OSCGraphicsText.ck" => Machine.add; "@chuckdir@/OSCGraphics.ck" => Machine.add; |