Branch libreoffice-5-0-4
[LibreOffice.git] / include / canvas / base / canvascustomspritehelper.hxx
blobb77144d8a50cef6a0f8e1ace92f3e1949058bd36
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEHELPER_HXX
21 #define INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEHELPER_HXX
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>
32 namespace canvas
34 /* Definition of CanvasCustomSpriteHelper class */
36 /** Base class for an XSprite helper implementation - to be used
37 in concert with CanvasCustomSpriteBase
39 class CANVASTOOLS_DLLPUBLIC CanvasCustomSpriteHelper
41 public:
42 CanvasCustomSpriteHelper();
43 virtual ~CanvasCustomSpriteHelper() {}
45 /** Init helper
47 @param rSpriteSize
48 Requested size of the sprite, as passed to the
49 XSpriteCanvas::createCustomSprite() method
51 @param rOwningSpriteCanvas
52 The XSpriteCanvas this sprite is displayed on
54 void init( const ::com::sun::star::geometry::RealSize2D& rSpriteSize,
55 const SpriteSurface::Reference& rOwningSpriteCanvas );
57 /** Object is being disposed, release all internal references
59 @derive when overriding this method in derived classes,
60 <em>always</em> call the base class' method!
62 void disposing();
64 // XCanvas
65 /// need to call this method for XCanvas::clear(), for opacity tracking
66 void clearingContent( const Sprite::Reference& rSprite );
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 );
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 );
90 // Sprite
91 bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const;
92 ::basegfx::B2DPoint getPosPixel() const { return maPosition; }
93 ::basegfx::B2DVector getSizePixel() const { return maSize; }
94 ::basegfx::B2DRange getUpdateArea() const;
95 double getPriority() const { return mfPriority; }
97 // redraw must be implemented by derived - non sensible default implementation
98 // void redraw( const Sprite::Reference& rSprite,
99 // const ::basegfx::B2DPoint& rPos ) const;
102 // Helper methods for derived classes
105 /// Calc sprite update area from given raw sprite bounds
106 ::basegfx::B2DRange getUpdateArea( const ::basegfx::B2DRange& rUntransformedSpriteBounds ) const;
108 /// Calc update area for unclipped sprite content
109 ::basegfx::B2DRange getFullSpriteRect() const;
111 /** Returns true, if sprite content bitmap is fully opaque.
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
117 bool isContentFullyOpaque() const { return mbIsContentFullyOpaque; }
119 /// Returns true, if transformation has changed since last transformUpdated() call
120 bool hasAlphaChanged() const { return mbAlphaDirty; }
122 /// Returns true, if transformation has changed since last transformUpdated() call
123 bool hasPositionChanged() const { return mbPositionDirty; }
125 /// Returns true, if transformation has changed since last transformUpdated() call
126 bool hasTransformChanged() const { return mbTransformDirty; }
128 /// Returns true, if transformation has changed since last transformUpdated() call
129 bool hasClipChanged() const { return mbClipDirty; }
131 /// Returns true, if transformation has changed since last transformUpdated() call
132 bool hasPrioChanged() const { return mbPrioDirty; }
134 /// Returns true, if transformation has changed since last transformUpdated() call
135 bool hasVisibilityChanged() const { return mbVisibilityDirty; }
137 /// Retrieve current alpha value
138 double getAlpha() const { return mfAlpha; }
140 /// Retrieve current clip
141 const ::com::sun::star::uno::Reference<
142 ::com::sun::star::rendering::XPolyPolygon2D >& getClip() const { return mxClipPoly; }
144 const ::basegfx::B2DHomMatrix& getTransformation() const { return maTransform; }
146 /// Retrieve current activation state
147 bool isActive() const { return mbActive; }
149 protected:
150 /** Notifies that caller is again in sync with current alph
152 const, but modifies state visible to derived
153 classes. beware of passing this information to the
154 outside!
156 void alphaUpdated() const { mbAlphaDirty=false; }
158 /** Notifies that caller is again in sync with current position
160 const, but modifies state visible to derived
161 classes. beware of passing this information to the
162 outside!
164 void positionUpdated() const { mbPositionDirty=false; }
166 /** Notifies that caller is again in sync with current transformation
168 const, but modifies state visible to derived
169 classes. beware of passing this information to the
170 outside!
172 void transformUpdated() const { mbTransformDirty=false; }
174 /** Notifies that caller is again in sync with current clip
176 const, but modifies state visible to derived
177 classes. beware of passing this information to the
178 outside!
180 void clipUpdated() const { mbClipDirty=false; }
182 /** Notifies that caller is again in sync with current priority
184 const, but modifies state visible to derived
185 classes. beware of passing this information to the
186 outside!
188 void prioUpdated() const { mbPrioDirty=false; }
190 /** Notifies that caller is again in sync with current visibility
192 const, but modifies state visible to derived
193 classes. beware of passing this information to the
194 outside!
196 void visibilityUpdated() const { mbVisibilityDirty=false; }
198 private:
199 CanvasCustomSpriteHelper( const CanvasCustomSpriteHelper& ) SAL_DELETED_FUNCTION;
200 CanvasCustomSpriteHelper& operator=( const CanvasCustomSpriteHelper& ) SAL_DELETED_FUNCTION;
202 /** Called to convert an API polygon to a basegfx polygon
204 @derive Needs to be provided by backend-specific code
206 virtual ::basegfx::B2DPolyPolygon polyPolygonFromXPolyPolygon2D(
207 ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPoly ) const = 0;
209 /** Update clip information from current state
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.
217 @return true, if SpriteSurface::updateSprite() was already
218 called within this method.
220 bool updateClipState( const Sprite::Reference& rSprite );
224 /// Owning sprite canvas
225 SpriteSurface::Reference mpSpriteCanvas;
227 /** Currently active clip area.
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.
234 @see mbIsCurrClipRectangle
236 ::basegfx::B2DRange maCurrClipBounds;
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
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.
252 @see maCurrClipBounds
254 bool mbIsCurrClipRectangle;
256 /** Redraw speedup.
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.
263 mutable bool mbIsContentFullyOpaque;
265 /// True, iff mfAlpha has changed
266 mutable bool mbAlphaDirty;
268 /// True, iff maPosition has changed
269 mutable bool mbPositionDirty;
271 /// True, iff maTransform has changed
272 mutable bool mbTransformDirty;
274 /// True, iff mxClipPoly has changed
275 mutable bool mbClipDirty;
277 /// True, iff mnPriority has changed
278 mutable bool mbPrioDirty;
280 /// True, iff mbActive has changed
281 mutable bool mbVisibilityDirty;
285 #endif // INCLUDED_CANVAS_BASE_CANVASCUSTOMSPRITEHELPER_HXX
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */