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 Flora License, Version 1.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://floralicense.org/license/
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.
24 #include <dali/dali.h>
25 #include <dali/integration-api/debug.h>
28 #include <dali-toolkit/public-api/builder/json-parser.h>
29 #include <dali-toolkit/public-api/builder/builder.h>
30 #include <dali-toolkit/internal/builder/builder-declarations.h>
32 // Warning messages usually displayed
33 #define DALI_SCRIPT_WARNING(format, args...) \
34 DALI_LOG_WARNING("Script:" format, ## args)
36 // Info messages are usually debug build
37 #define DALI_SCRIPT_INFO(format, args...) \
38 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ## args)
40 // Info Verbose need to be swiched on in gFilterScript filter constructor (by default set to General)
41 #define DALI_SCRIPT_VERBOSE(format, args...) \
42 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ## args)
58 #if defined(DEBUG_ENABLED)
59 extern Dali::Integration::Log::Filter* gFilterScript;
66 * @copydoc Toolkit::Builder
68 class Builder : public Dali::BaseObject
75 * @copydoc Toolkit::Builder::LoadFromString
77 void LoadFromString( const std::string &data,
78 Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON );
81 * @copydoc Toolkit::Builder::AddConstants
83 void AddConstants( const PropertyValueMap& map );
86 * @copydoc Toolkit::Builder::AddConstant
88 void AddConstant( const std::string& key, const Property::Value& value );
91 * @copydoc Toolkit::Builder::GetConstants
93 const PropertyValueMap& GetConstants() const;
96 * @copydoc Toolkit::Builder::GetConstant
98 const Property::Value& GetConstant( const std::string& key ) const;
101 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
103 Animation CreateAnimation( const std::string& animationName );
106 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map );
108 Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map );
111 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
113 Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
116 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const PropertyValueMap&,Dali::Actor);
118 Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor );
121 * @copydoc Toolkit::Builder::Create( const std::string& templateName );
123 BaseHandle Create( const std::string& templateName );
126 * @copydoc Toolkit::Builder::Create( const std::string& templateName, const PropertyValueMap& map );
128 BaseHandle Create( const std::string& templateName, const PropertyValueMap& map );
131 * @copydoc Toolkit::Builder::GetFont
133 Font GetFont(const std::string &name) const;
136 * @copydoc Toolkit::Builder::GetTextStyle
138 TextStyle GetTextStyle(const std::string &name) const;
141 * @copydoc Toolkit::Builder::GetImage
143 Image GetImage(const std::string &name) const;
146 * @copydoc Toolkit::Builder::GetActor
148 Actor GetActor( const std::string &name ) const;
151 * @copydoc Toolkit::Builder::ApplyStyle
153 bool ApplyStyle( const std::string& styleName, Handle& handle );
155 void AnimateTo( const std::string& styleName, Handle& handle );
158 * @copydoc Toolkit::Builder::AddActors
160 void AddActors( Actor toActor );
163 * @copydoc Toolkit::Builder::AddActors
165 void AddActors( const std::string §ionName, Actor toActor );
168 * @copydoc Toolkit::Builder::GetAnimation
170 Animation GetAnimation( const std::string &name ) const;
173 * @copydoc Toolkit::Builder::CreateRenderTask
175 void CreateRenderTask( const std::string &name );
178 * @copydoc Toolkit::Builder::GetShaderEffect
180 ShaderEffect GetShaderEffect( const std::string &name );
183 * @copydoc Toolkit::Builder::GetShaderEffect
185 ShaderEffect GetShaderEffect( const std::string &name, const Replacement& constant );
188 * @copydoc Toolkit::Builder::GetFrameBufferImage
190 FrameBufferImage GetFrameBufferImage( const std::string &name );
193 * @copydoc Toolkit::Builder::GetFrameBufferImage
195 FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
198 * @copydoc Toolkit::Builder::GetTopLevelActors
200 ActorContainer GetTopLevelActors( void ) const;
208 Builder(const Builder&);
209 Builder& operator=(const Builder& rhs);
211 void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
214 Toolkit::JsonParser mParser;
216 typedef std::map<const std::string, FrameBufferImage> ImageLut;
217 ImageLut mFrameBufferImageLut;
219 typedef std::map<const std::string, ShaderEffect> ShaderEffectLut;
220 ShaderEffectLut mShaderEffectLut;
222 SlotDelegate<Builder> mSlotDelegate;
224 PropertyValueMap mReplacementMap;
226 BaseHandle Create( const std::string& templateName, const Replacement& constant );
228 BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
230 void LoadConstants( const TreeNode& root, PropertyValueMap& intoMap );
232 void LoadIncludes( const std::string& data );
234 bool ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
236 Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
238 void ApplyProperties( const TreeNode& root, const TreeNode& node,
239 Dali::Handle& handle, const Replacement& constant );
241 void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
242 Dali::Handle& handle, const Replacement& constant );
244 void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
245 Dali::Handle& handle, const Replacement& constant );
247 void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
251 } // namespace Internal
253 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
255 DALI_ASSERT_ALWAYS(obj);
257 Dali::BaseObject& handle = obj.GetBaseObject();
259 return static_cast<Internal::Builder&>(handle);
262 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
264 DALI_ASSERT_ALWAYS(obj);
266 const Dali::BaseObject& handle = obj.GetBaseObject();
268 return static_cast<const Internal::Builder&>(handle);
271 } // namespace Toolkit
275 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__