source: main/trunk/model-sites-dev/von-sparql/js/paper/docs/classes/View.html@ 28914

Last change on this file since 28914 was 28914, checked in by ak19, 10 years ago

Supporting javascript libraries and bespoke code written by Steffan to support the von-sparql user interface

File size: 12.2 KB
Line 
1<!DOCTYPE html>
2<html>
3<head>
4<meta charset="UTF-8">
5<title>View</title>
6<base target="class-frame">
7<link href="../assets/css/docs.css" rel="stylesheet" type="text/css">
8<script src="../assets/js/paper.js"></script>
9<script src="../assets/js/jquery.js"></script>
10<script src="../assets/js/codemirror.js"></script>
11<script src="../assets/js/docs.js"></script>
12</head>
13<body class="reference">
14<div class="reference-class">
15<h1>View</h1>
16
17<p>The View object wraps an HTML element and handles drawing and user
18interaction through mouse and keyboard for it. It offer means to scroll the
19view, find the currently visible bounds in project coordinates, or the
20center, both useful for constructing artwork that should appear centered on
21screen.</p>
22
23</div>
24
25
26
27
28
29 <div class="reference-members"><h2>Properties</h2>
30
31
32<div id="element" class="member">
33<div class="member-link">
34<a name="element" href="#element"><tt><b>element</b></tt></a>
35</div>
36<div class="member-description hidden">
37
38<div class="member-text">
39 <p>The underlying native element.</p>
40
41 <p>Read only.</p>
42
43
44 <ul><b>Type:</b>
45 <li>
46 <tt>HTMLCanvasElement</tt>
47 </li>
48 </ul>
49
50
51</div>
52
53</div>
54</div>
55
56
57<div id="viewsize" class="member">
58<div class="member-link">
59<a name="viewsize" href="#viewsize"><tt><b>viewSize</b></tt></a>
60</div>
61<div class="member-description hidden">
62
63<div class="member-text">
64 <p>The size of the view. Changing the view's size will resize it's
65underlying element.</p>
66
67
68 <ul><b>Type:</b>
69 <li>
70 <a href="../classes/Size.html"><tt>Size</tt></a>
71 </li>
72 </ul>
73
74
75</div>
76
77</div>
78</div>
79
80
81<div id="bounds" class="member">
82<div class="member-link">
83<a name="bounds" href="#bounds"><tt><b>bounds</b></tt></a>
84</div>
85<div class="member-description hidden">
86
87<div class="member-text">
88 <p>The bounds of the currently visible area in project coordinates.</p>
89
90 <p>Read only.</p>
91
92
93 <ul><b>Type:</b>
94 <li>
95 <a href="../classes/Rectangle.html"><tt>Rectangle</tt></a>
96 </li>
97 </ul>
98
99
100</div>
101
102</div>
103</div>
104
105
106<div id="size" class="member">
107<div class="member-link">
108<a name="size" href="#size"><tt><b>size</b></tt></a>
109</div>
110<div class="member-description hidden">
111
112<div class="member-text">
113 <p>The size of the visible area in project coordinates.</p>
114
115 <p>Read only.</p>
116
117
118 <ul><b>Type:</b>
119 <li>
120 <a href="../classes/Size.html"><tt>Size</tt></a>
121 </li>
122 </ul>
123
124
125</div>
126
127</div>
128</div>
129
130
131<div id="center" class="member">
132<div class="member-link">
133<a name="center" href="#center"><tt><b>center</b></tt></a>
134</div>
135<div class="member-description hidden">
136
137<div class="member-text">
138 <p>The center of the visible area in project coordinates.</p>
139
140
141 <ul><b>Type:</b>
142 <li>
143 <a href="../classes/Point.html"><tt>Point</tt></a>
144 </li>
145 </ul>
146
147
148</div>
149
150</div>
151</div>
152
153
154<div id="zoom" class="member">
155<div class="member-link">
156<a name="zoom" href="#zoom"><tt><b>zoom</b></tt></a>
157</div>
158<div class="member-description hidden">
159
160<div class="member-text">
161 <p>The zoom factor by which the project coordinates are magnified.</p>
162
163
164 <ul><b>Type:</b>
165 <li>
166 <tt>Number</tt>
167 </li>
168 </ul>
169
170
171</div>
172
173</div>
174</div>
175
176
177 <h3>Event Handlers</h3>
178
179<div id="onframe" class="member">
180<div class="member-link">
181<a name="onframe" href="#onframe"><tt><b>onFrame</b></tt></a>
182</div>
183<div class="member-description hidden">
184
185<div class="member-text">
186 <p>Handler function to be called on each frame of an animation.</p>
187<p>The function receives an event object which contains information about
188the frame event:</p>
189<p><b><tt>event.count</tt></b>: the number of times the frame event was
190fired.</p>
191<p><b><tt>event.time</tt></b>: the total amount of time passed since the
192first frame event in seconds.</p>
193<p><b><tt>event.delta</tt></b>: the time passed in seconds since the last
194frame event.</p>
195
196
197 <ul><b>Type:</b>
198 <li>
199 <tt>Function</tt>
200 </li>
201 </ul>
202
203 <p>
204<b>Example</b> &mdash; Creating an animation:
205</p>
206
207<div class="paperscript split">
208
209<div class="buttons">
210<div class="button run">Run</div>
211</div>
212
213<script type="text/paperscript" canvas="canvas-0">
214// Create a rectangle shaped path with its top left point at:
215// {x: 50, y: 25} and a size of {width: 50, height: 50}
216var path = new Path.Rectangle(new Point(50, 25), new Size(50, 50));
217path.fillColor = 'black';
218
219function onFrame(event) {
220 // Every frame, rotate the path by 3 degrees:
221 path.rotate(3);
222}
223</script>
224<div class="canvas"><canvas width="516" height="100" id="canvas-0"></canvas></div>
225</div>
226
227
228</div>
229
230</div>
231</div>
232
233
234<div id="onresize" class="member">
235<div class="member-link">
236<a name="onresize" href="#onresize"><tt><b>onResize</b></tt></a>
237</div>
238<div class="member-description hidden">
239
240<div class="member-text">
241 <p>Handler function that is called whenever a view is resized.</p>
242
243
244 <ul><b>Type:</b>
245 <li>
246 <tt>Function</tt>
247 </li>
248 </ul>
249
250 <p>
251<b>Example</b> &mdash; Repositioning items when a view is resized:
252</p>
253
254
255<pre class="code">// Create a circle shaped path in the center of the view:
256var path = new Path.Circle(view.bounds.center, 30);
257path.fillColor = 'red';
258
259function onResize(event) {
260 // Whenever the view is resized, move the path to its center:
261 path.position = view.center;
262}</pre>
263
264</div>
265
266</div>
267</div>
268
269 </div>
270
271
272
273<!-- ============================== methods ================================ -->
274 <div class="reference-members"><h2>Methods</h2>
275
276
277<div id="draw" class="member">
278<div class="member-link">
279<a name="draw" href="#draw"><tt><b>draw</b>()</tt></a>
280</div>
281<div class="member-description hidden">
282<div class="member-text">
283 <p>Draws the view.</p>
284
285
286
287
288</div>
289</div>
290</div>
291
292
293<div id="remove" class="member">
294<div class="member-link">
295<a name="remove" href="#remove"><tt><b>remove</b>()</tt></a>
296</div>
297<div class="member-description hidden">
298<div class="member-text">
299 <p>Removes this view from the project and frees the associated element.</p>
300
301
302
303
304</div>
305</div>
306</div>
307
308
309<div id="isvisible" class="member">
310<div class="member-link">
311<a name="isvisible" href="#isvisible"><tt><b>isVisible</b>()</tt></a>
312</div>
313<div class="member-description hidden">
314<div class="member-text">
315 <p>Checks whether the view is currently visible within the current browser
316viewport.</p>
317
318
319 <ul><b>Returns:</b>
320
321 <li>
322<tt><tt>Boolean</tt></tt>&nbsp;&mdash;&nbsp;whether the view is visible.
323</li>
324
325 </ul>
326
327
328
329</div>
330</div>
331</div>
332
333
334<div id="scrollby-point" class="member">
335<div class="member-link">
336<a name="scrollby-point" href="#scrollby-point"><tt><b>scrollBy</b>(point)</tt></a>
337</div>
338<div class="member-description hidden">
339<div class="member-text">
340 <p>Scrolls the view by the given vector.</p>
341
342<ul><b>Parameters:</b>
343
344<li>
345<tt>point:</tt>
346<a href="../classes/Point.html"><tt>Point</tt></a>
347
348
349</li>
350
351</ul>
352
353
354
355
356</div>
357</div>
358</div>
359
360
361<div id="draw" class="member">
362<div class="member-link">
363<a name="draw" href="#draw"><tt><b>draw</b>()</tt></a>
364</div>
365<div class="member-description hidden">
366<div class="member-text">
367 <p>Draws the view.</p>
368
369
370
371
372</div>
373</div>
374</div>
375
376
377<h3>Event Handling</h3>
378
379<div id="attach-type-function" class="member">
380<div class="member-link">
381<a name="attach-type-function" href="#attach-type-function"><tt><b>attach</b>(type, function)</tt></a>
382</div>
383<div class="member-description hidden">
384<div class="member-text">
385 <p>Attach an event handler to the view.</p>
386
387<ul><b>Parameters:</b>
388
389<li>
390<tt>type:</tt>
391<tt>String('frame'|'resize')</tt>
392&mdash;&nbsp;the event type
393
394</li>
395
396<li>
397<tt>function:</tt>
398<tt>Function</tt>
399&mdash;&nbsp;The function to be called when the event
400occurs
401
402</li>
403
404</ul>
405
406
407
408 <p>
409<b>Example</b> &mdash; Create a rectangle shaped path with its top left point at: {x: 50, y: 25} and a size of {width: 50, height: 50}
410</p>
411
412<div class="paperscript split">
413
414<div class="buttons">
415<div class="button run">Run</div>
416</div>
417
418<script type="text/paperscript" canvas="canvas-1">
419var path = new Path.Rectangle(new Point(50, 25), new Size(50, 50));
420path.fillColor = 'black';
421
422var frameHandler = function(event) {
423 // Every frame, rotate the path by 3 degrees:
424 path.rotate(3);
425};
426
427view.on('frame', frameHandler);
428</script>
429<div class="canvas"><canvas width="516" height="100" id="canvas-1"></canvas></div>
430</div>
431
432
433</div>
434</div>
435</div>
436
437
438<div id="attach-param" class="member">
439<div class="member-link">
440<a name="attach-param" href="#attach-param"><tt><b>attach</b>(param)</tt></a>
441</div>
442<div class="member-description hidden">
443<div class="member-text">
444 <p>Attach one or more event handlers to the view.</p>
445
446<ul><b>Parameters:</b>
447
448<li>
449<tt>param:</tt>
450<tt>Object</tt>
451&mdash;&nbsp;an object literal containing one or more of the
452following properties: <tt>frame, resize</tt>.
453// Create a rectangle shaped path with its top left point at:
454// {x: 50, y: 25} and a size of {width: 50, height: 50}
455var path = new Path.Rectangle(new Point(50, 25), new Size(50, 50));
456path.fillColor = 'black';
457
458var frameHandler = function(event) {
459 // Every frame, rotate the path by 3 degrees:
460 path.rotate(3);
461};
462
463view.on({
464 frame: frameHandler
465});
466
467</li>
468
469</ul>
470
471
472
473
474</div>
475</div>
476</div>
477
478
479<div id="detach-type-function" class="member">
480<div class="member-link">
481<a name="detach-type-function" href="#detach-type-function"><tt><b>detach</b>(type, function)</tt></a>
482</div>
483<div class="member-description hidden">
484<div class="member-text">
485 <p>Detach an event handler from the view.</p>
486
487<ul><b>Parameters:</b>
488
489<li>
490<tt>type:</tt>
491<tt>String('frame'|'resize')</tt>
492&mdash;&nbsp;the event type
493
494</li>
495
496<li>
497<tt>function:</tt>
498<tt>Function</tt>
499&mdash;&nbsp;The function to be detached
500
501</li>
502
503</ul>
504
505
506
507 <p>
508<b>Example</b> &mdash; Create a rectangle shaped path with its top left point at: {x: 50, y: 25} and a size of {width: 50, height: 50}
509</p>
510
511<div class="paperscript split">
512
513<div class="buttons">
514<div class="button run">Run</div>
515</div>
516
517<script type="text/paperscript" canvas="canvas-2">
518var path = new Path.Rectangle(new Point(50, 25), new Size(50, 50));
519path.fillColor = 'black';
520
521var frameHandler = function(event) {
522 // Every frame, rotate the path by 3 degrees:
523 path.rotate(3);
524};
525
526view.on({
527 frame: frameHandler
528});
529
530// When the user presses the mouse,
531// detach the frame handler from the view:
532function onMouseDown(event) {
533 view.detach('frame');
534}
535</script>
536<div class="canvas"><canvas width="516" height="100" id="canvas-2"></canvas></div>
537</div>
538
539
540</div>
541</div>
542</div>
543
544
545<div id="detach-param" class="member">
546<div class="member-link">
547<a name="detach-param" href="#detach-param"><tt><b>detach</b>(param)</tt></a>
548</div>
549<div class="member-description hidden">
550<div class="member-text">
551 <p>Detach one or more event handlers from the view.</p>
552
553<ul><b>Parameters:</b>
554
555<li>
556<tt>param:</tt>
557<tt>Object</tt>
558&mdash;&nbsp;an object literal containing one or more of the
559following properties: <tt>frame, resize</tt>
560
561</li>
562
563</ul>
564
565
566
567
568</div>
569</div>
570</div>
571
572
573<div id="fire-type-event" class="member">
574<div class="member-link">
575<a name="fire-type-event" href="#fire-type-event"><tt><b>fire</b>(type, event)</tt></a>
576</div>
577<div class="member-description hidden">
578<div class="member-text">
579 <p>Fire an event on the view.</p>
580
581<ul><b>Parameters:</b>
582
583<li>
584<tt>type:</tt>
585<tt>String('frame'|'resize')</tt>
586&mdash;&nbsp;the event type
587
588</li>
589
590<li>
591<tt>event:</tt>
592<tt>Object</tt>
593&mdash;&nbsp;an object literal containing properties describing
594the event.
595
596</li>
597
598</ul>
599
600
601
602
603</div>
604</div>
605</div>
606
607
608<div id="responds-type" class="member">
609<div class="member-link">
610<a name="responds-type" href="#responds-type"><tt><b>responds</b>(type)</tt></a>
611</div>
612<div class="member-description hidden">
613<div class="member-text">
614 <p>Check if the view has one or more event handlers of the specified type.</p>
615
616<ul><b>Parameters:</b>
617
618<li>
619<tt>type:</tt>
620<tt>String('frame'|'resize')</tt>
621&mdash;&nbsp;the event type
622
623</li>
624
625</ul>
626
627
628 <ul><b>Returns:</b>
629
630 <li>
631<tt><tt>Boolean</tt></tt>&nbsp;&mdash;&nbsp;<tt>true</tt> if the view has one or more event handlers of
632the specified type, <tt>false</tt> otherwise
633</li>
634
635 </ul>
636
637
638
639</div>
640</div>
641</div>
642
643 </div>
644
645
646
647
648<!-- =========================== copyright notice ========================= -->
649<p class="footer">Copyright &#169; 2011 <a href="http://www.lehni.org" target="_blank">J&uuml;rg Lehni</a> &amp; <a href="http://www.jonathanpuckey.com" target="_blank">Jonathan Puckey</a>. All Rights Reserved.</p>
650<div class="content-end"></div>
651
652</body>
Note: See TracBrowser for help on using the repository browser.