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.54">
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: 9.0px Monaco
; min-height: 12.0px}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #001bec}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 9.0px Monaco
; min-height: 12.0px}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica
}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 12.0px Helvetica
; min-height: 14.0px}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica
}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 57.0px; text-indent: -57.0px; font: 14.0px Helvetica
}
20 p
.p11
{margin: 0.0px 0.0px 0.0px 85.0px; text-indent: -85.0px; font: 12.0px Helvetica
; min-height: 14.0px}
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 0.0px; font: 14.0px Helvetica
; min-height: 17.0px}
23 p
.p14
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #bf0000}
24 p
.p15
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000; min-height: 12.0px}
25 p
.p16
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #000000}
26 p
.p17
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #606060}
27 span
.s1
{font: 18.0px Helvetica
}
28 span
.s2
{color: #002fb1}
29 span
.s3
{color: #000000}
30 span
.s4
{text-decoration: underline
}
31 span
.s5
{text-decoration: underline
; color: #002fb1}
32 span
.s6
{color: #0036f4}
33 span
.s7
{font: 14.0px Helvetica
}
34 span
.s8
{text-decoration: underline
; color: #001bec}
35 span
.s9
{text-decoration: underline
; color: #000000}
36 span
.s10
{color: #0000bf}
37 span
.s11
{color: #007300}
38 span
.s12
{color: #606060}
39 span
.s13
{color: #bf0000}
40 span
.Apple-tab-span
{white-space:pre
}
44 <p class=
"p1"><span class=
"s1"><b>SCUserView
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b></span><b>user-definable view
</b><span class=
"s1"><b><span class=
"Apple-tab-span"> </span></b></span></p>
45 <p class=
"p2"><br></p>
46 <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></p>
47 <p class=
"p3"><br></p>
48 <p class=
"p1">SCUserView is a user-definable View intended mainly for use with Pen and drawHooks. It is also good for making custom buttons or other gui interfaces and displays. Thus anything you can draw with the methods of
<a href=
"SCPen.html"><span class=
"s2">Pen
</span></a>, combined with mouse tracking, can be used to create a vast variety of interfaces and displays. When a view is refreshed, either maunually, or triggered by a refresh of the parent view, drawFunc is evaluated. Using
<b>refreshInRect
</b>constrains the receiver's refresh area to the rectangle passed in a Rect (see
<a href=
"SCView.html"><span class=
"s2">SCView
</span></a>).
</p>
49 <p class=
"p2"><br></p>
50 <p class=
"p4"><span class=
"s3"><b>See also:
</b><a href=
"../GUI-Overview.html"><span class=
"s4">GUI-Overview
</span></a><b>,
</b> <a href=
"SCWindow.html"><span class=
"s5">SCWindow
</span></a>,
<a href=
"SCPen.html"><span class=
"s5">Pen
</span></a>,
<a href=
"../GUI-Tools/Color.html"><span class=
"s5">Color
</span></a>, and
<a href=
"../../Collections/String.html"><span class=
"s5">String
</span></a> <a href=
"SCUserViewSubclassing/SCUserView-Subclassing.html"><span class=
"s4">SCUserView-Subclassing
</span></a></span></p>
51 <p class=
"p2"><br></p>
52 <p class=
"p5"><b>Creation / Class Methods
</b></p>
53 <p class=
"p6"><br></p>
54 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>*new (parent, bounds)
</b></p>
55 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
56 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>parent
</b>- The parent view.
</p>
57 <p class=
"p9"><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>
58 <p class=
"p6"><br></p>
59 <p class=
"p10"><b>Accessing Instance and Class Variables
</b></p>
60 <p class=
"p8"><span class=
"Apple-tab-span"> </span></p>
61 <p class=
"p8"><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>
62 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>drawFunc_(arg1)
</b></p>
63 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>drawFunc
</b></p>
64 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b><span class=
"Apple-tab-span"> </span></p>
65 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Set the function which should be evaluated if the view is refreshed. This happens every time the view or the whole window is refreshed (manually by calling SCView:refresh, SCWindow:refresh or e.g. by selecting the view or resizing the window).
</p>
67 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>arg1
</b>- An instance of
<a href=
"../../Core/Kernel/Function.html"><span class=
"s2">Function
</span></a>. Default value is nil. Refreshing passes the instance of SCUserView itself as the first argument to the function.
</p>
68 <p class=
"p6"><br></p>
69 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>clearOnRefresh
</b></p>
70 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>clearOnRefresh_ (bool)
</b></p>
71 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
72 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Determines whether the drawn content of the view is cleared on refresh.
</p>
73 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>bool
</b>- An instance of
<a href=
"../../Core/Boolean.html"><span class=
"s2">Boolean
</span></a>. Default value is true.
</p>
74 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
75 <p class=
"p9"><b><span class=
"Apple-tab-span"> </span>drawingEnabled
</b></p>
76 <p class=
"p9"><b><span class=
"Apple-tab-span"> </span>drawingEnabled_(bool)
</b></p>
77 <p class=
"p11"><span class=
"Apple-tab-span"> </span></p>
78 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Determines whether to execute the draw function or not
</p>
79 <p class=
"p9"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>bool
</b>- An instance of
<a href=
"../../Core/Boolean.html"><span class=
"s2">Boolean
</span></a>. Default value is true.
</p>
80 <p class=
"p11"><span class=
"Apple-tab-span"> </span></p>
81 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>animate_(bool)
</b></p>
82 <p class=
"p8"><span class=
"Apple-tab-span"> </span></p>
83 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Determines whether the view should refresh itself internally at a constant frame rate or not.
</p>
84 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Use thisProcess.setDeferredTaskInterval(
1/fps) to change this global frame rate. The default is
60fps.
</p>
85 <p class=
"p7"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><b>bool
</b>- An instance of
<a href=
"../../Core/Boolean.html"><span class=
"s2">Boolean
</span></a>. Default value is false.
</p>
86 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
87 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>frame
</b></p>
88 <p class=
"p8"><span class=
"Apple-tab-span"> </span></p>
89 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>An
<a href=
"../../Math/Integer.html"><span class=
"s6">Integer
</span></a> counter that increases by one each time the view is redrawn. Useful for driving animation.
</p>
90 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
91 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>frameRate
</b></p>
92 <p class=
"p8"><span class=
"Apple-tab-span"> </span></p>
93 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>A
<a href=
"../../Math/Float.html"><span class=
"s6">Float
</span></a> that represents the current average frame rate. Useful for benchmarking while animating. If this value drops below
60, it is an indication of that the current drawFunc is heavy for the program to execute.
</p>
94 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
95 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>draw
</b></p>
96 <p class=
"p8"><span class=
"Apple-tab-span"> </span></p>
97 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Evaluates the draw function, passing the instance of SCUserView itself as the first argument to the function
</p>
98 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
99 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>clearDrawing
</b></p>
100 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
101 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>If
<b>clearOnRefresh
</b> is set to false, then you can use this to manually clear the drawing (you must refesh in order for it to show)
</p>
102 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
103 <p class=
"p10"><b>Deprecated
</b></p>
104 <p class=
"p12"><br></p>
105 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>mousePosition
</b></p>
106 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
107 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>Deprecated
</b>. R the relative position of the mouse cklick as a
<a href=
"../../Geometry/Point.html"><span class=
"s2">Point
</span></a>.
</p>
108 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
109 <p class=
"p10"><b>Subclassing and Internal Methods
</b></p>
110 <p class=
"p7"><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. For a Tutorial on how to subclass SCUserView to make your own custom GUI Widgets, see
<a href=
"SCUserViewSubclassing/SCUserView-Subclassing.html"><span class=
"s2">SCUserView-Subclassing
</span></a></p>
111 <p class=
"p6"><br></p>
112 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>init (argParent, argBounds)
</b></p>
113 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
114 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span></b><span class=
"Apple-tab-span"> </span><b>parent
</b>- The parent view.
</p>
115 <p class=
"p9"><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>
116 <p class=
"p11"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
117 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>keyDownFunc
</b></p>
118 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>keyDownFunc_ (action)
</b></p>
119 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
120 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Deprecated. Use
<b>keyDownAction
</b> instead. See
<a href=
"SCView.html"><span class=
"s2">SCView
</span></a>.
</p>
121 <p class=
"p6"><br></p>
122 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>mouseDownFunc
</b></p>
123 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>mouseDownFunc_ (action)
</b></p>
124 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
125 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Deprecated. Use
<b>mouseDownAction
</b> instead. See
<a href=
"SCView.html"><span class=
"s2">SCView
</span></a>.
</p>
126 <p class=
"p6"><br></p>
127 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>mouseMoveFunc
</b></p>
128 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>mouseMoveFunc_ (action)
</b></p>
129 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
130 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Deprecated. Use
<b>mouseMoveAction
</b> instead. See
<a href=
"SCView.html"><span class=
"s2">SCView
</span></a>.
</p>
131 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
132 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>mouseUpFunc
</b></p>
133 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span>mouseUpFunc_ (action)
</b></p>
134 <p class=
"p8"><b><span class=
"Apple-tab-span"> </span></b></p>
135 <p class=
"p7"><b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></b>Deprecated. Use
<b>mouseUpAction
</b> instead. See
<a href=
"SCView.html"><span class=
"s2">SCView
</span></a>.
</p>
136 <p class=
"p8"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
137 <p class=
"p10"><b>Examples
</b></p>
138 <p class=
"p13"><br></p>
139 <p class=
"p1"><span class=
"s8"><a href=
"../GUI-Overview.html">GUI
<span class=
"s9">-
</span><span class=
"s4">Overview
</span></a></span> contains an elobarate example on how to make a gui widget with
<span class=
"s2">SCUserView
</span> using interface level coding.
<span class=
"s2">For
</span> a
<span class=
"s2">Tutorial
</span> on how to write a subclass of
<span class=
"s2">SCUserView
</span> to make your own custom
<span class=
"s2">GUI
</span> <span class=
"s2">Widgets
</span>, see
<a href=
"SCUserViewSubclassing/SCUserView-Subclassing.html"><span class=
"s2">SCUserView
</span><span class=
"s5">-
</span><span class=
"s2">Subclassing
</span></a></p>
140 <p class=
"p12"><br></p>
141 <p class=
"p14">// Basic Usage. Resize the window to refresh the drawing. Or use mouse click.
</p>
142 <p class=
"p15"><br></p>
143 <p class=
"p16">(
<span class=
"Apple-tab-span"> </span></p>
144 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w=
<span class=
"s10">Window
</span>.new;
</p>
145 <p class=
"p16"><span class=
"Apple-tab-span"> </span>v=
<span class=
"s10">UserView
</span>(w, w.view.bounds.insetBy(
50,
50));
</p>
146 <p class=
"p16"><span class=
"Apple-tab-span"> </span>v.background_(
<span class=
"s10">Color
</span>.rand);
</p>
147 <p class=
"p16"><span class=
"Apple-tab-span"> </span>v.drawFunc={
<span class=
"s10">|uview|
</span></p>
148 <p class=
"p15"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
149 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.moveTo(
0@uview.bounds.height.rand);
</p>
150 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.lineTo(uview.bounds.width@uview.bounds.height.rand);
</p>
151 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.stroke;
</p>
152 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>};
</p>
153 <p class=
"p16"><span class=
"Apple-tab-span"> </span>v.mouseDownAction={v.refresh};
</p>
154 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.front;
</p>
155 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
157 <p class=
"p15"><br></p>
158 <p class=
"p15"><br></p>
159 <p class=
"p15"><br></p>
160 <p class=
"p14">// Coordinates are relative to the SCUserView
</p>
161 <p class=
"p14">// Try resizing the Window.
</p>
162 <p class=
"p15"><br></p>
163 <p class=
"p16">(
<span class=
"Apple-tab-span"> </span></p>
164 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> func;
</p>
165 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
166 <p class=
"p16"><span class=
"Apple-tab-span"> </span>func = {
<span class=
"s10">|me|
</span></p>
167 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.use{
</p>
168 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>10.do{
</p>
169 <p class=
"p16"><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=
"s10">Color
</span>.red(rrand(
0.0,
1), rrand(
0.0,
0.5)).set;
</p>
170 <p class=
"p16"><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=
"s10">Pen
</span>.addArc((
400.exprand(
2))@(
100.rand), rrand(
10,
100),
2pi.rand, pi);
</p>
171 <p class=
"p16"><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=
"s10">Pen
</span>.perform([
<span class=
"s11">\stroke
</span>,
<span class=
"s11">\fill
</span>].choose);
</p>
172 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
173 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
174 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
175 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
176 <p class=
"p17"><span class=
"s3"><span class=
"Apple-tab-span"> </span>w =
</span><span class=
"s10">SCWindow
</span><span class=
"s3">.new(
</span>"DrawFunc Examples"<span class=
"s3">).front;
</span></p>
177 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.view.background_(
<span class=
"s10">Color
</span>.white);
</p>
178 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
179 <p class=
"p16"><span class=
"Apple-tab-span"> </span>3.do{
<span class=
"s10">|i|
</span></p>
180 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v =
<span class=
"s10">SCUserView
</span>(w,
<span class=
"s10">Rect
</span>(
20+(i*
120),
100,
100,
100))
</p>
181 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.drawFunc_(func);
</p>
182 <p class=
"p14"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.resize=
3;
</span>// the func coordinates ar valid even though the view move on resize
</p>
183 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.background_(
<span class=
"s10">Color
</span>.rand);
</p>
184 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
185 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
186 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.refresh;
</p>
188 <p class=
"p15"><br></p>
189 <p class=
"p15"><br></p>
190 <p class=
"p14">// Mouse Tracking
</p>
191 <p class=
"p14">// Set the function which should be evaluated if the mouse is at the end of tracking (mouse-up).
</p>
192 <p class=
"p14">// This function will be passed four arguments: theView, x coordinate, y coordinate, and keyboard modifiers.
</p>
193 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
195 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> drawFunc, mouseDownFunc, mouseUpFunc, mouseMoveFunc, sat =
0, startX;
</p>
196 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
197 <p class=
"p16"><span class=
"Apple-tab-span"> </span>drawFunc = {
<span class=
"s10">|me|
</span></p>
198 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.use{
</p>
199 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>10.do{
</p>
200 <p class=
"p16"><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=
"s10">Color
</span>.red(rrand(
0.0,
1), rrand(
0.0,
0.5)).set;
</p>
201 <p class=
"p16"><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=
"s10">Pen
</span>.addArc((
400.exprand(
2))@(
100.rand), rrand(
10,
100),
2pi.rand, pi);
</p>
202 <p class=
"p16"><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=
"s10">Pen
</span>.perform([
<span class=
"s11">\stroke
</span>,
<span class=
"s11">\fill
</span>].choose);
</p>
203 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
204 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
205 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
206 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
207 <p class=
"p16"><span class=
"Apple-tab-span"> </span>mouseDownFunc = {
<span class=
"s10">|me, x, y, mod|
</span></p>
208 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>startX = x;
</p>
209 <p class=
"p17"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>postf(
</span>"begin path: x=% realtive mouse coordinates:%\n"<span class=
"s3">,startX, x@y);
</span></p>
210 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
211 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
212 <p class=
"p16"><span class=
"Apple-tab-span"> </span>mouseUpFunc = {
<span class=
"s10">|me, x, y, mod|
</span></p>
213 <p class=
"p17"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>postf(
</span>"end path: (startX-x)==% mouse coordinates:%\n"<span class=
"s3">,(startX-x), x@y);
</span></p>
214 <p class=
"p15"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
215 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
216 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
217 <p class=
"p16"><span class=
"Apple-tab-span"> </span>mouseMoveFunc = {
<span class=
"s10">|me, x, y, mod|
</span></p>
218 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>sat = ((startX-x)/
100);
</p>
219 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>(x@y).postln;
</p>
220 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>me.refresh;
</p>
221 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
222 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
223 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w =
<span class=
"s10">SCWindow
</span>.new.front;
</p>
224 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.view.background_(
<span class=
"s10">Color
</span>.white);
</p>
225 <p class=
"p16"><span class=
"Apple-tab-span"> </span>3.do{
<span class=
"s10">|i|
</span></p>
226 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v =
<span class=
"s10">SCUserView
</span>(w,
<span class=
"s10">Rect
</span>(
20+(i*
120),
100,
100,
100));
</p>
227 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.background_(
<span class=
"s10">Color
</span>.rand);
</p>
228 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.drawFunc = drawFunc;
</p>
229 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.mouseDownAction = mouseDownFunc;
</p>
230 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.mouseUpAction = mouseUpFunc;
</p>
231 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.mouseMoveAction = mouseMoveFunc;
</p>
232 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
233 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.refresh;
</p>
235 <p class=
"p15"><br></p>
236 <p class=
"p15"><br></p>
237 <p class=
"p14">// Prevent redrawing:
</p>
238 <p class=
"p15"><br></p>
239 <p class=
"p16">(
<span class=
"Apple-tab-span"> </span></p>
240 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> func, views;
</p>
241 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
242 <p class=
"p16"><span class=
"Apple-tab-span"> </span>func = {
<span class=
"s10">|me|
</span></p>
243 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.use{
</p>
244 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>10.do{
</p>
245 <p class=
"p16"><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=
"s10">Color
</span>.red(rrand(
0.0,
1), rrand(
0.0,
0.5)).set;
</p>
246 <p class=
"p16"><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=
"s10">Pen
</span>.addArc((
400.exprand(
2))@(
100.rand), rrand(
10,
100),
2pi.rand, pi);
</p>
247 <p class=
"p16"><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=
"s10">Pen
</span>.perform([
<span class=
"s11">\stroke
</span>,
<span class=
"s11">\fill
</span>].choose);
</p>
248 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
249 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>}
</p>
250 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
251 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
252 <p class=
"p17"><span class=
"s3"><span class=
"Apple-tab-span"> </span>w =
</span><span class=
"s10">SCWindow
</span><span class=
"s3">.new(
</span>"DrawFunc Examples"<span class=
"s3">).front;
</span></p>
253 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.view.background_(
<span class=
"s10">Color
</span>.white);
</p>
254 <p class=
"p16"><span class=
"Apple-tab-span"> </span>views = {
<span class=
"s10">|i|
</span></p>
255 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v =
<span class=
"s10">SCUserView
</span>(w,
<span class=
"s10">Rect
</span>(
20+(i*
120),
100,
100,
100));
</p>
256 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.drawFunc = func;
</p>
257 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.clearOnRefresh_(
<span class=
"s10">false
</span>);
</p>
258 <p class=
"p16"><span class=
"Apple-tab-span"> </span>} !
3;
</p>
259 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.refresh;
</p>
260 <p class=
"p16"><span class=
"Apple-tab-span"> </span>{views.do{
<span class=
"s10">|v|
</span> v.drawFunc =
<span class=
"s10">nil
</span>}}.defer(
0.4);
</p>
262 <p class=
"p15"><br></p>
263 <p class=
"p15"><br></p>
264 <p class=
"p14">// Use the mouse to draw on the view
</p>
265 <p class=
"p15"><br></p>
267 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> w, txt, tmppoints, all;
</p>
268 <p class=
"p16"><span class=
"Apple-tab-span"> </span>tmppoints = [];
</p>
269 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
270 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w =
<span class=
"s10">SCWindow
</span>(
<span class=
"s12">"draw on me"</span>,
<span class=
"s10">Rect
</span>(
128,
64,
340,
360));
</p>
271 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
272 <p class=
"p16"><span class=
"Apple-tab-span"> </span>v =
<span class=
"s10">SCUserView
</span>(w,w.view.bounds)
</p>
273 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.mouseMoveAction_({
<span class=
"s10">|v,x,y|
</span></p>
274 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>[x,y].postln;
</p>
275 <p class=
"p15"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
276 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>tmppoints = tmppoints.add(x@y);
</p>
277 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.refresh;
</p>
278 <p class=
"p16"><span class=
"Apple-tab-span"> </span>})
</p>
279 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.mouseUpAction_({
<span class=
"s10">|v,x,y|
</span></p>
280 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>all = all.add(tmppoints.copy);
</p>
281 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>tmppoints = [];
</p>
282 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.refresh;
</p>
283 <p class=
"p16"><span class=
"Apple-tab-span"> </span>})
</p>
284 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.drawFunc_{
<span class=
"s10">|me|
</span></p>
285 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.use {
<span class=
"Apple-tab-span"> </span></p>
286 <p class=
"p16"><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=
"s10">Color
</span>.white.set;
</p>
287 <p class=
"p16"><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=
"s10">Pen
</span>.fillRect(me.bounds.moveTo(
0,
0));
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
288 <p class=
"p16"><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=
"s10">Pen
</span>.width =
1;
</p>
289 <p class=
"p16"><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=
"s10">Color
</span>.black.set;
</p>
290 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
291 <p class=
"p16"><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=
"s10">Pen
</span>.beginPath;
</p>
292 <p class=
"p15"><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>
293 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>tmppoints.do{
<span class=
"Apple-tab-span"> </span><span class=
"s10">|p, i|
</span></p>
294 <p class=
"p16"><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>if(i ==
0){
</p>
295 <p class=
"p16"><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=
"s10">Pen
</span>.moveTo(p);
</p>
296 <p class=
"p16"><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>
297 <p class=
"p16"><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=
"s10">Pen
</span>.lineTo(p);
</p>
298 <p class=
"p16"><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>
299 <p class=
"p16"><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>
300 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>all.do{
<span class=
"s10">|points|
</span></p>
301 <p class=
"p16"><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>points.do{
<span class=
"s10">|p, i|
</span></p>
302 <p class=
"p16"><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>if(i ==
0){
</p>
303 <p class=
"p16"><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=
"s10">Pen
</span>.moveTo(p);
</p>
304 <p class=
"p16"><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>
305 <p class=
"p16"><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=
"s10">Pen
</span>.lineTo(p);
</p>
306 <p class=
"p16"><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>
307 <p class=
"p16"><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>
308 <p class=
"p16"><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>
309 <p class=
"p16"><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=
"s10">Pen
</span>.stroke;
</p>
310 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>};
</p>
311 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>};
<span class=
"Apple-tab-span"> </span></p>
312 <p class=
"p15"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
313 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.front;
</p>
315 <p class=
"p15"><br></p>
316 <p class=
"p15"><br></p>
317 <p class=
"p14">// Animation
</p>
318 <p class=
"p14">// with mouse interaction
</p>
319 <p class=
"p15"><br></p>
321 <p class=
"p16"><span class=
"s10">var
</span> width =
400, height =
400, mx =
0, my =
0;
</p>
322 <p class=
"p16">w =
<span class=
"s10">Window
</span>(
<span class=
"s12">"animation and mouse interaction"</span>,
<span class=
"s10">Rect
</span>(
100,
200, width, height),
<span class=
"s10">false
</span>);
</p>
323 <p class=
"p16">u =
<span class=
"s10">UserView
</span>(w,
<span class=
"s10">Rect
</span>(
0,
0, width, height));
</p>
324 <p class=
"p16">u.background =
<span class=
"s10">Color
</span>.black;
</p>
325 <p class=
"p16">u.animate =
<span class=
"s10">true
</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=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s13">//animate this view
</span></p>
326 <p class=
"p16">u.drawFunc = {
</p>
327 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillColor =
<span class=
"s10">Color
</span>.green;
</p>
328 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.stringAtPoint(u.frameRate.asString,
<span class=
"s10">Point
</span>(
10,
10));
<span class=
"Apple-tab-span"> </span><span class=
"s13">//get frame rate
</span></p>
329 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.stringAtPoint(u.frame.asString,
<span class=
"s10">Point
</span>(
10,
30));
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s13">//get frame counter
</span></p>
330 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.color =
<span class=
"s10">Color
</span>.white;
</p>
331 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.moveTo(
<span class=
"s10">Point
</span>(my, mx));
</p>
332 <p class=
"p16"><span class=
"Apple-tab-span"> </span>100.do{
<span class=
"s10">|i|
</span></p>
333 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> x = sin(u.frame*
0.04.neg+i)*(
5*i)+mx;
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s13">//use .frame to drive animation
</span></p>
334 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> y = cos(u.frame*
0.05+i)*(
5*i)+my;
</p>
335 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.lineTo(
<span class=
"s10">Point
</span>(y, x));
</p>
336 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.addOval(
<span class=
"s10">Rect
</span>(x, y, i, i));
</p>
337 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
338 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillStroke;
</p>
339 <p class=
"p16">};
</p>
340 <p class=
"p16">u.mouseDownAction = {
<span class=
"s10">|v, x, y|
</span></p>
341 <p class=
"p16"><span class=
"Apple-tab-span"> </span>mx = x;
</p>
342 <p class=
"p16"><span class=
"Apple-tab-span"> </span>my = y;
</p>
343 <p class=
"p16">};
</p>
344 <p class=
"p16">u.mouseMoveAction = u.mouseDownAction;
</p>
345 <p class=
"p16">w.front;
</p>
347 <p class=
"p15"><br></p>
348 <p class=
"p14"><span class=
"s3">u.animate =
</span><span class=
"s10">false
</span><span class=
"s3">;
<span class=
"Apple-tab-span"> </span></span>//animation can be paused and resumed
</p>
349 <p class=
"p16">u.animate =
<span class=
"s10">true
</span>;
</p>
350 <p class=
"p14"><span class=
"s3">w.close;
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>//stops animation
</p>
351 <p class=
"p15"><br></p>
352 <p class=
"p15"><br></p>
353 <p class=
"p15"><br></p>
354 <p class=
"p14">// Simple ball animation
</p>
355 <p class=
"p14">//
</p>
356 <p class=
"p15"><br></p>
358 <p class=
"p16"><span class=
"s10">var
</span> width =
400, height =
400, xspeed =
3, yspeed =
2, x = width*
0.5, y = height*
0.5;
</p>
359 <p class=
"p16">w =
<span class=
"s10">Window
</span>(
<span class=
"s12">"ball"</span>,
<span class=
"s10">Rect
</span>(
100,
200, width, height));
</p>
360 <p class=
"p16">u =
<span class=
"s10">UserView
</span>(w,
<span class=
"s10">Rect
</span>(
0,
0, width, height));
</p>
361 <p class=
"p16">u.background =
<span class=
"s10">Color
</span>.black;
</p>
362 <p class=
"p16">u.animate =
<span class=
"s10">true
</span>;
</p>
363 <p class=
"p16">u.drawFunc = {
</p>
364 <p class=
"p16"><span class=
"Apple-tab-span"> </span>if(x
<0 or:{x
>width}, {xspeed =
0-xspeed});
</p>
365 <p class=
"p16"><span class=
"Apple-tab-span"> </span>if(y
<0 or:{y
>height}, {yspeed =
0-yspeed});
</p>
366 <p class=
"p16"><span class=
"Apple-tab-span"> </span>x = x+xspeed;
</p>
367 <p class=
"p16"><span class=
"Apple-tab-span"> </span>y = y+yspeed;
</p>
368 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillColor =
<span class=
"s10">Color
</span>.white;
</p>
369 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillOval(
<span class=
"s10">Rect
</span>.aboutPoint(
<span class=
"s10">Point
</span>(x, y),
8,
8));
</p>
370 <p class=
"p16">};
</p>
371 <p class=
"p16">w.front;
</p>
373 <p class=
"p15"><br></p>
374 <p class=
"p14"><span class=
"s3">(
<span class=
"Apple-tab-span"> </span></span>//replace the drawFunc above while running
</p>
375 <p class=
"p16">u.drawFunc = {
</p>
376 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillColor =
<span class=
"s10">Color
</span>.red;
</p>
377 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillOval(
<span class=
"s10">Rect
</span>(
200,
200, sin(u.frame*
0.031)*
200, sin(u.frame*
0.044)*
200));
</p>
378 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillOval(
<span class=
"s10">Rect
</span>(
200,
200, sin(u.frame*
0.052)*
200, sin(u.frame*
0.065)*
200));
</p>
379 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillOval(
<span class=
"s10">Rect
</span>(
200,
200, sin(u.frame*
0.073)*
200, sin(u.frame*
0.086)*
200));
</p>
382 <p class=
"p15"><br></p>
383 <p class=
"p14">//close the window to stop
</p>
384 <p class=
"p16">w.close;
</p>
385 <p class=
"p15"><br></p>
386 <p class=
"p15"><br></p>
387 <p class=
"p14">// Clearing on Refresh
</p>
388 <p class=
"p14">//
</p>
389 <p class=
"p14">// Set the behaviour for refreshing the view.
</p>
390 <p class=
"p14">// If this flag is true (the default) the view will be cleared before each refresh call,
</p>
391 <p class=
"p14">// otherwise It will draw in top of it.
</p>
392 <p class=
"p14">// On OSX this functionality is only available for the version
>=
10.4 .
</p>
393 <p class=
"p15"><br></p>
395 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> width =
640, height =
480, w, theta =
0, drawFunc;
</p>
396 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w =
<span class=
"s10">Window
</span>(
<span class=
"s12">"trails"</span>,
<span class=
"s10">Rect
</span>(
128,
64, width, height ),
<span class=
"s10">false
</span> );
</p>
397 <p class=
"p16"><span class=
"Apple-tab-span"> </span>drawFunc = {
<span class=
"s10">arg
</span> view;
</p>
398 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> x =
20 * sin( theta ), y =
42 * cos( theta );
</p>
399 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>theta = theta +
0.01;
</p>
400 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillColor_(
<span class=
"s10">Color
</span>.red(
0.2,
0.1 ));
</p>
401 <p class=
"p14"><span class=
"s3"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span><span class=
"s10">Pen
</span><span class=
"s3">.fillRect(
</span><span class=
"s10">Rect
</span><span class=
"s3">(
0,
0, width, height ));
</span>//draw a semitransparent rect filling the screen
</p>
402 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.strokeColor_(
<span class=
"s10">Color
</span>.white );
</p>
403 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.translate( width *
0.5, height *
0.5 );
</p>
404 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>6.do {
<span class=
"s10">arg
</span> i;
</p>
405 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.rotate( theta * (
1 - (i /
6)) );
</p>
406 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.scale(
0.7 + (i *
0.4),
0.4 + (i *
0.5) );
</p>
407 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.strokeOval(
<span class=
"s10">Rect
</span>.aboutPoint(
<span class=
"s10">Point
</span>( x, y ),
60,
40 ));
</p>
408 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>};
</p>
409 <p class=
"p16"><span class=
"Apple-tab-span"> </span>};
</p>
410 <p class=
"p16"><span class=
"Apple-tab-span"> </span>x =
<span class=
"s10">UserView
</span>( w,
<span class=
"s10">Rect
</span>(
10,
10, width -
20, height -
20 ))
</p>
411 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.canFocus_(
<span class=
"s10">false
</span> )
</p>
412 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.drawFunc_( drawFunc )
</p>
413 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.clearOnRefresh_(
<span class=
"s10">false
</span> );
</p>
414 <p class=
"p15"><br></p>
415 <p class=
"p16"><span class=
"Apple-tab-span"> </span>w.front;
</p>
416 <p class=
"p16"><span class=
"Apple-tab-span"> </span>x.animate =
<span class=
"s10">true
</span></p>
418 <p class=
"p15"><br></p>
419 <p class=
"p15"><br></p>
420 <p class=
"p14">// Use refreshInRect(aRect).
</p>
421 <p class=
"p14">// Constrains the receiver's refresh area to the rectangle passed in aRect.
</p>
422 <p class=
"p14">// you may use Quartz Debug's flash screen updates to see the refresh area of the view
</p>
423 <p class=
"p15"><br></p>
425 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> userView, win, blob =
<span class=
"s10">Rect
</span>(
0,
0,
50,
50), trackblob=
<span class=
"s10">false
</span>, pmouse;
</p>
426 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
427 <p class=
"p17"><span class=
"s3"><span class=
"Apple-tab-span"> </span>a =
</span><span class=
"s10">SCImage
</span><span class=
"s3">.new(
</span>"/Library/Desktop Pictures/Ripples Blue.jpg"<span class=
"s3">);
</span></p>
428 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
429 <p class=
"p16"><span class=
"Apple-tab-span"> </span>win =
<span class=
"s10">SCWindow
</span>.new(
<span class=
"s12">"refreshInRect Test"</span>,
<span class=
"s10">Rect
</span>(
400,
400,
600,
200), scroll:
<span class=
"s10">true
</span>).front;
</p>
430 <p class=
"p16"><span class=
"Apple-tab-span"> </span>win.onClose_({ a.free; });
</p>
431 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
432 <p class=
"p16"><span class=
"Apple-tab-span"> </span>userView =
<span class=
"s10">SCUserView
</span>(win,
<span class=
"s10">Rect
</span>(
10,
10,
2000,
800))
</p>
433 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.backgroundImage_(a,
5)
</p>
434 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.drawFunc_({
<span class=
"s10">|me|
</span></p>
435 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Color
</span>.blue.setFill;
</p>
436 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">Pen
</span>.fillRect(blob);
</p>
437 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>})
</p>
438 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.mouseDownAction_({
<span class=
"s10">|v, x, y, mod|
</span></p>
439 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>pmouse = x@y;
</p>
440 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>trackblob = blob.containsPoint(pmouse);
</p>
441 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>})
</p>
442 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.mouseUpAction_({
<span class=
"s10">|v, x, y, mod|
</span></p>
443 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>trackblob =
<span class=
"s10">false
</span>;
</p>
444 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>})
</p>
445 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>.mouseMoveAction_({
<span class=
"s10">|v, x, y, mod|
</span></p>
446 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s10">var
</span> refresh, mouse, delta;
</p>
447 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>mouse = x@y;
</p>
448 <p class=
"p15"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></p>
449 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>if(trackblob, {
</p>
450 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>refresh = blob.copy;
</p>
451 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>delta = mouse-pmouse;
</p>
452 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>blob = blob.moveBy(delta.x, delta.y);
</p>
453 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>refresh = refresh.union(blob);
</p>
454 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>v.refreshInRect(refresh);
</p>
455 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
456 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>pmouse = mouse;
</p>
457 <p class=
"p16"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>});
</p>
458 <p class=
"p15"><span class=
"Apple-tab-span"> </span></p>
459 <p class=
"p16"><span class=
"Apple-tab-span"> </span>blob = blob.moveBy(userView.bounds.left, userView.bounds.top);
</p>
460 <p class=
"p16"><span class=
"Apple-tab-span"> </span>userView.bounds.postln;
</p>
462 <p class=
"p15"><br></p>
463 <p class=
"p15"><br></p>
464 <p class=
"p15"><br></p>
465 <p class=
"p15"><br></p>