1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"949.46">
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: #0000bf}
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 0.0px; font: 14.0px Helvetica
; min-height: 17.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 0.0px; font: 9.0px Monaco
}
20 p
.p11
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica
}
21 p
.p12
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica
; min-height: 17.0px}
22 p
.p13
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
; min-height: 12.0px}
23 p
.p14
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
}
24 p
.p15
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
; color: #007300}
25 p
.p16
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
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: #606060}
28 span
.s1
{font: 18.0px Helvetica
}
29 span
.s2
{color: #000000}
30 span
.s3
{text-decoration: underline
}
31 span
.s4
{color: #0000bf}
32 span
.s5
{color: #0000bf}
33 span
.s6
{font: 12.0px Helvetica
}
34 span
.s7
{font: 11.0px Monaco
}
35 span
.s8
{font: 11.0px Monaco
; color: #0000bf}
36 span
.s9
{font: 14.0px Helvetica
}
37 span
.s10
{text-decoration: underline
; color: #0000bf}
38 span
.s11
{color: #007300}
39 span
.s12
{color: #606060}
40 span
.Apple-tab-span
{white-space:pre
}
44 <p class=
"p1"><span class=
"s1"><b>SCSlider
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></span><b>a gui slider
</b><span class=
"s1"><b><span class=
"Apple-tab-span"> </span></b></span></p>
45 <p class=
"p2"><br></p>
46 <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=
"SCControlView.html"><b>SCControlView
</b></a><b> :
</b><a href=
"SCSliderBase.html"><b>SCSliderBase
</b></a></span></p>
47 <p class=
"p2"><br></p>
48 <p class=
"p3"><span class=
"s2"><b>See also:
</b> <a href=
"SCRangeSlider.html"><span class=
"s3">SCRangeSlider
</span></a>,
<a href=
"../EZ-GUI/EZSlider.html"><span class=
"s3">EZSlider
</span></a></span></p>
49 <p class=
"p2"><br></p>
50 <p class=
"p4"><b>Some Important Issues Regarding SCSlider
</b></p>
51 <p class=
"p2"><br></p>
52 <p class=
"p1">SCSlider always has a range between zero and one. You must scale the output and input values to your needs. Using
<b>map
</b> and
<b>unmap,
</b> combined with a
<a href=
"../../Control/Spec.html"><span class=
"s4">Spec
</span></a>, is helpful for this. To set the increment or decrement value of the slider, set the
<b>step
</b>.
<span class=
"Apple-converted-space"> </span>By default, the shift, ctrl, and alt keys will modify the stepping by
100x,
10x, or
0.1x repectively, though you can customize this by setting
<b>shift_scale, ctrl_scale,
</b>or
<b> alt_scale
<span class=
"Apple-converted-space"> </span></b> (see
<a href=
"SCSliderBase.html"><span class=
"s5">SCSliderBase
</span></a>) .
<span class=
"Apple-converted-space"> </span>Inherits some formatting from
<a href=
"SCSliderBase.html"><span class=
"s5">SCSliderBase
</span></a>.
</p>
53 <p class=
"p5"><br></p>
54 <p class=
"p6">By default, SCSlider will respond only to drags where the drag contains a
<a href=
"../../Math/Number.html"><span class=
"s5">Number
</span></a>.
</p>
55 <p class=
"p2"><br></p>
56 <p class=
"p4"><b>Creation / Class Methods
</b></p>
57 <p class=
"p5"><br></p>
58 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>*new (parent, bounds)
</b></p>
59 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
60 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>parent
</b>- The parent view.
</p>
61 <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=
"s5">Rect
</span></a>, or a
<a href=
"../../Geometry/Point.html"><span class=
"s5">Point
</span></a> indicating width@height.
</p>
62 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
63 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(
</p>
64 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>w =
<span class=
"s5">Window
</span>.new.front;
</p>
65 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
20,
60,
150,
20));
</p>
66 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>a.action = { a.value.postln };
</p>
67 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>)
</p>
68 <p class=
"p9"><br></p>
69 <p class=
"p11"><b>Accessing Instance and Class Variables
</b><span class=
"s6"><span class=
"Apple-tab-span"> </span></span></p>
70 <p class=
"p12"><br></p>
71 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>value
</b></p>
72 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>value_ (val)
</b></p>
73 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></p>
74 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Gets/sets the property, \value, by calling get/setProperty(\value,
<b>val
</b>). This will not do the
<b>action
</b> of the slider.
</p>
75 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
76 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>valueAction_ (val)
</b></p>
77 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
78 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Sets the property, \value, by calling setPropertyWithAction(\value,
<b>val
</b>). Does the sliders
<b>action
</b>.
</p>
79 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
80 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>increment (zoom)
</b></p>
81 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>decrement (zoom)
</b></p>
82 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
83 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>These are the methods called by pressing the arrow keys. These methods increment or decrement the slider value by
<span class=
"s7">(max(
</span><span class=
"s8">this
</span><span class=
"s7">.step,
</span><span class=
"s8">this
</span><span class=
"s7">.pixelStep) * zoom)
</span>. This means that by default increment and decrement change the value by
<b>pixelStep
</b> (
<b>step
</b> is nil by default). You can set
<b>step
</b> to quantize the increment/decrement of the slider values. If you call these methods from your code, you can also change the resolution of the values with the
<b>zoom
</b> factor. This will not effect how the keys work, since they will always use a zoom factor of
1, or a multiple of that depending on the key modifier. See
<a href=
"SCSliderBase.html"><span class=
"s5">SCSliderBase
</span></a>. Performs the action of the slider.
<span class=
"Apple-converted-space"> </span></p>
84 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
85 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>zoom
</b>- Defaults to
1, though it is effected by key modifiers when using arrow keys.
</p>
86 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
87 <p class=
"p11"><b>Customizing Appearance
</b></p>
88 <p class=
"p7"><br></p>
89 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>thumbSize
</b></p>
90 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>thumbSize_ (size)
</b></p>
91 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
92 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>size
</b>- The size of the slider button in pixels. Its width or height, depending on the slider orientation
</p>
93 <p class=
"p7"><br></p>
94 <p class=
"p11"><b>Subclassing and Internal Methods
</b></p>
95 <p class=
"p6"><span class=
"s9"><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>
96 <p class=
"p7"><br></p>
97 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>properties
</b></p>
98 <p class=
"p7"><br></p>
99 <p class=
"p6"><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=
"s5">SCView
</span></a>.
</p>
100 <p class=
"p13"><br></p>
101 <p class=
"p14"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>returns:
</p>
102 <p class=
"p15"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>[
</span>\bounds
<span class=
"s2">,
</span>\visible
<span class=
"s2">,
</span>\enabled
<span class=
"s2">,
</span>\canFocus
<span class=
"s2">,
</span>\resize
<span class=
"s2">,
</span>\background
<span class=
"s2">,
</span>\minWidth
<span class=
"s2">,
</span>\maxWidth
<span class=
"s2">,
</span>\minHeight
<span class=
"s2">,
</span>\maxHeight
<span class=
"s2">,
</span>\knobColor
<span class=
"s2">,
</span>\step
<span class=
"s2">,
</span>\thumbSize
<span class=
"s2">,
</span>\focusColor
<span class=
"s2">]
</span></p>
103 <p class=
"p7"><br></p>
104 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>pixelStep
</b></p>
105 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
106 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Returns the reciprocal of: the slider width or height (depending on orientation) minus the
<b>thumbSize
</b><span class=
"Apple-tab-span"> </span></p>
107 <p class=
"p13"><br></p>
108 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>defaultKeyDownAction (char, modifiers, unicode)
</b></p>
109 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
110 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>The default keydown actions are:
</p>
111 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
112 <p class=
"p6"><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><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>comment
</b></p>
113 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>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><b>valueAction_
</b>(
1.0.rand)
<span class=
"Apple-tab-span"> </span></p>
114 <p class=
"p6"><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><b>valueAction_
</b>(
0)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
115 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>x
<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>valueAction_
</b>(
1)
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
116 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>c
<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>valueAction_
</b>(
0.5)
<span class=
"Apple-tab-span"> </span></p>
117 <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>increment by
<b>step
</b></p>
118 <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>decrement by
<b>step
</b></p>
119 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>unicode
16rF700,
<span class=
"Apple-tab-span"> </span>increment by
<b>step
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>up arrow
</p>
120 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>unicode
16rF703,
<span class=
"Apple-tab-span"> </span>increment by
<b>step
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>right arrow
</p>
121 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>unicode
16rF701,
<span class=
"Apple-tab-span"> </span>decrement by
<b>step
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>down arrow
</p>
122 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>unicode
16rF702,
<span class=
"Apple-tab-span"> </span>decrement by
<b>step
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>left arrow
</p>
123 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
124 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span>defaultGetDrag
</b></p>
125 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
126 <p class=
"p6"><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 SCSlider. Returns the same as
<b>value
</b>.
</p>
127 <p class=
"p7"><br></p>
128 <p class=
"p6"><span class=
"Apple-tab-span"> </span><b>defaultCanReceiveDrag
</b></p>
129 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
130 <p class=
"p6"><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, SCSlider will respond only to drags where the drag contains a
<a href=
"../../Math/Number.html"><span class=
"s5">Number
</span></a>.
</p>
131 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
132 <p class=
"p6"><span class=
"Apple-tab-span"> </span><b>defaultReceiveDrag
</b></p>
133 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b></p>
134 <p class=
"p6"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>The default method called when a drag has been recieved. Performs
<b>valueAction_()
</b> using
<b>currentDrag
</b> as an argument.
</p>
135 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
136 <p class=
"p11"><b>Examples
</b></p>
137 <p class=
"p16"><br></p>
138 <p class=
"p16"><br></p>
139 <p class=
"p17">// the simplest version will give you a very long float
</p>
141 <p class=
"p10">w =
<span class=
"s5">Window
</span>.new.front;
</p>
142 <p class=
"p10">c =
<span class=
"s5">NumberBox
</span>(w,
<span class=
"s5">Rect
</span>(
20,
20,
150,
20));
</p>
143 <p class=
"p10">a =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
20,
60,
150,
20))
</p>
144 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.action_({
</p>
145 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>c.value_(a.value)
</p>
146 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
147 <p class=
"p10">a.action.value;
</p>
149 <p class=
"p16"><br></p>
150 <p class=
"p17"><span class=
"s2">(
</span>// change the bounds to become vertical
</p>
151 <p class=
"p10">w =
<span class=
"s5">Window
</span>.new.front;
</p>
152 <p class=
"p10">c =
<span class=
"s5">NumberBox
</span>(w,
<span class=
"s5">Rect
</span>(
20,
20,
150,
20));
</p>
153 <p class=
"p10">a =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
200,
60,
20,
150))
</p>
154 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.action_({
</p>
155 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>c.value_(a.value)
</p>
156 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
157 <p class=
"p10">a.action.value;
</p>
159 <p class=
"p16"><br></p>
160 <p class=
"p16"><br></p>
161 <p class=
"p17">// use a
<a href=
"../../Control/Spec.html"><span class=
"s10">Spec
</span></a> to round and map the output range for clearer display
</p>
163 <p class=
"p10">w =
<span class=
"s5">Window
</span>.new.front;
</p>
164 <p class=
"p17"><span class=
"s2">b =
</span><span class=
"s5">ControlSpec
</span><span class=
"s2">(-
50,
50,
</span><span class=
"s11">\linear
</span><span class=
"s2">,
0.01);
</span>// min, max, mapping, step
</p>
165 <p class=
"p10">c =
<span class=
"s5">StaticText
</span>(w,
<span class=
"s5">Rect
</span>(
20,
20,
150,
20)).align_(
<span class=
"s11">\center
</span>).background_(
<span class=
"s5">Color
</span>.rand);
</p>
166 <p class=
"p10">a =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
20,
50,
150,
20))
</p>
167 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.focusColor_(
<span class=
"s5">Color
</span>.red(alpha:
0.2))
</p>
168 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.background_(
<span class=
"s5">Color
</span>.rand)
</p>
169 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.value_(
0.5)
</p>
170 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.action_({
</p>
171 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>c.string_(b.map(a.value).asString)
</p>
172 <p class=
"p17"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// round the float so it will fit in the NumberBox
</p>
173 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
174 <p class=
"p10">a.action.value;
</p>
175 <p class=
"p16"><br></p>
177 <p class=
"p16"><br></p>
178 <p class=
"p16"><br></p>
179 <p class=
"p17">// change the stepsize of the slider, selected via a PopUpMenu
</p>
181 <p class=
"p10">w =
<span class=
"s5">Window
</span>.new.front;
</p>
182 <p class=
"p18"><span class=
"s2">a = [
</span>"0"<span class=
"s2">,
</span>"0.0625"<span class=
"s2">,
</span>"0.125"<span class=
"s2">,
</span>"0.25"<span class=
"s2">,
</span>"0.5"<span class=
"s2">,
</span>"1"<span class=
"s2">];
</span></p>
183 <p class=
"p10">b =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
20,
100,
100,
20))
</p>
184 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.action_({
</p>
185 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>c.value_(b.value)
</p>
186 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}).background_(
<span class=
"s5">Color
</span>.rand);
</p>
187 <p class=
"p10">d =
<span class=
"s5">PopUpMenu
</span>(w,
<span class=
"s5">Rect
</span>(
20,
60,
100,
20))
</p>
188 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.items_(a)
</p>
189 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.action_({
</p>
190 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>b.step_((a.at(d.value)).asFloat);
</p>
191 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
192 <p class=
"p10"><span class=
"s5">StaticText
</span>(w,
<span class=
"s5">Rect
</span>(
130,
60,
100,
20)).string_(
<span class=
"s12">"change step"</span>);
<span class=
"Apple-tab-span"> </span></p>
193 <p class=
"p10">c =
<span class=
"s5">NumberBox
</span>(w,
<span class=
"s5">Rect
</span>(
20,
20,
100,
20));
</p>
195 <p class=
"p16"><br></p>
196 <p class=
"p16"><br></p>
197 <p class=
"p17">// use the slider view to accept key actions
</p>
198 <p class=
"p16"><br></p>
199 <p class=
"p17"><span class=
"s2">(
</span>// select the slider, type something and watch the post window
</p>
200 <p class=
"p10">w =
<span class=
"s5">Window
</span>.new;
</p>
201 <p class=
"p10">c =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
0,
0,
100,
30));
</p>
202 <p class=
"p10">c.keyDownAction = {
<span class=
"s5">arg
</span> view,char,modifiers,unicode,keycode;
</p>
203 <p class=
"p10">[char,modifiers,unicode,keycode].postln;
</p>
204 <p class=
"p10">};
</p>
205 <p class=
"p10">w.front;
</p>
207 <p class=
"p16"><br></p>
208 <p class=
"p16"><br></p>
209 <p class=
"p16"><br></p>
210 <p class=
"p17">// adding functionality to a view by the method addAction
</p>
211 <p class=
"p17">// this is useful for adding things to existing frameworks
</p>
212 <p class=
"p17">// that have action functions already.
</p>
213 <p class=
"p16"><br></p>
215 <p class=
"p10">w =
<span class=
"s5">Window
</span>.new(
<span class=
"s12">"A Slider"</span>);
</p>
216 <p class=
"p10">a =
<span class=
"s5">Slider
</span>.new(w,
<span class=
"s5">Rect
</span>(
40,
10,
300,
30));
</p>
217 <p class=
"p10">w.front
</p>
218 <p class=
"p10">);
</p>
219 <p class=
"p16"><br></p>
220 <p class=
"p17">// now incrementally add some action to the slider
</p>
221 <p class=
"p10">a.addAction({
<span class=
"s5">|sl|
</span> sl.value.postln });
</p>
222 <p class=
"p10">a.addAction({
<span class=
"s5">|sl|
</span> w.view.background =
<span class=
"s5">Color
</span>.green(sl.value) });
</p>
223 <p class=
"p10">a.addAction({
<span class=
"s5">|sl|
</span> sl.background =
<span class=
"s5">Color
</span>.red(
1 - sl.value) });
</p>
224 <p class=
"p16"><br></p>
225 <p class=
"p17">// adding and removing an action:
</p>
226 <p class=
"p18"><span class=
"s2">f = {
</span><span class=
"s5">|sl|
</span><span class=
"s2"> </span>"--------*******-------"<span class=
"s2">.postln; };
</span></p>
227 <p class=
"p10">a.addAction(f);
</p>
228 <p class=
"p10">a.removeAction(f);
</p>
229 <p class=
"p16"><br></p>
230 <p class=
"p17">// or remove all, of course
</p>
231 <p class=
"p10">a.action =
<span class=
"s5">nil
</span>;
</p>
232 <p class=
"p16"><br></p>
233 <p class=
"p16"><br></p>
234 <p class=
"p16"><br></p>
235 <p class=
"p10">-----
</p>
236 <p class=
"p16"><br></p>
237 <p class=
"p16"><br></p>
238 <p class=
"p16"><br></p>
239 <p class=
"p16"><br></p>
240 <p class=
"p10">// you can use
<span class=
"s5">Slider
</span> for triggering sounds also:
</p>
241 <p class=
"p16"><br></p>
243 <p class=
"p10">s.waitForBoot({
</p>
244 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"s5">SynthDef
</span>(
<span class=
"s11">\pluck
</span>,{
<span class=
"s5">arg
</span> freq=
55;
</p>
245 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">Out
</span>.ar(
0,
</p>
246 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">Pluck
</span>.ar(
<span class=
"s5">WhiteNoise
</span>.ar(
0.06),
</p>
247 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">EnvGen
</span>.kr(
<span class=
"s5">Env
</span>.perc(
0,
4),
1.0, doneAction:
2),
</p>
248 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>freq.reciprocal,
</p>
249 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>freq.reciprocal,
</p>
250 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>10,
</p>
251 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>coef:
0.1)
</p>
252 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>);
</p>
253 <p class=
"p10"><span class=
"Apple-tab-span"> </span>}).send(s);
</p>
254 <p class=
"p16"><span class=
"Apple-tab-span"> </span></p>
255 <p class=
"p16"><br></p>
256 <p class=
"p10"><span class=
"Apple-tab-span"> </span>w =
<span class=
"s5">Window
</span>.new(
<span class=
"s12">"Hold arrow keys to trigger sound"</span>,
<span class=
"s5">Rect
</span>(
300,
<span class=
"s5">Window
</span>.screenBounds.height-
300,
400,
100)).front;
</p>
257 <p class=
"p10"><span class=
"Apple-tab-span"> </span>a =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
50,
20,
300,
40))
</p>
258 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.value_(
0.5)
</p>
259 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.step_(
0.05)
</p>
260 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.focus
</p>
261 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.action_({
</p>
262 <p class=
"p17"><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// trigger a synth with varying frequencies
</p>
263 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s5">Synth
</span>(
<span class=
"s11">\pluck
</span>, [
<span class=
"s11">\freq
</span>,
55+(
1100*a.value)]);
</p>
264 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>w.view.background_(
<span class=
"s5">Gradient
</span>(
<span class=
"s5">Color
</span>.rand,
<span class=
"s5">Color
</span>.rand));
</p>
265 <p class=
"p10"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>})
</p>
266 <p class=
"p10">});
</p>
267 <p class=
"p16"><br></p>
269 <p class=
"p16"><br></p>
270 <p class=
"p17">// change the background color of WIndow by moving the sliders
</p>
272 <p class=
"p10">w =
<span class=
"s5">Window
</span>(
<span class=
"s12">"RGB fader"</span>,
<span class=
"s5">Rect
</span>(
100,
500,
400,
400))
</p>
273 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.front;
</p>
274 <p class=
"p10">f = { w.view.background_(
<span class=
"s5">Color
</span>.new(r.value, g.value, b.value,
1)) };
</p>
275 <p class=
"p10">r =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
100,
140,
200,
20))
</p>
276 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.value_(
0.5)
</p>
277 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.action_({ f.value });
</p>
278 <p class=
"p10">g =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
100,
170,
200,
20))
</p>
279 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.value_(
0.5)
</p>
280 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.action_({ f.value });
</p>
281 <p class=
"p10">b =
<span class=
"s5">Slider
</span>(w,
<span class=
"s5">Rect
</span>(
100,
200,
200,
20))
</p>
282 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.value_(
0.5)
</p>
283 <p class=
"p10"><span class=
"Apple-tab-span"> </span>.action_({ f.value });
</p>
284 <p class=
"p10">f.value;
</p>
285 <p class=
"p10">);
</p>
286 <p class=
"p16"><br></p>
287 <p class=
"p16"><br></p>
288 <p class=
"p16"><br></p>
289 <p class=
"p16"><br></p>
290 <p class=
"p16"><br></p>