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