FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/core/src/processing/javafx/PGraphicsFX2D.java at master · dimr/processing · GitHub
dimr
processing
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
core
/
src
/
processing
/
javafx
/
PGraphicsFX2D.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
2306 lines (1690 loc) · 58.6 KB
Breadcrumbs
processing
/
core
/
src
/
processing
/
javafx
/
PGraphicsFX2D.java
Copy path
File metadata and controls
2306 lines (1690 loc) · 58.6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2015 The Processing Foundation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, version 2.1.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
package
processing
.
javafx
;
import
com
.
sun
.
javafx
.
geom
.
Path2D
;
import
com
.
sun
.
javafx
.
geom
.
PathIterator
;
import
com
.
sun
.
javafx
.
geom
.
Shape
;
import
java
.
nio
.
IntBuffer
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
LinkedHashMap
;
import
java
.
util
.
Map
;
import
javafx
.
scene
.
SnapshotParameters
;
import
javafx
.
scene
.
canvas
.
GraphicsContext
;
import
javafx
.
scene
.
effect
.
BlendMode
;
import
javafx
.
scene
.
image
.
PixelFormat
;
import
javafx
.
scene
.
image
.
PixelReader
;
import
javafx
.
scene
.
image
.
PixelWriter
;
import
javafx
.
scene
.
image
.
WritableImage
;
import
javafx
.
scene
.
image
.
WritablePixelFormat
;
import
javafx
.
scene
.
paint
.
Color
;
import
javafx
.
scene
.
shape
.
ArcType
;
import
javafx
.
scene
.
shape
.
StrokeLineCap
;
import
javafx
.
scene
.
shape
.
StrokeLineJoin
;
import
javafx
.
scene
.
text
.
Font
;
import
javafx
.
scene
.
text
.
Text
;
import
javafx
.
scene
.
transform
.
Affine
;
import
javafx
.
scene
.
transform
.
Transform
;
import
processing
.
core
.*;
public
class
PGraphicsFX2D
extends
PGraphics
{
GraphicsContext
context
;
static
final
WritablePixelFormat
<
IntBuffer
>
argbFormat
=
PixelFormat
.
getIntArgbInstance
();
WritableImage
snapshotImage
;
Path2D
workPath
=
new
Path2D
();
Path2D
auxPath
=
new
Path2D
();
boolean
openContour
;
boolean
adjustedForThinLines
;
/// break the shape at the next vertex (next vertex() call is a moveto())
boolean
breakShape
;
private
float
pathCoordsBuffer
[] =
new
float
[
6
];
/// coordinates for internal curve calculation
float
[]
curveCoordX
;
float
[]
curveCoordY
;
float
[]
curveDrawX
;
float
[]
curveDrawY
;
int
transformCount
;
Affine
transformStack
[] =
new
Affine
[
MATRIX_STACK_DEPTH
];
// Line2D.Float line = new Line2D.Float();
// Ellipse2D.Float ellipse = new Ellipse2D.Float();
// Rectangle2D.Float rect = new Rectangle2D.Float();
// Arc2D.Float arc = new Arc2D.Float();
//
// protected Color tintColorObject;
//
// protected Color fillColorObject;
// public boolean fillGradient;
// public Paint fillGradientObject;
//
// protected Color strokeColorObject;
// public boolean strokeGradient;
// public Paint strokeGradientObject;
//////////////////////////////////////////////////////////////
// INTERNAL
public
PGraphicsFX2D
() { }
//public void setParent(PApplet parent)
//public void setPrimary(boolean primary)
//public void setPath(String path)
//public void setSize(int width, int height)
//public void dispose()
@
Override
public
PSurface
createSurface
() {
return
surface
=
new
PSurfaceFX
(
this
);
}
/** Returns the javafx.scene.canvas.GraphicsContext used by this renderer. */
@
Override
public
Object
getNative
() {
return
context
;
}
//////////////////////////////////////////////////////////////
// FRAME
// @Override
// public boolean canDraw() {
// return true;
// }
@
Override
public
void
beginDraw
() {
checkSettings
();
resetMatrix
();
// reset model matrix
vertexCount
=
0
;
}
@
Override
public
void
endDraw
() {
flush
();
if
(!
primaryGraphics
) {
// TODO this is probably overkill for most tasks...
loadPixels
();
}
}
//////////////////////////////////////////////////////////////
// SETTINGS
//protected void checkSettings()
//protected void defaultSettings()
//protected void reapplySettings()
//////////////////////////////////////////////////////////////
// HINT
//public void hint(int which)
//////////////////////////////////////////////////////////////
// SHAPE CREATION
//protected PShape createShapeFamily(int type)
//protected PShape createShapePrimitive(int kind, float... p)
//////////////////////////////////////////////////////////////
// SHAPE
@
Override
public
void
beginShape
(
int
kind
) {
shape
=
kind
;
vertexCount
=
0
;
curveVertexCount
=
0
;
workPath
.
reset
();
auxPath
.
reset
();
flushPixels
();
if
(
drawingThinLines
()) {
adjustedForThinLines
=
true
;
translate
(
0.5f
,
0.5f
);
}
}
//public boolean edge(boolean e)
//public void normal(float nx, float ny, float nz) {
//public void textureMode(int mode)
@
Override
public
void
texture
(
PImage
image
) {
showMethodWarning
(
"texture"
);
}
@
Override
public
void
vertex
(
float
x
,
float
y
) {
if
(
vertexCount
==
vertices
.
length
) {
float
temp
[][] =
new
float
[
vertexCount
<<
1
][
VERTEX_FIELD_COUNT
];
System
.
arraycopy
(
vertices
,
0
,
temp
,
0
,
vertexCount
);
vertices
=
temp
;
//message(CHATTER, "allocating more vertices " + vertices.length);
}
// not everyone needs this, but just easier to store rather
// than adding another moving part to the code...
vertices
[
vertexCount
][
X
] =
x
;
vertices
[
vertexCount
][
Y
] =
y
;
vertexCount
++;
switch
(
shape
) {
case
POINTS
:
point
(
x
,
y
);
break
;
case
LINES
:
if
((
vertexCount
%
2
) ==
0
) {
line
(
vertices
[
vertexCount
-
2
][
X
],
vertices
[
vertexCount
-
2
][
Y
],
x
,
y
);
}
break
;
case
TRIANGLES
:
if
((
vertexCount
%
3
) ==
0
) {
triangle
(
vertices
[
vertexCount
-
3
][
X
],
vertices
[
vertexCount
-
3
][
Y
],
vertices
[
vertexCount
-
2
][
X
],
vertices
[
vertexCount
-
2
][
Y
],
x
,
y
);
}
break
;
case
TRIANGLE_STRIP
:
if
(
vertexCount
>=
3
) {
triangle
(
vertices
[
vertexCount
-
2
][
X
],
vertices
[
vertexCount
-
2
][
Y
],
vertices
[
vertexCount
-
1
][
X
],
vertices
[
vertexCount
-
1
][
Y
],
vertices
[
vertexCount
-
3
][
X
],
vertices
[
vertexCount
-
3
][
Y
]);
}
break
;
case
TRIANGLE_FAN
:
if
(
vertexCount
>=
3
) {
// This is an unfortunate implementation because the stroke for an
// adjacent triangle will be repeated. However, if the stroke is not
// redrawn, it will replace the adjacent line (when it lines up
// perfectly) or show a faint line (when off by a small amount).
// The alternative would be to wait, then draw the shape as a
// polygon fill, followed by a series of vertices. But that's a
// poor method when used with PDF, DXF, or other recording objects,
// since discrete triangles would likely be preferred.
triangle
(
vertices
[
0
][
X
],
vertices
[
0
][
Y
],
vertices
[
vertexCount
-
2
][
X
],
vertices
[
vertexCount
-
2
][
Y
],
x
,
y
);
}
break
;
case
QUAD
:
case
QUADS
:
if
((
vertexCount
%
4
) ==
0
) {
quad
(
vertices
[
vertexCount
-
4
][
X
],
vertices
[
vertexCount
-
4
][
Y
],
vertices
[
vertexCount
-
3
][
X
],
vertices
[
vertexCount
-
3
][
Y
],
vertices
[
vertexCount
-
2
][
X
],
vertices
[
vertexCount
-
2
][
Y
],
x
,
y
);
}
break
;
case
QUAD_STRIP
:
// 0---2---4
// | | |
// 1---3---5
if
((
vertexCount
>=
4
) && ((
vertexCount
%
2
) ==
0
)) {
quad
(
vertices
[
vertexCount
-
4
][
X
],
vertices
[
vertexCount
-
4
][
Y
],
vertices
[
vertexCount
-
2
][
X
],
vertices
[
vertexCount
-
2
][
Y
],
x
,
y
,
vertices
[
vertexCount
-
3
][
X
],
vertices
[
vertexCount
-
3
][
Y
]);
}
break
;
case
POLYGON
:
if
(
workPath
.
getNumCommands
() ==
0
||
breakShape
) {
workPath
.
moveTo
(
x
,
y
);
breakShape
=
false
;
}
else
{
workPath
.
lineTo
(
x
,
y
);
}
break
;
}
}
@
Override
public
void
vertex
(
float
x
,
float
y
,
float
z
) {
showDepthWarningXYZ
(
"vertex"
);
}
@
Override
public
void
vertex
(
float
[]
v
) {
vertex
(
v
[
X
],
v
[
Y
]);
}
@
Override
public
void
vertex
(
float
x
,
float
y
,
float
u
,
float
v
) {
showVariationWarning
(
"vertex(x, y, u, v)"
);
}
@
Override
public
void
vertex
(
float
x
,
float
y
,
float
z
,
float
u
,
float
v
) {
showDepthWarningXYZ
(
"vertex"
);
}
@
Override
public
void
beginContour
() {
if
(
openContour
) {
PGraphics
.
showWarning
(
"Already called beginContour()"
);
return
;
}
// draw contours to auxiliary path so main path can be closed later
Path2D
contourPath
=
auxPath
;
auxPath
=
workPath
;
workPath
=
contourPath
;
if
(
contourPath
.
getNumCommands
() >
0
) {
// first contour does not break
breakShape
=
true
;
}
openContour
=
true
;
}
@
Override
public
void
endContour
() {
if
(!
openContour
) {
PGraphics
.
showWarning
(
"Need to call beginContour() first"
);
return
;
}
if
(
workPath
.
getNumCommands
() >
0
)
workPath
.
closePath
();
Path2D
temp
=
workPath
;
workPath
=
auxPath
;
auxPath
=
temp
;
openContour
=
false
;
}
@
Override
public
void
endShape
(
int
mode
) {
if
(
openContour
) {
// correct automagically, notify user
endContour
();
PGraphics
.
showWarning
(
"Missing endContour() before endShape()"
);
}
if
(
workPath
.
getNumCommands
() >
0
) {
if
(
shape
==
POLYGON
) {
if
(
mode
==
CLOSE
) {
workPath
.
closePath
();
}
if
(
auxPath
.
getNumCommands
() >
0
) {
workPath
.
append
(
auxPath
,
false
);
}
drawShape
(
workPath
);
}
}
shape
=
0
;
if
(
adjustedForThinLines
) {
adjustedForThinLines
=
false
;
translate
(-
0.5f
, -
0.5f
);
}
loaded
=
false
;
}
private
void
drawShape
(
Shape
s
) {
context
.
beginPath
();
PathIterator
pi
=
s
.
getPathIterator
(
null
);
while
(!
pi
.
isDone
()) {
int
pitype
=
pi
.
currentSegment
(
pathCoordsBuffer
);
switch
(
pitype
) {
case
PathIterator
.
SEG_MOVETO
:
context
.
moveTo
(
pathCoordsBuffer
[
0
],
pathCoordsBuffer
[
1
]);
break
;
case
PathIterator
.
SEG_LINETO
:
context
.
lineTo
(
pathCoordsBuffer
[
0
],
pathCoordsBuffer
[
1
]);
break
;
case
PathIterator
.
SEG_QUADTO
:
context
.
quadraticCurveTo
(
pathCoordsBuffer
[
0
],
pathCoordsBuffer
[
1
],
pathCoordsBuffer
[
2
],
pathCoordsBuffer
[
3
]);
break
;
case
PathIterator
.
SEG_CUBICTO
:
context
.
bezierCurveTo
(
pathCoordsBuffer
[
0
],
pathCoordsBuffer
[
1
],
pathCoordsBuffer
[
2
],
pathCoordsBuffer
[
3
],
pathCoordsBuffer
[
4
],
pathCoordsBuffer
[
5
]);
break
;
case
PathIterator
.
SEG_CLOSE
:
context
.
closePath
();
break
;
default
:
showWarning
(
"Unknown segment type "
+
pitype
);
}
pi
.
next
();
}
if
(
fill
)
context
.
fill
();
if
(
stroke
)
context
.
stroke
();
}
//////////////////////////////////////////////////////////////
// CLIPPING
@
Override
protected
void
clipImpl
(
float
x1
,
float
y1
,
float
x2
,
float
y2
) {
//g2.setClip(new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1));
showTodoWarning
(
"clip()"
,
3274
);
}
@
Override
public
void
noClip
() {
//g2.setClip(null);
showTodoWarning
(
"noClip()"
,
3274
);
}
//////////////////////////////////////////////////////////////
// BLEND
@
Override
protected
void
blendModeImpl
() {
BlendMode
mode
=
BlendMode
.
SRC_OVER
;
switch
(
blendMode
) {
case
REPLACE
:
showWarning
(
"blendMode(REPLACE) is not supported"
);
break
;
case
BLEND
:
break
;
// this is SRC_OVER, the default
case
ADD
:
mode
=
BlendMode
.
ADD
;
break
;
// everyone's favorite
case
SUBTRACT
:
showWarning
(
"blendMode(SUBTRACT) is not supported"
);
break
;
case
LIGHTEST
:
mode
=
BlendMode
.
LIGHTEN
;
break
;
case
DARKEST
:
mode
=
BlendMode
.
DARKEN
;
break
;
case
DIFFERENCE
:
mode
=
BlendMode
.
DIFFERENCE
;
break
;
case
EXCLUSION
:
mode
=
BlendMode
.
EXCLUSION
;
break
;
case
MULTIPLY
:
mode
=
BlendMode
.
MULTIPLY
;
break
;
case
SCREEN
:
mode
=
BlendMode
.
SCREEN
;
break
;
case
OVERLAY
:
mode
=
BlendMode
.
OVERLAY
;
break
;
case
HARD_LIGHT
:
mode
=
BlendMode
.
HARD_LIGHT
;
break
;
case
SOFT_LIGHT
:
mode
=
BlendMode
.
SOFT_LIGHT
;
break
;
case
DODGE
:
mode
=
BlendMode
.
COLOR_DODGE
;
break
;
case
BURN
:
mode
=
BlendMode
.
COLOR_BURN
;
break
;
}
context
.
setGlobalBlendMode
(
mode
);
}
//////////////////////////////////////////////////////////////
// BEZIER VERTICES
@
Override
protected
void
bezierVertexCheck
() {
if
(
shape
==
0
||
shape
!=
POLYGON
) {
throw
new
RuntimeException
(
"beginShape() or beginShape(POLYGON) "
+
"must be used before bezierVertex() or quadraticVertex()"
);
}
if
(
workPath
.
getNumCommands
() ==
0
) {
throw
new
RuntimeException
(
"vertex() must be used at least once "
+
"before bezierVertex() or quadraticVertex()"
);
}
}
@
Override
public
void
bezierVertex
(
float
x1
,
float
y1
,
float
x2
,
float
y2
,
float
x3
,
float
y3
) {
bezierVertexCheck
();
workPath
.
curveTo
(
x1
,
y1
,
x2
,
y2
,
x3
,
y3
);
}
@
Override
public
void
bezierVertex
(
float
x2
,
float
y2
,
float
z2
,
float
x3
,
float
y3
,
float
z3
,
float
x4
,
float
y4
,
float
z4
) {
showDepthWarningXYZ
(
"bezierVertex"
);
}
//////////////////////////////////////////////////////////////
// QUADRATIC BEZIER VERTICES
@
Override
public
void
quadraticVertex
(
float
ctrlX
,
float
ctrlY
,
float
endX
,
float
endY
) {
bezierVertexCheck
();
workPath
.
quadTo
(
ctrlX
,
ctrlY
,
endX
,
endY
);
}
@
Override
public
void
quadraticVertex
(
float
x2
,
float
y2
,
float
z2
,
float
x4
,
float
y4
,
float
z4
) {
showDepthWarningXYZ
(
"quadVertex"
);
}
//////////////////////////////////////////////////////////////
// CURVE VERTICES
@
Override
protected
void
curveVertexSegment
(
float
x1
,
float
y1
,
float
x2
,
float
y2
,
float
x3
,
float
y3
,
float
x4
,
float
y4
) {
if
(
curveCoordX
==
null
) {
curveCoordX
=
new
float
[
4
];
curveCoordY
=
new
float
[
4
];
curveDrawX
=
new
float
[
4
];
curveDrawY
=
new
float
[
4
];
}
curveCoordX
[
0
] =
x1
;
curveCoordY
[
0
] =
y1
;
curveCoordX
[
1
] =
x2
;
curveCoordY
[
1
] =
y2
;
curveCoordX
[
2
] =
x3
;
curveCoordY
[
2
] =
y3
;
curveCoordX
[
3
] =
x4
;
curveCoordY
[
3
] =
y4
;
curveToBezierMatrix
.
mult
(
curveCoordX
,
curveDrawX
);
curveToBezierMatrix
.
mult
(
curveCoordY
,
curveDrawY
);
// since the paths are continuous,
// only the first point needs the actual moveto
if
(
workPath
.
getNumCommands
() ==
0
) {
workPath
.
moveTo
(
curveDrawX
[
0
],
curveDrawY
[
0
]);
breakShape
=
false
;
}
workPath
.
curveTo
(
curveDrawX
[
1
],
curveDrawY
[
1
],
curveDrawX
[
2
],
curveDrawY
[
2
],
curveDrawX
[
3
],
curveDrawY
[
3
]);
}
@
Override
public
void
curveVertex
(
float
x
,
float
y
,
float
z
) {
showDepthWarningXYZ
(
"curveVertex"
);
}
//////////////////////////////////////////////////////////////
// RENDERER
@
Override
public
void
flush
() {
flushPixels
();
}
protected
void
flushPixels
() {
boolean
hasPixels
=
modified
&&
pixels
!=
null
;
if
(
hasPixels
) {
// If the user has been manipulating individual pixels,
// the changes need to be copied to the screen before
// drawing any new geometry.
int
mx1
=
getModifiedX1
();
int
mx2
=
getModifiedX2
();
int
my1
=
getModifiedY1
();
int
my2
=
getModifiedY2
();
int
mw
=
mx2
-
mx1
;
int
mh
=
my2
-
my1
;
PixelWriter
pw
=
context
.
getPixelWriter
();
pw
.
setPixels
(
mx1
,
my1
,
mw
,
mh
,
argbFormat
,
pixels
,
mx1
+
my1
*
pixelWidth
,
pixelWidth
);
}
modified
=
false
;
}
protected
void
beforeContextDraw
() {
flushPixels
();
loaded
=
false
;
}
//////////////////////////////////////////////////////////////
// POINT, LINE, TRIANGLE, QUAD
@
Override
public
void
point
(
float
x
,
float
y
) {
if
(
stroke
) {
// if (strokeWeight > 1) {
line
(
x
,
y
,
x
+
EPSILON
,
y
+
EPSILON
);
// } else {
// set((int) screenX(x, y), (int) screenY(x, y), strokeColor);
// }
}
}
@
Override
public
void
line
(
float
x1
,
float
y1
,
float
x2
,
float
y2
) {
beforeContextDraw
();
if
(
drawingThinLines
()) {
x1
+=
0.5f
;
x2
+=
0.5f
;
y1
+=
0.5f
;
y2
+=
0.5f
;
}
context
.
strokeLine
(
x1
,
y1
,
x2
,
y2
);
}
@
Override
public
void
triangle
(
float
x1
,
float
y1
,
float
x2
,
float
y2
,
float
x3
,
float
y3
) {
beforeContextDraw
();
if
(
drawingThinLines
()) {
x1
+=
0.5f
;
x2
+=
0.5f
;
x3
+=
0.5f
;
y1
+=
0.5f
;
y2
+=
0.5f
;
y3
+=
0.5f
;
}
context
.
beginPath
();
context
.
moveTo
(
x1
,
y1
);
context
.
lineTo
(
x2
,
y2
);
context
.
lineTo
(
x3
,
y3
);
context
.
closePath
();
if
(
fill
)
context
.
fill
();
if
(
stroke
)
context
.
stroke
();
}
@
Override
public
void
quad
(
float
x1
,
float
y1
,
float
x2
,
float
y2
,
float
x3
,
float
y3
,
float
x4
,
float
y4
) {
beforeContextDraw
();
if
(
drawingThinLines
()) {
x1
+=
0.5f
;
x2
+=
0.5f
;
x3
+=
0.5f
;
x4
+=
0.5f
;
y1
+=
0.5f
;
y2
+=
0.5f
;
y3
+=
0.5f
;
y4
+=
0.5f
;
}
context
.
beginPath
();
context
.
moveTo
(
x1
,
y1
);
context
.
lineTo
(
x2
,
y2
);
context
.
lineTo
(
x3
,
y3
);
context
.
lineTo
(
x4
,
y4
);
context
.
closePath
();
if
(
fill
)
context
.
fill
();
if
(
stroke
)
context
.
stroke
();
}
//////////////////////////////////////////////////////////////
// RECT
//public void rectMode(int mode)
//public void rect(float a, float b, float c, float d)
@
Override
protected
void
rectImpl
(
float
x1
,
float
y1
,
float
x2
,
float
y2
) {
beforeContextDraw
();
if
(
drawingThinLines
()) {
x1
+=
0.5f
;
x2
+=
0.5f
;
y1
+=
0.5f
;
y2
+=
0.5f
;
}
if
(
fill
)
context
.
fillRect
(
x1
,
y1
,
x2
-
x1
,
y2
-
y1
);
if
(
stroke
)
context
.
strokeRect
(
x1
,
y1
,
x2
-
x1
,
y2
-
y1
);
}
//////////////////////////////////////////////////////////////
// ELLIPSE
//public void ellipseMode(int mode)
//public void ellipse(float a, float b, float c, float d)
@
Override
protected
void
ellipseImpl
(
float
x
,
float
y
,
float
w
,
float
h
) {
beforeContextDraw
();
if
(
drawingThinLines
()) {
x
+=
0.5f
;
y
+=
0.5f
;
}
if
(
fill
)
context
.
fillOval
(
x
,
y
,
w
,
h
);
if
(
stroke
)
context
.
strokeOval
(
x
,
y
,
w
,
h
);
}
//////////////////////////////////////////////////////////////
// ARC
//public void arc(float a, float b, float c, float d,
// float start, float stop)
@
Override
protected
void
arcImpl
(
float
x
,
float
y
,
float
w
,
float
h
,
float
start
,
float
stop
,
int
mode
) {
beforeContextDraw
();
if
(
drawingThinLines
()) {
x
+=
0.5f
;
y
+=
0.5f
;
}
// 0 to 90 in java would be 0 to -90 for p5 renderer
// but that won't work, so -90 to 0?
start
= -
start
;
stop
= -
stop
;
float
sweep
=
stop
-
start
;
// The defaults, before 2.0b7, were to stroke as Arc2D.OPEN, and then fill
// using Arc2D.PIE. That's a little wonky, but it's here for compatability.
ArcType
fillMode
=
ArcType
.
ROUND
;
// Arc2D.PIE
ArcType
strokeMode
=
ArcType
.
OPEN
;
if
(
mode
==
OPEN
) {
fillMode
=
ArcType
.
OPEN
;
}
else
if
(
mode
==
PIE
) {
strokeMode
=
ArcType
.
ROUND
;
// PIE
}
else
if
(
mode
==
CHORD
) {
fillMode
=
ArcType
.
CHORD
;
strokeMode
=
ArcType
.
CHORD
;
}
if
(
fill
) {
context
.
fillArc
(
x
,
y
,
w
,
h
,
PApplet
.
degrees
(
start
),
PApplet
.
degrees
(
sweep
),
fillMode
);
}
if
(
stroke
) {
context
.
strokeArc
(
x
,
y
,
w
,
h
,
PApplet
.
degrees
(
start
),
PApplet
.
degrees
(
sweep
),
strokeMode
);
}
}
//////////////////////////////////////////////////////////////
// BOX
//public void box(float size)
@
Override
public
void
box
(
float
w
,
float
h
,
float
d
) {
showMethodWarning
(
"box"
);
}
//////////////////////////////////////////////////////////////
// SPHERE
//public void sphereDetail(int res)
//public void sphereDetail(int ures, int vres)
@
Override
public
void
sphere
(
float
r
) {
showMethodWarning
(
"sphere"
);
}
//////////////////////////////////////////////////////////////
// BEZIER
//public float bezierPoint(float a, float b, float c, float d, float t)
//public float bezierTangent(float a, float b, float c, float d, float t)
//protected void bezierInitCheck()
//protected void bezierInit()
/** Ignored (not needed) by this renderer. */
@
Override
public
void
bezierDetail
(
int
detail
) { }
//public void bezier(float x1, float y1,
// float x2, float y2,
// float x3, float y3,
// float x4, float y4)
//public void bezier(float x1, float y1, float z1,
// float x2, float y2, float z2,
// float x3, float y3, float z3,
// float x4, float y4, float z4)
//////////////////////////////////////////////////////////////
// CURVE
//public float curvePoint(float a, float b, float c, float d, float t)
//public float curveTangent(float a, float b, float c, float d, float t)
/** Ignored (not needed) by this renderer. */
@
Override
public
void
curveDetail
(
int
detail
) { }
//public void curveTightness(float tightness)
//protected void curveInitCheck()
//protected void curveInit()
//public void curve(float x1, float y1,
// float x2, float y2,
// float x3, float y3,
// float x4, float y4)
//public void curve(float x1, float y1, float z1,
// float x2, float y2, float z2,
// float x3, float y3, float z3,
// float x4, float y4, float z4)
//////////////////////////////////////////////////////////////
// SMOOTH
// @Override
// public void smooth() {
// smooth = true;
//
// if (quality == 0) {
// quality = 4; // change back to bicubic
// }
// }
// @Override
// public void smooth(int quality) {
//// this.quality = quality;
//// if (quality == 0) {
//// noSmooth();
//// } else {
//// smooth();
//// }
// showMissingWarning("smooth");
// }
//
//
// @Override
// public void noSmooth() {
// showMissingWarning("noSmooth");
// }
//////////////////////////////////////////////////////////////
// IMAGE
//public void imageMode(int mode)
//public void image(PImage image, float x, float y)
//public void image(PImage image, float x, float y, float c, float d)
//public void image(PImage image,
// float a, float b, float c, float d,
// int u1, int v1, int u2, int v2)
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL