1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
14 #include <basegfx/matrix/b2dhommatrix.hxx>
15 #include <basegfx/polygon/b2dpolygontriangulator.hxx>
16 #include <basegfx/polygon/b2dpolypolygon.hxx>
17 #include <basegfx/utils/tools.hxx>
18 #include <com/sun/star/rendering/ARGBColor.hpp>
20 #include "ogl_canvastools.hxx"
22 using namespace ::com::sun::star
;
26 /// triangulates polygon before
27 void renderComplexPolyPolygon( const ::basegfx::B2DPolyPolygon
& rPolyPoly
)
29 ::basegfx::B2DPolyPolygon
aPolyPoly(rPolyPoly
);
30 if( aPolyPoly
.areControlPointsUsed() )
31 aPolyPoly
= rPolyPoly
.getDefaultAdaptiveSubdivision();
32 const ::basegfx::B2DRange
aBounds(aPolyPoly
.getB2DRange());
33 const double nWidth
=aBounds
.getWidth();
34 const double nHeight
=aBounds
.getHeight();
35 const ::basegfx::triangulator::B2DTriangleVector
rTriangulatedPolygon(
36 ::basegfx::triangulator::triangulate(aPolyPoly
));
38 for( auto const& rTriangulatedPolygonItem
: rTriangulatedPolygon
)
40 const::basegfx::triangulator::B2DTriangle
& rCandidate(rTriangulatedPolygonItem
);
42 rCandidate
.getA().getX()/nWidth
,
43 rCandidate
.getA().getY()/nHeight
);
45 rCandidate
.getA().getX(),
46 rCandidate
.getA().getY());
49 rCandidate
.getB().getX()/nWidth
,
50 rCandidate
.getB().getY()/nHeight
);
52 rCandidate
.getB().getX(),
53 rCandidate
.getB().getY());
56 rCandidate
.getC().getX()/nWidth
,
57 rCandidate
.getC().getY()/nHeight
);
59 rCandidate
.getC().getX(),
60 rCandidate
.getC().getY());
64 /** only use this for line polygons.
66 better not leave triangulation to OpenGL. also, ignores texturing
68 void renderPolyPolygon( const ::basegfx::B2DPolyPolygon
& rPolyPoly
)
70 ::basegfx::B2DPolyPolygon
aPolyPoly(rPolyPoly
);
71 if( aPolyPoly
.areControlPointsUsed() )
72 aPolyPoly
= rPolyPoly
.getDefaultAdaptiveSubdivision();
74 for( sal_uInt32 i
=0; i
<aPolyPoly
.count(); i
++ )
76 glBegin(GL_LINE_STRIP
);
78 const ::basegfx::B2DPolygon
& rPolygon( aPolyPoly
.getB2DPolygon(i
) );
80 const sal_uInt32 nPts
=rPolygon
.count();
81 const sal_uInt32 nExtPts
=nPts
+ int(rPolygon
.isClosed());
82 for( sal_uInt32 j
=0; j
<nExtPts
; j
++ )
84 const ::basegfx::B2DPoint
& rPt( rPolygon
.getB2DPoint( j
% nPts
) );
85 glVertex2d(rPt
.getX(), rPt
.getY());
92 void setupState( const ::basegfx::B2DHomMatrix
& rTransform
,
95 const rendering::ARGBColor
& rColor
)
97 double aGLTransform
[] =
99 rTransform
.get(0,0), rTransform
.get(1,0), 0, 0,
100 rTransform
.get(0,1), rTransform
.get(1,1), 0, 0,
102 rTransform
.get(0,2), rTransform
.get(1,2), 0, 1
104 glMultMatrixd(aGLTransform
);
107 glBlendFunc(eSrcBlend
, eDstBlend
);
109 glColor4d(rColor
.Red
,
115 // glBlendEquation( GLenum mode );
116 // glBlendColor( GLclampf red, GLclampf green,GLclampf blue, GLclampf alpha );
117 // glConvolutionFilter1D
118 // glConvolutionFilter2D
119 // glSeparableFilter2D
122 void renderOSD( const std::vector
<double>& rNumbers
, double scale
)
125 basegfx::B2DHomMatrix aTmp
;
126 basegfx::B2DHomMatrix aScaleShear
;
127 aScaleShear
.shearX(-0.1);
128 aScaleShear
.scale(scale
,scale
);
130 for(double rNumber
: rNumbers
)
136 basegfx::B2DPolyPolygon aPoly
=
137 basegfx::utils::number2PolyPolygon(rNumber
,10,3);
139 aTmp
=aTmp
*aScaleShear
;
140 aPoly
.transform(aTmp
);
143 renderPolyPolygon(aPoly
);
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */