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