1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYER_HXX
21 #define INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYER_HXX
23 #include <basegfx/range/b2dpolyrange.hxx>
24 #include <cppcanvas/spritecanvas.hxx>
27 #include "animatableshape.hxx"
29 #include <boost/shared_ptr.hpp>
30 #include <boost/weak_ptr.hpp>
31 #include <boost/noncopyable.hpp>
32 #include <boost/enable_shared_from_this.hpp>
43 /* Definition of Layer class */
45 /** This class represents one layer of output on a Slide.
47 Layers group shapes for a certain depth region of a slide.
49 Since slides have a notion of depth, i.e. shapes on it
50 have a certain order in which they lie upon each other,
51 this layering must be modelled. A prime example for this
52 necessity are animations of shapes lying behind other
53 shapes. Then, everything behind the animated shape will be
54 in a background layer, the shape itself will be in an
55 animation layer, and everything before it will be in a
56 foreground layer (these layers are most preferably
57 modelled as XSprite objects internally).
59 @attention All methods of this class are only supposed to
60 be called from the LayerManager. Normally, it shouldn't be
61 possible to get hold of an instance of this class at all.
63 class Layer
: public boost::enable_shared_from_this
<Layer
>,
64 private boost::noncopyable
67 typedef boost::shared_ptr
<LayerEndUpdate
> EndUpdater
;
69 /** Create background layer
71 This method will create a layer without a ViewLayer,
72 i.e. one that displays directly on the background.
74 @param rMaxLayerBounds
75 Maximal bounds of this layer, in user
76 coordinates. This layer will never be larger or extend
79 static ::boost::shared_ptr
< Layer
> createBackgroundLayer( const basegfx::B2DRange
& rMaxLayerBounds
);
81 /** Create non-background layer
83 This method will create a layer in front of the
84 background, to contain shapes that should appear in
85 front of animated objects.
87 @param rMaxLayerBounds
88 Maximal bounds of this layer, in user
89 coordinates. This layer will never be larger or extend
92 static ::boost::shared_ptr
< Layer
> createLayer( const basegfx::B2DRange
& rMaxLayerBounds
);
98 /** Predicate, whether this layer is the special
101 This method is mostly useful for checking invariants.
103 bool isBackgroundLayer() const { return mbBackgroundLayer
; }
105 /** Add a view to this layer.
107 If the view is already added, this method does not add
108 it a second time, just returning the existing ViewLayer.
111 New view to add to this layer.
113 @return the newly generated ViewLayer for this View
115 ViewLayerSharedPtr
addView( const ViewSharedPtr
& rNewView
);
119 This method removes the view from this Layer and all
120 shapes included herein.
122 @return the ViewLayer of the removed Layer, if
123 any. Otherwise, NULL is returned.
125 ViewLayerSharedPtr
removeView( const ViewSharedPtr
& rView
);
127 /** Init shape with this layer's views
130 The shape, that will subsequently display on this
133 void setShapeViews( ShapeSharedPtr
const& rShape
) const;
139 /** Change layer priority range.
141 The layer priority affects the position of the layer
142 in the z direction (i.e. before/behind which other
143 layers this one appears). The higher the prio, the
144 further on top of the layer stack this one appears.
147 The priority range of differing layers must not
150 void setPriority( const ::basegfx::B1DRange
& rPrioRange
);
152 /** Add an area that needs update
155 Area on this layer that needs update
157 void addUpdateRange( ::basegfx::B2DRange
const& rUpdateRange
);
159 /** Whether any update ranges have been added
161 @return true, if any non-empty addUpdateRange() calls
162 have been made since the last render()/update() call.
164 bool isUpdatePending() const { return maUpdateAreas
.count()!=0; }
166 /** Update layer bound rect from shape bounds
168 void updateBounds( ShapeSharedPtr
const& rShape
);
170 /** Commit collected layer bounds to ViewLayer
172 Call this method when you're done adding new shapes to
175 @return true, if layer needed a resize (which
176 invalidates its content - you have to repaint all
181 /** Clear all registered update ranges
183 This method clears all update ranges that are
184 registered at this layer.
186 void clearUpdateRanges();
188 /** Clear whole layer content
190 This method clears the whole layer content. As a
191 byproduct, all update ranges are cleared as well. It
192 makes no sense to maintain them any further, since
193 they only serve for partial updates.
197 /** Init layer update.
199 This method initializes a full layer update of the
200 update area. When the last copy of the returned
201 EndUpdater is destroyed, the Layer leaves update mode
204 @return a update end RAII object.
206 EndUpdater
beginUpdate();
208 /** Finish layer update
210 Resets clipping and transformation to normal values
214 /** Check whether given shape is inside current update area.
216 @return true, if the given shape is at least partially
217 inside the current update area.
219 bool isInsideUpdateArea( ShapeSharedPtr
const& rShape
) const;
222 enum Dummy
{ BackgroundLayer
};
224 /** Create background layer
226 This constructor will create a layer without a
227 ViewLayer, i.e. one that displays directly on the
230 @param rMaxLayerBounds
231 Maximal bounds of this layer, in user
232 coordinates. This layer will never be larger or extend
233 outside these bounds.
236 Dummy parameter, to disambiguate from normal layer
239 Layer( const basegfx::B2DRange
& rMaxLayerBounds
,
242 /** Create non-background layer
244 This constructor will create a layer in front of the
245 background, to contain shapes that should appear in
246 front of animated objects.
248 @param rMaxLayerBounds
249 Maximal bounds of this layer, in user
250 coordinates. This layer will never be larger or extend
251 outside these bounds.
253 explicit Layer( const basegfx::B2DRange
& rMaxLayerBounds
);
257 ViewEntry( const ViewSharedPtr
& rView
,
258 const ViewLayerSharedPtr
& rViewLayer
) :
260 mpViewLayer( rViewLayer
)
263 ViewSharedPtr mpView
;
264 ViewLayerSharedPtr mpViewLayer
;
266 // for generic algo access (which needs actual functions)
267 const ViewSharedPtr
& getView() const { return mpView
; }
268 const ViewLayerSharedPtr
& getViewLayer() const { return mpViewLayer
; }
271 typedef ::std::vector
< ViewEntry
> ViewEntryVector
;
273 ViewEntryVector maViewEntries
;
274 basegfx::B2DPolyRange maUpdateAreas
;
275 basegfx::B2DRange maBounds
;
276 basegfx::B2DRange maNewBounds
;
277 const basegfx::B2DRange maMaxBounds
; // maBounds is clipped against this
278 bool mbBoundsDirty
; // true, if view layers need resize
279 bool mbBackgroundLayer
; // true, if this
283 bool mbClipSet
; // true, if beginUpdate set a clip
286 typedef ::boost::shared_ptr
< Layer
> LayerSharedPtr
;
287 typedef ::boost::weak_ptr
< Layer
> LayerWeakPtr
;
288 typedef ::std::vector
< LayerSharedPtr
> LayerVector
;
293 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYER_HXX
295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */