/
Display.js.html
1543 lines (1316 loc) · 58.9 KB
/
Display.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: Display.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: Display.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
var Guacamole = Guacamole || {};
/**
* The Guacamole display. The display does not deal with the Guacamole
* protocol, and instead implements a set of graphical operations which
* embody the set of operations present in the protocol. The order operations
* are executed is guaranteed to be in the same order as their corresponding
* functions are called.
*
* @constructor
*/
Guacamole.Display = function() {
/**
* Reference to this Guacamole.Display.
* @private
*/
var guac_display = this;
var displayWidth = 0;
var displayHeight = 0;
var displayScale = 1;
// Create display
var display = document.createElement("div");
display.style.position = "relative";
display.style.width = displayWidth + "px";
display.style.height = displayHeight + "px";
// Ensure transformations on display originate at 0,0
display.style.transformOrigin =
display.style.webkitTransformOrigin =
display.style.MozTransformOrigin =
display.style.OTransformOrigin =
display.style.msTransformOrigin =
"0 0";
// Create default layer
var default_layer = new Guacamole.Display.VisibleLayer(displayWidth, displayHeight);
// Create cursor layer
var cursor = new Guacamole.Display.VisibleLayer(0, 0);
cursor.setChannelMask(Guacamole.Layer.SRC);
// Add default layer and cursor to display
display.appendChild(default_layer.getElement());
display.appendChild(cursor.getElement());
// Create bounding div
var bounds = document.createElement("div");
bounds.style.position = "relative";
bounds.style.width = (displayWidth*displayScale) + "px";
bounds.style.height = (displayHeight*displayScale) + "px";
// Add display to bounds
bounds.appendChild(display);
/**
* The X coordinate of the hotspot of the mouse cursor. The hotspot is
* the relative location within the image of the mouse cursor at which
* each click occurs.
*
* @type {Number}
*/
this.cursorHotspotX = 0;
/**
* The Y coordinate of the hotspot of the mouse cursor. The hotspot is
* the relative location within the image of the mouse cursor at which
* each click occurs.
*
* @type {Number}
*/
this.cursorHotspotY = 0;
/**
* The current X coordinate of the local mouse cursor. This is not
* necessarily the location of the actual mouse - it refers only to
* the location of the cursor image within the Guacamole display, as
* last set by moveCursor().
*
* @type {Number}
*/
this.cursorX = 0;
/**
* The current X coordinate of the local mouse cursor. This is not
* necessarily the location of the actual mouse - it refers only to
* the location of the cursor image within the Guacamole display, as
* last set by moveCursor().
*
* @type {Number}
*/
this.cursorY = 0;
/**
* Fired when the default layer (and thus the entire Guacamole display)
* is resized.
*
* @event
* @param {Number} width The new width of the Guacamole display.
* @param {Number} height The new height of the Guacamole display.
*/
this.onresize = null;
/**
* Fired whenever the local cursor image is changed. This can be used to
* implement special handling of the client-side cursor, or to override
* the default use of a software cursor layer.
*
* @event
* @param {HTMLCanvasElement} canvas The cursor image.
* @param {Number} x The X-coordinate of the cursor hotspot.
* @param {Number} y The Y-coordinate of the cursor hotspot.
*/
this.oncursor = null;
/**
* The queue of all pending Tasks. Tasks will be run in order, with new
* tasks added at the end of the queue and old tasks removed from the
* front of the queue (FIFO). These tasks will eventually be grouped
* into a Frame.
* @private
* @type {Task[]}
*/
var tasks = [];
/**
* The queue of all frames. Each frame is a pairing of an array of tasks
* and a callback which must be called when the frame is rendered.
* @private
* @type {Frame[]}
*/
var frames = [];
/**
* Flushes all pending frames.
* @private
*/
function __flush_frames() {
var rendered_frames = 0;
// Draw all pending frames, if ready
while (rendered_frames < frames.length) {
var frame = frames[rendered_frames];
if (!frame.isReady())
break;
frame.flush();
rendered_frames++;
}
// Remove rendered frames from array
frames.splice(0, rendered_frames);
}
/**
* An ordered list of tasks which must be executed atomically. Once
* executed, an associated (and optional) callback will be called.
*
* @private
* @constructor
* @param {function} callback The function to call when this frame is
* rendered.
* @param {Task[]} tasks The set of tasks which must be executed to render
* this frame.
*/
function Frame(callback, tasks) {
/**
* Returns whether this frame is ready to be rendered. This function
* returns true if and only if ALL underlying tasks are unblocked.
*
* @returns {Boolean} true if all underlying tasks are unblocked,
* false otherwise.
*/
this.isReady = function() {
// Search for blocked tasks
for (var i=0; i < tasks.length; i++) {
if (tasks[i].blocked)
return false;
}
// If no blocked tasks, the frame is ready
return true;
};
/**
* Renders this frame, calling the associated callback, if any, after
* the frame is complete. This function MUST only be called when no
* blocked tasks exist. Calling this function with blocked tasks
* will result in undefined behavior.
*/
this.flush = function() {
// Draw all pending tasks.
for (var i=0; i < tasks.length; i++)
tasks[i].execute();
// Call callback
if (callback) callback();
};
}
/**
* A container for an task handler. Each operation which must be ordered
* is associated with a Task that goes into a task queue. Tasks in this
* queue are executed in order once their handlers are set, while Tasks
* without handlers block themselves and any following Tasks from running.
*
* @constructor
* @private
* @param {function} taskHandler The function to call when this task
* runs, if any.
* @param {boolean} blocked Whether this task should start blocked.
*/
function Task(taskHandler, blocked) {
var task = this;
/**
* Whether this Task is blocked.
*
* @type {boolean}
*/
this.blocked = blocked;
/**
* Unblocks this Task, allowing it to run.
*/
this.unblock = function() {
if (task.blocked) {
task.blocked = false;
__flush_frames();
}
};
/**
* Calls the handler associated with this task IMMEDIATELY. This
* function does not track whether this task is marked as blocked.
* Enforcing the blocked status of tasks is up to the caller.
*/
this.execute = function() {
if (taskHandler) taskHandler();
};
}
/**
* Schedules a task for future execution. The given handler will execute
* immediately after all previous tasks upon frame flush, unless this
* task is blocked. If any tasks is blocked, the entire frame will not
* render (and no tasks within will execute) until all tasks are unblocked.
*
* @private
* @param {function} handler The function to call when possible, if any.
* @param {boolean} blocked Whether the task should start blocked.
* @returns {Task} The Task created and added to the queue for future
* running.
*/
function scheduleTask(handler, blocked) {
var task = new Task(handler, blocked);
tasks.push(task);
return task;
}
/**
* Returns the element which contains the Guacamole display.
*
* @return {Element} The element containing the Guacamole display.
*/
this.getElement = function() {
return bounds;
};
/**
* Returns the width of this display.
*
* @return {Number} The width of this display;
*/
this.getWidth = function() {
return displayWidth;
};
/**
* Returns the height of this display.
*
* @return {Number} The height of this display;
*/
this.getHeight = function() {
return displayHeight;
};
/**
* Returns the default layer of this display. Each Guacamole display always
* has at least one layer. Other layers can optionally be created within
* this layer, but the default layer cannot be removed and is the absolute
* ancestor of all other layers.
*
* @return {Guacamole.Display.VisibleLayer} The default layer.
*/
this.getDefaultLayer = function() {
return default_layer;
};
/**
* Returns the cursor layer of this display. Each Guacamole display contains
* a layer for the image of the mouse cursor. This layer is a special case
* and exists above all other layers, similar to the hardware mouse cursor.
*
* @return {Guacamole.Display.VisibleLayer} The cursor layer.
*/
this.getCursorLayer = function() {
return cursor;
};
/**
* Creates a new layer. The new layer will be a direct child of the default
* layer, but can be moved to be a child of any other layer. Layers returned
* by this function are visible.
*
* @return {Guacamole.Display.VisibleLayer} The newly-created layer.
*/
this.createLayer = function() {
var layer = new Guacamole.Display.VisibleLayer(displayWidth, displayHeight);
layer.move(default_layer, 0, 0, 0);
return layer;
};
/**
* Creates a new buffer. Buffers are invisible, off-screen surfaces. They
* are implemented in the same manner as layers, but do not provide the
* same nesting semantics.
*
* @return {Guacamole.Layer} The newly-created buffer.
*/
this.createBuffer = function() {
var buffer = new Guacamole.Layer(0, 0);
buffer.autosize = 1;
return buffer;
};
/**
* Flush all pending draw tasks, if possible, as a new frame. If the entire
* frame is not ready, the flush will wait until all required tasks are
* unblocked.
*
* @param {function} callback The function to call when this frame is
* flushed. This may happen immediately, or
* later when blocked tasks become unblocked.
*/
this.flush = function(callback) {
// Add frame, reset tasks
frames.push(new Frame(callback, tasks));
tasks = [];
// Attempt flush
__flush_frames();
};
/**
* Sets the hotspot and image of the mouse cursor displayed within the
* Guacamole display.
*
* @param {Number} hotspotX The X coordinate of the cursor hotspot.
* @param {Number} hotspotY The Y coordinate of the cursor hotspot.
* @param {Guacamole.Layer} layer The source layer containing the data which
* should be used as the mouse cursor image.
* @param {Number} srcx The X coordinate of the upper-left corner of the
* rectangle within the source layer's coordinate
* space to copy data from.
* @param {Number} srcy The Y coordinate of the upper-left corner of the
* rectangle within the source layer's coordinate
* space to copy data from.
* @param {Number} srcw The width of the rectangle within the source layer's
* coordinate space to copy data from.
* @param {Number} srch The height of the rectangle within the source
* layer's coordinate space to copy data from.
*/
this.setCursor = function(hotspotX, hotspotY, layer, srcx, srcy, srcw, srch) {
scheduleTask(function __display_set_cursor() {
// Set hotspot
guac_display.cursorHotspotX = hotspotX;
guac_display.cursorHotspotY = hotspotY;
// Reset cursor size
cursor.resize(srcw, srch);
// Draw cursor to cursor layer
cursor.copy(layer, srcx, srcy, srcw, srch, 0, 0);
guac_display.moveCursor(guac_display.cursorX, guac_display.cursorY);
// Fire cursor change event
if (guac_display.oncursor)
guac_display.oncursor(cursor.toCanvas(), hotspotX, hotspotY);
});
};
/**
* Sets whether the software-rendered cursor is shown. This cursor differs
* from the hardware cursor in that it is built into the Guacamole.Display,
* and relies on its own Guacamole layer to render.
*
* @param {Boolean} [shown=true] Whether to show the software cursor.
*/
this.showCursor = function(shown) {
var element = cursor.getElement();
var parent = element.parentNode;
// Remove from DOM if hidden
if (shown === false) {
if (parent)
parent.removeChild(element);
}
// Otherwise, ensure cursor is child of display
else if (parent !== display)
display.appendChild(element);
};
/**
* Sets the location of the local cursor to the given coordinates. For the
* sake of responsiveness, this function performs its action immediately.
* Cursor motion is not maintained within atomic frames.
*
* @param {Number} x The X coordinate to move the cursor to.
* @param {Number} y The Y coordinate to move the cursor to.
*/
this.moveCursor = function(x, y) {
// Move cursor layer
cursor.translate(x - guac_display.cursorHotspotX,
y - guac_display.cursorHotspotY);
// Update stored position
guac_display.cursorX = x;
guac_display.cursorY = y;
};
/**
* Changes the size of the given Layer to the given width and height.
* Resizing is only attempted if the new size provided is actually different
* from the current size.
*
* @param {Guacamole.Layer} layer The layer to resize.
* @param {Number} width The new width.
* @param {Number} height The new height.
*/
this.resize = function(layer, width, height) {
scheduleTask(function __display_resize() {
layer.resize(width, height);
// Resize display if default layer is resized
if (layer === default_layer) {
// Update (set) display size
displayWidth = width;
displayHeight = height;
display.style.width = displayWidth + "px";
display.style.height = displayHeight + "px";
// Update bounds size
bounds.style.width = (displayWidth*displayScale) + "px";
bounds.style.height = (displayHeight*displayScale) + "px";
// Notify of resize
if (guac_display.onresize)
guac_display.onresize(width, height);
}
});
};
/**
* Draws the specified image at the given coordinates. The image specified
* must already be loaded.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Number} x The destination X coordinate.
* @param {Number} y The destination Y coordinate.
* @param {Image} image The image to draw. Note that this is an Image
* object - not a URL.
*/
this.drawImage = function(layer, x, y, image) {
scheduleTask(function __display_drawImage() {
layer.drawImage(x, y, image);
});
};
/**
* Draws the image contained within the specified Blob at the given
* coordinates. The Blob specified must already be populated with image
* data.
*
* @param {Guacamole.Layer} layer
* The layer to draw upon.
*
* @param {Number} x
* The destination X coordinate.
*
* @param {Number} y
* The destination Y coordinate.
*
* @param {Blob} blob
* The Blob containing the image data to draw.
*/
this.drawBlob = function(layer, x, y, blob) {
// Create URL for blob
var url = URL.createObjectURL(blob);
// Draw and free blob URL when ready
var task = scheduleTask(function __display_drawBlob() {
// Draw the image only if it loaded without errors
if (image.width && image.height)
layer.drawImage(x, y, image);
// Blob URL no longer needed
URL.revokeObjectURL(url);
}, true);
// Load image from URL
var image = new Image();
image.onload = task.unblock;
image.onerror = task.unblock;
image.src = url;
};
/**
* Draws the image at the specified URL at the given coordinates. The image
* will be loaded automatically, and this and any future operations will
* wait for the image to finish loading.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Number} x The destination X coordinate.
* @param {Number} y The destination Y coordinate.
* @param {String} url The URL of the image to draw.
*/
this.draw = function(layer, x, y, url) {
var task = scheduleTask(function __display_draw() {
// Draw the image only if it loaded without errors
if (image.width && image.height)
layer.drawImage(x, y, image);
}, true);
var image = new Image();
image.onload = task.unblock;
image.onerror = task.unblock;
image.src = url;
};
/**
* Plays the video at the specified URL within this layer. The video
* will be loaded automatically, and this and any future operations will
* wait for the video to finish loading. Future operations will not be
* executed until the video finishes playing.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {String} mimetype The mimetype of the video to play.
* @param {Number} duration The duration of the video in milliseconds.
* @param {String} url The URL of the video to play.
*/
this.play = function(layer, mimetype, duration, url) {
// Start loading the video
var video = document.createElement("video");
video.type = mimetype;
video.src = url;
// Start copying frames when playing
video.addEventListener("play", function() {
function render_callback() {
layer.drawImage(0, 0, video);
if (!video.ended)
window.setTimeout(render_callback, 20);
}
render_callback();
}, false);
scheduleTask(video.play);
};
/**
* Transfer a rectangle of image data from one Layer to this Layer using the
* specified transfer function.
*
* @param {Guacamole.Layer} srcLayer The Layer to copy image data from.
* @param {Number} srcx The X coordinate of the upper-left corner of the
* rectangle within the source Layer's coordinate
* space to copy data from.
* @param {Number} srcy The Y coordinate of the upper-left corner of the
* rectangle within the source Layer's coordinate
* space to copy data from.
* @param {Number} srcw The width of the rectangle within the source Layer's
* coordinate space to copy data from.
* @param {Number} srch The height of the rectangle within the source
* Layer's coordinate space to copy data from.
* @param {Guacamole.Layer} dstLayer The layer to draw upon.
* @param {Number} x The destination X coordinate.
* @param {Number} y The destination Y coordinate.
* @param {Function} transferFunction The transfer function to use to
* transfer data from source to
* destination.
*/
this.transfer = function(srcLayer, srcx, srcy, srcw, srch, dstLayer, x, y, transferFunction) {
scheduleTask(function __display_transfer() {
dstLayer.transfer(srcLayer, srcx, srcy, srcw, srch, x, y, transferFunction);
});
};
/**
* Put a rectangle of image data from one Layer to this Layer directly
* without performing any alpha blending. Simply copy the data.
*
* @param {Guacamole.Layer} srcLayer The Layer to copy image data from.
* @param {Number} srcx The X coordinate of the upper-left corner of the
* rectangle within the source Layer's coordinate
* space to copy data from.
* @param {Number} srcy The Y coordinate of the upper-left corner of the
* rectangle within the source Layer's coordinate
* space to copy data from.
* @param {Number} srcw The width of the rectangle within the source Layer's
* coordinate space to copy data from.
* @param {Number} srch The height of the rectangle within the source
* Layer's coordinate space to copy data from.
* @param {Guacamole.Layer} dstLayer The layer to draw upon.
* @param {Number} x The destination X coordinate.
* @param {Number} y The destination Y coordinate.
*/
this.put = function(srcLayer, srcx, srcy, srcw, srch, dstLayer, x, y) {
scheduleTask(function __display_put() {
dstLayer.put(srcLayer, srcx, srcy, srcw, srch, x, y);
});
};
/**
* Copy a rectangle of image data from one Layer to this Layer. This
* operation will copy exactly the image data that will be drawn once all
* operations of the source Layer that were pending at the time this
* function was called are complete. This operation will not alter the
* size of the source Layer even if its autosize property is set to true.
*
* @param {Guacamole.Layer} srcLayer The Layer to copy image data from.
* @param {Number} srcx The X coordinate of the upper-left corner of the
* rectangle within the source Layer's coordinate
* space to copy data from.
* @param {Number} srcy The Y coordinate of the upper-left corner of the
* rectangle within the source Layer's coordinate
* space to copy data from.
* @param {Number} srcw The width of the rectangle within the source Layer's
* coordinate space to copy data from.
* @param {Number} srch The height of the rectangle within the source
* Layer's coordinate space to copy data from.
* @param {Guacamole.Layer} dstLayer The layer to draw upon.
* @param {Number} x The destination X coordinate.
* @param {Number} y The destination Y coordinate.
*/
this.copy = function(srcLayer, srcx, srcy, srcw, srch, dstLayer, x, y) {
scheduleTask(function __display_copy() {
dstLayer.copy(srcLayer, srcx, srcy, srcw, srch, x, y);
});
};
/**
* Starts a new path at the specified point.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Number} x The X coordinate of the point to draw.
* @param {Number} y The Y coordinate of the point to draw.
*/
this.moveTo = function(layer, x, y) {
scheduleTask(function __display_moveTo() {
layer.moveTo(x, y);
});
};
/**
* Add the specified line to the current path.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Number} x The X coordinate of the endpoint of the line to draw.
* @param {Number} y The Y coordinate of the endpoint of the line to draw.
*/
this.lineTo = function(layer, x, y) {
scheduleTask(function __display_lineTo() {
layer.lineTo(x, y);
});
};
/**
* Add the specified arc to the current path.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Number} x The X coordinate of the center of the circle which
* will contain the arc.
* @param {Number} y The Y coordinate of the center of the circle which
* will contain the arc.
* @param {Number} radius The radius of the circle.
* @param {Number} startAngle The starting angle of the arc, in radians.
* @param {Number} endAngle The ending angle of the arc, in radians.
* @param {Boolean} negative Whether the arc should be drawn in order of
* decreasing angle.
*/
this.arc = function(layer, x, y, radius, startAngle, endAngle, negative) {
scheduleTask(function __display_arc() {
layer.arc(x, y, radius, startAngle, endAngle, negative);
});
};
/**
* Starts a new path at the specified point.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Number} cp1x The X coordinate of the first control point.
* @param {Number} cp1y The Y coordinate of the first control point.
* @param {Number} cp2x The X coordinate of the second control point.
* @param {Number} cp2y The Y coordinate of the second control point.
* @param {Number} x The X coordinate of the endpoint of the curve.
* @param {Number} y The Y coordinate of the endpoint of the curve.
*/
this.curveTo = function(layer, cp1x, cp1y, cp2x, cp2y, x, y) {
scheduleTask(function __display_curveTo() {
layer.curveTo(cp1x, cp1y, cp2x, cp2y, x, y);
});
};
/**
* Closes the current path by connecting the end point with the start
* point (if any) with a straight line.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
*/
this.close = function(layer) {
scheduleTask(function __display_close() {
layer.close();
});
};
/**
* Add the specified rectangle to the current path.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Number} x The X coordinate of the upper-left corner of the
* rectangle to draw.
* @param {Number} y The Y coordinate of the upper-left corner of the
* rectangle to draw.
* @param {Number} w The width of the rectangle to draw.
* @param {Number} h The height of the rectangle to draw.
*/
this.rect = function(layer, x, y, w, h) {
scheduleTask(function __display_rect() {
layer.rect(x, y, w, h);
});
};
/**
* Clip all future drawing operations by the current path. The current path
* is implicitly closed. The current path can continue to be reused
* for other operations (such as fillColor()) but a new path will be started
* once a path drawing operation (path() or rect()) is used.
*
* @param {Guacamole.Layer} layer The layer to affect.
*/
this.clip = function(layer) {
scheduleTask(function __display_clip() {
layer.clip();
});
};
/**
* Stroke the current path with the specified color. The current path
* is implicitly closed. The current path can continue to be reused
* for other operations (such as clip()) but a new path will be started
* once a path drawing operation (path() or rect()) is used.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {String} cap The line cap style. Can be "round", "square",
* or "butt".
* @param {String} join The line join style. Can be "round", "bevel",
* or "miter".
* @param {Number} thickness The line thickness in pixels.
* @param {Number} r The red component of the color to fill.
* @param {Number} g The green component of the color to fill.
* @param {Number} b The blue component of the color to fill.
* @param {Number} a The alpha component of the color to fill.
*/
this.strokeColor = function(layer, cap, join, thickness, r, g, b, a) {
scheduleTask(function __display_strokeColor() {
layer.strokeColor(cap, join, thickness, r, g, b, a);
});
};
/**
* Fills the current path with the specified color. The current path
* is implicitly closed. The current path can continue to be reused
* for other operations (such as clip()) but a new path will be started
* once a path drawing operation (path() or rect()) is used.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Number} r The red component of the color to fill.
* @param {Number} g The green component of the color to fill.
* @param {Number} b The blue component of the color to fill.
* @param {Number} a The alpha component of the color to fill.
*/
this.fillColor = function(layer, r, g, b, a) {
scheduleTask(function __display_fillColor() {
layer.fillColor(r, g, b, a);
});
};
/**
* Stroke the current path with the image within the specified layer. The
* image data will be tiled infinitely within the stroke. The current path
* is implicitly closed. The current path can continue to be reused
* for other operations (such as clip()) but a new path will be started
* once a path drawing operation (path() or rect()) is used.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {String} cap The line cap style. Can be "round", "square",
* or "butt".
* @param {String} join The line join style. Can be "round", "bevel",
* or "miter".
* @param {Number} thickness The line thickness in pixels.
* @param {Guacamole.Layer} srcLayer The layer to use as a repeating pattern
* within the stroke.
*/
this.strokeLayer = function(layer, cap, join, thickness, srcLayer) {
scheduleTask(function __display_strokeLayer() {
layer.strokeLayer(cap, join, thickness, srcLayer);
});
};
/**
* Fills the current path with the image within the specified layer. The
* image data will be tiled infinitely within the stroke. The current path
* is implicitly closed. The current path can continue to be reused
* for other operations (such as clip()) but a new path will be started
* once a path drawing operation (path() or rect()) is used.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
* @param {Guacamole.Layer} srcLayer The layer to use as a repeating pattern
* within the fill.
*/
this.fillLayer = function(layer, srcLayer) {
scheduleTask(function __display_fillLayer() {
layer.fillLayer(srcLayer);
});
};
/**
* Push current layer state onto stack.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
*/
this.push = function(layer) {
scheduleTask(function __display_push() {
layer.push();
});
};
/**
* Pop layer state off stack.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
*/
this.pop = function(layer) {
scheduleTask(function __display_pop() {
layer.pop();
});
};
/**
* Reset the layer, clearing the stack, the current path, and any transform
* matrix.
*
* @param {Guacamole.Layer} layer The layer to draw upon.
*/
this.reset = function(layer) {
scheduleTask(function __display_reset() {
layer.reset();
});
};
/**
* Sets the given affine transform (defined with six values from the
* transform's matrix).
*
* @param {Guacamole.Layer} layer The layer to modify.
* @param {Number} a The first value in the affine transform's matrix.
* @param {Number} b The second value in the affine transform's matrix.
* @param {Number} c The third value in the affine transform's matrix.
* @param {Number} d The fourth value in the affine transform's matrix.
* @param {Number} e The fifth value in the affine transform's matrix.
* @param {Number} f The sixth value in the affine transform's matrix.
*/
this.setTransform = function(layer, a, b, c, d, e, f) {
scheduleTask(function __display_setTransform() {
layer.setTransform(a, b, c, d, e, f);
});
};
/**
* Applies the given affine transform (defined with six values from the
* transform's matrix).
*
* @param {Guacamole.Layer} layer The layer to modify.
* @param {Number} a The first value in the affine transform's matrix.
* @param {Number} b The second value in the affine transform's matrix.
* @param {Number} c The third value in the affine transform's matrix.
* @param {Number} d The fourth value in the affine transform's matrix.
* @param {Number} e The fifth value in the affine transform's matrix.
* @param {Number} f The sixth value in the affine transform's matrix.
*/
this.transform = function(layer, a, b, c, d, e, f) {
scheduleTask(function __display_transform() {
layer.transform(a, b, c, d, e, f);
});
};
/**
* Sets the channel mask for future operations on this Layer.
*
* The channel mask is a Guacamole-specific compositing operation identifier
* with a single bit representing each of four channels (in order): source