d5333660e6b42e7024e90b70c372bb48400dc952
[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::CreateFromJson( const std::string& json );
133    */
134   BaseHandle CreateFromJson( const std::string& json );
135
136   /**
137    * @copydoc Toolkit::Builder::ApplyFromJson( Handle& handle, const std::string& json );
138    */
139   bool ApplyFromJson(  Handle& handle, const std::string& json );
140
141   /**
142    * @copydoc Toolkit::Builder::ApplyStyle
143    */
144   bool ApplyStyle( const std::string& styleName, Handle& handle );
145
146   /**
147    * @copydoc Toolkit::Builder::AddActors
148    */
149   void AddActors( Actor toActor );
150
151   /**
152    * @copydoc Toolkit::Builder::AddActors
153    */
154   void AddActors( const std::string &sectionName, Actor toActor );
155
156   /**
157    * @copydoc Toolkit::Builder::CreateRenderTask
158    */
159   void CreateRenderTask( const std::string &name );
160
161   /**
162    * @copydoc Toolkit::Builder::GetShaderEffect
163    */
164   ShaderEffect GetShaderEffect( const std::string &name );
165
166   /**
167    * @copydoc Toolkit::Builder::GetShaderEffect
168    */
169   ShaderEffect GetShaderEffect( const std::string &name, const Replacement& constant );
170
171   /**
172    * @copydoc Toolkit::Builder::GetFrameBufferImage
173    */
174   FrameBufferImage GetFrameBufferImage( const std::string &name );
175
176   /**
177    * @copydoc Toolkit::Builder::GetFrameBufferImage
178    */
179   FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
180
181 protected:
182
183   virtual ~Builder();
184
185 private:
186   // Undefined
187   Builder(const Builder&);
188   Builder& operator=(const Builder& rhs);
189
190   void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
191
192 private:
193   Toolkit::JsonParser mParser;
194
195   typedef std::map<const std::string, FrameBufferImage> ImageLut;
196   ImageLut mFrameBufferImageLut;
197
198   typedef std::map<const std::string, ShaderEffect> ShaderEffectLut;
199   ShaderEffectLut mShaderEffectLut;
200
201   SlotDelegate<Builder> mSlotDelegate;
202
203   PropertyValueMap mReplacementMap;
204
205   BaseHandle Create( const std::string& templateName, const Replacement& constant );
206
207   BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
208
209   void LoadConstants( const TreeNode& root, PropertyValueMap& intoMap );
210
211   void LoadIncludes( const std::string& data );
212
213   bool ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
214
215   Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
216
217   void ApplyProperties( const TreeNode& root, const TreeNode& node,
218                         Dali::Handle& handle, const Replacement& constant );
219
220   void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
221                            Dali::Handle& handle, const Replacement& constant );
222
223   void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
224                                 Dali::Handle& handle, const Replacement& constant );
225
226   void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
227
228 };
229
230 } // namespace Internal
231
232 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
233 {
234   DALI_ASSERT_ALWAYS(obj);
235
236   Dali::BaseObject& handle = obj.GetBaseObject();
237
238   return static_cast<Internal::Builder&>(handle);
239 }
240
241 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
242 {
243   DALI_ASSERT_ALWAYS(obj);
244
245   const Dali::BaseObject& handle = obj.GetBaseObject();
246
247   return static_cast<const Internal::Builder&>(handle);
248 }
249
250 } // namespace Toolkit
251
252 } // namespace Dali
253
254 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__