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