Removing an old, cherished, yet pointless caveat "This documentation is
[supercollider.git] / Help / GUI / Cocoa-GUI / SCButton.html
blob3807d1ebf6bb20158a692492a7cd45f7f7fa6d71
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: 14.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; min-height: 12.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica}
15 p.p6 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica; min-height: 14.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica}
17 p.p8 {margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica; min-height: 14.0px}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
21 p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
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 57.0px; text-indent: -57.0px; font: 14.0px Helvetica; min-height: 17.0px}
24 p.p15 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco}
25 p.p16 {margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco; color: #007300}
26 p.p17 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
27 p.p18 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0000bf}
28 span.s1 {font: 18.0px Helvetica}
29 span.s2 {color: #6f7178}
30 span.s3 {font: 9.0px Monaco}
31 span.s4 {color: #000000}
32 span.s5 {color: #0000bf}
33 span.s6 {color: #606060}
34 span.s7 {font: 14.0px Helvetica}
35 span.s8 {font: 9.0px Monaco; color: #51535a}
36 span.s9 {color: #bf0000}
37 span.s10 {color: #007300}
38 span.s11 {text-decoration: underline}
39 span.Apple-tab-span {white-space:pre}
40 </style>
41 </head>
42 <body>
43 <p class="p1"><span class="s1"><b>SCButton<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>a multi-state button</b><span class="s1"><b><span class="Apple-tab-span"> </span></b></span></p>
44 <p class="p2"><br></p>
45 <p class="p1"><b>Inherits from: </b><a href="../../Core/Object.html"><span class="s2"><b>Object</b></span></a><b> : </b><a href="SCView.html"><span class="s2"><b>SCView</b></span></a><b> : SCControlView</b></p>
46 <p class="p2"><br></p>
47 <p class="p3"><b>Some Important Issues Regarding SCButton</b></p>
48 <p class="p2"><br></p>
49 <p class="p1">Failure to set any <b>states</b> at all results in an invisible button.</p>
50 <p class="p2"><br></p>
51 <p class="p1">The button performs its action upon releasing the mouse. In musical contexts, you might want to use <span class="s3">mouseDownAction_() </span>to set a function to be performed on pressing the mouse (see <a href="SCView.html"><span class="s2">SCView</span></a>, and examples below).</p>
52 <p class="p2"><br></p>
53 <p class="p1">If the drag contains a number, then <b>valueAction_()</b> is performed using the <b>currentDrag</b>. If the drag contains anything else, <b>action </b>ist set to the current drag. You could, for example, drag a function to an SCButton, and action would then be set to that function.</p>
54 <p class="p2"><br></p>
55 <p class="p3"><b>Creation / Class Methods</b></p>
56 <p class="p4"><br></p>
57 <p class="p5"><b><span class="Apple-tab-span"> </span>*new (parent, bounds)</b></p>
58 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
59 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>parent </b>- The parent view.</p>
60 <p class="p7"><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="s2">Rect</span></a>, or a <a href="../../Geometry/Point.html"><span class="s2">Point</span></a> indicating width@height.</p>
61 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
62 <p class="p9"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(</p>
63 <p class="p10"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>w = </span><span class="s5">Window</span><span class="s4">.new(</span>"The Four Noble Truths"<span class="s4">);</span></p>
64 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
65 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s5">Button</span>(w, <span class="s5">Rect</span>(20,20,340,30))</p>
66 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.states_([</p>
67 <p class="p12"><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="s6">"there is suffering"</span>, <span class="s5">Color</span>.black, <span class="s5">Color</span>.red],</p>
68 <p class="p10"><span class="s4"><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>"the origin of suffering"<span class="s4">, </span><span class="s5">Color</span><span class="s4">.white, </span><span class="s5">Color</span><span class="s4">.black],</span></p>
69 <p class="p10"><span class="s4"><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>"the cessation of suffering"<span class="s4">, </span><span class="s5">Color</span><span class="s4">.red, </span><span class="s5">Color</span><span class="s4">.white],</span></p>
70 <p class="p10"><span class="s4"><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>"there is a path to cessation of suffering"<span class="s4">, </span><span class="s5">Color</span><span class="s4">.blue, </span><span class="s5">Color</span><span class="s4">.clear]</span></p>
71 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>])</p>
72 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.action_({ <span class="s5">arg</span> butt;</p>
73 <p class="p12"><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>butt.value.postln;<span class="Apple-tab-span"> </span></p>
74 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
75 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>w.front;</p>
76 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">)</span></p>
77 <p class="p4"><br></p>
78 <p class="p13"><b>Accessing Instance and Class Variables</b></p>
79 <p class="p6"><span class="Apple-tab-span"> </span></p>
80 <p class="p5"><b><span class="Apple-tab-span"> </span>states</b></p>
81 <p class="p5"><b><span class="Apple-tab-span"> </span>states_ (array)</b></p>
82 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
83 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>An array of labels and colors defining the states ofthe button</p>
84 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>array </b>- an <a href="../../Collections/Array.html"><span class="s2">Array</span></a> of arrays of the form [ [String, strColor, bgColor] , .... ]</p>
85 <p class="p6"><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><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
86 <p class="p5"><b><span class="Apple-tab-span"> </span>value</b></p>
87 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
88 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>Returns the index of the current state. This will <b>not</b> evaluate the function assigned to <b>action</b> (see <a href="SCView.html"><span class="s2">SCView</span></a>).</p>
89 <p class="p4"><br></p>
90 <p class="p5"><b><span class="Apple-tab-span"> </span>value_ (val)</b></p>
91 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
92 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Sets the button to display the state at index <b>val</b> of the <b>states</b> array. This will <b>not</b> evaluate the function assigned to <b>action</b> (see <a href="SCView.html"><span class="s2">SCView</span></a>).</p>
93 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>val </b>- The index of an item in the <b>states</b> array .</p>
94 <p class="p4"><br></p>
95 <p class="p5"><b><span class="Apple-tab-span"> </span>valueAction_ (val)</b></p>
96 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
97 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Sets the button to display the item at index <b>val</b> of the <b>states</b> array, and evaluates action (see <a href="SCView.html"><span class="s2">SCView</span></a>), if the value has changed.</p>
98 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>val </b>- The index of an item in the <b>states</b> array .</p>
99 <p class="p6"><br></p>
100 <p class="p5"><b><span class="Apple-tab-span"> </span>font</b></p>
101 <p class="p5"><b><span class="Apple-tab-span"> </span>font_ (argFont)</b></p>
102 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
103 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>Sets the <a href="../Main-GUI/Font.html"><span class="s2">Font</span></a> of the button. Default value is the default font: Font.default .</p>
104 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>argFont </b>- An instance of <a href="../Main-GUI/Font.html"><span class="s2">Font</span></a>.</p>
105 <p class="p14"><br></p>
106 <p class="p13"><b>Subclassing and Internal Methods</b></p>
107 <p class="p5"><span class="s7"><span class="Apple-tab-span"> </span></span>The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.</p>
108 <p class="p4"><br></p>
109 <p class="p5"><b><span class="Apple-tab-span"> </span>doAction (modifiers)</b></p>
110 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
111 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>The method called by the primitive upon releasing the mouse.</p>
112 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>modifiers </b>- A key modifier number, which is passed to the <b>action</b> as its second argument upon mouse-releasing the button.</p>
113 <p class="p4"><br></p>
114 <p class="p5"><b><span class="Apple-tab-span"> </span>defaultKeyDownAction (char, modifiers, unicode)</b></p>
115 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
116 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>The default keydown actions are:</p>
117 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
118 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>key</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>action</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><b>comment</b></p>
119 <p class="p5"><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>value + 1<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>space</p>
120 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>\r <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>value + 1</p>
121 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>\n, <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>value + 1<span class="Apple-tab-span"> </span></p>
122 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>3.asAscii,<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>value + 1<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>(enter key or cmd-C on Mac OSX )</p>
123 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
124 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>To change these use <span class="s8">defaultKeyDownAction_</span> , see <a href="SCView.html"><span class="s2">SCView</span></a>.</p>
125 <p class="p4"><br></p>
126 <p class="p5"><b><span class="Apple-tab-span"> </span>properties</b></p>
127 <p class="p6"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></p>
128 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>A list of properties to which this view responds. See <a href="SCView.html"><span class="s2">SCView</span></a>.</p>
129 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
130 <p class="p15"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>returns:</p>
131 <p class="p16"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[ </span>\bounds<span class="s4">, </span>\visible<span class="s4">, </span>\enabled<span class="s4">, </span>\canFocus<span class="s4">, </span>\resize<span class="s4">, </span>\background<span class="s4">, </span>\minWidth<span class="s4">, </span>\maxWidth<span class="s4">, </span>\minHeight<span class="s4">, </span>\maxHeight<span class="s4">, </span>\value<span class="s4">, </span>\font<span class="s4">, </span>\states<span class="s4">, </span>\focusColor<span class="s4"> ]</span></p>
132 <p class="p4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
133 <p class="p5"><b><span class="Apple-tab-span"> </span>defaultGetDrag</b></p>
134 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
135 <p class="p5"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>The method called by default when initiating a drag <b>from</b> an SCButton. Returns the same as <b>value</b>.</p>
136 <p class="p6"><span class="Apple-tab-span"> </span></p>
137 <p class="p5"><span class="Apple-tab-span"> </span><b>defaultCanReceiveDrag</b></p>
138 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
139 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>The method called by default when attempting to drop a drag in this object. By default, SCButton will respond only to drags where the drag contains a <a href="../../Math/Number.html"><span class="s2">Number</span></a> or <a href="../../Core/Kernel/Function.html"><span class="s2">Function</span></a>.</p>
140 <p class="p6"><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="s3"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span></p>
141 <p class="p5"><span class="Apple-tab-span"> </span><b>defaultReceiveDrag</b></p>
142 <p class="p6"><b><span class="Apple-tab-span"> </span></b></p>
143 <p class="p5"><b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b>The default method called when a drag has been recieved. If the drag contains a number, then <b>action </b>ist set to the current drag. Otherwise <b>valueAction_()</b> is performed using the <b>currentDrag</b>.</p>
144 <p class="p6"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
145 <p class="p13"><b>Examples</b></p>
146 <p class="p11"><br></p>
147 <p class="p12">(</p>
148 <p class="p12">w = <span class="s5">Window</span>.new(<span class="s6">"Example"</span>);</p>
149 <p class="p11"><br></p>
150 <p class="p12">b = <span class="s5">Button</span>(w, <span class="s5">Rect</span>(90,20,200,30))</p>
151 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.states_([</p>
152 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[<span class="s6">"sine"</span>, <span class="s5">Color</span>.black, <span class="s5">Color</span>.rand],</p>
153 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[<span class="s6">"saw"</span>, <span class="s5">Color</span>.black, <span class="s5">Color</span>.rand],</p>
154 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[<span class="s6">"noise"</span>, <span class="s5">Color</span>.black, <span class="s5">Color</span>.rand],</p>
155 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[<span class="s6">"pulse"</span>, <span class="s5">Color</span>.black, <span class="s5">Color</span>.rand]</p>
156 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>])</p>
157 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.action_({ <span class="s5">arg</span> butt;</p>
158 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>butt.value.postln;<span class="Apple-tab-span"> </span></p>
159 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
160 <p class="p12">w.front;</p>
161 <p class="p12">)</p>
162 <p class="p11"><br></p>
163 <p class="p17">// does not do action</p>
164 <p class="p12">b.value = 2;</p>
165 <p class="p11"><br></p>
166 <p class="p17">// does action if it results in a change of value</p>
167 <p class="p12">b.valueAction = 3;</p>
168 <p class="p11"><br></p>
169 <p class="p17">// clips to size of states</p>
170 <p class="p12">b.valueAction = -1;</p>
171 <p class="p11"><br></p>
172 <p class="p17">// floats no problem</p>
173 <p class="p12">b.valueAction = 3.3;</p>
174 <p class="p11"><br></p>
175 <p class="p11"><br></p>
176 <p class="p17">//In a musical context, a button-down press is more meaningful than a button-up (release) as it's more</p>
177 <p class="p17">//intuitive to press a button on the beat. For that you can use View's mouseDownAction</p>
178 <p class="p17">//(a superclass of Button)</p>
179 <p class="p11"><br></p>
180 <p class="p12">(</p>
181 <p class="p12">s.waitForBoot({</p>
182 <p class="p12"><span class="Apple-tab-span"> </span>w = <span class="s5">Window</span>.new;</p>
183 <p class="p12"><span class="Apple-tab-span"> </span>b = <span class="s5">Button</span>(w, <span class="s5">Rect</span>(20,20,80,26))</p>
184 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.states_([[<span class="s6">"play"</span>, <span class="s5">Color</span>.black, <span class="s5">Color</span>.rand]])</p>
185 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.mouseDownAction_({</p>
186 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a = <span class="Apple-tab-span"> </span>{<span class="s5">EnvGen</span>.kr(<span class="s5">Env</span>.adsr,doneAction:2)*<span class="s5">SinOsc</span>.ar(440,0,0.4)}.play;<span class="Apple-tab-span"> </span></p>
187 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>})</p>
188 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.action_({ <span class="s5">arg</span> butt, mod;</p>
189 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>a.release(0.3);</p>
190 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
191 <p class="p12"><span class="Apple-tab-span"> </span>w.front;</p>
192 <p class="p12">})</p>
193 <p class="p12">)</p>
194 <p class="p11"><br></p>
195 <p class="p11"><br></p>
196 <p class="p17">// if you drag a function to a button, the the button's action is set to that function.</p>
197 <p class="p17">// you can us this for swapping functions.</p>
198 <p class="p12">(</p>
199 <p class="p11"><br></p>
200 <p class="p12">s.waitForBoot({</p>
201 <p class="p12"><span class="Apple-tab-span"> </span><span class="s5">var</span> w,p,snd,b;</p>
202 <p class="p11"><span class="Apple-tab-span"> </span></p>
203 <p class="p12"><span class="Apple-tab-span"> </span>w = <span class="s5">Window</span>.new;</p>
204 <p class="p11"><span class="Apple-tab-span"> </span></p>
205 <p class="p12"><span class="Apple-tab-span"> </span>b=<span class="s5">Button</span>(w, <span class="s5">Rect</span>(20,20,80,26))</p>
206 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.states_([[<span class="s6">"start a sound"</span>, <span class="s5">Color</span>.black, <span class="s5">Color</span>.green],[<span class="s6">"stop"</span>, <span class="s5">Color</span>.black, <span class="s5">Color</span>.red]])</p>
207 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.action_({});</p>
208 <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></p>
209 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span>v=</span><span class="s5">VLayoutView</span><span class="s4">(w,</span><span class="s5">Rect</span><span class="s4">(140,20,200,300)); </span>//Group the following views</p>
210 <p class="p12"><span class="Apple-tab-span"> </span><span class="s5">StaticText</span>(v, <span class="s5">Rect</span>(20,20,180,60))</p>
211 <p class="p10"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.string_(</span>"The button does nothing at first, so try dragging a function to the button"<span class="s4">);</span></p>
212 <p class="p11"><span class="Apple-tab-span"> </span></p>
213 <p class="p12"><span class="Apple-tab-span"> </span><span class="s5">DragSource</span>(v, <span class="s5">Rect</span>(20,20,80,26))</p>
214 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.object_(</p>
215 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{<span class="s5">|b|</span> (b.value==1).if{snd={ <span class="s5">SinOsc</span>.ar(440,0,0.6) }.play}{snd.free};}<span class="s9">//a button action function</span></p>
216 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
217 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.string_(<span class="s6">"a play sine function"</span>).align_(<span class="s10">\center</span>).background_(<span class="s5">Color</span>.rand);</p>
218 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
219 <p class="p12"><span class="Apple-tab-span"> </span><span class="s5">DragSource</span>(v, <span class="s5">Rect</span>(20,20,80,26))</p>
220 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.object_(</p>
221 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{<span class="s5">|b|</span> (b.value==1).if{snd={ <span class="s5">Saw</span>.ar(440,0.4) }.play}{snd.free};} <span class="s9">//a button action function</span></p>
222 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
223 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.string_(<span class="s6">"a play saw function"</span>).align_(<span class="s10">\center</span>).background_(<span class="s5">Color</span>.rand);</p>
224 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
225 <p class="p12"><span class="Apple-tab-span"> </span><span class="s5">DragSource</span>(v, <span class="s5">Rect</span>(20,20,80,26))</p>
226 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.object_(</p>
227 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{<span class="s5">|b|</span> (b.value==1).if{snd={ <span class="s5">WhiteNoise</span>.ar(0.4) }.play}{snd.free};} <span class="s9">//a button action function</span></p>
228 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
229 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.string_(<span class="s6">"a play noise function"</span>).align_(<span class="s10">\center</span>).background_(<span class="s5">Color</span>.rand);</p>
230 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
231 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span>p=</span><span class="s5">CmdPeriod</span><span class="s4">.add({b.value_(0)});</span>// set button to 0 on hitting Cmd-period</p>
232 <p class="p12"><span class="Apple-tab-span"> </span>w.onClose_{ snd.free; <span class="s5">CmdPeriod</span>.removeAll };<span class="s9">//clean up when window is closed</span></p>
233 <p class="p12"><span class="Apple-tab-span"> </span>w.front;</p>
234 <p class="p11"><br></p>
235 <p class="p12">})</p>
236 <p class="p12">)</p>
237 <p class="p11"><br></p>
238 <p class="p17">// Using <a href="../../Core/Kernel/Routine.html"><span class="s11">Routine</span></a> to set button states on the fly.</p>
239 <p class="p12">(</p>
240 <p class="p12"><span class="s5">var</span> update, w, b;</p>
241 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>w = <span class="s5">Window</span>.new(<span class="s6">"State Window"</span>, <span class="s5">Rect</span>(150,<span class="s5">Window</span>.screenBounds.height-140,380,60));</p>
242 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
243 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// a convenient way to set the button label</p>
244 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>update = {</p>
245 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">|but, string|</span> but.states = [[string.asString, <span class="s5">Color</span>.black, <span class="s5">Color</span>.red]];</p>
246 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>but.refresh;</p>
247 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>};</p>
248 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
249 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s5">Button</span>(w, <span class="s5">Rect</span>(10,10,360,40));</p>
250 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.font_(<span class="s5">Font</span>(<span class="s6">"Impact"</span>, 24));</p>
251 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
252 <p class="p10"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>update.value(b, </span>"there is only one state"<span class="s4">);</span></p>
253 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
254 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// if an action should do something different each time it is called, a routine is the</p>
255 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// right thing to use. This is better than creating variables outside and setting them</p>
256 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// from the action function to keep state from one action to the next</p>
257 <p class="p11"><br></p>
258 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.action_(<span class="s5">Routine</span> { <span class="s5">|butt|</span></p>
259 <p class="p12"><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>rrand(15, 45).do { <span class="s5">|i|</span></p>
260 <p class="p12"><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><span class="Apple-tab-span"> </span>update.value(butt, <span class="s6">"%. there is still only 1 state"</span>.format(i + 2));</p>
261 <p class="p12"><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><span class="Apple-tab-span"> </span>0.yield; <span class="s9">// stop here</span></p>
262 <p class="p12"><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>};</p>
263 <p class="p12"><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.close;</p>
264 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
265 <p class="p11"><br></p>
266 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>w.front;</p>
267 <p class="p12">)</p>
268 <p class="p11"><br></p>
269 <p class="p17">// Using <a href="../../Core/Kernel/Routine.html"><span class="s11">Routine</span></a> to set button states on the fly 2.</p>
270 <p class="p12">(</p>
271 <p class="p12">s.waitForBoot({</p>
272 <p class="p12"><span class="s5">var</span> update, w, b;</p>
273 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>w = <span class="s5">Window</span>.new(<span class="s6">"State Window"</span>, <span class="s5">Rect</span>(150,<span class="s5">Window</span>.screenBounds.height-140,380,60));</p>
274 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
275 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// a convenient way to set the button label</p>
276 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>update = { <span class="s5">|but, string|</span></p>
277 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>but.states = [[string.asString, <span class="s5">Color</span>.black, <span class="s5">Color</span>.red]]; but.refresh };</p>
278 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
279 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b = <span class="s5">Button</span>(w, <span class="s5">Rect</span>(10,10,360,40));</p>
280 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.font_(<span class="s5">Font</span>(<span class="s6">"Impact"</span>, 24));</p>
281 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
282 <p class="p10"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>update.value(b, </span>"there is only one state"<span class="s4">);</span></p>
283 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
284 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// if an action should do something different each time it is called, a routine is the</p>
285 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// right thing to use. This is better than creating variables outside and setting them</p>
286 <p class="p17"><span class="s4"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span>// from the action function to keep state from one action to the next</p>
287 <p class="p11"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
288 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>b.action_(<span class="s5">Routine</span> { <span class="s5">|butt|</span></p>
289 <p class="p12"><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="s5">var</span> synth, guessVal;</p>
290 <p class="p12"><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>update.value(butt, <span class="s6">"there are only two states"</span>);</p>
291 <p class="p12"><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>0.yield; <span class="s9">// stop here</span></p>
292 <p class="p12"><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>update.value(butt, <span class="s6">"click me"</span>);</p>
293 <p class="p12"><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>0.yield; <span class="s9">// stop here</span></p>
294 <p class="p12"><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>update.value(butt, <span class="s6">"click me again"</span>);</p>
295 <p class="p12"><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>0.yield; <span class="s9">// stop here ..</span></p>
296 <p class="p17"><span class="s4"><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></span>// create a synth</p>
297 <p class="p18"><span class="s4"><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>synth = { </span>|freq=1000, rate=5|</p>
298 <p class="p12"><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><span class="Apple-tab-span"> </span><span class="s5">Ringz</span>.ar(</p>
299 <p class="p12"><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><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">Impulse</span>.ar(rate.lag(4) * [1,1.01]), freq, rrand(0.01, 0.1),0.3</p>
300 <p class="p12"><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><span class="Apple-tab-span"> </span>)</p>
301 <p class="p12"><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>}.play;</p>
302 <p class="p12"><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>0.yield;</p>
303 <p class="p12"><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>guessVal = exprand(200.0, 18000).round;</p>
304 <p class="p12"><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>synth.set(<span class="s10">\freq</span>, guessVal); <span class="s9">// set the synth</span></p>
305 <p class="p12"><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>update.value(butt, <span class="s6">"?"</span>);</p>
306 <p class="p12"><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>0.yield;</p>
307 <p class="p12"><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>update.value(butt, guessVal.asString + <span class="s6">"Hz"</span>); <span class="s9">// display frequency</span></p>
308 <p class="p12"><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>0.yield;</p>
309 <p class="p12"><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>synth.set(<span class="s10">\rate</span>, rrand(10, 50)); <span class="s9">// set trigger rate</span></p>
310 <p class="p17"><span class="s4"><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></span>// start an independent process</p>
311 <p class="p12"><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>fork({ 5.wait; synth.release; update.value(butt, <span class="s6">"."</span>); 1.wait; w.close }, <span class="s5">AppClock</span>);</p>
312 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>});</p>
313 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">CmdPeriod</span>.doOnce({w.close});</p>
314 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>w.front;</p>
315 <p class="p12">});</p>
316 <p class="p12">)</p>
317 <p class="p11"><br></p>
318 <p class="p11"><br></p>
319 <p class="p17">// complex drag and drop example</p>
320 <p class="p17">// try dragging the buttons to white slot, adn then between white slots, or simply out fo the view</p>
321 <p class="p11"><br></p>
322 <p class="p12">(</p>
323 <p class="p12"><span class="s5">var</span> w, f, slots;</p>
324 <p class="p12"><span class="s5">var</span> insert, remove;</p>
325 <p class="p11"><br></p>
326 <p class="p12">slots = <span class="s5">Dictionary</span>.new;</p>
327 <p class="p11"><br></p>
328 <p class="p12">remove = {<span class="s5">arg</span> slot, id;</p>
329 <p class="p12"><span class="Apple-tab-span"> </span>[slot, id].postln;</p>
330 <p class="p12">};</p>
331 <p class="p11"><br></p>
332 <p class="p12">insert = {<span class="s5">arg</span> slot, fx;</p>
333 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>if(fx!=<span class="s6">""</span>){</p>
334 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>slots[<span class="s6">"slot"</span>++slot].value_(0).states_([[fx, <span class="s5">Color</span>.white, <span class="s5">Color</span>.blue]]);</p>
335 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>[slot, fx].postln;</p>
336 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>}{</p>
337 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>slots[<span class="s6">"slot"</span>++slot].value_(0).states_([[ <span class="s6">""</span>, <span class="s5">Color</span>.white, <span class="s5">Color</span>.white ]]);</p>
338 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>remove.value(slot, fx);</p>
339 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>};</p>
340 <p class="p12">};</p>
341 <p class="p11"><br></p>
342 <p class="p12">w = <span class="s5">Window</span>.new(<span class="s6">""</span>,<span class="s5">Rect</span>(200, 400, 448, 180));</p>
343 <p class="p12">w.view.decorator = f = <span class="s5">FlowLayout</span>(w.view.bounds);</p>
344 <p class="p11"><br></p>
345 <p class="p10"><span class="s5">StaticText</span><span class="s4">(w, 400@20).string_(</span>"Drag &amp; Drop holding down Cmd-key"<span class="s4">);</span></p>
346 <p class="p12">f.nextLine;</p>
347 <p class="p12">6.do{<span class="s5">arg</span> i;</p>
348 <p class="p12"><span class="Apple-tab-span"> </span><span class="s5">var</span> fxwin, winOpen=<span class="s5">false</span>, empty = [ <span class="s6">""</span>, <span class="s5">Color</span>.white, <span class="s5">Color</span>.white ];</p>
349 <p class="p11"><span class="Apple-tab-span"> </span></p>
350 <p class="p12"><span class="Apple-tab-span"> </span>slots[<span class="s6">"slot"</span>++i] = <span class="s5">Button</span>.new(w, 70@70)</p>
351 <p class="p12"><span class="Apple-tab-span"> </span>.states_([empty])</p>
352 <p class="p12"><span class="Apple-tab-span"> </span>.action_({<span class="s5">|v|</span></p>
353 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>if((slots[<span class="s6">"slot"</span>++i].states[0][0]!=<span class="s6">""</span>)&amp;&amp;(winOpen==<span class="s5">false</span>)){</p>
354 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>fxwin = <span class="s5">Window</span>(slots[<span class="s6">"slot"</span>++i].states[0][0], <span class="s5">Rect</span>(rrand(0,500),rrand(0,500),200,200)).front;</p>
355 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>fxwin.view.background_(<span class="s5">Color</span>.rand);</p>
356 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>fxwin.onClose_({winOpen=<span class="s5">false</span>});</p>
357 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>winOpen = <span class="s5">true</span>}</p>
358 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{if(winOpen==<span class="s5">true</span>){fxwin.front}};</p>
359 <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></p>
360 <p class="p12"><span class="Apple-tab-span"> </span>})</p>
361 <p class="p12"><span class="Apple-tab-span"> </span>.canReceiveDragHandler_({<span class="s5">View</span>.currentDrag.isString})</p>
362 <p class="p12"><span class="Apple-tab-span"> </span>.receiveDragHandler_({</p>
363 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>insert.value(i, <span class="s5">View</span>.currentDrag);</p>
364 <p class="p12"><span class="Apple-tab-span"> </span>})</p>
365 <p class="p12"><span class="Apple-tab-span"> </span>.beginDragAction_({</p>
366 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">var</span> drag;</p>
367 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>drag = slots[<span class="s6">"slot"</span>++i].states[0][0];</p>
368 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>slots[<span class="s6">"slot"</span>++i].value_(0).states_([empty]);</p>
369 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>remove.value(i, <span class="s5">View</span>.currentDrag);</p>
370 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>drag;</p>
371 <p class="p12"><span class="Apple-tab-span"> </span>})</p>
372 <p class="p12"><span class="Apple-tab-span"> </span>.keyDownAction_({ <span class="s5">arg</span> view,char,modifiers,unicode,keycode;</p>
373 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>switch (keycode)</p>
374 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>{51} {slots[<span class="s6">"slot"</span>++i].value_(0).states_([empty]);</p>
375 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>slots[<span class="s6">"slot"</span>++i].refresh;</p>
376 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>remove.value(i, <span class="s5">View</span>.currentDrag);</p>
377 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>};</p>
378 <p class="p12"><span class="Apple-tab-span"> </span>});</p>
379 <p class="p11"><br></p>
380 <p class="p12">};</p>
381 <p class="p11"><span class="Apple-tab-span"> </span></p>
382 <p class="p12">f.nextLine;</p>
383 <p class="p11"><br></p>
384 <p class="p12">[<span class="s6">"a"</span>, <span class="s6">"b"</span>, <span class="s6">"c"</span>, <span class="s6">"d"</span>, <span class="s6">"e"</span>, <span class="s6">"f"</span>].do{<span class="s5">arg</span> item, i;</p>
385 <p class="p12"><span class="Apple-tab-span"> </span><span class="s5">Button</span>.new(w, 70@70)</p>
386 <p class="p12"><span class="Apple-tab-span"> </span>.states_([ [ item ] ])</p>
387 <p class="p12"><span class="Apple-tab-span"> </span>.action_({<span class="s5">|v|</span> })</p>
388 <p class="p12"><span class="Apple-tab-span"> </span>.beginDragAction_({item})</p>
389 <p class="p12">};</p>
390 <p class="p12">w.front;</p>
391 <p class="p12">)</p>
392 <p class="p11"><br></p>
393 </body>
394 </html>