Removing an old, cherished, yet pointless caveat "This documentation is
[supercollider.git] / Help / GUI / Cocoa-GUI / SCStaticText.html
blob2e540040c53a8a5e97677716381fa328021bd1f4
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.43">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; color: #001ee6}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
14 p.p5 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica}
16 p.p7 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica; min-height: 14.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica}
18 p.p9 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica; min-height: 14.0px}
19 p.p10 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 9.0px Monaco}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
21 p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
22 p.p13 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica}
23 p.p14 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
24 p.p15 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
25 p.p16 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0000bf}
26 p.p17 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
27 span.s1 {font: 18.0px Helvetica}
28 span.s2 {color: #000000}
29 span.s3 {color: #5f689f}
30 span.s4 {color: #6f717e}
31 span.s5 {font: 12.0px Helvetica}
32 span.s6 {color: #0000bf}
33 span.s7 {color: #007300}
34 span.s8 {color: #606060}
35 span.s9 {color: #bf0000}
36 span.Apple-tab-span {white-space:pre}
37 </style>
38 </head>
39 <body>
40 <p class="p1"><span class="s1"><b>SCStaticText<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>a view for displaying text</b><span class="s1"><b><span class="Apple-tab-span"> </span></b></span></p>
41 <p class="p2"><br></p>
42 <p class="p3"><span class="s2"><b>Inherits from: </b><a href="../../Core/Object.html"><b>Object</b></a><b> : </b><a href="SCView.html"><b>SCView</b></a><b> : </b><a href="SCStaticTextBase.html"><b>SCStaticTextBase</b></a></span></p>
43 <p class="p2"><br></p>
44 <p class="p1">Inherits formatting methods from <a href="SCStaticTextBase.html"><span class="s3">SCStaticTextBase</span></a>.</p>
45 <p class="p2"><br></p>
46 <p class="p4"><b>Creation / Class Methods</b></p>
47 <p class="p5"><br></p>
48 <p class="p6"><b><span class="Apple-tab-span"> </span>*new (parent, bounds)</b></p>
49 <p class="p7"><b><span class="Apple-tab-span"> </span></b></p>
50 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>parent </b>- The parent view.</p>
51 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>bounds </b>- An instance of <a href="../../Geometry/Rect.html"><span class="s4">Rect</span></a>, or a <a href="../../Geometry/Point.html"><span class="s4">Point</span></a> indicating width@height.</p>
52 <p class="p9"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
53 <p class="p10"><span class="s5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>(<span class="s2"><span class="Apple-tab-span"> </span></span></p>
54 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>w = <span class="s6">Window</span>.new.front;</p>
55 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a = <span class="s6">StaticText</span>(w, <span class="s6">Rect</span>(10, 10, 200, 20));</p>
56 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a.string = </span>"an instance of String"<span class="s2">;</span></p>
57 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s2">)</span></p>
58 <p class="p9"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
59 <p class="p13"><b>Examples</b></p>
60 <p class="p14"><br></p>
61 <p class="p15">// basic usage</p>
62 <p class="p11">(<span class="Apple-tab-span"> </span></p>
63 <p class="p11"><span class="Apple-tab-span"> </span>w = <span class="s6">Window</span>.new.front;</p>
64 <p class="p11"><span class="Apple-tab-span"> </span>a = <span class="s6">StaticText</span>(w, <span class="s6">Rect</span>(10, 10, 200, 20));</p>
65 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span>a.string = </span>"Rolof's Rolex"<span class="s2">;</span></p>
66 <p class="p11">)</p>
67 <p class="p14"><br></p>
68 <p class="p15">// adjust look , alignment and content</p>
69 <p class="p11">a.background=<span class="s6">Color</span>.grey;</p>
70 <p class="p11">a.align = <span class="s7">\center</span>;</p>
71 <p class="p11">a.font = <span class="s6">Font</span>(<span class="s8">"Monaco"</span>, 11);</p>
72 <p class="p11">a.string = <span class="s8">"Your Rolex"</span>;</p>
73 <p class="p14"><br></p>
74 <p class="p15">// Monitoring values in a synth</p>
75 <p class="p11">(</p>
76 <p class="p14"><br></p>
77 <p class="p11">w = <span class="s6">Window</span>(<span class="s8">"Frequency Monitor"</span>, <span class="s6">Rect</span>(200, <span class="s6">SCWindow</span>.screenBounds.height-200,300,150)).front;</p>
78 <p class="p14"><br></p>
79 <p class="p11">a = <span class="s6">StaticText</span>(w, <span class="s6">Rect</span>(45, 10, 200, 20)).background_(<span class="s6">Color</span>.rand);</p>
80 <p class="p14"><br></p>
81 <p class="p12"><span class="s2">a.string = </span>" Current Frequency "<span class="s2">;</span></p>
82 <p class="p14"><br></p>
83 <p class="p11"><span class="s6">Button</span>.new(w, <span class="s6">Rect</span>(45, 70, 200, 20)).states_([[<span class="s8">"close"</span>,<span class="s6">Color</span>.black,<span class="s6">Color</span>.rand]]).action_({w.close});</p>
84 <p class="p14"><br></p>
85 <p class="p11">s.waitForBoot({</p>
86 <p class="p14"><br></p>
87 <p class="p11"><span class="Apple-tab-span"> </span>b=<span class="s6">Bus</span>.new(<span class="s7">\control</span>,0,1);</p>
88 <p class="p14"><span class="Apple-tab-span"> </span></p>
89 <p class="p11"><span class="Apple-tab-span"> </span>q=<span class="s6">SynthDef</span>(<span class="s7">\Docs_FreqMonitor</span>, {<span class="s6">var</span> freq,snd;</p>
90 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>freq=<span class="s6">LFNoise0</span>.ar(2, 400, 650);</p>
91 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>snd=<span class="s6">SinOsc</span>.ar(freq,0,0.2);</p>
92 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s6">Out</span>.ar(0,snd);</p>
93 <p class="p15"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><span class="s6">Out</span><span class="s2">.kr(b.index,freq); </span>// output the frequency to a control bus</p>
94 <p class="p11"><span class="Apple-tab-span"> </span>}).play;</p>
95 <p class="p14"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
96 <p class="p16"><span class="s2"><span class="Apple-tab-span"> </span>r= </span>Routine<span class="s2">{</span></p>
97 <p class="p15"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// Set the value of the StaticText to the value in the control bus.</p>
98 <p class="p15"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// Setting GUI values is asynchronous, so you must use .defer in the system clock.</p>
99 <p class="p15"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// Also you must check if the window is still open, since Routine will continue for at least</p>
100 <p class="p15"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// one step after you close the window.</p>
101 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.get( {<span class="s6">arg</span> v; {w.isClosed.not.if{ a.string= <span class="s8">" Current Frequency: "</span>++v.round(0.01)}; }.defer} );</p>
102 <p class="p14"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
103 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.01.wait;</p>
104 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}.loop</p>
105 <p class="p14"><span class="Apple-tab-span"> </span></p>
106 <p class="p11"><span class="Apple-tab-span"> </span>}.play</p>
107 <p class="p11">});</p>
108 <p class="p14"><br></p>
109 <p class="p11"><span class="s6">CmdPeriod</span>.doOnce({w.close});</p>
110 <p class="p11">w.onClose={r.stop; q.free; b.free }; <span class="s9">//clean up if the window closes</span></p>
111 <p class="p14"><br></p>
112 <p class="p11">)</p>
113 <p class="p14"><br></p>
114 <p class="p15">// dynamic text</p>
115 <p class="p14"><br></p>
116 <p class="p11">(<span class="Apple-tab-span"> </span></p>
117 <p class="p11"><span class="Apple-tab-span"> </span>w = <span class="s6">Window</span>.new.front;</p>
118 <p class="p11"><span class="Apple-tab-span"> </span>w.view.background=<span class="s6">Color</span>.white;</p>
119 <p class="p11"><span class="Apple-tab-span"> </span>a = <span class="s6">Array</span>.fill(20, {<span class="s6">StaticText</span>(w, <span class="s6">Rect</span>(w.bounds.extent.x.rand, w.bounds.extent.y.rand, 160, 16))</p>
120 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.string_(<span class="s8">"Rolof's Rolex"</span>.scramble)</p>
121 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.align_(<span class="s7">\center</span>)</p>
122 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.stringColor_(<span class="s6">Color</span>.rand)</p>
123 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.font_(<span class="s6">Font</span>([</p>
124 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>"Helvetica-Bold"<span class="s2">,</span></p>
125 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>"Helvetica"<span class="s2">,</span></p>
126 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>"Monaco"<span class="s2">,</span></p>
127 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>"Arial"<span class="s2">,</span></p>
128 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>"Gadget"<span class="s2">,</span></p>
129 <p class="p12"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>"MarkerFelt-Thin"</p>
130 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>].choose, 11))</p>
131 <p class="p11"><span class="Apple-tab-span"> </span>});</p>
132 <p class="p14"><span class="Apple-tab-span"> </span></p>
133 <p class="p11"><span class="Apple-tab-span"> </span>r = {<span class="s6">inf</span>.do{<span class="s6">|i|</span></p>
134 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s6">thisThread</span>.randSeed_(1284);</p>
135 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a.do{<span class="s6">|item|</span></p>
136 <p class="p15"><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// setting GUI values is asynchronous, so you must use .defer</p>
137 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{item.bounds = <span class="s6">Rect</span>(5+w.bounds.extent.x.rand * (cos(i*0.01)).abs,</p>
138 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>w.bounds.extent.y.rand * sin(i*0.01),</p>
139 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>160, 20)}.defer;</p>
140 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>};</p>
141 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.15.wait;</p>
142 <p class="p11"><span class="Apple-tab-span"> </span>}}.fork;</p>
143 <p class="p11"><span class="Apple-tab-span"> </span><span class="s6">CmdPeriod</span>.doOnce({w.close});</p>
144 <p class="p11"><span class="Apple-tab-span"> </span>w.onClose_({r.stop});</p>
145 <p class="p11">)</p>
146 <p class="p14"><br></p>
147 <p class="p14"><br></p>
148 <p class="p17"><br></p>
149 <p class="p17"><br></p>
150 <p class="p17"><br></p>
151 </body>
152 </html>