1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  * ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_slideshow.hxx"
30 
31 #include <canvas/debug.hxx>
32 #include <basegfx/numeric/ftools.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <basegfx/point/b2dpoint.hxx>
35 #include <basegfx/matrix/b2dhommatrixtools.hxx>
36 #include "transitiontools.hxx"
37 #include "figurewipe.hxx"
38 
39 
40 namespace slideshow {
41 namespace internal {
42 
43 ::basegfx::B2DPolyPolygon FigureWipe::operator () ( double t )
44 {
45     ::basegfx::B2DPolyPolygon res(m_figure);
46     res.transform(basegfx::tools::createScaleTranslateB2DHomMatrix(t, t, 0.5, 0.5));
47     return res;
48 }
49 
50 FigureWipe * FigureWipe::createTriangleWipe()
51 {
52     const double s60 = sin( basegfx::deg2rad(60.0) );
53     const double s30 = sin( basegfx::deg2rad(30.0) );
54     ::basegfx::B2DPolygon figure;
55     figure.append( ::basegfx::B2DPoint( 0.5 + s30, 0.5 ) );
56     figure.append( ::basegfx::B2DPoint( 0.0, -0.5 - s60 ) );
57     figure.append( ::basegfx::B2DPoint( -0.5 - s30, 0.5 ) );
58     figure.setClosed(true);
59     return new FigureWipe(figure);
60 }
61 
62 FigureWipe * FigureWipe::createArrowHeadWipe()
63 {
64     const double s60 = sin( basegfx::deg2rad(60.0) );
65     const double s30 = sin( basegfx::deg2rad(30.0) );
66     const double off = s30;
67     ::basegfx::B2DPolygon figure;
68     figure.append( ::basegfx::B2DPoint( 0.5 + s30 + off, 0.5 + off ) );
69     figure.append( ::basegfx::B2DPoint( 0.0, -0.5 - s60 ) );
70     figure.append( ::basegfx::B2DPoint( -0.5 - s30 - off, 0.5 + off ) );
71     figure.append( ::basegfx::B2DPoint( 0.0, 0.5 ) );
72     figure.setClosed(true);
73     return new FigureWipe(figure);
74 }
75 
76 FigureWipe * FigureWipe::createPentagonWipe()
77 {
78     const double s = sin( basegfx::deg2rad(18.0) );
79     const double c = cos( basegfx::deg2rad(18.0) );
80     ::basegfx::B2DPolygon figure;
81     figure.append( ::basegfx::B2DPoint( 0.5, 0.5 ) );
82     figure.append( ::basegfx::B2DPoint( 0.5 + s, 0.5 - c ) );
83     figure.append( ::basegfx::B2DPoint( 0.0, 0.5 - c - sin(basegfx::deg2rad(36.0)) ) );
84     figure.append( ::basegfx::B2DPoint( -0.5 - s, 0.5 - c ) );
85     figure.append( ::basegfx::B2DPoint( -0.5, 0.5 ) );
86     figure.setClosed(true);
87     return new FigureWipe(figure);
88 }
89 
90 FigureWipe * FigureWipe::createHexagonWipe()
91 {
92     const double s = sin( basegfx::deg2rad(30.0) );
93     const double c = cos( basegfx::deg2rad(30.0) );
94     ::basegfx::B2DPolygon figure;
95     figure.append( ::basegfx::B2DPoint( 0.5, c ) );
96     figure.append( ::basegfx::B2DPoint( 0.5 + s, 0.0 ) );
97     figure.append( ::basegfx::B2DPoint( 0.5, -c ) );
98     figure.append( ::basegfx::B2DPoint( -0.5, -c ) );
99     figure.append( ::basegfx::B2DPoint( -0.5 - s, 0.0 ) );
100     figure.append( ::basegfx::B2DPoint( -0.5, c ) );
101     figure.setClosed(true);
102     return new FigureWipe(figure);
103 }
104 
105 FigureWipe * FigureWipe::createStarWipe( sal_Int32 nPoints )
106 {
107     const double v = (M_PI / nPoints);
108     const ::basegfx::B2DPoint p_( 0.0, -M_SQRT2 );
109     ::basegfx::B2DPolygon figure;
110     for ( sal_Int32 pos = 0; pos < nPoints; ++pos ) {
111         const double w = (pos * 2.0 * M_PI / nPoints);
112         ::basegfx::B2DHomMatrix aTransform;
113         ::basegfx::B2DPoint p(p_);
114         aTransform.rotate( -w );
115         p *= aTransform;
116         figure.append(p);
117         p = p_;
118         aTransform.identity();
119         aTransform.scale( 0.5, 0.5 );
120         aTransform.rotate( -w - v );
121         p *= aTransform;
122         figure.append(p);
123     }
124     figure.setClosed(true);
125     return new FigureWipe(figure);
126 }
127 
128 }
129 }
130