Bump version to 6.0-36
[LibreOffice.git] / slideshow / source / engine / slide / layer.hxx
blob25dddde4f477ae0172e2bca7cdf4ff6b2bf4d3af
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_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>
26 #include <view.hxx>
27 #include <animatableshape.hxx>
29 #include <vector>
30 #include <memory>
33 namespace slideshow
35 namespace internal
37 class LayerEndUpdate;
39 /* Definition of Layer class */
41 /** This class represents one layer of output on a Slide.
43 Layers group shapes for a certain depth region of a slide.
45 Since slides have a notion of depth, i.e. shapes on it
46 have a certain order in which they lie upon each other,
47 this layering must be modelled. A prime example for this
48 necessity are animations of shapes lying behind other
49 shapes. Then, everything behind the animated shape will be
50 in a background layer, the shape itself will be in an
51 animation layer, and everything before it will be in a
52 foreground layer (these layers are most preferably
53 modelled as XSprite objects internally).
55 @attention All methods of this class are only supposed to
56 be called from the LayerManager. Normally, it shouldn't be
57 possible to get hold of an instance of this class at all.
59 class Layer : public std::enable_shared_from_this<Layer>
61 public:
62 typedef std::shared_ptr<LayerEndUpdate> EndUpdater;
64 /// Forbid copy construction
65 Layer(const Layer&) = delete;
66 /// Forbid copy assignment
67 Layer& operator=(const Layer&) = delete;
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 static ::std::shared_ptr< Layer > createBackgroundLayer();
76 /** Create non-background layer
78 This method will create a layer in front of the
79 background, to contain shapes that should appear in
80 front of animated objects.
82 static ::std::shared_ptr< Layer > createLayer();
85 /** Predicate, whether this layer is the special
86 background layer
88 This method is mostly useful for checking invariants.
90 bool isBackgroundLayer() const { return mbBackgroundLayer; }
92 /** Add a view to this layer.
94 If the view is already added, this method does not add
95 it a second time, just returning the existing ViewLayer.
97 @param rNewView
98 New view to add to this layer.
100 @return the newly generated ViewLayer for this View
102 ViewLayerSharedPtr addView( const ViewSharedPtr& rNewView );
104 /** Remove a view
106 This method removes the view from this Layer and all
107 shapes included herein.
109 @return the ViewLayer of the removed Layer, if
110 any. Otherwise, NULL is returned.
112 ViewLayerSharedPtr removeView( const ViewSharedPtr& rView );
114 /** Init shape with this layer's views
116 @param rShape
117 The shape, that will subsequently display on this
118 layer's views
120 void setShapeViews( ShapeSharedPtr const& rShape ) const;
123 /** Change layer priority range.
125 The layer priority affects the position of the layer
126 in the z direction (i.e. before/behind which other
127 layers this one appears). The higher the prio, the
128 further on top of the layer stack this one appears.
130 @param rPrioRange
131 The priority range of differing layers must not
132 intersect
134 void setPriority( const ::basegfx::B1DRange& rPrioRange );
136 /** Add an area that needs update
138 @param rUpdateRange
139 Area on this layer that needs update
141 void addUpdateRange( ::basegfx::B2DRange const& rUpdateRange );
143 /** Whether any update ranges have been added
145 @return true, if any non-empty addUpdateRange() calls
146 have been made since the last render()/update() call.
148 bool isUpdatePending() const { return maUpdateAreas.count()!=0; }
150 /** Update layer bound rect from shape bounds
152 void updateBounds( ShapeSharedPtr const& rShape );
154 /** Commit collected layer bounds to ViewLayer
156 Call this method when you're done adding new shapes to
157 the layer.
159 @return true, if layer needed a resize (which
160 invalidates its content - you have to repaint all
161 contained shapes!)
163 bool commitBounds();
165 /** Clear all registered update ranges
167 This method clears all update ranges that are
168 registered at this layer.
170 void clearUpdateRanges();
172 /** Clear whole layer content
174 This method clears the whole layer content. As a
175 byproduct, all update ranges are cleared as well. It
176 makes no sense to maintain them any further, since
177 they only serve for partial updates.
179 void clearContent();
181 /** Init layer update.
183 This method initializes a full layer update of the
184 update area. When the last copy of the returned
185 EndUpdater is destroyed, the Layer leaves update mode
186 again.
188 @return a update end RAII object.
190 EndUpdater beginUpdate();
192 /** Finish layer update
194 Resets clipping and transformation to normal values
196 void endUpdate();
198 /** Check whether given shape is inside current update area.
200 @return true, if the given shape is at least partially
201 inside the current update area.
203 bool isInsideUpdateArea( ShapeSharedPtr const& rShape ) const;
205 private:
206 enum Dummy{ BackgroundLayer };
208 /** Create background layer
210 This constructor will create a layer without a
211 ViewLayer, i.e. one that displays directly on the
212 background.
214 @param eFlag
215 Dummy parameter, to disambiguate from normal layer
216 constructor
218 explicit Layer( Dummy eFlag );
220 /** Create non-background layer
222 This constructor will create a layer in front of the
223 background, to contain shapes that should appear in
224 front of animated objects.
226 explicit Layer();
228 struct ViewEntry
230 ViewEntry( const ViewSharedPtr& rView,
231 const ViewLayerSharedPtr& rViewLayer ) :
232 mpView( rView ),
233 mpViewLayer( rViewLayer )
236 ViewSharedPtr mpView;
237 ViewLayerSharedPtr mpViewLayer;
239 // for generic algo access (which needs actual functions)
240 const ViewSharedPtr& getView() const { return mpView; }
241 const ViewLayerSharedPtr& getViewLayer() const { return mpViewLayer; }
244 typedef ::std::vector< ViewEntry > ViewEntryVector;
246 ViewEntryVector maViewEntries;
247 basegfx::B2DPolyRange maUpdateAreas;
248 basegfx::B2DRange maBounds;
249 basegfx::B2DRange maNewBounds;
250 bool mbBoundsDirty; // true, if view layers need resize
251 bool mbBackgroundLayer; // true, if this
252 // layer is the
253 // special
254 // background layer
255 bool mbClipSet; // true, if beginUpdate set a clip
258 typedef ::std::shared_ptr< Layer > LayerSharedPtr;
259 typedef ::std::weak_ptr< Layer > LayerWeakPtr;
260 typedef ::std::vector< LayerSharedPtr > LayerVector;
265 #endif // INCLUDED_SLIDESHOW_SOURCE_ENGINE_SLIDE_LAYER_HXX
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */