27ca2d302b9149aad78216066d0b5dbe4beaf946
[platform/core/uifw/dali-toolkit.git] / optional / 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 <boost/property_tree/ptree.hpp>
26 #include <dali/dali.h>
27 #include <dali/integration-api/debug.h>
28
29 // INTERNAL INCLUDES
30 #include <dali-toolkit/public-api/builder/json-parser.h>
31 #include <dali-toolkit/public-api/builder/builder.h>
32 #include <dali-toolkit/internal/builder/builder-declarations.h>
33
34 // Warning messages usually displayed
35 #define DALI_SCRIPT_WARNING(format, args...) \
36   DALI_LOG_WARNING("Script:" format, ## args)
37
38 // Info messages are usually debug build
39 #define DALI_SCRIPT_INFO(format, args...) \
40   DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ## args)
41
42 // Info Verbose need to be swiched on in gFilterScript filter constructor (by default set to General)
43 #define DALI_SCRIPT_VERBOSE(format, args...) \
44   DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ## args)
45
46 namespace Dali
47 {
48
49 namespace Toolkit
50 {
51   class TreeNode;
52 }
53
54 namespace Toolkit
55 {
56
57 namespace Internal
58 {
59
60 #if defined(DEBUG_ENABLED)
61 extern Dali::Integration::Log::Filter* gFilterScript;
62 #endif
63
64 class Builder;
65 class Replacement;
66
67 /**
68  * @copydoc Toolkit::Builder
69  */
70 class Builder : public Dali::BaseObject
71 {
72 public:
73
74   Builder();
75
76   /**
77    * @copydoc Toolkit::Builder::LoadFromString
78    */
79   void LoadFromString( const std::string &data,
80                        Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON );
81
82   /**
83    * @copydoc Toolkit::Builder::AddConstants
84    */
85   void AddConstants( const PropertyValueMap& map );
86
87   /**
88    * @copydoc Toolkit::Builder::AddConstant
89    */
90   void AddConstant( const std::string& key, const Property::Value& value );
91
92   /**
93    * @copydoc Toolkit::Builder::GetConstants
94    */
95   const PropertyValueMap& GetConstants() const;
96
97   /**
98    * @copydoc Toolkit::Builder::GetConstant
99    */
100   const Property::Value& GetConstant( const std::string& key ) const;
101
102   /**
103    * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
104    */
105   Animation CreateAnimation( const std::string& animationName );
106
107   /**
108    * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map );
109    */
110   Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map );
111
112   /**
113    * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
114    */
115   Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
116
117   /**
118    * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const PropertyValueMap&,Dali::Actor);
119    */
120   Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor );
121
122   /**
123    * @copydoc Toolkit::Builder::Create( const std::string& templateName );
124    */
125   BaseHandle Create( const std::string& templateName );
126
127   /**
128    * @copydoc Toolkit::Builder::Create( const std::string& templateName, const PropertyValueMap& map );
129    */
130   BaseHandle Create( const std::string& templateName, const PropertyValueMap& map );
131
132  /**
133    * @copydoc Toolkit::Builder::GetFont
134    */
135   Font GetFont(const std::string &name) const;
136
137   /**
138    * @copydoc Toolkit::Builder::GetTextStyle
139    */
140   TextStyle GetTextStyle(const std::string &name) const;
141
142   /**
143    * @copydoc Toolkit::Builder::GetImage
144    */
145   Image GetImage(const std::string &name) const;
146
147   /**
148    * @copydoc Toolkit::Builder::GetActor
149    */
150   Actor GetActor( const std::string &name ) const;
151
152   /**
153    * @copydoc Toolkit::Builder::ApplyStyle
154    */
155   void ApplyStyle( const std::string& styleName, Handle& handle );
156
157   void AnimateTo( const std::string& styleName, Handle& handle );
158
159   /**
160    * @copydoc Toolkit::Builder::AddActors
161    */
162   void AddActors( Actor toActor );
163
164   /**
165    * @copydoc Toolkit::Builder::AddActors
166    */
167   void AddActors( const std::string &sectionName, Actor toActor );
168
169   /**
170    * @copydoc Toolkit::Builder::GetAnimation
171    */
172   Animation GetAnimation( const std::string &name ) const;
173
174   /**
175    * @copydoc Toolkit::Builder::CreateRenderTask
176    */
177   void CreateRenderTask( const std::string &name );
178
179   /**
180    * @copydoc Toolkit::Builder::GetShaderEffect
181    */
182   ShaderEffect GetShaderEffect( const std::string &name );
183
184   /**
185    * @copydoc Toolkit::Builder::GetShaderEffect
186    */
187   ShaderEffect GetShaderEffect( const std::string &name, const Replacement& constant );
188
189   /**
190    * @copydoc Toolkit::Builder::GetFrameBufferImage
191    */
192   FrameBufferImage GetFrameBufferImage( const std::string &name );
193
194   /**
195    * @copydoc Toolkit::Builder::GetFrameBufferImage
196    */
197   FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
198
199   /**
200    * @copydoc Toolkit::Builder::GetTopLevelActors
201    */
202   ActorContainer GetTopLevelActors( void ) const;
203
204 protected:
205
206   virtual ~Builder();
207
208 private:
209   // Undefined
210   Builder(const Builder&);
211   Builder& operator=(const Builder& rhs);
212
213   void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
214
215 private:
216   Toolkit::JsonParser mParser;
217
218   typedef std::map<const std::string, FrameBufferImage> ImageLut;
219   ImageLut mFrameBufferImageLut;
220
221   typedef std::map<const std::string, ShaderEffect> ShaderEffectLut;
222   ShaderEffectLut mShaderEffectLut;
223
224   SlotDelegate<Builder> mSlotDelegate;
225
226   PropertyValueMap mReplacementMap;
227
228   BaseHandle Create( const std::string& templateName, const Replacement& constant );
229
230   BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
231
232   void LoadConstants( const TreeNode& root, PropertyValueMap& intoMap );
233
234   void LoadIncludes( const std::string& data );
235
236   void ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
237
238   Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
239
240   void ApplyProperties( const TreeNode& root, const TreeNode& node,
241                         Dali::Handle& handle, const Replacement& constant );
242
243   void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
244                            Dali::Handle& handle, const Replacement& constant );
245
246   void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
247                                 Dali::Handle& handle, const Replacement& constant );
248
249   void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
250
251 };
252
253 } // namespace Internal
254
255 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
256 {
257   DALI_ASSERT_ALWAYS(obj);
258
259   Dali::BaseObject& handle = obj.GetBaseObject();
260
261   return static_cast<Internal::Builder&>(handle);
262 }
263
264 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
265 {
266   DALI_ASSERT_ALWAYS(obj);
267
268   const Dali::BaseObject& handle = obj.GetBaseObject();
269
270   return static_cast<const Internal::Builder&>(handle);
271 }
272
273 } // namespace Toolkit
274
275 } // namespace Dali
276
277 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__