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 <dali/dali.h>
26 #include <dali/integration-api/debug.h>
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>
33 // Warning messages usually displayed
34 #define DALI_SCRIPT_WARNING(format, args...) \
35 DALI_LOG_WARNING("Script:" format, ## args)
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)
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)
59 #if defined(DEBUG_ENABLED)
60 extern Dali::Integration::Log::Filter* gFilterScript;
67 * @copydoc Toolkit::Builder
69 class Builder : public Dali::BaseObject
76 * @copydoc Toolkit::Builder::LoadFromString
78 void LoadFromString( const std::string &data,
79 Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON );
82 * @copydoc Toolkit::Builder::AddConstants
84 void AddConstants( const PropertyValueMap& map );
87 * @copydoc Toolkit::Builder::AddConstant
89 void AddConstant( const std::string& key, const Property::Value& value );
92 * @copydoc Toolkit::Builder::GetConstants
94 const PropertyValueMap& GetConstants() const;
97 * @copydoc Toolkit::Builder::GetConstant
99 const Property::Value& GetConstant( const std::string& key ) const;
102 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
104 Animation CreateAnimation( const std::string& animationName );
107 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map );
109 Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map );
112 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
114 Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
117 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const PropertyValueMap&,Dali::Actor);
119 Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor );
122 * @copydoc Toolkit::Builder::Create( const std::string& templateName );
124 BaseHandle Create( const std::string& templateName );
127 * @copydoc Toolkit::Builder::Create( const std::string& templateName, const PropertyValueMap& map );
129 BaseHandle Create( const std::string& templateName, const PropertyValueMap& map );
132 * @copydoc Toolkit::Builder::GetFont
134 Font GetFont(const std::string &name) const;
137 * @copydoc Toolkit::Builder::GetTextStyle
139 TextStyle GetTextStyle(const std::string &name) const;
142 * @copydoc Toolkit::Builder::GetImage
144 Image GetImage(const std::string &name) const;
147 * @copydoc Toolkit::Builder::GetActor
149 Actor GetActor( const std::string &name ) const;
152 * @copydoc Toolkit::Builder::ApplyStyle
154 bool ApplyStyle( const std::string& styleName, Handle& handle );
156 void AnimateTo( const std::string& styleName, Handle& handle );
159 * @copydoc Toolkit::Builder::AddActors
161 void AddActors( Actor toActor );
164 * @copydoc Toolkit::Builder::AddActors
166 void AddActors( const std::string §ionName, Actor toActor );
169 * @copydoc Toolkit::Builder::GetAnimation
171 Animation GetAnimation( const std::string &name ) const;
174 * @copydoc Toolkit::Builder::CreateRenderTask
176 void CreateRenderTask( const std::string &name );
179 * @copydoc Toolkit::Builder::GetShaderEffect
181 ShaderEffect GetShaderEffect( const std::string &name );
184 * @copydoc Toolkit::Builder::GetShaderEffect
186 ShaderEffect GetShaderEffect( const std::string &name, const Replacement& constant );
189 * @copydoc Toolkit::Builder::GetFrameBufferImage
191 FrameBufferImage GetFrameBufferImage( const std::string &name );
194 * @copydoc Toolkit::Builder::GetFrameBufferImage
196 FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
199 * @copydoc Toolkit::Builder::GetTopLevelActors
201 ActorContainer GetTopLevelActors( void ) const;
209 Builder(const Builder&);
210 Builder& operator=(const Builder& rhs);
212 void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
215 Toolkit::JsonParser mParser;
217 typedef std::map<const std::string, FrameBufferImage> ImageLut;
218 ImageLut mFrameBufferImageLut;
220 typedef std::map<const std::string, ShaderEffect> ShaderEffectLut;
221 ShaderEffectLut mShaderEffectLut;
223 SlotDelegate<Builder> mSlotDelegate;
225 PropertyValueMap mReplacementMap;
227 BaseHandle Create( const std::string& templateName, const Replacement& constant );
229 BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
231 void LoadConstants( const TreeNode& root, PropertyValueMap& intoMap );
233 void LoadIncludes( const std::string& data );
235 bool ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
237 Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
239 void ApplyProperties( const TreeNode& root, const TreeNode& node,
240 Dali::Handle& handle, const Replacement& constant );
242 void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
243 Dali::Handle& handle, const Replacement& constant );
245 void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
246 Dali::Handle& handle, const Replacement& constant );
248 void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
252 } // namespace Internal
254 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
256 DALI_ASSERT_ALWAYS(obj);
258 Dali::BaseObject& handle = obj.GetBaseObject();
260 return static_cast<Internal::Builder&>(handle);
263 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
265 DALI_ASSERT_ALWAYS(obj);
267 const Dali::BaseObject& handle = obj.GetBaseObject();
269 return static_cast<const Internal::Builder&>(handle);
272 } // namespace Toolkit
276 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__