Making DALi core internals typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / layer-list.h
1 #ifndef __DALI_INTERNAL_LAYER_LIST_H__
2 #define __DALI_INTERNAL_LAYER_LIST_H__
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/vector-wrapper.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace SceneGraph
34 {
35 class UpdateManager;
36 }
37
38 class Layer;
39
40 /**
41  * An ordered list of layers.
42  * Layers are not owned by the LayerList; each layer is responsible for registering & unregistering.
43  * This is used by the Stage, to keep track of layer depths.
44  * A separate LayerList is maintained for actors added via the SystemOverlay::Add().
45  */
46 class LayerList
47 {
48 public:
49
50   /**
51    * Create a new list of layers.
52    * @param[in] updateManager A reference to the update manager.
53    * @param[in] systemLevel True if the layers are added via the SystemOverlay API.
54    */
55   static LayerList* New( SceneGraph::UpdateManager& updateManager, bool systemLevel );
56
57   /**
58    * Non-virtual destructor; not suitable as a base class.
59    */
60   ~LayerList();
61
62   /**
63    * Query the number of layers.
64    * @return The number of layers.
65    */
66   uint32_t GetLayerCount() const;
67
68   /**
69    * Retrieve the layer at a specified depth.
70    * @pre depth is less than layer count; see GetLayerCount().
71    * @param[in] depth The depth.
72    * @return The layer found at the given depth.
73    */
74   Layer* GetLayer( uint32_t depth ) const;
75
76   /**
77    * Gets the depth of a given layer
78    * @param layer which depth to check
79    */
80   uint32_t GetDepth( const Layer* layer ) const;
81
82   /**
83    * Register a layer with the stage.
84    * The stage determines the relative depth of each layer.
85    */
86   void RegisterLayer( Layer& layer );
87
88   /**
89    * Unregister a layer from the stage
90    */
91   void UnregisterLayer(Layer& layer);
92
93   /**
94    * Increment the depth of the layer inside the stage
95    * @pre layer is on stage
96    */
97   void RaiseLayer(Layer& layer);
98
99   /**
100    * Decrement the depth of the layer inside the stage
101    * @pre layer is on stage
102    */
103   void LowerLayer(Layer& layer);
104
105   /**
106    * Raises the layer to the top of the stage
107    * @pre layer is on stage
108    * @param layer to move
109    */
110   void RaiseLayerToTop( const Layer& layer );
111
112   /**
113    * Lowers the layer to the bottom of the stage
114    * @pre layer is on stage
115    * @param layer to move
116    */
117   void LowerLayerToBottom( const Layer& layer );
118
119   /**
120    * Moves the layer above the target layer on the stage
121    * @pre layer is on stage
122    * @pre target is on stage
123    * @param layer to move
124    * @param target to move above of
125    */
126   void MoveLayerAbove( const Layer& layer, const Layer& target );
127
128   /**
129    * Moves the layer below the target layer on the stage
130    * @pre layer is on stage
131    * @pre target is on stage
132    * @param layer to move
133    * @param target to move below of
134    */
135   void MoveLayerBelow( const Layer& layer, const Layer& target );
136
137 private:
138
139   /**
140    * Protected constructor; see also LayerList::New().
141    * @param[in] updateManager to send messages.
142    * @param[in] systemLevel True if the layers are added via the SystemOverlay API.
143    */
144   LayerList( SceneGraph::UpdateManager& updateManager, bool systemLevel );
145
146   /**
147    * A private helper method to set the depth for each layer.
148    * Layers have depth which is the same as their ordinal number in the stage container
149    * This method propagates any changes in the layer depths onto the scene graph side
150    */
151   void SetLayerDepths();
152
153 private:
154
155   SceneGraph::UpdateManager& mUpdateManager;
156
157   bool mIsSystemLevel; ///< True if the layers are added via the SystemOverlay API.
158
159   typedef std::vector<Layer*> LayerContainer;
160
161   // Layers are not owned by the LayerList.
162   // Each layer is responsible for registering & unregistering before the end of its life-time.
163   LayerContainer mLayers;
164 };
165
166 } // namespace Internal
167
168 } // namespace Dali
169
170 #endif // __DALI_INTERNAL_LAYER_LIST_H__