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 #ifndef INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX 29 #define INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX 30 31 #include <cppcanvas/customsprite.hxx> 32 33 #include <basegfx/matrix/b2dhommatrix.hxx> 34 #include <basegfx/vector/b2dsize.hxx> 35 #include <basegfx/point/b2dpoint.hxx> 36 #include <basegfx/polygon/b2dpolypolygon.hxx> 37 38 #include "viewlayer.hxx" 39 40 #include <boost/optional.hpp> 41 #include <boost/shared_ptr.hpp> 42 #include <boost/noncopyable.hpp> 43 44 45 /* Definition of AnimatedSprite class */ 46 47 namespace slideshow 48 { 49 namespace internal 50 { 51 /** This class provides the sprite for animated shapes. 52 53 Besides encapsulating the Canvas sprite for animated 54 shapes, this class also handles dynamic sprite resizing 55 and all the gory details of offset calculations and 56 rounding prevention. 57 */ 58 class AnimatedSprite : private boost::noncopyable 59 { 60 public: 61 /** Create a new AnimatedSprite, for the given metafile 62 shape. 63 64 @param rViewLayer 65 The destination view layer, on which the animation should appear 66 67 @param rSpriteSizePixel 68 The overall size of the sprite in device coordinate 69 space, sufficient to display all transformations, 70 shape changes and clips. 71 72 @param nSpritePrio 73 Priority of the sprite. Must remain static over the 74 lifetime of this object 75 */ 76 AnimatedSprite( const ViewLayerSharedPtr& rViewLayer, 77 const ::basegfx::B2DSize& rSpriteSizePixel, 78 double nSpritePrio ); 79 80 /** Resize the sprite. 81 82 @param rSpriteSizePixel 83 The new size in pixel 84 85 @return true, if the resize was successful. If false 86 is returned, the sprite might be invalid. 87 */ 88 bool resize( const ::basegfx::B2DSize& rSpriteSizePixel ); 89 90 /** Set an offset for the content output in pixel 91 92 This method offsets the output on the sprite content 93 canvas by the specified amount of device pixel (for 94 subsequent render operations). 95 */ 96 void setPixelOffset( const ::basegfx::B2DSize& rPixelOffset ); 97 98 /// Retrieve current pixel offset for content output. 99 ::basegfx::B2DSize getPixelOffset() const; 100 101 /// Show the sprite 102 void show(); 103 104 /// Hide the sprite 105 void hide(); 106 107 /** Query the content canvas for the current sprite. 108 109 Note that this method must be called 110 <em>everytime</em> something is rendered to the 111 sprite, because XCustomSprite does not guarantee the 112 validity of the canvas after a render operation. 113 114 Furthermore, the view transformation on the returned 115 canvas is already correctly setup, matching the 116 associated destination canvas. 117 */ 118 ::cppcanvas::CanvasSharedPtr getContentCanvas() const; 119 120 /** Move the sprite in device pixel space. 121 122 If the sprite is not yet created, this method has no 123 effect. 124 */ 125 void movePixel( const ::basegfx::B2DPoint& rNewPos ); 126 127 /** Set the alpha value of the sprite. 128 129 If the sprite is not yet created, this method has no 130 effect. 131 */ 132 void setAlpha( double rAlpha ); 133 134 /** Set a sprite clip in user coordinate space. 135 136 If the sprite is not yet created, this method has no 137 effect. 138 */ 139 void clip( const ::basegfx::B2DPolyPolygon& rClip ); 140 141 /** Clears a sprite clip 142 143 If the sprite is not yet created, this method has no 144 effect. 145 */ 146 void clip(); 147 148 /** Set a sprite transformation. 149 150 If the sprite is not yet created, this method has no 151 effect. 152 */ 153 void transform( const ::basegfx::B2DHomMatrix& rTransform ); 154 155 /** Set the sprite priority. 156 157 The sprite priority determines the ordering of the 158 sprites on screen, i.e. which sprite lies before which. 159 160 @param rPrio 161 The new sprite prio. Must be in the range [0,1] 162 */ 163 void setPriority( double rPrio ); 164 165 private: 166 ViewLayerSharedPtr mpViewLayer; 167 168 ::cppcanvas::CustomSpriteSharedPtr mpSprite; 169 ::basegfx::B2DSize maEffectiveSpriteSizePixel; 170 ::basegfx::B2DSize maContentPixelOffset; 171 172 double mnSpritePrio; 173 double mnAlpha; 174 ::boost::optional< ::basegfx::B2DPoint > maPosPixel; 175 ::boost::optional< ::basegfx::B2DPolyPolygon > maClip; 176 ::boost::optional< ::basegfx::B2DHomMatrix > maTransform; 177 178 bool mbSpriteVisible; 179 }; 180 181 typedef ::boost::shared_ptr< AnimatedSprite > AnimatedSpriteSharedPtr; 182 183 } 184 } 185 186 #endif /* INCLUDED_SLIDESHOW_ANIMATEDSPRITE_HXX */ 187