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