1aaef562fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3aaef562fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4aaef562fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5aaef562fSAndrew Rist  * distributed with this work for additional information
6aaef562fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7aaef562fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8aaef562fSAndrew Rist  * "License"); you may not use this file except in compliance
9aaef562fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10aaef562fSAndrew Rist  *
11aaef562fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12aaef562fSAndrew Rist  *
13aaef562fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14aaef562fSAndrew Rist  * software distributed under the License is distributed on an
15aaef562fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16aaef562fSAndrew Rist  * KIND, either express or implied.  See the License for the
17aaef562fSAndrew Rist  * specific language governing permissions and limitations
18aaef562fSAndrew Rist  * under the License.
19aaef562fSAndrew Rist  *
20aaef562fSAndrew Rist  *************************************************************/
21aaef562fSAndrew Rist 
22aaef562fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX
25cdf0e10cSrcweir #define INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <cppcanvas/customsprite.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
30cdf0e10cSrcweir #include <basegfx/vector/b2dsize.hxx>
31cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "viewlayer.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <boost/optional.hpp>
37cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
38cdf0e10cSrcweir #include <boost/noncopyable.hpp>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir /* Definition of AnimatedSprite class */
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace slideshow
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     namespace internal
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir         /** This class provides the sprite for animated shapes.
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 			Besides encapsulating the Canvas sprite for animated
50cdf0e10cSrcweir 			shapes, this class also handles dynamic sprite resizing
51cdf0e10cSrcweir 			and all the gory details of offset calculations and
52cdf0e10cSrcweir 			rounding prevention.
53cdf0e10cSrcweir          */
54cdf0e10cSrcweir         class AnimatedSprite : private boost::noncopyable
55cdf0e10cSrcweir         {
56cdf0e10cSrcweir         public:
57cdf0e10cSrcweir             /** Create a new AnimatedSprite, for the given metafile
58cdf0e10cSrcweir                 shape.
59cdf0e10cSrcweir 
60cdf0e10cSrcweir                 @param rViewLayer
61cdf0e10cSrcweir                 The destination view layer, on which the animation should appear
62cdf0e10cSrcweir 
63cdf0e10cSrcweir             	@param rSpriteSizePixel
64cdf0e10cSrcweir                 The overall size of the sprite in device coordinate
65cdf0e10cSrcweir                 space, sufficient to display all transformations,
66cdf0e10cSrcweir                 shape changes and clips.
67cdf0e10cSrcweir 
68cdf0e10cSrcweir                 @param nSpritePrio
69cdf0e10cSrcweir                 Priority of the sprite. Must remain static over the
70cdf0e10cSrcweir                 lifetime of this object
71cdf0e10cSrcweir              */
72cdf0e10cSrcweir             AnimatedSprite( const ViewLayerSharedPtr&	rViewLayer,
73cdf0e10cSrcweir                             const ::basegfx::B2DSize&	rSpriteSizePixel,
74cdf0e10cSrcweir                             double                      nSpritePrio );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir             /** Resize the sprite.
77cdf0e10cSrcweir 
78cdf0e10cSrcweir             	@param rSpriteSizePixel
79cdf0e10cSrcweir                 The new size in pixel
80cdf0e10cSrcweir 
81cdf0e10cSrcweir                 @return true, if the resize was successful. If false
82cdf0e10cSrcweir                 is returned, the sprite might be invalid.
83cdf0e10cSrcweir              */
84cdf0e10cSrcweir             bool resize( const ::basegfx::B2DSize& rSpriteSizePixel );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir             /** Set an offset for the content output in pixel
87cdf0e10cSrcweir 
88cdf0e10cSrcweir             	This method offsets the output on the sprite content
89cdf0e10cSrcweir             	canvas by the specified amount of device pixel (for
90cdf0e10cSrcweir             	subsequent render operations).
91cdf0e10cSrcweir              */
92cdf0e10cSrcweir             void 				setPixelOffset( const ::basegfx::B2DSize& rPixelOffset );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir             /// Retrieve current pixel offset for content output.
95cdf0e10cSrcweir             ::basegfx::B2DSize	getPixelOffset() const;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             /// Show the sprite
98cdf0e10cSrcweir             void show();
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             /// Hide the sprite
101cdf0e10cSrcweir             void hide();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             /** Query the content canvas for the current sprite.
104cdf0e10cSrcweir 
105cdf0e10cSrcweir             	Note that this method must be called
106*86e1cf34SPedro Giffuni             	<em>every time</em> something is rendered to the
107cdf0e10cSrcweir             	sprite, because XCustomSprite does not guarantee the
108cdf0e10cSrcweir             	validity of the canvas after a render operation.
109cdf0e10cSrcweir 
110cdf0e10cSrcweir                 Furthermore, the view transformation on the returned
111cdf0e10cSrcweir                 canvas is already correctly setup, matching the
112cdf0e10cSrcweir                 associated destination canvas.
113cdf0e10cSrcweir              */
114cdf0e10cSrcweir             ::cppcanvas::CanvasSharedPtr getContentCanvas() const;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir             /** Move the sprite in device pixel space.
117cdf0e10cSrcweir 
118cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
119cdf0e10cSrcweir             	effect.
120cdf0e10cSrcweir              */
121cdf0e10cSrcweir             void movePixel( const ::basegfx::B2DPoint& rNewPos );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir             /** Set the alpha value of the sprite.
124cdf0e10cSrcweir 
125cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
126cdf0e10cSrcweir             	effect.
127cdf0e10cSrcweir              */
128cdf0e10cSrcweir             void setAlpha( double rAlpha );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir             /** Set a sprite clip in user coordinate space.
131cdf0e10cSrcweir 
132cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
133cdf0e10cSrcweir             	effect.
134cdf0e10cSrcweir              */
135cdf0e10cSrcweir             void clip( const ::basegfx::B2DPolyPolygon& rClip );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir             /** Clears a sprite clip
138cdf0e10cSrcweir 
139cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
140cdf0e10cSrcweir             	effect.
141cdf0e10cSrcweir              */
142cdf0e10cSrcweir             void clip();
143cdf0e10cSrcweir 
144cdf0e10cSrcweir             /** Set a sprite transformation.
145cdf0e10cSrcweir 
146cdf0e10cSrcweir             	If the sprite is not yet created, this method has no
147cdf0e10cSrcweir             	effect.
148cdf0e10cSrcweir              */
149cdf0e10cSrcweir             void transform( const ::basegfx::B2DHomMatrix& rTransform );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir             /** Set the sprite priority.
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 				The sprite priority determines the ordering of the
154cdf0e10cSrcweir 				sprites on screen, i.e. which sprite lies before which.
155cdf0e10cSrcweir 
156cdf0e10cSrcweir                 @param rPrio
157cdf0e10cSrcweir                 The new sprite prio. Must be in the range [0,1]
158cdf0e10cSrcweir              */
159cdf0e10cSrcweir             void setPriority( double rPrio );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         private:
162cdf0e10cSrcweir             ViewLayerSharedPtr											mpViewLayer;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir             ::cppcanvas::CustomSpriteSharedPtr							mpSprite;
165cdf0e10cSrcweir             ::basegfx::B2DSize											maEffectiveSpriteSizePixel;
166cdf0e10cSrcweir             ::basegfx::B2DSize											maContentPixelOffset;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir             double                                                      mnSpritePrio;
169cdf0e10cSrcweir             double														mnAlpha;
170cdf0e10cSrcweir             ::boost::optional< ::basegfx::B2DPoint >                    maPosPixel;
171cdf0e10cSrcweir             ::boost::optional< ::basegfx::B2DPolyPolygon >              maClip;
172cdf0e10cSrcweir             ::boost::optional< ::basegfx::B2DHomMatrix >                maTransform;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir             bool														mbSpriteVisible;
175cdf0e10cSrcweir         };
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         typedef ::boost::shared_ptr< AnimatedSprite > AnimatedSpriteSharedPtr;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir #endif /* INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX */
183