/src/libreoffice/canvas/inc/base/canvascustomspritehelper.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <basegfx/matrix/b2dhommatrix.hxx> |
23 | | #include <basegfx/point/b2dpoint.hxx> |
24 | | #include <basegfx/polygon/b2dpolypolygon.hxx> |
25 | | #include <basegfx/range/b2drange.hxx> |
26 | | #include <basegfx/vector/b2dvector.hxx> |
27 | | #include <base/spritesurface.hxx> |
28 | | #include <canvas/canvastoolsdllapi.h> |
29 | | |
30 | | namespace com::sun::star::geometry { struct AffineMatrix2D; } |
31 | | namespace com::sun::star::geometry { struct RealPoint2D; } |
32 | | namespace com::sun::star::geometry { struct RealSize2D; } |
33 | | namespace com::sun::star::rendering { class XBitmap; } |
34 | | namespace com::sun::star::rendering { class XPolyPolygon2D; } |
35 | | namespace com::sun::star::rendering { struct RenderState; } |
36 | | namespace com::sun::star::rendering { struct ViewState; } |
37 | | |
38 | | |
39 | | namespace canvas |
40 | | { |
41 | | /* Definition of CanvasCustomSpriteHelper class */ |
42 | | |
43 | | /** Base class for an XSprite helper implementation - to be used |
44 | | in concert with CanvasCustomSpriteBase |
45 | | */ |
46 | | class CANVASTOOLS_DLLPUBLIC CanvasCustomSpriteHelper |
47 | | { |
48 | | public: |
49 | | CanvasCustomSpriteHelper(); |
50 | 0 | virtual ~CanvasCustomSpriteHelper() {} |
51 | | |
52 | | /** Init helper |
53 | | |
54 | | @param rSpriteSize |
55 | | Requested size of the sprite, as passed to the |
56 | | XSpriteCanvas::createCustomSprite() method |
57 | | |
58 | | @param rOwningSpriteCanvas |
59 | | The XSpriteCanvas this sprite is displayed on |
60 | | */ |
61 | | void init( const css::geometry::RealSize2D& rSpriteSize, |
62 | | const SpriteSurface::Reference& rOwningSpriteCanvas ); |
63 | | |
64 | | /** Object is being disposed, release all internal references |
65 | | |
66 | | @derive when overriding this method in derived classes, |
67 | | <em>always</em> call the base class' method! |
68 | | */ |
69 | | void disposing(); |
70 | | |
71 | | // XCanvas |
72 | | /// need to call this method for XCanvas::clear(), for opacity tracking |
73 | | void clearingContent( const Sprite::Reference& rSprite ); |
74 | | |
75 | | /// need to call this method for XCanvas::drawBitmap(), for opacity tracking |
76 | | void checkDrawBitmap( const Sprite::Reference& rSprite, |
77 | | const css::uno::Reference< css::rendering::XBitmap >& xBitmap, |
78 | | const css::rendering::ViewState& viewState, |
79 | | const css::rendering::RenderState& renderState ); |
80 | | |
81 | | // XSprite |
82 | | void setAlpha( const Sprite::Reference& rSprite, |
83 | | double alpha ); |
84 | | void move( const Sprite::Reference& rSprite, |
85 | | const css::geometry::RealPoint2D& aNewPos, |
86 | | const css::rendering::ViewState& viewState, |
87 | | const css::rendering::RenderState& renderState ); |
88 | | void transform( const Sprite::Reference& rSprite, |
89 | | const css::geometry::AffineMatrix2D& aTransformation ); |
90 | | void clip( const Sprite::Reference& rSprite, |
91 | | const css::uno::Reference< css::rendering::XPolyPolygon2D >& aClip ); |
92 | | void setPriority( const Sprite::Reference& rSprite, |
93 | | double nPriority ); |
94 | | void show( const Sprite::Reference& rSprite ); |
95 | | void hide( const Sprite::Reference& rSprite ); |
96 | | |
97 | | // Sprite |
98 | | bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const; |
99 | 0 | const ::basegfx::B2DPoint& getPosPixel() const { return maPosition; } |
100 | 0 | const ::basegfx::B2DVector& getSizePixel() const { return maSize; } |
101 | | ::basegfx::B2DRange getUpdateArea() const; |
102 | 0 | double getPriority() const { return mfPriority; } |
103 | | |
104 | | // redraw must be implemented by derived - non sensible default implementation |
105 | | // void redraw( const Sprite::Reference& rSprite, |
106 | | // const ::basegfx::B2DPoint& rPos ) const; |
107 | | |
108 | | |
109 | | // Helper methods for derived classes |
110 | | |
111 | | |
112 | | /// Calc sprite update area from given raw sprite bounds |
113 | | ::basegfx::B2DRange getUpdateArea( const ::basegfx::B2DRange& rUntransformedSpriteBounds ) 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 | | */ |
121 | 0 | bool isContentFullyOpaque() const { return mbIsContentFullyOpaque; } |
122 | | |
123 | | /// Returns true, if transformation has changed since last transformUpdated() call |
124 | 0 | bool hasTransformChanged() const { return mbTransformDirty; } |
125 | | |
126 | | /// Retrieve current alpha value |
127 | 0 | double getAlpha() const { return mfAlpha; } |
128 | | |
129 | | /// Retrieve current clip |
130 | | const css::uno::Reference< |
131 | 0 | css::rendering::XPolyPolygon2D >& getClip() const { return mxClipPoly; } |
132 | | |
133 | 0 | const ::basegfx::B2DHomMatrix& getTransformation() const { return maTransform; } |
134 | | |
135 | | /// Retrieve current activation state |
136 | 0 | bool isActive() const { return mbActive; } |
137 | | |
138 | | protected: |
139 | | /** Notifies that caller is again in sync with current transformation |
140 | | |
141 | | const, but modifies state visible to derived |
142 | | classes. beware of passing this information to the |
143 | | outside! |
144 | | */ |
145 | 0 | void transformUpdated() const { mbTransformDirty=false; } |
146 | | |
147 | | private: |
148 | | CanvasCustomSpriteHelper( const CanvasCustomSpriteHelper& ) = delete; |
149 | | CanvasCustomSpriteHelper& operator=( const CanvasCustomSpriteHelper& ) = delete; |
150 | | |
151 | | /** Called to convert an API polygon to a basegfx polygon |
152 | | |
153 | | @derive Needs to be provided by backend-specific code |
154 | | */ |
155 | | virtual ::basegfx::B2DPolyPolygon polyPolygonFromXPolyPolygon2D( |
156 | | css::uno::Reference< css::rendering::XPolyPolygon2D >& xPoly ) const = 0; |
157 | | |
158 | | /** Update clip information from current state |
159 | | |
160 | | This method recomputes the maCurrClipBounds and |
161 | | mbIsCurrClipRectangle members from the current clip and |
162 | | transformation. IFF the clip changed from rectangular to |
163 | | rectangular again, this method issues a sequence of |
164 | | optimized SpriteSurface::updateSprite() calls. |
165 | | |
166 | | @return true, if SpriteSurface::updateSprite() was already |
167 | | called within this method. |
168 | | */ |
169 | | bool updateClipState( const Sprite::Reference& rSprite ); |
170 | | |
171 | | |
172 | | /// Owning sprite canvas |
173 | | SpriteSurface::Reference mpSpriteCanvas; |
174 | | |
175 | | /** Currently active clip area. |
176 | | |
177 | | This member is either empty, denoting that the current |
178 | | clip shows the full sprite content, or contains a |
179 | | rectangular subarea of the sprite, outside of which |
180 | | the sprite content is fully clipped. |
181 | | |
182 | | @see mbIsCurrClipRectangle |
183 | | */ |
184 | | ::basegfx::B2DRange maCurrClipBounds; |
185 | | |
186 | | // sprite state |
187 | | ::basegfx::B2DPoint maPosition; |
188 | | ::basegfx::B2DVector maSize; |
189 | | ::basegfx::B2DHomMatrix maTransform; |
190 | | css::uno::Reference< css::rendering::XPolyPolygon2D > mxClipPoly; |
191 | | double mfPriority; |
192 | | double mfAlpha; |
193 | | bool mbActive; // true, if not hidden |
194 | | |
195 | | /** If true, denotes that the current sprite clip is a true |
196 | | rectangle, i.e. maCurrClipBounds <em>exactly</em> |
197 | | describes the visible area of the sprite. |
198 | | |
199 | | @see maCurrClipBounds |
200 | | */ |
201 | | bool mbIsCurrClipRectangle; |
202 | | |
203 | | /** Redraw speedup. |
204 | | |
205 | | When true, this flag denotes that the current sprite |
206 | | content is fully opaque, thus, that blits to the screen do |
207 | | neither have to take alpha into account, nor prepare any |
208 | | background for the sprite area. |
209 | | */ |
210 | | mutable bool mbIsContentFullyOpaque; |
211 | | |
212 | | /// True, iff maTransform has changed |
213 | | mutable bool mbTransformDirty; |
214 | | }; |
215 | | } |
216 | | |
217 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |