1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: animatedsprite.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX
32 #define INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX
34 #include <cppcanvas/customsprite.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
37 #include <basegfx/vector/b2dsize.hxx>
38 #include <basegfx/point/b2dpoint.hxx>
39 #include <basegfx/polygon/b2dpolypolygon.hxx>
41 #include "viewlayer.hxx"
43 #include <boost/optional.hpp>
44 #include <boost/shared_ptr.hpp>
45 #include <boost/noncopyable.hpp>
48 /* Definition of AnimatedSprite class */
54 /** This class provides the sprite for animated shapes.
56 Besides encapsulating the Canvas sprite for animated
57 shapes, this class also handles dynamic sprite resizing
58 and all the gory details of offset calculations and
61 class AnimatedSprite
: private boost::noncopyable
64 /** Create a new AnimatedSprite, for the given metafile
68 The destination view layer, on which the animation should appear
70 @param rSpriteSizePixel
71 The overall size of the sprite in device coordinate
72 space, sufficient to display all transformations,
73 shape changes and clips.
76 Priority of the sprite. Must remain static over the
77 lifetime of this object
79 AnimatedSprite( const ViewLayerSharedPtr
& rViewLayer
,
80 const ::basegfx::B2DSize
& rSpriteSizePixel
,
83 /** Resize the sprite.
85 @param rSpriteSizePixel
88 @return true, if the resize was successful. If false
89 is returned, the sprite might be invalid.
91 bool resize( const ::basegfx::B2DSize
& rSpriteSizePixel
);
93 /** Set an offset for the content output in pixel
95 This method offsets the output on the sprite content
96 canvas by the specified amount of device pixel (for
97 subsequent render operations).
99 void setPixelOffset( const ::basegfx::B2DSize
& rPixelOffset
);
101 /// Retrieve current pixel offset for content output.
102 ::basegfx::B2DSize
getPixelOffset() const;
110 /** Query the content canvas for the current sprite.
112 Note that this method must be called
113 <em>everytime</em> something is rendered to the
114 sprite, because XCustomSprite does not guarantee the
115 validity of the canvas after a render operation.
117 Furthermore, the view transformation on the returned
118 canvas is already correctly setup, matching the
119 associated destination canvas.
121 ::cppcanvas::CanvasSharedPtr
getContentCanvas() const;
123 /** Move the sprite in device pixel space.
125 If the sprite is not yet created, this method has no
128 void movePixel( const ::basegfx::B2DPoint
& rNewPos
);
130 /** Set the alpha value of the sprite.
132 If the sprite is not yet created, this method has no
135 void setAlpha( double rAlpha
);
137 /** Set a sprite clip in user coordinate space.
139 If the sprite is not yet created, this method has no
142 void clip( const ::basegfx::B2DPolyPolygon
& rClip
);
144 /** Clears a sprite clip
146 If the sprite is not yet created, this method has no
151 /** Set a sprite transformation.
153 If the sprite is not yet created, this method has no
156 void transform( const ::basegfx::B2DHomMatrix
& rTransform
);
158 /** Set the sprite priority.
160 The sprite priority determines the ordering of the
161 sprites on screen, i.e. which sprite lies before which.
164 The new sprite prio. Must be in the range [0,1]
166 void setPriority( double rPrio
);
169 ViewLayerSharedPtr mpViewLayer
;
171 ::cppcanvas::CustomSpriteSharedPtr mpSprite
;
172 ::basegfx::B2DSize maEffectiveSpriteSizePixel
;
173 ::basegfx::B2DSize maContentPixelOffset
;
177 ::boost::optional
< ::basegfx::B2DPoint
> maPosPixel
;
178 ::boost::optional
< ::basegfx::B2DPolyPolygon
> maClip
;
179 ::boost::optional
< ::basegfx::B2DHomMatrix
> maTransform
;
181 bool mbSpriteVisible
;
184 typedef ::boost::shared_ptr
< AnimatedSprite
> AnimatedSpriteSharedPtr
;
189 #endif /* INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX */