1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewshape.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_SLIDESHOW_VIEWSHAPE_HXX
32 #define INCLUDED_SLIDESHOW_VIEWSHAPE_HXX
34 #include <cppcanvas/renderer.hxx>
35 #include <cppcanvas/bitmap.hxx>
37 #include <basegfx/range/b2drectangle.hxx>
38 #include <basegfx/polygon/b2dpolygon.hxx>
40 #include <boost/shared_ptr.hpp>
41 #include <boost/utility.hpp>
44 #include "shapeattributelayer.hxx"
45 #include "animatedsprite.hxx"
46 #include "viewlayer.hxx"
47 #include "doctreenode.hxx"
56 /** This class is the viewable representation of a draw
57 document's XShape, associated to a specific View
59 The class is able to render the associated XShape on
62 class ViewShape
: private boost::noncopyable
65 /** Create a ViewShape for the given View
68 The associated View object.
70 explicit ViewShape( const ViewLayerSharedPtr
& rViewLayer
);
72 /** Query the associated view layer of this shape
74 ViewLayerSharedPtr
getViewLayer() const;
76 /** Query dimension of a safety border around the shape for AA
78 If the view performs antialiasing, this method
79 calculates a safety border around the shape, in the
80 shape coordinate system, which is guaranteed to
81 include every pixel touched when rendering the shape.
83 ::basegfx::B2DSize
getAntialiasingBorder() const;
87 //------------------------------------------------------------------
89 /** Notify the ViewShape that an animation starts now
91 This method enters animation mode on the associate
92 target view. The shape can be animated in parallel on
95 @return whether the mode change finished successfully.
97 bool enterAnimationMode();
99 /** Notify the ViewShape that it is no longer animated
101 This methods ends animation mode on the associate
104 void leaveAnimationMode();
106 /** Query whether the ViewShape is currently animated
108 This method checks whether the ViewShape is currently in
111 bool isBackgroundDetached() const { return mbAnimationMode
; }
115 //------------------------------------------------------------------
130 /** Create render argument struct
133 The initial shape bounds
136 The area covered by the shape
139 The current shape bounds
142 The current shape attribute set. Can be NULL, for
143 default attributes. Attention: stored as a reference,
144 thus, parameter object must stay valid!
147 Vector of subset rendering ranges. Attention:
148 stored as a reference, thus, parameter object must
154 RenderArgs( const ::basegfx::B2DRectangle
& rOrigBounds
,
155 const ::basegfx::B2DRectangle
& rUpdateBounds
,
156 const ::basegfx::B2DRectangle
& rBounds
,
157 const ::basegfx::B2DRectangle
& rUnitBounds
,
158 const ShapeAttributeLayerSharedPtr
& rAttr
,
159 const VectorOfDocTreeNodes
& rSubsets
,
161 maOrigBounds( rOrigBounds
),
162 maUpdateBounds( rUpdateBounds
),
164 maUnitBounds( rUnitBounds
),
166 mrSubsets( rSubsets
),
167 mnShapePriority( nPrio
)
171 const ::basegfx::B2DRectangle maOrigBounds
;
172 const ::basegfx::B2DRectangle maUpdateBounds
;
173 const ::basegfx::B2DRectangle maBounds
;
174 const ::basegfx::B2DRectangle maUnitBounds
;
175 const ShapeAttributeLayerSharedPtr
& mrAttr
;
176 const VectorOfDocTreeNodes
& mrSubsets
;
177 const double mnShapePriority
;
180 /** Update the ViewShape
182 This method updates the ViewShape on the associated
183 view. If the shape is currently animated, the render
184 target is the sprite, otherwise the view's
185 canvas. This method does not render anything, if the
189 The metafile representation of the shape
192 Parameter structure, containing all necessary arguments
195 Bitmask of things to update. Use FORCE to force a repaint.
198 When false, the shape is fully invisible (and possibly
199 don't need to be painted)
201 @return whether the rendering finished successfully.
203 bool update( const GDIMetaFileSharedPtr
& rMtf
,
204 const RenderArgs
& rArgs
,
206 bool bIsVisible
) const;
208 /** Retrieve renderer for given canvas and metafile.
210 If necessary, the renderer is created or updated for
211 the metafile and attribute layer.
213 @return a renderer that renders to the given
216 ::cppcanvas::RendererSharedPtr
getRenderer( const ::cppcanvas::CanvasSharedPtr
& rDestinationCanvas
,
217 const GDIMetaFileSharedPtr
& rMtf
,
218 const ShapeAttributeLayerSharedPtr
& rAttr
) const;
222 struct RendererCacheEntry
224 RendererCacheEntry() :
225 mpDestinationCanvas(),
233 ::cppcanvas::CanvasSharedPtr
getDestinationCanvas()
235 return mpDestinationCanvas
;
238 ::cppcanvas::CanvasSharedPtr mpDestinationCanvas
;
239 ::cppcanvas::RendererSharedPtr mpRenderer
;
240 GDIMetaFileSharedPtr mpMtf
;
241 ::cppcanvas::BitmapSharedPtr mpLastBitmap
;
242 ::cppcanvas::BitmapCanvasSharedPtr mpLastBitmapCanvas
;
245 typedef ::std::vector
< RendererCacheEntry
> RendererCacheVector
;
248 /** Prefetch Renderer for given canvas
250 bool prefetch( RendererCacheEntry
& io_rCacheEntry
,
251 const ::cppcanvas::CanvasSharedPtr
& rDestinationCanvas
,
252 const GDIMetaFileSharedPtr
& rMtf
,
253 const ShapeAttributeLayerSharedPtr
& rAttr
) const;
255 /** Draw with prefetched Renderer to stored canvas
257 This method draws prefetched Renderer to its
258 associated canvas (which happens to be mpLastCanvas).
260 bool draw( const ::cppcanvas::CanvasSharedPtr
& rDestinationCanvas
,
261 const GDIMetaFileSharedPtr
& rMtf
,
262 const ShapeAttributeLayerSharedPtr
& rAttr
,
263 const ::basegfx::B2DHomMatrix
& rTransform
,
264 const ::basegfx::B2DPolyPolygon
* pClip
,
265 const VectorOfDocTreeNodes
& rSubsets
) const;
267 /** Render shape to an active sprite
269 bool renderSprite( const ViewLayerSharedPtr
& rViewLayer
,
270 const GDIMetaFileSharedPtr
& rMtf
,
271 const ::basegfx::B2DRectangle
& rOrigBounds
,
272 const ::basegfx::B2DRectangle
& rBounds
,
273 const ::basegfx::B2DRectangle
& rUnitBounds
,
275 const ShapeAttributeLayerSharedPtr
& pAttr
,
276 const VectorOfDocTreeNodes
& rSubsets
,
278 bool bIsVisible
) const;
280 /** Render shape to given canvas
282 bool render( const ::cppcanvas::CanvasSharedPtr
& rDestinationCanvas
,
283 const GDIMetaFileSharedPtr
& rMtf
,
284 const ::basegfx::B2DRectangle
& rBounds
,
285 const ::basegfx::B2DRectangle
& rUpdateBounds
,
287 const ShapeAttributeLayerSharedPtr
& pAttr
,
288 const VectorOfDocTreeNodes
& rSubsets
,
289 bool bIsVisible
) const;
291 /** Calc sprite size in pixel
293 Converts user coordinate system to device pixel, and
294 adds antialiasing border.
297 Size of the sprite in user coordinate system (doc coordinates)
299 ::basegfx::B2DSize
calcSpriteSizePixel( const ::basegfx::B2DSize
& rUserSize
) const;
301 enum{ MAX_RENDER_CACHE_ENTRIES
=2 };
303 /** Retrieve a valid iterator to renderer cache entry
305 This method ensures that an internal limit of
306 MAX_RENDER_CACHE_ENTRIES is not exceeded.
308 @param rDestinationCanvas
309 Destination canvas to retrieve cache entry for
311 @return a valid iterator to a renderer cache entry for
312 the given canvas. The entry might be
313 default-constructed (if newly added)
315 RendererCacheVector::iterator
getCacheEntry( const ::cppcanvas::CanvasSharedPtr
& rDestinationCanvas
) const;
317 void invalidateRenderer() const;
319 /** The view layer this object is part of.
321 Needed for sprite creation
323 ViewLayerSharedPtr mpViewLayer
;
325 /// A set of cached mtf/canvas combinations
326 mutable RendererCacheVector maRenderers
;
328 /// The sprite object
329 mutable AnimatedSpriteSharedPtr mpSprite
;
331 /// If true, render() calls go to the sprite
332 mutable bool mbAnimationMode
;
334 /// If true, shape needs full repaint (and the sprite a setup, if any)
335 mutable bool mbForceUpdate
;
338 typedef ::boost::shared_ptr
< ViewShape
> ViewShapeSharedPtr
;
343 #endif /* INCLUDED_SLIDESHOW_VIEWSHAPE_HXX */