1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX
29*cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <cppcanvas/customsprite.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
34*cdf0e10cSrcweir #include <basegfx/vector/b2dsize.hxx>
35*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
36*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "viewlayer.hxx"
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <boost/optional.hpp>
41*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
42*cdf0e10cSrcweir #include <boost/noncopyable.hpp>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir /* Definition of AnimatedSprite class */
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir namespace slideshow
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir     namespace internal
50*cdf0e10cSrcweir     {
51*cdf0e10cSrcweir         /** This class provides the sprite for animated shapes.
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 			Besides encapsulating the Canvas sprite for animated
54*cdf0e10cSrcweir 			shapes, this class also handles dynamic sprite resizing
55*cdf0e10cSrcweir 			and all the gory details of offset calculations and
56*cdf0e10cSrcweir 			rounding prevention.
57*cdf0e10cSrcweir          */
58*cdf0e10cSrcweir         class AnimatedSprite : private boost::noncopyable
59*cdf0e10cSrcweir         {
60*cdf0e10cSrcweir         public:
61*cdf0e10cSrcweir             /** Create a new AnimatedSprite, for the given metafile
62*cdf0e10cSrcweir                 shape.
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir                 @param rViewLayer
65*cdf0e10cSrcweir                 The destination view layer, on which the animation should appear
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir             	@param rSpriteSizePixel
68*cdf0e10cSrcweir                 The overall size of the sprite in device coordinate
69*cdf0e10cSrcweir                 space, sufficient to display all transformations,
70*cdf0e10cSrcweir                 shape changes and clips.
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir                 @param nSpritePrio
73*cdf0e10cSrcweir                 Priority of the sprite. Must remain static over the
74*cdf0e10cSrcweir                 lifetime of this object
75*cdf0e10cSrcweir              */
76*cdf0e10cSrcweir             AnimatedSprite( const ViewLayerSharedPtr&	rViewLayer,
77*cdf0e10cSrcweir                             const ::basegfx::B2DSize&	rSpriteSizePixel,
78*cdf0e10cSrcweir                             double                      nSpritePrio );
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir             /** Resize the sprite.
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir             	@param rSpriteSizePixel
83*cdf0e10cSrcweir                 The new size in pixel
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir                 @return true, if the resize was successful. If false
86*cdf0e10cSrcweir                 is returned, the sprite might be invalid.
87*cdf0e10cSrcweir              */
88*cdf0e10cSrcweir             bool resize( const ::basegfx::B2DSize& rSpriteSizePixel );
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir             /** Set an offset for the content output in pixel
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir             	This method offsets the output on the sprite content
93*cdf0e10cSrcweir             	canvas by the specified amount of device pixel (for
94*cdf0e10cSrcweir             	subsequent render operations).
95*cdf0e10cSrcweir              */
96*cdf0e10cSrcweir             void 				setPixelOffset( const ::basegfx::B2DSize& rPixelOffset );
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir             /// Retrieve current pixel offset for content output.
99*cdf0e10cSrcweir             ::basegfx::B2DSize	getPixelOffset() const;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir             /// Show the sprite
102*cdf0e10cSrcweir             void show();
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir             /// Hide the sprite
105*cdf0e10cSrcweir             void hide();
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir             /** Query the content canvas for the current sprite.
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir             	Note that this method must be called
110*cdf0e10cSrcweir             	<em>everytime</em> something is rendered to the
111*cdf0e10cSrcweir             	sprite, because XCustomSprite does not guarantee the
112*cdf0e10cSrcweir             	validity of the canvas after a render operation.
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir                 Furthermore, the view transformation on the returned
115*cdf0e10cSrcweir                 canvas is already correctly setup, matching the
116*cdf0e10cSrcweir                 associated destination canvas.
117*cdf0e10cSrcweir              */
118*cdf0e10cSrcweir             ::cppcanvas::CanvasSharedPtr getContentCanvas() const;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir             /** Move the sprite in device pixel space.
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
123*cdf0e10cSrcweir             	effect.
124*cdf0e10cSrcweir              */
125*cdf0e10cSrcweir             void movePixel( const ::basegfx::B2DPoint& rNewPos );
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir             /** Set the alpha value of the sprite.
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
130*cdf0e10cSrcweir             	effect.
131*cdf0e10cSrcweir              */
132*cdf0e10cSrcweir             void setAlpha( double rAlpha );
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir             /** Set a sprite clip in user coordinate space.
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
137*cdf0e10cSrcweir             	effect.
138*cdf0e10cSrcweir              */
139*cdf0e10cSrcweir             void clip( const ::basegfx::B2DPolyPolygon& rClip );
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir             /** Clears a sprite clip
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
144*cdf0e10cSrcweir             	effect.
145*cdf0e10cSrcweir              */
146*cdf0e10cSrcweir             void clip();
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir             /** Set a sprite transformation.
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
151*cdf0e10cSrcweir             	effect.
152*cdf0e10cSrcweir              */
153*cdf0e10cSrcweir             void transform( const ::basegfx::B2DHomMatrix& rTransform );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir             /** Set the sprite priority.
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 				The sprite priority determines the ordering of the
158*cdf0e10cSrcweir 				sprites on screen, i.e. which sprite lies before which.
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir                 @param rPrio
161*cdf0e10cSrcweir                 The new sprite prio. Must be in the range [0,1]
162*cdf0e10cSrcweir              */
163*cdf0e10cSrcweir             void setPriority( double rPrio );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         private:
166*cdf0e10cSrcweir             ViewLayerSharedPtr											mpViewLayer;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir             ::cppcanvas::CustomSpriteSharedPtr							mpSprite;
169*cdf0e10cSrcweir             ::basegfx::B2DSize											maEffectiveSpriteSizePixel;
170*cdf0e10cSrcweir             ::basegfx::B2DSize											maContentPixelOffset;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir             double                                                      mnSpritePrio;
173*cdf0e10cSrcweir             double														mnAlpha;
174*cdf0e10cSrcweir             ::boost::optional< ::basegfx::B2DPoint >                    maPosPixel;
175*cdf0e10cSrcweir             ::boost::optional< ::basegfx::B2DPolyPolygon >              maClip;
176*cdf0e10cSrcweir             ::boost::optional< ::basegfx::B2DHomMatrix >                maTransform;
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir             bool														mbSpriteVisible;
179*cdf0e10cSrcweir         };
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir         typedef ::boost::shared_ptr< AnimatedSprite > AnimatedSpriteSharedPtr;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX */
187