aboutsummaryrefslogtreecommitdiff
path: root/chuck/OSCGraphicsText.ck
blob: 58377be8dd6deb38cfc56368e94a04fa93d7c5fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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)
			"b" +=> style;
		if (flags & STYLE_ITALIC)
			"i" +=> style;
		if (flags & STYLE_UNDERLINE)
			"u" +=> style;

		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;