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