-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpxscene_pixi.patch
8408 lines (8297 loc) · 260 KB
/
pxscene_pixi.patch
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
diff --git a/src/core/autoDetectRenderer.js b/src/core/autoDetectRenderer.js
index 8960425..d44e19d 100644
--- a/src/core/autoDetectRenderer.js
+++ b/src/core/autoDetectRenderer.js
@@ -1,6 +1,7 @@
import * as utils from './utils';
import CanvasRenderer from './renderers/canvas/CanvasRenderer';
import WebGLRenderer from './renderers/webgl/WebGLRenderer';
+import PXSceneRenderer from './renderers/pxscene/PXSceneRenderer';
/**
* This helper function will automatically detect which renderer you should be using.
@@ -19,10 +20,19 @@ import WebGLRenderer from './renderers/webgl/WebGLRenderer';
* need to call toDataUrl on the webgl context
* @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2
* @param {boolean} [noWebGL=false] - prevents selection of WebGL renderer, even if such is present
- * @return {PIXI.WebGLRenderer|PIXI.CanvasRenderer} Returns WebGL renderer if available, otherwise CanvasRenderer
+ * @return {PIXI.WebGLRenderer|PIXI.CanvasRenderer|PIXI.PXSceneRenderer} Returns the detected renderer
*/
export function autoDetectRenderer(width = 800, height = 600, options, noWebGL)
{
+ if (utils.isV8())
+ {
+ const PXSceneHelper = require('./utils/PXSceneHelper').default; // eslint-disable-line global-require
+
+ PXSceneHelper.getInstance().injectPxScene(options.view);
+
+ return new PXSceneRenderer(width, height, options);
+ }
+
if (!noWebGL && utils.isWebGLSupported())
{
return new WebGLRenderer(width, height, options);
diff --git a/src/core/const.js b/src/core/const.js
index f9235e4..4d29a35 100644
--- a/src/core/const.js
+++ b/src/core/const.js
@@ -50,11 +50,13 @@ export const DEG_TO_RAD = Math.PI / 180;
* @property {number} UNKNOWN - Unknown render type.
* @property {number} WEBGL - WebGL render type.
* @property {number} CANVAS - Canvas render type.
+ * @property {number} PXSCENE - PXScene render type.
*/
export const RENDERER_TYPE = {
UNKNOWN: 0,
WEBGL: 1,
CANVAS: 2,
+ PXSCENE: 3,
};
/**
diff --git a/src/core/display/Container.js b/src/core/display/Container.js
index ed8cd5f..b25ac64 100644
--- a/src/core/display/Container.js
+++ b/src/core/display/Container.js
@@ -317,10 +317,10 @@ export default class Container extends DisplayObject
{
this._boundsID++;
- this.transform.updateTransform(this.parent.transform);
-
- // TODO: check render flags, how to process stuff here
- this.worldAlpha = this.alpha * this.parent.worldAlpha;
+ if (this.parent)
+ {
+ this.transform.updateTransform(this.parent.transform);
+ }
for (let i = 0, j = this.children.length; i < j; ++i)
{
@@ -500,6 +500,122 @@ export default class Container extends DisplayObject
}
/**
+ * To be overridden by the subclass
+ *
+ * @private
+ * @param {PIXI.PXSceneRenderer} renderer - The renderer
+ */
+ _renderPXScene(renderer) // eslint-disable-line no-unused-vars
+ {
+ // this is where content itself gets rendered...
+ if (!this.renderedObject)
+ {
+ const parentRenderedObject = (this.parent && this.parent.renderedObject) || renderer.context;
+
+ this.renderedObject = renderer.view.create({
+ t: 'rect',
+ parent: parentRenderedObject,
+ clip: false,
+ fillColor: 0,
+ });
+ }
+
+ const renderedObject = this.renderedObject;
+
+ renderedObject.cx = this.pivot.x;
+ renderedObject.cy = this.pivot.y;
+ renderedObject.x = (this.x - renderedObject.cx);
+ renderedObject.y = (this.y - renderedObject.cy);
+ renderedObject.w = this.width;
+ renderedObject.h = this.height;
+ renderedObject.r = this.rotation * (180 / Math.PI);
+ renderedObject.sx = this.scale.x;
+ renderedObject.sy = this.scale.y;
+
+ // mask
+ if (this.mask)
+ {
+ const maskRenderedObject = this.mask.renderedObject;
+
+ if (maskRenderedObject)
+ {
+ this.__backupMaskWidth = maskRenderedObject.w;
+ this.__backupMaskHeight = maskRenderedObject.h;
+ this.__backupMaskParent = maskRenderedObject.parent;
+ this.__backupMaskRenderedObject = maskRenderedObject;
+
+ if (this.mask.renderedObjects)
+ {
+ for (let i = 0, j = this.mask.renderedObjects.length; i < j; ++i)
+ {
+ const maskRenderedObject = this.mask.renderedObjects[i];
+
+ this.mask.renderedObject.w = maskRenderedObject.w;
+ this.mask.renderedObject.h = maskRenderedObject.h;
+
+ innerRenderMask.call(this, this.mask.renderedObject);
+ }
+ }
+ else
+ {
+ const maskRenderedObject = this.mask.renderedObject;
+
+ innerRenderMask.call(this, maskRenderedObject);
+ }
+ }
+ }
+ else
+ {
+ const renderedObjectMaskContainer = this.renderedObjectMaskContainer;
+
+ if (renderedObjectMaskContainer)
+ {
+ const maskRenderedObject = this.__backupMaskRenderedObject;
+
+ renderedObject.parent = renderedObjectMaskContainer.parent;
+
+ maskRenderedObject.parent = this.__backupMaskParent;
+
+ renderedObjectMaskContainer.remove();
+
+ maskRenderedObject.w = this.__backupMaskWidth;
+ maskRenderedObject.h = this.__backupMaskHeight;
+ maskRenderedObject.mask = false;
+
+ this.__backupMaskWidth = undefined;
+ this.__backupMaskHeight = undefined;
+ this.__backupMaskParent = undefined;
+ this.__backupMaskRenderedObject = undefined;
+ this.renderedObjectMaskContainer = null;
+ }
+ }
+
+ function innerRenderMask(maskRenderedObject)
+ {
+ if (!this.renderedObjectMaskContainer)
+ {
+ this.renderedObjectMaskContainer = renderer.view.create({
+ t: 'rect',
+ parent: renderedObject.parent,
+ fillColor: 0,
+ });
+ }
+
+ maskRenderedObject.parent = this.renderedObjectMaskContainer;
+ renderedObject.parent = this.renderedObjectMaskContainer;
+
+ const renderedObjectMaskContainer = this.renderedObjectMaskContainer;
+
+ renderedObjectMaskContainer.x = 0;
+ renderedObjectMaskContainer.y = 0;
+ renderedObjectMaskContainer.w = renderer.width;
+ renderedObjectMaskContainer.h = renderer.height;
+
+ maskRenderedObject.mask = true;
+ }
+ }
+
+ /**
* Renders the object using the Canvas renderer
*
* @param {PIXI.CanvasRenderer} renderer - The renderer
@@ -530,6 +646,26 @@ export default class Container extends DisplayObject
}
/**
+ * Renders the object using the PXScene renderer
+ *
+ * @param {PIXI.PXSceneRenderer} renderer - The renderer
+ */
+ renderPXScene(renderer)
+ {
+ // if not visible or the alpha is 0 then no need to render this
+ if (!this.visible || this.worldAlpha <= 0 || !this.renderable)
+ {
+ return;
+ }
+
+ this._renderPXScene(renderer);
+ for (let i = 0, j = this.children.length; i < j; ++i)
+ {
+ this.children[i].renderPXScene(renderer);
+ }
+ }
+
+ /**
* Removes all internal references and listeners as well as removes children from the display list.
* Do not use a Container after calling `destroy`.
*
@@ -546,6 +682,23 @@ export default class Container extends DisplayObject
{
super.destroy();
+ this.destroyAllChildren(options);
+ }
+
+ /**
+ * Removes children from the display list.
+ *
+ * @param {object|boolean} [options] - Options parameter. A boolean will act as if all options
+ * have been set to that value
+ * @param {boolean} [options.children=false] - if set to true, all the children will have their destroy
+ * method called as well. 'options' will be passed on to those calls.
+ * @param {boolean} [options.texture=false] - Only used for child Sprites if options.children is set to true
+ * Should it destroy the texture of the child sprite
+ * @param {boolean} [options.baseTexture=false] - Only used for child Sprites if options.children is set to true
+ * Should it destroy the base texture of the child sprite
+ */
+ destroyAllChildren(options)
+ {
const destroyChildren = typeof options === 'boolean' ? options : options && options.children;
const oldChildren = this.removeChildren(0, this.children.length);
@@ -566,7 +719,14 @@ export default class Container extends DisplayObject
*/
get width()
{
- return this.scale.x * this.getLocalBounds().width;
+ const width = this.getLocalBounds().width;
+
+ if (width !== 0)
+ {
+ return this.scale.x * width;
+ }
+
+ return this._width;
}
set width(value) // eslint-disable-line require-jsdoc
@@ -592,7 +752,14 @@ export default class Container extends DisplayObject
*/
get height()
{
- return this.scale.y * this.getLocalBounds().height;
+ const height = this.getLocalBounds().height;
+
+ if (height !== 0)
+ {
+ return this.scale.y * height;
+ }
+
+ return this._height;
}
set height(value) // eslint-disable-line require-jsdoc
diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js
index 4e6c77d..41f69ac 100644
--- a/src/core/display/DisplayObject.js
+++ b/src/core/display/DisplayObject.js
@@ -5,6 +5,7 @@ import TransformStatic from './TransformStatic';
import Transform from './Transform';
import Bounds from './Bounds';
import { Rectangle } from '../math';
+import { isV8 } from '../utils';
// _tempDisplayObjectParent = new DisplayObject();
/**
@@ -331,6 +332,16 @@ export default class DisplayObject extends EventEmitter
}
/**
+ * Renders the object using the PXScene renderer
+ *
+ * @param {PIXI.PXSceneRenderer} renderer - The renderer
+ */
+ renderPXScene(renderer) // eslint-disable-line no-unused-vars
+ {
+ // OVERWRITE;
+ }
+
+ /**
* Set the parent Container of this DisplayObject
*
* @param {PIXI.Container} container - The Container to add this DisplayObject to
@@ -578,16 +589,23 @@ export default class DisplayObject extends EventEmitter
set mask(value) // eslint-disable-line require-jsdoc
{
- if (this._mask)
+ if (isV8())
{
- this._mask.renderable = true;
+ this._mask = value;
}
+ else
+ {
+ if (this._mask)
+ {
+ this._mask.renderable = true;
+ }
- this._mask = value;
+ this._mask = value;
- if (this._mask)
- {
- this._mask.renderable = false;
+ if (this._mask)
+ {
+ this._mask.renderable = false;
+ }
}
}
diff --git a/src/core/graphics/GraphicsV8.js b/src/core/graphics/GraphicsV8.js
new file mode 100644
index 0000000..b409c29
--- /dev/null
+++ b/src/core/graphics/GraphicsV8.js
@@ -0,0 +1,1040 @@
+import Container from '../display/Container';
+import GraphicsData from './GraphicsData';
+import { Point, Rectangle, RoundedRectangle, Ellipse, Polygon, Circle } from '../math';
+import { SHAPES, BLEND_MODES } from '../const';
+import Bounds from '../display/Bounds';
+import bezierCurveTo from './utils/bezierCurveTo';
+
+const tempPoint = new Point();
+
+/**
+ * The Graphics class contains methods used to draw primitive shapes such as lines, circles and
+ * rectangles to the display, and to color and fill them.
+ *
+ * @class
+ * @extends PIXI.Container
+ * @memberof PIXI
+ */
+export default class GraphicsV8 extends Container
+{
+ /**
+ * Constructor
+ */
+ constructor()
+ {
+ super();
+
+ // Native lines default to fault
+ this.nativeLines = false;
+
+ /**
+ * The alpha value used when filling the Graphics object.
+ *
+ * @member {number}
+ * @default 1
+ */
+ this.fillAlpha = 1;
+
+ /**
+ * The width (thickness) of any lines drawn.
+ *
+ * @member {number}
+ * @default 0
+ */
+ this.lineWidth = 0;
+
+ /**
+ * The color of any lines drawn.
+ *
+ * @member {string}
+ * @default 0
+ */
+ this.lineColor = 0;
+
+ /**
+ * Graphics data
+ *
+ * @member {PIXI.GraphicsData[]}
+ * @private
+ */
+ this.graphicsData = [];
+
+ /**
+ * The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to
+ * reset the tint.
+ *
+ * @member {number}
+ * @default 0xFFFFFF
+ */
+ this.tint = 0xFFFFFF;
+
+ /**
+ * The previous tint applied to the graphic shape. Used to compare to the current tint and
+ * check if theres change.
+ *
+ * @member {number}
+ * @private
+ * @default 0xFFFFFF
+ */
+ this._prevTint = 0xFFFFFF;
+
+ /**
+ * The blend mode to be applied to the graphic shape. Apply a value of
+ * `PIXI.BLEND_MODES.NORMAL` to reset the blend mode.
+ *
+ * @member {number}
+ * @default PIXI.BLEND_MODES.NORMAL;
+ * @see PIXI.BLEND_MODES
+ */
+ this.blendMode = BLEND_MODES.NORMAL;
+
+ /**
+ * Current path
+ *
+ * @member {PIXI.GraphicsData}
+ * @private
+ */
+ this.currentPath = null;
+
+ /**
+ * Whether this shape is being used as a mask.
+ *
+ * @member {boolean}
+ */
+ this.isMask = false;
+
+ /**
+ * The bounds' padding used for bounds calculation.
+ *
+ * @member {number}
+ */
+ this.boundsPadding = 0;
+
+ /**
+ * A cache of the local bounds to prevent recalculation.
+ *
+ * @member {PIXI.Rectangle}
+ * @private
+ */
+ this._localBounds = new Bounds();
+
+ /**
+ * Used to detect if the graphics object has changed. If this is set to true then the graphics
+ * object will be recalculated.
+ *
+ * @member {boolean}
+ * @private
+ */
+ this.dirty = 0;
+
+ /**
+ * Used to detect if we need to do a fast rect check using the id compare method
+ * @type {Number}
+ */
+ this.fastRectDirty = -1;
+
+ /**
+ * Used to detect if we clear the graphics webGL data
+ * @type {Number}
+ */
+ this.clearDirty = 0;
+
+ /**
+ * Used to detect if we we need to recalculate local bounds
+ * @type {Number}
+ */
+ this.boundsDirty = -1;
+
+ /**
+ * Used to detect if the cached sprite object needs to be updated.
+ *
+ * @member {boolean}
+ * @private
+ */
+ this.cachedSpriteDirty = false;
+
+ this._spriteRect = null;
+ this._fastRect = false;
+
+ /**
+ * When cacheAsBitmap is set to true the graphics object will be rendered as if it was a sprite.
+ * This is useful if your graphics element does not change often, as it will speed up the rendering
+ * of the object in exchange for taking up texture memory. It is also useful if you need the graphics
+ * object to be anti-aliased, because it will be rendered using canvas. This is not recommended if
+ * you are constantly redrawing the graphics element.
+ *
+ * @name cacheAsBitmap
+ * @member {boolean}
+ * @memberof PIXI.Graphics#
+ * @default false
+ */
+
+ /**
+ * Plugin that is responsible for rendering this element.
+ * Allows to customize the rendering process without overriding '_renderWebGL' & '_renderCanvas' methods.
+ *
+ * @member {string}
+ * @default 'TextV8'
+ */
+ this.pluginName = 'graphicsV8';
+
+ // Cached objects for clearing.
+ this.renderedObjects = [];
+ }
+
+ /**
+ * Creates a new Graphics object with the same values as this one.
+ * Note that the only the properties of the object are cloned, not its transform (position,scale,etc)
+ *
+ * @return {PIXI.Graphics} A clone of the graphics object
+ */
+ clone()
+ {
+ const clone = new GraphicsV8();
+
+ clone.renderable = this.renderable;
+ clone.fillAlpha = this.fillAlpha;
+ clone.lineWidth = this.lineWidth;
+ clone.lineColor = this.lineColor;
+ clone.tint = this.tint;
+ clone.blendMode = this.blendMode;
+ clone.isMask = this.isMask;
+ clone.boundsPadding = this.boundsPadding;
+ clone.dirty = 0;
+ clone.cachedSpriteDirty = this.cachedSpriteDirty;
+
+ // copy graphics data
+ for (let i = 0; i < this.graphicsData.length; ++i)
+ {
+ clone.graphicsData.push(this.graphicsData[i].clone());
+ }
+
+ clone.currentPath = clone.graphicsData[clone.graphicsData.length - 1];
+
+ clone.updateLocalBounds();
+
+ return clone;
+ }
+
+ /**
+ * Renders the object using the PXScene renderer
+ *
+ * @private
+ * @param {PIXI.PXSceneRenderer} renderer - The renderer
+ */
+ _renderPXScene(renderer)
+ {
+ super._renderPXScene(renderer);
+
+ // this is where content itself gets rendered...
+ if (this.renderedObject)
+ {
+ this.renderedObject.x = this.x;
+ this.renderedObject.y = this.y;
+ this.renderedObject.w = renderer.view.w;
+ this.renderedObject.h = renderer.view.h;
+ this.renderedObject.sx = this.scale.x;
+ this.renderedObject.sy = this.scale.y;
+ }
+ renderer.plugins[this.pluginName].render(this);
+ }
+
+ /**
+ * Specifies the line style used for subsequent calls to GraphicsV8 methods such as the lineTo()
+ * method or the drawCircle() method.
+ *
+ * @param {number} [lineWidth=0] - width of the line to draw, will update the objects stored style
+ * @param {number} [color=0] - color of the line to draw, will update the objects stored style
+ * @param {number} [alpha=1] - alpha of the line to draw, will update the objects stored style
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ lineStyle(lineWidth = 0, color = 0, alpha = 1)
+ {
+ this.lineWidth = lineWidth;
+ this.lineColor = color;
+ this.lineAlpha = alpha;
+
+ if (this.currentPath)
+ {
+ if (this.currentPath.shape.points.length)
+ {
+ // halfway through a line? start a new one!
+ const shape = new Polygon(this.currentPath.shape.points.slice(-2));
+
+ shape.closed = false;
+
+ this.drawShape(shape);
+ }
+ else
+ {
+ // otherwise its empty so lets just set the line properties
+ this.currentPath.lineWidth = this.lineWidth;
+ this.currentPath.lineColor = this.lineColor;
+ this.currentPath.lineAlpha = this.lineAlpha;
+ }
+ }
+
+ return this;
+ }
+
+ /**
+ * Moves the current drawing position to x, y.
+ *
+ * @param {number} x - the X coordinate to move to
+ * @param {number} y - the Y coordinate to move to
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ moveTo(x, y)
+ {
+ const shape = new Polygon([x, y]);
+
+ shape.closed = false;
+ this.drawShape(shape);
+
+ return this;
+ }
+
+ /**
+ * Draws a line using the current line style from the current drawing position to (x, y);
+ * The current drawing position is then set to (x, y).
+ *
+ * @param {number} x - the X coordinate to draw to
+ * @param {number} y - the Y coordinate to draw to
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ lineTo(x, y)
+ {
+ this.currentPath.shape.points.push(x, y);
+ this.dirty++;
+
+ return this;
+ }
+
+ /**
+ * Calculate the points for a quadratic bezier curve and then draws it.
+ * Based on: https://stackoverflow.com/questions/785097/how-do-i-implement-a-bezier-curve-in-c
+ *
+ * @param {number} cpX - Control point x
+ * @param {number} cpY - Control point y
+ * @param {number} toX - Destination point x
+ * @param {number} toY - Destination point y
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ quadraticCurveTo(cpX, cpY, toX, toY)
+ {
+ if (this.currentPath)
+ {
+ if (this.currentPath.shape.points.length === 0)
+ {
+ this.currentPath.shape.points = [0, 0];
+ }
+ }
+ else
+ {
+ this.moveTo(0, 0);
+ }
+
+ const n = 20;
+ const points = this.currentPath.shape.points;
+ let xa = 0;
+ let ya = 0;
+
+ if (points.length === 0)
+ {
+ this.moveTo(0, 0);
+ }
+
+ const fromX = points[points.length - 2];
+ const fromY = points[points.length - 1];
+
+ for (let i = 1; i <= n; ++i)
+ {
+ const j = i / n;
+
+ xa = fromX + ((cpX - fromX) * j);
+ ya = fromY + ((cpY - fromY) * j);
+
+ points.push(xa + (((cpX + ((toX - cpX) * j)) - xa) * j),
+ ya + (((cpY + ((toY - cpY) * j)) - ya) * j));
+ }
+
+ this.dirty++;
+
+ return this;
+ }
+
+ /**
+ * Calculate the points for a bezier curve and then draws it.
+ *
+ * @param {number} cpX - Control point x
+ * @param {number} cpY - Control point y
+ * @param {number} cpX2 - Second Control point x
+ * @param {number} cpY2 - Second Control point y
+ * @param {number} toX - Destination point x
+ * @param {number} toY - Destination point y
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ bezierCurveTo(cpX, cpY, cpX2, cpY2, toX, toY)
+ {
+ if (this.currentPath)
+ {
+ if (this.currentPath.shape.points.length === 0)
+ {
+ this.currentPath.shape.points = [0, 0];
+ }
+ }
+ else
+ {
+ this.moveTo(0, 0);
+ }
+
+ const points = this.currentPath.shape.points;
+
+ const fromX = points[points.length - 2];
+ const fromY = points[points.length - 1];
+
+ points.length -= 2;
+
+ bezierCurveTo(fromX, fromY, cpX, cpY, cpX2, cpY2, toX, toY, points);
+
+ this.dirty++;
+
+ return this;
+ }
+
+ /**
+ * The arcTo() method creates an arc/curve between two tangents on the canvas.
+ *
+ * "borrowed" from https://code.google.com/p/fxcanvas/ - thanks google!
+ *
+ * @param {number} x1 - The x-coordinate of the beginning of the arc
+ * @param {number} y1 - The y-coordinate of the beginning of the arc
+ * @param {number} x2 - The x-coordinate of the end of the arc
+ * @param {number} y2 - The y-coordinate of the end of the arc
+ * @param {number} radius - The radius of the arc
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ arcTo(x1, y1, x2, y2, radius)
+ {
+ if (this.currentPath)
+ {
+ if (this.currentPath.shape.points.length === 0)
+ {
+ this.currentPath.shape.points.push(x1, y1);
+ }
+ }
+ else
+ {
+ this.moveTo(x1, y1);
+ }
+
+ const points = this.currentPath.shape.points;
+ const fromX = points[points.length - 2];
+ const fromY = points[points.length - 1];
+ const a1 = fromY - y1;
+ const b1 = fromX - x1;
+ const a2 = y2 - y1;
+ const b2 = x2 - x1;
+ const mm = Math.abs((a1 * b2) - (b1 * a2));
+
+ if (mm < 1.0e-8 || radius === 0)
+ {
+ if (points[points.length - 2] !== x1 || points[points.length - 1] !== y1)
+ {
+ points.push(x1, y1);
+ }
+ }
+ else
+ {
+ const dd = (a1 * a1) + (b1 * b1);
+ const cc = (a2 * a2) + (b2 * b2);
+ const tt = (a1 * a2) + (b1 * b2);
+ const k1 = radius * Math.sqrt(dd) / mm;
+ const k2 = radius * Math.sqrt(cc) / mm;
+ const j1 = k1 * tt / dd;
+ const j2 = k2 * tt / cc;
+ const cx = (k1 * b2) + (k2 * b1);
+ const cy = (k1 * a2) + (k2 * a1);
+ const px = b1 * (k2 + j1);
+ const py = a1 * (k2 + j1);
+ const qx = b2 * (k1 + j2);
+ const qy = a2 * (k1 + j2);
+ const startAngle = Math.atan2(py - cy, px - cx);
+ const endAngle = Math.atan2(qy - cy, qx - cx);
+
+ this.arc(cx + x1, cy + y1, radius, startAngle, endAngle, b1 * a2 > b2 * a1);
+ }
+
+ this.dirty++;
+
+ return this;
+ }
+
+ /**
+ * The arc method creates an arc/curve (used to create circles, or parts of circles).
+ *
+ * @param {number} cx - The x-coordinate of the center of the circle
+ * @param {number} cy - The y-coordinate of the center of the circle
+ * @param {number} radius - The radius of the circle
+ * @param {number} startAngle - The starting angle, in radians (0 is at the 3 o'clock position
+ * of the arc's circle)
+ * @param {number} endAngle - The ending angle, in radians
+ * @param {boolean} [anticlockwise=false] - Specifies whether the drawing should be
+ * counter-clockwise or clockwise. False is default, and indicates clockwise, while true
+ * indicates counter-clockwise.
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ arc(cx, cy, radius, startAngle, endAngle, anticlockwise = false)
+ {
+ if (startAngle === endAngle)
+ {
+ return this;
+ }
+
+ if (!anticlockwise && endAngle <= startAngle)
+ {
+ endAngle += Math.PI * 2;
+ }
+ else if (anticlockwise && startAngle <= endAngle)
+ {
+ startAngle += Math.PI * 2;
+ }
+
+ const sweep = endAngle - startAngle;
+ const segs = Math.ceil(Math.abs(sweep) / (Math.PI * 2)) * 40;
+
+ if (sweep === 0)
+ {
+ return this;
+ }
+
+ const startX = cx + (Math.cos(startAngle) * radius);
+ const startY = cy + (Math.sin(startAngle) * radius);
+
+ // If the currentPath exists, take its points. Otherwise call `moveTo` to start a path.
+ let points = this.currentPath ? this.currentPath.shape.points : null;
+
+ if (points)
+ {
+ if (points[points.length - 2] !== startX || points[points.length - 1] !== startY)
+ {
+ points.push(startX, startY);
+ }
+ }
+ else
+ {
+ this.moveTo(startX, startY);
+ points = this.currentPath.shape.points;
+ }
+
+ const theta = sweep / (segs * 2);
+ const theta2 = theta * 2;
+
+ const cTheta = Math.cos(theta);
+ const sTheta = Math.sin(theta);
+
+ const segMinus = segs - 1;
+
+ const remainder = (segMinus % 1) / segMinus;
+
+ for (let i = 0; i <= segMinus; ++i)
+ {
+ const real = i + (remainder * i);
+
+ const angle = ((theta) + startAngle + (theta2 * real));
+
+ const c = Math.cos(angle);
+ const s = -Math.sin(angle);
+
+ points.push(
+ (((cTheta * c) + (sTheta * s)) * radius) + cx,
+ (((cTheta * -s) + (sTheta * c)) * radius) + cy
+ );
+ }
+
+ this.dirty++;
+
+ return this;
+ }
+
+ /**
+ * Specifies a simple one-color fill that subsequent calls to other GraphicsV8 methods
+ * (such as lineTo() or drawCircle()) use when drawing.
+ *
+ * @param {number} [color=0] - the color of the fill
+ * @param {number} [alpha=1] - the alpha of the fill
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ beginFill(color = 0, alpha = 1)
+ {
+ this.filling = true;
+ this.fillColor = color;
+ this.fillAlpha = alpha;
+
+ if (this.currentPath)
+ {
+ if (this.currentPath.shape.points.length <= 2)
+ {
+ this.currentPath.fill = this.filling;
+ this.currentPath.fillColor = this.fillColor;
+ this.currentPath.fillAlpha = this.fillAlpha;
+ }
+ }
+
+ return this;
+ }
+
+ /**
+ * Applies a fill to the lines and shapes that were added since the last call to the beginFill() method.
+ *
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ endFill()
+ {
+ this.filling = false;
+ this.fillColor = null;
+ this.fillAlpha = 1;
+
+ return this;
+ }
+
+ /**
+ *
+ * @param {number} x - The X coord of the top-left of the rectangle
+ * @param {number} y - The Y coord of the top-left of the rectangle
+ * @param {number} width - The width of the rectangle
+ * @param {number} height - The height of the rectangle
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ drawRect(x, y, width, height)
+ {
+ this.drawShape(new Rectangle(x, y, width, height));
+
+ return this;
+ }
+
+ /**
+ *
+ * @param {number} x - The X coord of the top-left of the rectangle
+ * @param {number} y - The Y coord of the top-left of the rectangle
+ * @param {number} width - The width of the rectangle
+ * @param {number} height - The height of the rectangle
+ * @param {number} radius - Radius of the rectangle corners
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ drawRoundedRect(x, y, width, height, radius)
+ {
+ this.drawShape(new RoundedRectangle(x, y, width, height, radius));
+
+ return this;
+ }
+
+ /**
+ * Draws a circle.
+ *
+ * @param {number} x - The X coordinate of the center of the circle
+ * @param {number} y - The Y coordinate of the center of the circle
+ * @param {number} radius - The radius of the circle
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ drawCircle(x, y, radius)
+ {
+ this.drawShape(new Circle(x, y, radius));
+
+ return this;
+ }
+
+ /**
+ * Draws an ellipse.
+ *
+ * @param {number} x - The X coordinate of the center of the ellipse
+ * @param {number} y - The Y coordinate of the center of the ellipse
+ * @param {number} width - The half width of the ellipse
+ * @param {number} height - The half height of the ellipse
+ * @return {PIXI.GraphicsV8} This GraphicsV8 object. Good for chaining method calls
+ */
+ drawEllipse(x, y, width, height)
+ {
+ this.drawShape(new Ellipse(x, y, width, height));
+