xref: /AOO41X/main/canvas/inc/canvas/base/canvascustomspritehelper.hxx (revision 91c99ff47293b0d0832bde809a8978c8bfc37548)
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_CANVAS_CANVASCUSTOMSPRITEHELPER_HXX
25 #define INCLUDED_CANVAS_CANVASCUSTOMSPRITEHELPER_HXX
26 
27 #include <com/sun/star/rendering/XCustomSprite.hpp>
28 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
29 #include <basegfx/point/b2dpoint.hxx>
30 #include <basegfx/vector/b2dvector.hxx>
31 #include <basegfx/range/b2drange.hxx>
32 #include <basegfx/matrix/b2dhommatrix.hxx>
33 #include <canvas/base/spritesurface.hxx>
34 
35 
36 namespace canvas
37 {
38     /* Definition of CanvasCustomSpriteHelper class */
39 
40     /** Base class for an XSprite helper implementation - to be used
41         in concert with CanvasCustomSpriteBase
42      */
43     class CanvasCustomSpriteHelper
44     {
45     public:
46         CanvasCustomSpriteHelper();
~CanvasCustomSpriteHelper()47         virtual ~CanvasCustomSpriteHelper() {}
48 
49         /** Init helper
50 
51             @param rSpriteSize
52             Requested size of the sprite, as passed to the
53             XSpriteCanvas::createCustomSprite() method
54 
55             @param rOwningSpriteCanvas
56             The XSpriteCanvas this sprite is displayed on
57          */
58         void init( const ::com::sun::star::geometry::RealSize2D&    rSpriteSize,
59                    const SpriteSurface::Reference&                  rOwningSpriteCanvas );
60 
61         /** Object is being disposed, release all internal references
62 
63             @derive when overriding this method in derived classes,
64             <em>always</em> call the base class' method!
65          */
66         void disposing();
67 
68         // XCanvas
69         /// need  to call this method for XCanvas::clear(), for opacity tracking
70         void clearingContent( const Sprite::Reference& rSprite );
71 
72         /// need to call this method for XCanvas::drawBitmap(), for opacity tracking
73         void checkDrawBitmap( const Sprite::Reference&                                                          rSprite,
74                               const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >&   xBitmap,
75                               const ::com::sun::star::rendering::ViewState&                                     viewState,
76                               const ::com::sun::star::rendering::RenderState&                                   renderState );
77 
78         // XSprite
79         void setAlpha( const Sprite::Reference& rSprite,
80                        double                   alpha );
81         void move( const Sprite::Reference&                         rSprite,
82                    const ::com::sun::star::geometry::RealPoint2D&   aNewPos,
83                    const ::com::sun::star::rendering::ViewState&    viewState,
84                    const ::com::sun::star::rendering::RenderState&  renderState );
85         void transform( const Sprite::Reference&                            rSprite,
86                        const ::com::sun::star::geometry::AffineMatrix2D&    aTransformation );
87         void clip( const Sprite::Reference&                                                                 rSprite,
88                    const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >&   aClip );
89         void setPriority( const Sprite::Reference&  rSprite,
90                           double                    nPriority );
91         void show( const Sprite::Reference& rSprite );
92         void hide( const Sprite::Reference& rSprite );
93 
94         // Sprite
95         bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const;
96         ::basegfx::B2DPoint  getPosPixel() const;
97         ::basegfx::B2DVector getSizePixel() const;
98         ::basegfx::B2DRange  getUpdateArea() const;
99         double               getPriority() const;
100 
101         // redraw must be implemented by derived - non sensible default implementation
102         // void redraw( const Sprite::Reference& rSprite,
103         //              const ::basegfx::B2DPoint& rPos ) const;
104 
105 
106         // Helper methods for derived classes
107         // ----------------------------------
108 
109         /// Calc sprite update area from given raw sprite bounds
110         ::basegfx::B2DRange getUpdateArea( const ::basegfx::B2DRange& rUntransformedSpriteBounds ) const;
111 
112         /// Calc update area for unclipped sprite content
113         ::basegfx::B2DRange getFullSpriteRect() const;
114 
115         /** Returns true, if sprite content bitmap is fully opaque.
116 
117             This does not take clipping or transformation into
118             account, but only denotes that the sprite bitmap's alpha
119             channel is all 1.0
120          */
isContentFullyOpaque() const121         bool isContentFullyOpaque() const { return mbIsContentFullyOpaque; }
122 
123         /// Returns true, if transformation has changed since last transformUpdated() call
hasAlphaChanged() const124         bool hasAlphaChanged() const { return mbAlphaDirty; }
125 
126         /// Returns true, if transformation has changed since last transformUpdated() call
hasPositionChanged() const127         bool hasPositionChanged() const { return mbPositionDirty; }
128 
129         /// Returns true, if transformation has changed since last transformUpdated() call
hasTransformChanged() const130         bool hasTransformChanged() const { return mbTransformDirty; }
131 
132         /// Returns true, if transformation has changed since last transformUpdated() call
hasClipChanged() const133         bool hasClipChanged() const { return mbClipDirty; }
134 
135         /// Returns true, if transformation has changed since last transformUpdated() call
hasPrioChanged() const136         bool hasPrioChanged() const { return mbPrioDirty; }
137 
138         /// Returns true, if transformation has changed since last transformUpdated() call
hasVisibilityChanged() const139         bool hasVisibilityChanged() const { return mbVisibilityDirty; }
140 
141         /// Retrieve current alpha value
getAlpha() const142         double getAlpha() const { return mfAlpha; }
143 
144         /// Retrieve current clip
145         const ::com::sun::star::uno::Reference<
getClip() const146             ::com::sun::star::rendering::XPolyPolygon2D >& getClip() const { return mxClipPoly; }
147 
getTransformation() const148         const ::basegfx::B2DHomMatrix& getTransformation() const { return maTransform; }
149 
150         /// Retrieve current activation state
isActive() const151         bool isActive() const { return mbActive; }
152 
153     protected:
154         /** Notifies that caller is again in sync with current alph
155 
156             const, but modifies state visible to derived
157             classes. beware of passing this information to the
158             outside!
159          */
alphaUpdated() const160         void alphaUpdated() const { mbAlphaDirty=false; }
161 
162         /** Notifies that caller is again in sync with current position
163 
164             const, but modifies state visible to derived
165             classes. beware of passing this information to the
166             outside!
167          */
positionUpdated() const168         void positionUpdated() const { mbPositionDirty=false; }
169 
170         /** Notifies that caller is again in sync with current transformation
171 
172             const, but modifies state visible to derived
173             classes. beware of passing this information to the
174             outside!
175          */
transformUpdated() const176         void transformUpdated() const { mbTransformDirty=false; }
177 
178         /** Notifies that caller is again in sync with current clip
179 
180             const, but modifies state visible to derived
181             classes. beware of passing this information to the
182             outside!
183          */
clipUpdated() const184         void clipUpdated() const { mbClipDirty=false; }
185 
186         /** Notifies that caller is again in sync with current priority
187 
188             const, but modifies state visible to derived
189             classes. beware of passing this information to the
190             outside!
191          */
prioUpdated() const192         void prioUpdated() const { mbPrioDirty=false; }
193 
194         /** Notifies that caller is again in sync with current visibility
195 
196             const, but modifies state visible to derived
197             classes. beware of passing this information to the
198             outside!
199          */
visibilityUpdated() const200         void visibilityUpdated() const { mbVisibilityDirty=false; }
201 
202     private:
203         CanvasCustomSpriteHelper( const CanvasCustomSpriteHelper& );
204         CanvasCustomSpriteHelper& operator=( const CanvasCustomSpriteHelper& );
205 
206         /** Called to convert an API polygon to a basegfx polygon
207 
208             @derive Needs to be provided by backend-specific code
209          */
210         virtual ::basegfx::B2DPolyPolygon polyPolygonFromXPolyPolygon2D(
211             ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPoly ) const = 0;
212 
213         /** Update clip information from current state
214 
215             This method recomputes the maCurrClipBounds and
216             mbIsCurrClipRectangle members from the current clip and
217             transformation. IFF the clip changed from rectangular to
218             rectangular again, this method issues a sequence of
219             optimized SpriteSurface::updateSprite() calls.
220 
221             @return true, if SpriteSurface::updateSprite() was already
222             called within this method.
223          */
224         bool updateClipState( const Sprite::Reference& rSprite );
225 
226         // --------------------------------------------------------------------
227 
228         /// Owning sprite canvas
229         SpriteSurface::Reference                            mpSpriteCanvas;
230 
231         /** Currently active clip area.
232 
233             This member is either empty, denoting that the current
234             clip shows the full sprite content, or contains a
235             rectangular subarea of the sprite, outside of which
236             the sprite content is fully clipped.
237 
238             @see mbIsCurrClipRectangle
239          */
240         ::basegfx::B2DRange                                 maCurrClipBounds;
241 
242         // sprite state
243         ::basegfx::B2DPoint                                 maPosition;
244         ::basegfx::B2DVector                                maSize;
245         ::basegfx::B2DHomMatrix                             maTransform;
246         ::com::sun::star::uno::Reference<
247               ::com::sun::star::rendering::XPolyPolygon2D > mxClipPoly;
248         double                                              mfPriority;
249         double                                              mfAlpha;
250         bool                                                mbActive; // true, if not hidden
251 
252         /** If true, denotes that the current sprite clip is a true
253             rectangle, i.e. maCurrClipBounds <em>exactly</em>
254             describes the visible area of the sprite.
255 
256             @see maCurrClipBounds
257          */
258         bool                                                mbIsCurrClipRectangle;
259 
260         /** Redraw speedup.
261 
262             When true, this flag denotes that the current sprite
263             content is fully opaque, thus, that blits to the screen do
264             neither have to take alpha into account, nor prepare any
265             background for the sprite area.
266          */
267         mutable bool                                        mbIsContentFullyOpaque;
268 
269         /// True, iff mfAlpha has changed
270         mutable bool                                        mbAlphaDirty;
271 
272         /// True, iff maPosition has changed
273         mutable bool                                        mbPositionDirty;
274 
275         /// True, iff maTransform has changed
276         mutable bool                                        mbTransformDirty;
277 
278         /// True, iff mxClipPoly has changed
279         mutable bool                                        mbClipDirty;
280 
281         /// True, iff mnPriority has changed
282         mutable bool                                        mbPrioDirty;
283 
284         /// True, iff mbActive has changed
285         mutable bool                                        mbVisibilityDirty;
286     };
287 }
288 
289 #endif /* INCLUDED_CANVAS_CANVASCUSTOMSPRITEHELPER_HXX */
290