Remove ImageActor from Builder & some doxygen update
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / builder / builder-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_BUILDER_H__
2 #define __DALI_TOOLKIT_INTERNAL_BUILDER_H__
3
4 /*
5  * Copyright (c) 2014 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 <string>
23 #include <list>
24 #include <map>
25 #include <dali/public-api/common/stage.h>
26 #include <dali/public-api/actors/actor.h>
27 #include <dali/public-api/object/base-object.h>
28 #include <dali/public-api/object/property-map.h>
29 #include <dali/public-api/render-tasks/render-task.h>
30 #include <dali/integration-api/debug.h>
31
32 // INTERNAL INCLUDES
33 #include <dali-toolkit/devel-api/builder/json-parser.h>
34 #include <dali-toolkit/devel-api/builder/builder.h>
35 #include <dali-toolkit/internal/builder/builder-declarations.h>
36
37 // Warning messages usually displayed
38 #define DALI_SCRIPT_WARNING(format, args...) \
39   DALI_LOG_WARNING("Script:" format, ## args)
40
41 // Info messages are usually debug build
42 #define DALI_SCRIPT_INFO(format, args...) \
43   DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ## args)
44
45 // Info Verbose need to be swiched on in gFilterScript filter constructor (by default set to General)
46 #define DALI_SCRIPT_VERBOSE(format, args...) \
47   DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ## args)
48
49 namespace Dali
50 {
51
52 namespace Toolkit
53 {
54   class TreeNode;
55 }
56
57 namespace Toolkit
58 {
59
60 namespace Internal
61 {
62
63 #if defined(DEBUG_ENABLED)
64 extern Dali::Integration::Log::Filter* gFilterScript;
65 #endif
66
67 class Builder;
68 class Replacement;
69
70 /**
71  * @copydoc Toolkit::Builder
72  */
73 class Builder : public Dali::BaseObject
74 {
75 public:
76
77   Builder();
78
79   /**
80    * @copydoc Toolkit::Builder::LoadFromString
81    */
82   void LoadFromString( const std::string &data,
83                        Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON );
84
85   /**
86    * @copydoc Toolkit::Builder::AddConstants
87    */
88   void AddConstants( const Property::Map& map );
89
90   /**
91    * @copydoc Toolkit::Builder::AddConstant
92    */
93   void AddConstant( const std::string& key, const Property::Value& value );
94
95   /**
96    * @copydoc Toolkit::Builder::GetConstants
97    */
98   const Property::Map& GetConstants() const;
99
100   /**
101    * @copydoc Toolkit::Builder::GetConstant
102    */
103   const Property::Value& GetConstant( const std::string& key ) const;
104
105   /**
106    * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
107    */
108   Animation CreateAnimation( const std::string& animationName );
109
110   /**
111    * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const Property::Map& map );
112    */
113   Animation CreateAnimation( const std::string& animationName, const Property::Map& map );
114
115   /**
116    * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
117    */
118   Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
119
120   /**
121    * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const Property::Map&, Dali::Actor);
122    */
123   Animation CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor );
124
125   /**
126    * @copydoc Toolkit::Builder::Create( const std::string& templateName );
127    */
128   BaseHandle Create( const std::string& templateName );
129
130   /**
131    * @copydoc Toolkit::Builder::Create( const std::string& templateName, const Property::Map& map );
132    */
133   BaseHandle Create( const std::string& templateName, const Property::Map& map );
134
135   /**
136    * @copydoc Toolkit::Builder::CreateFromJson( const std::string& json );
137    */
138   BaseHandle CreateFromJson( const std::string& json );
139
140   /**
141    * @copydoc Toolkit::Builder::ApplyFromJson( Handle& handle, const std::string& json );
142    */
143   bool ApplyFromJson(  Handle& handle, const std::string& json );
144
145   /**
146    * @copydoc Toolkit::Builder::ApplyStyle
147    */
148   bool ApplyStyle( const std::string& styleName, Handle& handle );
149
150   /**
151    * @copydoc Toolkit::Builder::AddActors
152    */
153   void AddActors( Actor toActor );
154
155   /**
156    * @copydoc Toolkit::Builder::AddActors
157    */
158   void AddActors( const std::string &sectionName, Actor toActor );
159
160   /**
161    * @copydoc Toolkit::Builder::CreateRenderTask
162    */
163   void CreateRenderTask( const std::string &name );
164
165   /**
166    * @copydoc Toolkit::Builder::GetFrameBufferImage
167    */
168   FrameBufferImage GetFrameBufferImage( const std::string &name );
169
170   /**
171    * @copydoc Toolkit::Builder::GetFrameBufferImage
172    */
173   FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
174
175   /**
176    * @copydoc Toolkit::Builder::GetPath
177    */
178   Path GetPath( const std::string &name );
179
180   /**
181    * @copydoc Toolkit::Builder::GetPathConstrainer
182    */
183   Dali::PathConstrainer GetPathConstrainer( const std::string& name );
184
185   /*
186    * Check if a given constrainer is of type PathConstrainer
187    * @param[in] name The name of the constrainer
188    * @return True if constainer is of type PathConstrainer, False otherwise
189    *
190    */
191   bool IsPathConstrainer( const std::string& name );
192
193   /**
194    * @copydoc Toolkit::Builder::GetLinearConstrainer
195    */
196   Dali::LinearConstrainer GetLinearConstrainer( const std::string& name );
197
198   /*
199    * Check if a given constrainer is of type LinearConstrainer
200    * @param[in] name The name of the constrainer
201    * @return True if constainer is of type LinearConstrainer, False otherwise
202    *
203    */
204   bool IsLinearConstrainer( const std::string& name );
205
206   /**
207    * @copydoc Toolkit::Builder::QuitSignal
208    */
209   Toolkit::Builder::BuilderSignalType& QuitSignal();
210
211   /**
212    * Emits the quit signal
213    */
214   void EmitQuitSignal();
215
216 protected:
217
218   virtual ~Builder();
219
220 private:
221   // Undefined
222   Builder(const Builder&);
223   Builder& operator=(const Builder& rhs);
224
225   void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
226
227   void SetCustomProperties( const TreeNode& node, Handle& handle, const Replacement& constant, const std::string& childName, Property::AccessMode accessMode );
228
229 private:
230   Toolkit::JsonParser mParser;
231
232   typedef std::map<const std::string, FrameBufferImage> ImageLut;
233   ImageLut mFrameBufferImageLut;
234
235   typedef std::map<const std::string, Path> PathLut;
236   PathLut mPathLut;
237
238   typedef struct{ std::string name; Dali::PathConstrainer pathConstrainer; } PathConstrainerEntry;
239   typedef std::vector<PathConstrainerEntry> PathConstrainerLut;
240   PathConstrainerLut mPathConstrainerLut;
241
242   typedef struct{ std::string name; Dali::LinearConstrainer linearConstrainer; } LinearConstrainerEntry;
243   typedef std::vector<LinearConstrainerEntry> LinearConstrainerLut;
244   LinearConstrainerLut mLinearConstrainerLut;
245
246   SlotDelegate<Builder> mSlotDelegate;
247
248   Property::Map mReplacementMap;
249
250   typedef std::vector< TreeNode::KeyNodePair > MappingsLut;
251   MappingsLut mCompleteMappings;
252
253   BaseHandle Create( const std::string& templateName, const Replacement& constant );
254
255   BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
256
257   void LoadConstants( const TreeNode& root, Property::Map& intoMap );
258
259   void LoadIncludes( const std::string& data );
260
261   bool ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
262
263   Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
264
265   typedef std::vector<const char*> KeyStack;
266
267   /**
268    * Tests if the value is a string delimited by <>. If it is, then it attempts to
269    * change the value to the mapping from a matching key in the mappings table.
270    * @param[in] mappingRoot The JSON node containing the mappings
271    * @param[in,out] keyStack the stack of visited keys
272    * @param[in,out] value The string value to test and write back to.
273    * @return true if the value was converted, false otherwise.
274    */
275   bool ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& value );
276
277   /**
278    * Find the key in the mapping table, if it's present, then generate a property value for it (of the given type if available), recursing as necessary, and stopping if any cycles
279    * are detected.
280    * @param[in] mappingRoot The JSON node containing the mappings
281    * @param[in] theKey The key to search for
282    * @param[in,out] keyStack the stack of visited keys
283    * @param[in] propertyType The property type if known, or NONE
284    * @param[in,out] value The string value to test and write back to.
285    */
286   bool RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, Property::Value& value );
287
288   /**
289    * Find the key in the mapping table, if it's present, then generate a property value for it (of the given type if available), recursing as necessary, and stopping if any cycles
290    * are detected.
291    * @param[in] mappingRoot The JSON node containing the mappings
292    * @param[in] theKey The key to search for
293    * @param[in] propertyType The property type if known, or NONE
294    * @param[in,out] value The string value to test and write back to.
295    */
296   bool GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value );
297
298   void ApplyProperties( const TreeNode& root, const TreeNode& node,
299                         Dali::Handle& handle, const Replacement& constant );
300
301   void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
302                            Dali::Handle& handle, const Replacement& constant );
303
304   void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
305                                 Dali::Handle& handle, const Replacement& constant );
306
307   void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
308
309   Toolkit::Builder::BuilderSignalType mQuitSignal;
310 };
311
312 } // namespace Internal
313
314 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
315 {
316   DALI_ASSERT_ALWAYS(obj);
317
318   Dali::BaseObject& handle = obj.GetBaseObject();
319
320   return static_cast<Internal::Builder&>(handle);
321 }
322
323 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
324 {
325   DALI_ASSERT_ALWAYS(obj);
326
327   const Dali::BaseObject& handle = obj.GetBaseObject();
328
329   return static_cast<const Internal::Builder&>(handle);
330 }
331
332 } // namespace Toolkit
333
334 } // namespace Dali
335
336 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__