-
Notifications
You must be signed in to change notification settings - Fork 0
/
agg2d.inl
1977 lines (1673 loc) · 62.7 KB
/
agg2d.inl
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
//----------------------------------------------------------------------------
// Agg2D - Version 1.0
// Based on Anti-Grain Geometry
// Copyright (C) 2005 Maxim Shemanarev (http://www.antigrain.com)
//
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
//
//----------------------------------------------------------------------------
// Contact: [email protected]
// http://www.antigrain.com
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//
// 25 Jan 2007 - Ported to AGG 2.4 Jerry Evans ([email protected])
// 11 Jul 2009 - significant refactors for introduction to desmume
//
//----------------------------------------------------------------------------
#include "agg2d.h"
static const double g_approxScale = 2.0;
#define TAGG2D Agg2D AGG2D_TEMPLATE_ARG
#define TAGG2DRENDERER Agg2DRenderer <PixFormatSet,PixFormatSet>
//AGG2D_TEMPLATE inline bool operator == (const TAGG2D::Color& c1, const TAGG2D::Color& c2)
//{
// return c1.r == c2.r && c1.g == c2.g && c1.b == c2.b && c1.a == c2.a;
//}
//
//AGG2D_TEMPLATE inline bool operator != (const Agg2D<PixFormat>::Color& c1, const Agg2D<PixFormat>::Color& c2)
//{
// return !(c1 == c2);
//}
AGG2D_TEMPLATE inline TAGG2D::~Agg2D()
{
#ifdef AGG2D_USE_VECTORFONTS
#ifndef AGG2D_USE_FREETYPE
::ReleaseDC(0, m_fontDC);
#endif
#endif
}
AGG2D_TEMPLATE inline TAGG2D::Agg2D() :
m_rbuf(),
m_pixFormat(m_rbuf),
m_pixFormatComp(m_rbuf),
m_pixFormatPre(m_rbuf),
m_pixFormatCompPre(m_rbuf),
m_renBase(m_pixFormat),
m_renBaseComp(m_pixFormatComp),
m_renBasePre(m_pixFormatPre),
m_renBaseCompPre(m_pixFormatCompPre),
m_renSolid(m_renBase),
m_renSolidComp(m_renBaseComp),
m_allocator(),
m_clipBox(0,0,0,0),
m_blendMode(BlendAlpha),
m_imageBlendMode(BlendDst),
m_imageBlendColor(0,0,0),
m_scanline(),
m_rasterizer(),
m_masterAlpha(1.0),
m_antiAliasGamma(1.0),
m_font(agg::gse4x6),
m_fillColor(255, 255, 255),
m_lineColor(0, 0, 0),
m_fillGradient(),
m_lineGradient(),
m_lineCap(CAP_ROUND),
m_lineJoin(JOIN_ROUND),
m_fillGradientFlag(Solid),
m_lineGradientFlag(Solid),
m_fillGradientMatrix(),
m_lineGradientMatrix(),
m_fillGradientD1(0.0),
m_lineGradientD1(0.0),
m_fillGradientD2(100.0),
m_lineGradientD2(100.0),
m_textAngle(0.0),
m_textAlignX(AlignLeft),
m_textAlignY(AlignBottom),
m_textHints(true),
m_fontHeight(0.0),
m_fontAscent(0.0),
m_fontDescent(0.0),
m_fontCacheType(RasterFontCache),
m_imageFilter(Bilinear), //less quality more speed
//m_imageFilter(NoFilter),
m_imageResample(NoResample),
m_imageFilterLut(agg::image_filter_bilinear(), true),
m_fillGradientInterpolator(m_fillGradientMatrix),
m_lineGradientInterpolator(m_lineGradientMatrix),
m_linearGradientFunction(),
m_radialGradientFunction(),
m_lineWidth(1),
m_evenOddFlag(false),
m_start_x(0.0),
m_start_y(0.0),
m_path(),
m_transform(),
m_convCurve(m_path),
m_convStroke(m_convCurve),
m_pathTransform(m_convCurve, m_transform),
m_strokeTransform(m_convStroke, m_transform)
#ifdef AGG2D_USE_VECTORFONTS
#ifdef AGG2D_USE_FREETYPE
, m_fontEngine(),
#else
m_fontDC(::GetDC(0)),
m_fontEngine(m_fontDC),
#endif
m_fontCacheManager(m_fontEngine)
#endif
{
lineCap(m_lineCap);
lineJoin(m_lineJoin);
}
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::saveStateTo(State& st)
{
st.m_clipBox = m_clipBox;
st.m_blendMode = m_blendMode;
st.m_imageBlendMode = m_imageBlendMode;
st.m_imageBlendColor = m_imageBlendColor;
st.m_masterAlpha = m_masterAlpha;
st.m_antiAliasGamma = m_antiAliasGamma;
st.m_font = m_font;
st.m_fillColor = m_fillColor;
st.m_lineColor = m_lineColor;
st.m_fillGradient = m_fillGradient;
st.m_lineGradient = m_lineGradient;
st.m_lineCap = m_lineCap;
st.m_lineJoin = m_lineJoin;
st.m_fillGradientFlag = m_fillGradientFlag;
st.m_lineGradientFlag = m_lineGradientFlag;
st.m_fillGradientMatrix = m_fillGradientMatrix;
st.m_lineGradientMatrix = m_lineGradientMatrix;
st.m_fillGradientD1 = m_fillGradientD1;
st.m_lineGradientD1 = m_lineGradientD1;
st.m_fillGradientD2 = m_fillGradientD2;
st.m_lineGradientD2 = m_lineGradientD2;
st.m_textAngle = m_textAngle;
st.m_textAlignX = m_textAlignX;
st.m_textAlignY = m_textAlignY;
st.m_textHints = m_textHints;
st.m_fontHeight = m_fontHeight;
st.m_fontAscent = m_fontAscent;
st.m_fontDescent = m_fontDescent;
st.m_fontCacheType = m_fontCacheType;
st.m_lineWidth = m_lineWidth;
st.m_evenOddFlag = m_evenOddFlag;
st.m_transform = m_transform;
st.m_affine = m_affine;
}
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::restoreStateFrom(const State& st)
{
m_clipBox = st.m_clipBox;
m_blendMode = st.m_blendMode;
m_imageBlendMode = st.m_imageBlendMode;
m_imageBlendColor = st.m_imageBlendColor;
m_masterAlpha = st.m_masterAlpha;
m_antiAliasGamma = st.m_antiAliasGamma;
m_font = st.m_font;
m_fillColor = st.m_fillColor;
m_lineColor = st.m_lineColor;
m_fillGradient = st.m_fillGradient;
m_lineGradient = st.m_lineGradient;
m_lineCap = st.m_lineCap;
m_lineJoin = st.m_lineJoin;
m_fillGradientFlag = st.m_fillGradientFlag;
m_lineGradientFlag = st.m_lineGradientFlag;
m_fillGradientMatrix = st.m_fillGradientMatrix;
m_lineGradientMatrix = st.m_lineGradientMatrix;
m_fillGradientD1 = st.m_fillGradientD1;
m_lineGradientD1 = st.m_lineGradientD1;
m_fillGradientD2 = st.m_fillGradientD2;
m_lineGradientD2 = st.m_lineGradientD2;
m_textAngle = st.m_textAngle;
m_textAlignX = st.m_textAlignX;
m_textAlignY = st.m_textAlignY;
m_textHints = st.m_textHints;
m_fontHeight = st.m_fontHeight;
m_fontAscent = st.m_fontAscent;
m_fontDescent = st.m_fontDescent;
m_fontCacheType = st.m_fontCacheType;
m_lineWidth = st.m_lineWidth;
m_evenOddFlag = st.m_evenOddFlag;
m_affine = st.m_affine;
m_transform = st.m_transform;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::attach(unsigned char* buf, unsigned width, unsigned height, int stride)
{
m_rbuf.attach(buf, width, height, stride);
m_renBase.reset_clipping(true);
m_renBaseComp.reset_clipping(true);
m_renBasePre.reset_clipping(true);
m_renBaseCompPre.reset_clipping(true);
//why is all this reset here???? seems silly.
resetTransformations();
lineWidth(1.0),
lineColor(0,0,0);
fillColor(255,255,255);
clipBox(0, 0, width, height);
lineCap(CAP_ROUND);
lineJoin(JOIN_ROUND);
#ifdef AGG2D_USE_VECTORFONTS
textAlignment(AlignLeft, AlignBottom);
flipText(false);
#endif
imageFilter(Bilinear); //less quality more speed
//imageFilter(NoFilter);
imageResample(NoResample);
m_masterAlpha = 1.0;
m_antiAliasGamma = 1.0;
m_rasterizer.gamma(agg::gamma_none());
m_blendMode = BlendAlpha;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::attach(MyImage& img)
{
attach(img.renBuf.buf(), img.renBuf.width(), img.renBuf.height(), img.renBuf.stride());
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::clipBox(double x1, double y1, double x2, double y2)
{
m_viewport.transform(&x1, &y1); //
m_viewport.transform(&x2, &y2); // see: http://article.gmane.org/gmane.comp.graphics.agg/3543
m_clipBox = RectD(x1, y1, x2, y2);
int rx1 = int(x1);
int ry1 = int(y1);
int rx2 = int(x2);
int ry2 = int(y2);
m_renBase.clip_box(rx1, ry1, rx2, ry2);
m_renBaseComp.clip_box(rx1, ry1, rx2, ry2);
m_renBasePre.clip_box(rx1, ry1, rx2, ry2);
m_renBaseCompPre.clip_box(rx1, ry1, rx2, ry2);
// m_rasterizer.clip_box(x1, y1, x2, y2);
m_rasterizer.clip_box(m_renBase.xmin(), m_renBase.ymin(),
m_renBase.xmax()+1, m_renBase.ymax()+1); // see link above
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::blendMode(BlendMode m)
{
m_blendMode = m;
m_pixFormatComp.comp_op(m);
m_pixFormatCompPre.comp_op(m);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE typename Agg2D AGG2D_TEMPLATE_ARG ::BlendMode Agg2D AGG2D_TEMPLATE_ARG ::blendMode() const
{
return m_blendMode;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::imageBlendMode(BlendMode m)
{
m_imageBlendMode = m;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE typename Agg2D AGG2D_TEMPLATE_ARG ::BlendMode Agg2D AGG2D_TEMPLATE_ARG ::imageBlendMode() const
{
return m_imageBlendMode;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::imageBlendColor(Color c)
{
m_imageBlendColor = c;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::imageBlendColor(unsigned r, unsigned g, unsigned b, unsigned a)
{
imageBlendColor(Color(r, g, b, a));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE typename Agg2D AGG2D_TEMPLATE_ARG ::Color Agg2D AGG2D_TEMPLATE_ARG ::imageBlendColor() const
{
return m_imageBlendColor;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::masterAlpha(double a)
{
m_masterAlpha = a;
updateRasterizerGamma();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE double Agg2D AGG2D_TEMPLATE_ARG ::masterAlpha() const
{
return m_masterAlpha;
}
//------------------------------------------------------------------------+
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::antiAliasGamma(double g)
{
m_antiAliasGamma = g;
updateRasterizerGamma();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE double Agg2D AGG2D_TEMPLATE_ARG ::antiAliasGamma() const
{
return m_antiAliasGamma;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE Agg2DBase::RectD Agg2D AGG2D_TEMPLATE_ARG ::clipBox() const
{
return m_clipBox;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::clearAll(Color c)
{
m_renBase.clear(c);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::clearAll(unsigned r, unsigned g, unsigned b, unsigned a)
{
clearAll(Color(r, g, b, a));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::clearClipBox(Color c)
{
m_renBase.copy_bar(0, 0, m_renBase.width(), m_renBase.height(), c);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::clearClipBox(unsigned r, unsigned g, unsigned b, unsigned a)
{
clearClipBox(Color(r, g, b, a));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::worldToScreen(double& x, double& y) const
{
m_transform.transform(&x, &y);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::screenToWorld(double& x, double& y) const
{
m_transform.inverse_transform(&x, &y);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE double Agg2D AGG2D_TEMPLATE_ARG ::worldToScreen(double scalar) const
{
double x1 = 0;
double y1 = 0;
double x2 = scalar;
double y2 = scalar;
worldToScreen(x1, y1);
worldToScreen(x2, y2);
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) * 0.7071068;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE double Agg2D AGG2D_TEMPLATE_ARG ::screenToWorld(double scalar) const
{
double x1 = 0;
double y1 = 0;
double x2 = scalar;
double y2 = scalar;
screenToWorld(x1, y1);
screenToWorld(x2, y2);
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) * 0.7071068;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::alignPoint(double& x, double& y) const
{
worldToScreen(x, y);
x = floor(x) + 0.5;
y = floor(y) + 0.5;
screenToWorld(x, y);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE bool Agg2D AGG2D_TEMPLATE_ARG ::inBox(double worldX, double worldY) const
{
worldToScreen(worldX, worldY);
return m_renBase.inbox(int(worldX), int(worldY));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE Agg2DBase::Transformations Agg2D AGG2D_TEMPLATE_ARG ::transformations() const
{
Transformations tr;
m_transform.store_to(tr.affineMatrix);
return tr;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE const Agg2DBase::Affine& Agg2D AGG2D_TEMPLATE_ARG ::affine() const
{
return m_affine;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::affine(const Affine& af)
{
m_affine = af;
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::transformations(const Transformations& tr)
{
m_transform.load_from(tr.affineMatrix);
m_convCurve.approximation_scale(worldToScreen(1.0) * g_approxScale);
m_convStroke.approximation_scale(worldToScreen(1.0) * g_approxScale);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::resetTransformations()
{
m_transform.reset();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::updateTransformations()
{
m_transform = m_affine;
m_transform *= m_viewport;
m_convCurve.approximation_scale(worldToScreen(1.0) * g_approxScale);
m_convStroke.approximation_scale(worldToScreen(1.0) * g_approxScale);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::rotate(double angle)
{
m_affine.premultiply(agg::trans_affine_rotation(angle));
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::rotate(double angle, double cx, double cy)
{
agg::trans_affine_translation m(-cx, -cy);
m *= agg::trans_affine_rotation(angle);
m *= agg::trans_affine_translation(cx, cy);
m_affine.premultiply(m);
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::skew(double sx, double sy)
{
m_affine.premultiply(agg::trans_affine_skewing(sx, sy));
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::translate(double x, double y)
{
m_affine.premultiply(agg::trans_affine_translation(x, y));
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::matrix(const Affine& tr)
{
m_affine.premultiply(tr);
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::matrix(const Transformations& tr)
{
matrix(agg::trans_affine(tr.affineMatrix[0], tr.affineMatrix[1], tr.affineMatrix[2],
tr.affineMatrix[3], tr.affineMatrix[4], tr.affineMatrix[5]));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::scale(double s)
{
m_affine.premultiply(agg::trans_affine_scaling(s));
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::scale(double sx, double sy)
{
m_affine.premultiply(agg::trans_affine_scaling(sx, sy));
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::parallelogram(double x1, double y1, double x2, double y2, const double* para)
{
m_affine.premultiply(agg::trans_affine(x1, y1, x2, y2, para));
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::viewport(double worldX1, double worldY1, double worldX2, double worldY2,
double screenX1, double screenY1, double screenX2, double screenY2,
ViewportOption opt, WindowFitLogic fl)
{
agg::trans_viewport vp;
agg::aspect_ratio_e ar =
(fl == WindowFitLogic_meet) ? agg::aspect_ratio_meet :
agg::aspect_ratio_slice;
switch(opt)
{
case Anisotropic: vp.preserve_aspect_ratio(0.0, 0.0, agg::aspect_ratio_stretch); break;
case XMinYMin: vp.preserve_aspect_ratio(0.0, 0.0, ar); break;
case XMidYMin: vp.preserve_aspect_ratio(0.5, 0.0, ar); break;
case XMaxYMin: vp.preserve_aspect_ratio(1.0, 0.0, ar); break;
case XMinYMid: vp.preserve_aspect_ratio(0.0, 0.5, ar); break;
case XMidYMid: vp.preserve_aspect_ratio(0.5, 0.5, ar); break;
case XMaxYMid: vp.preserve_aspect_ratio(1.0, 0.5, ar); break;
case XMinYMax: vp.preserve_aspect_ratio(0.0, 1.0, ar); break;
case XMidYMax: vp.preserve_aspect_ratio(0.5, 1.0, ar); break;
case XMaxYMax: vp.preserve_aspect_ratio(1.0, 1.0, ar); break;
}
vp.world_viewport(worldX1, worldY1, worldX2, worldY2);
vp.device_viewport(screenX1, screenY1, screenX2, screenY2);
m_viewport = vp.to_affine();
updateTransformations();
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::fillColor(Color c)
{
m_fillColor = c;
m_fillGradientFlag = Solid;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::fillColor(unsigned r, unsigned g, unsigned b, unsigned a)
{
fillColor(Color(r, g, b, a));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::noFill()
{
fillColor(Color(0, 0, 0, 0));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::lineColor(Color c)
{
m_lineColor = c;
m_lineGradientFlag = Solid;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::lineColor(unsigned r, unsigned g, unsigned b, unsigned a)
{
lineColor(Color(r, g, b, a));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void Agg2D AGG2D_TEMPLATE_ARG ::noLine()
{
lineColor(Color(0, 0, 0, 0));
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE typename TAGG2D::Color TAGG2D::fillColor() const
{
return m_fillColor;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE typename TAGG2D::Color TAGG2D::lineColor() const
{
return m_lineColor;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::fillLinearGradient(double x1, double y1, double x2, double y2, Color c1, Color c2, double profile)
{
int i;
int startGradient = 128 - int(profile * 127.0);
int endGradient = 128 + int(profile * 127.0);
if (endGradient <= startGradient) endGradient = startGradient + 1;
double k = 1.0 / double(endGradient - startGradient);
for (i = 0; i < startGradient; i++)
{
m_fillGradient[i] = c1;
}
for (; i < endGradient; i++)
{
m_fillGradient[i] = c1.gradient(c2, double(i - startGradient) * k);
}
for (; i < 256; i++)
{
m_fillGradient[i] = c2;
}
double angle = atan2(y2-y1, x2-x1);
m_fillGradientMatrix.reset();
m_fillGradientMatrix *= agg::trans_affine_rotation(angle);
m_fillGradientMatrix *= agg::trans_affine_translation(x1, y1);
m_fillGradientMatrix *= m_transform;
m_fillGradientMatrix.invert();
m_fillGradientD1 = 0.0;
m_fillGradientD2 = sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
m_fillGradientFlag = Linear;
m_fillColor = Color(0,0,0); // Set some real color
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::lineLinearGradient(double x1, double y1, double x2, double y2, Color c1, Color c2, double profile)
{
int i;
int startGradient = 128 - int(profile * 128.0);
int endGradient = 128 + int(profile * 128.0);
if (endGradient <= startGradient) endGradient = startGradient + 1;
double k = 1.0 / double(endGradient - startGradient);
for (i = 0; i < startGradient; i++)
{
m_lineGradient[i] = c1;
}
for (; i < endGradient; i++)
{
m_lineGradient[i] = c1.gradient(c2, double(i - startGradient) * k);
}
for (; i < 256; i++)
{
m_lineGradient[i] = c2;
}
double angle = atan2(y2-y1, x2-x1);
m_lineGradientMatrix.reset();
m_lineGradientMatrix *= agg::trans_affine_rotation(angle);
m_lineGradientMatrix *= agg::trans_affine_translation(x1, y1);
m_fillGradientMatrix *= m_transform;
m_lineGradientMatrix.invert();
m_lineGradientD1 = 0;
m_lineGradientD2 = sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
m_lineGradientFlag = Linear;
m_lineColor = Color(0,0,0); // Set some real color
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::fillRadialGradient(double x, double y, double r, Color c1, Color c2, double profile)
{
int i;
int startGradient = 128 - int(profile * 127.0);
int endGradient = 128 + int(profile * 127.0);
if (endGradient <= startGradient) endGradient = startGradient + 1;
double k = 1.0 / double(endGradient - startGradient);
for (i = 0; i < startGradient; i++)
{
m_fillGradient[i] = c1;
}
for (; i < endGradient; i++)
{
m_fillGradient[i] = c1.gradient(c2, double(i - startGradient) * k);
}
for (; i < 256; i++)
{
m_fillGradient[i] = c2;
}
m_fillGradientD2 = worldToScreen(r);
worldToScreen(x, y);
m_fillGradientMatrix.reset();
m_fillGradientMatrix *= agg::trans_affine_translation(x, y);
m_fillGradientMatrix.invert();
m_fillGradientD1 = 0;
m_fillGradientFlag = Radial;
m_fillColor = Color(0,0,0); // Set some real color
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::lineRadialGradient(double x, double y, double r, Color c1, Color c2, double profile)
{
int i;
int startGradient = 128 - int(profile * 128.0);
int endGradient = 128 + int(profile * 128.0);
if (endGradient <= startGradient) endGradient = startGradient + 1;
double k = 1.0 / double(endGradient - startGradient);
for (i = 0; i < startGradient; i++)
{
m_lineGradient[i] = c1;
}
for (; i < endGradient; i++)
{
m_lineGradient[i] = c1.gradient(c2, double(i - startGradient) * k);
}
for (; i < 256; i++)
{
m_lineGradient[i] = c2;
}
m_lineGradientD2 = worldToScreen(r);
worldToScreen(x, y);
m_lineGradientMatrix.reset();
m_lineGradientMatrix *= agg::trans_affine_translation(x, y);
m_lineGradientMatrix.invert();
m_lineGradientD1 = 0;
m_lineGradientFlag = Radial;
m_lineColor = Color(0,0,0); // Set some real color
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::fillRadialGradient(double x, double y, double r, Color c1, Color c2, Color c3)
{
int i;
for (i = 0; i < 128; i++)
{
m_fillGradient[i] = c1.gradient(c2, double(i) / 127.0);
}
for (; i < 256; i++)
{
m_fillGradient[i] = c2.gradient(c3, double(i - 128) / 127.0);
}
m_fillGradientD2 = worldToScreen(r);
worldToScreen(x, y);
m_fillGradientMatrix.reset();
m_fillGradientMatrix *= agg::trans_affine_translation(x, y);
m_fillGradientMatrix.invert();
m_fillGradientD1 = 0;
m_fillGradientFlag = Radial;
m_fillColor = Color(0,0,0); // Set some real color
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::lineRadialGradient(double x, double y, double r, Color c1, Color c2, Color c3)
{
int i;
for (i = 0; i < 128; i++)
{
m_lineGradient[i] = c1.gradient(c2, double(i) / 127.0);
}
for (; i < 256; i++)
{
m_lineGradient[i] = c2.gradient(c3, double(i - 128) / 127.0);
}
m_lineGradientD2 = worldToScreen(r);
worldToScreen(x, y);
m_lineGradientMatrix.reset();
m_lineGradientMatrix *= agg::trans_affine_translation(x, y);
m_lineGradientMatrix.invert();
m_lineGradientD1 = 0;
m_lineGradientFlag = Radial;
m_lineColor = Color(0,0,0); // Set some real color
}
AGG2D_TEMPLATE void TAGG2D::fillRadialGradient(double x, double y, double r)
{
m_fillGradientD2 = worldToScreen(r);
worldToScreen(x, y);
m_fillGradientMatrix.reset();
m_fillGradientMatrix *= agg::trans_affine_translation(x, y);
m_fillGradientMatrix.invert();
m_fillGradientD1 = 0;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::lineRadialGradient(double x, double y, double r)
{
m_lineGradientD2 = worldToScreen(r);
worldToScreen(x, y);
m_lineGradientMatrix.reset();
m_lineGradientMatrix *= agg::trans_affine_translation(x, y);
m_lineGradientMatrix.invert();
m_lineGradientD1 = 0;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::lineWidth(double w)
{
m_lineWidth = w;
m_convStroke.width(w);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE double TAGG2D::lineWidth() const
{
return m_lineWidth;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::fillEvenOdd(bool evenOddFlag)
{
m_evenOddFlag = evenOddFlag;
m_rasterizer.filling_rule(evenOddFlag ? agg::fill_even_odd : agg::fill_non_zero);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE bool TAGG2D::fillEvenOdd() const
{
return m_evenOddFlag;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::lineCap(LineCap cap)
{
m_lineCap = cap;
m_convStroke.line_cap((agg::line_cap_e)cap);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE Agg2DBase::LineCap TAGG2D::lineCap() const
{
return m_lineCap;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::lineJoin(LineJoin join)
{
m_lineJoin = join;
m_convStroke.line_join((agg::line_join_e)join);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE Agg2DBase::LineJoin TAGG2D::lineJoin() const
{
return m_lineJoin;
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::addLine(double x1, double y1, double x2, double y2)
{
m_path.move_to(x1, y1);
m_path.line_to(x2, y2);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::line(double x1, double y1, double x2, double y2)
{
m_path.remove_all();
addLine(x1, y1, x2, y2);
drawPath(StrokeOnly);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::triangle(double x1, double y1, double x2, double y2, double x3, double y3)
{
m_path.remove_all();
m_path.move_to(x1, y1);
m_path.line_to(x2, y2);
m_path.line_to(x3, y3);
m_path.close_polygon();
drawPath(FillAndStroke);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::rectangle(double x1, double y1, double x2, double y2)
{
m_path.remove_all();
m_path.move_to(x1, y1);
m_path.line_to(x2, y1);
m_path.line_to(x2, y2);
m_path.line_to(x1, y2);
m_path.close_polygon();
drawPath(FillAndStroke);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::roundedRect(double x1, double y1, double x2, double y2, double r)
{
m_path.remove_all();
agg::rounded_rect rc(x1, y1, x2, y2, r);
rc.normalize_radius();
rc.approximation_scale(worldToScreen(1.0) * g_approxScale);
// JME audit
//m_path.add_path(rc, 0, false);
m_path.concat_path(rc,0);
drawPath(FillAndStroke);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::roundedRect(double x1, double y1, double x2, double y2, double rx, double ry)
{
m_path.remove_all();
agg::rounded_rect rc;
rc.rect(x1, y1, x2, y2);
rc.radius(rx, ry);
rc.normalize_radius();
//m_path.add_path(rc, 0, false);
m_path.concat_path(rc,0); // JME
drawPath(FillAndStroke);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::roundedRect(double x1, double y1, double x2, double y2,
double rx_bottom, double ry_bottom,
double rx_top, double ry_top)
{
m_path.remove_all();
agg::rounded_rect rc;
rc.rect(x1, y1, x2, y2);
rc.radius(rx_bottom, ry_bottom, rx_top, ry_top);
rc.normalize_radius();
rc.approximation_scale(worldToScreen(1.0) * g_approxScale);
//m_path.add_path(rc, 0, false);
m_path.concat_path(rc,0); // JME
drawPath(FillAndStroke);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::ellipse(double cx, double cy, double rx, double ry)
{
m_path.remove_all();
agg::bezier_arc arc(cx, cy, rx, ry, 0, 2*pi());
//m_path.add_path(arc, 0, false);
m_path.concat_path(arc,0); // JME
m_path.close_polygon();
drawPath(FillAndStroke);
}
//------------------------------------------------------------------------
AGG2D_TEMPLATE void TAGG2D::arc(double cx, double cy, double rx, double ry, double start, double sweep)
{
m_path.remove_all();
agg::bezier_arc arc(cx, cy, rx, ry, start, sweep);
//m_path.add_path(arc, 0, false);
m_path.concat_path(arc,0); // JME
drawPath(StrokeOnly);
}