1 #ifndef __DALI_TOOLKIT_INTERNAL_BUILDER_H__
2 #define __DALI_TOOLKIT_INTERNAL_BUILDER_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <boost/property_tree/ptree.hpp>
26 #include <dali/dali.h>
27 #include <dali/integration-api/debug.h>
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>
34 // Warning messages usually displayed
35 #define DALI_SCRIPT_WARNING(format, args...) \
36 DALI_LOG_WARNING("Script:" format, ## args)
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)
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)
60 #if defined(DEBUG_ENABLED)
61 extern Dali::Integration::Log::Filter* gFilterScript;
68 * @copydoc Toolkit::Builder
70 class Builder : public Dali::BaseObject
77 * @copydoc Toolkit::Builder::LoadFromString
79 void LoadFromString( const std::string &data,
80 Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON );
83 * @copydoc Toolkit::Builder::AddConstants
85 void AddConstants( const PropertyValueMap& map );
88 * @copydoc Toolkit::Builder::AddConstant
90 void AddConstant( const std::string& key, const Property::Value& value );
93 * @copydoc Toolkit::Builder::GetConstants
95 const PropertyValueMap& GetConstants() const;
98 * @copydoc Toolkit::Builder::GetConstant
100 const Property::Value& GetConstant( const std::string& key ) const;
103 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
105 Animation CreateAnimation( const std::string& animationName );
108 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map );
110 Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map );
113 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
115 Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
118 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const PropertyValueMap&,Dali::Actor);
120 Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor );
123 * @copydoc Toolkit::Builder::Create( const std::string& templateName );
125 BaseHandle Create( const std::string& templateName );
128 * @copydoc Toolkit::Builder::Create( const std::string& templateName, const PropertyValueMap& map );
130 BaseHandle Create( const std::string& templateName, const PropertyValueMap& map );
133 * @copydoc Toolkit::Builder::GetFont
135 Font GetFont(const std::string &name) const;
138 * @copydoc Toolkit::Builder::GetTextStyle
140 TextStyle GetTextStyle(const std::string &name) const;
143 * @copydoc Toolkit::Builder::GetImage
145 Image GetImage(const std::string &name) const;
148 * @copydoc Toolkit::Builder::GetActor
150 Actor GetActor( const std::string &name ) const;
153 * @copydoc Toolkit::Builder::ApplyStyle
155 void ApplyStyle( const std::string& styleName, Handle& handle );
157 void AnimateTo( const std::string& styleName, Handle& handle );
160 * @copydoc Toolkit::Builder::AddActors
162 void AddActors( Actor toActor );
165 * @copydoc Toolkit::Builder::AddActors
167 void AddActors( const std::string §ionName, Actor toActor );
170 * @copydoc Toolkit::Builder::GetAnimation
172 Animation GetAnimation( const std::string &name ) const;
175 * @copydoc Toolkit::Builder::CreateRenderTask
177 void CreateRenderTask( const std::string &name );
180 * @copydoc Toolkit::Builder::GetShaderEffect
182 ShaderEffect GetShaderEffect( const std::string &name );
185 * @copydoc Toolkit::Builder::GetShaderEffect
187 ShaderEffect GetShaderEffect( const std::string &name, const Replacement& constant );
190 * @copydoc Toolkit::Builder::GetFrameBufferImage
192 FrameBufferImage GetFrameBufferImage( const std::string &name );
195 * @copydoc Toolkit::Builder::GetFrameBufferImage
197 FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
200 * @copydoc Toolkit::Builder::GetTopLevelActors
202 ActorContainer GetTopLevelActors( void ) const;
210 Builder(const Builder&);
211 Builder& operator=(const Builder& rhs);
213 void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
216 Toolkit::JsonParser mParser;
218 typedef std::map<const std::string, FrameBufferImage> ImageLut;
219 ImageLut mFrameBufferImageLut;
221 typedef std::map<const std::string, ShaderEffect> ShaderEffectLut;
222 ShaderEffectLut mShaderEffectLut;
224 SlotDelegate<Builder> mSlotDelegate;
226 PropertyValueMap mReplacementMap;
228 BaseHandle Create( const std::string& templateName, const Replacement& constant );
230 BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
232 void LoadConstants( const TreeNode& root, PropertyValueMap& intoMap );
234 void LoadIncludes( const std::string& data );
236 void ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
238 Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
240 void ApplyProperties( const TreeNode& root, const TreeNode& node,
241 Dali::Handle& handle, const Replacement& constant );
243 void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
244 Dali::Handle& handle, const Replacement& constant );
246 void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
247 Dali::Handle& handle, const Replacement& constant );
249 void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
253 } // namespace Internal
255 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
257 DALI_ASSERT_ALWAYS(obj);
259 Dali::BaseObject& handle = obj.GetBaseObject();
261 return static_cast<Internal::Builder&>(handle);
264 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
266 DALI_ASSERT_ALWAYS(obj);
268 const Dali::BaseObject& handle = obj.GetBaseObject();
270 return static_cast<const Internal::Builder&>(handle);
273 } // namespace Toolkit
277 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__