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/public-api/common/stage.h>
26 #include <dali/public-api/actors/actor.h>
27 #include <dali/public-api/object/base-object.h>
28 #include <dali/public-api/object/property-map.h>
29 #include <dali/public-api/render-tasks/render-task.h>
30 #include <dali/integration-api/debug.h>
33 #include <dali-toolkit/devel-api/builder/json-parser.h>
34 #include <dali-toolkit/devel-api/builder/builder.h>
35 #include <dali-toolkit/internal/builder/builder-declarations.h>
37 // Warning messages usually displayed
38 #define DALI_SCRIPT_WARNING(format, args...) \
39 DALI_LOG_WARNING("Script:" format, ## args)
41 // Info messages are usually debug build
42 #define DALI_SCRIPT_INFO(format, args...) \
43 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ## args)
45 // Info Verbose need to be swiched on in gFilterScript filter constructor (by default set to General)
46 #define DALI_SCRIPT_VERBOSE(format, args...) \
47 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ## args)
63 #if defined(DEBUG_ENABLED)
64 extern Dali::Integration::Log::Filter* gFilterScript;
71 * @copydoc Toolkit::Builder
73 class Builder : public Dali::BaseObject
80 * @copydoc Toolkit::Builder::LoadFromString
82 void LoadFromString( const std::string &data,
83 Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON );
86 * @copydoc Toolkit::Builder::AddConstants
88 void AddConstants( const Property::Map& map );
91 * @copydoc Toolkit::Builder::AddConstant
93 void AddConstant( const std::string& key, const Property::Value& value );
96 * @copydoc Toolkit::Builder::GetConstants
98 const Property::Map& GetConstants() const;
101 * @copydoc Toolkit::Builder::GetConstant
103 const Property::Value& GetConstant( const std::string& key ) const;
106 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
108 Animation CreateAnimation( const std::string& animationName );
111 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const Property::Map& map );
113 Animation CreateAnimation( const std::string& animationName, const Property::Map& map );
116 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
118 Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
121 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const Property::Map&, Dali::Actor);
123 Animation CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor );
126 * @copydoc Toolkit::Builder::Create( const std::string& templateName );
128 BaseHandle Create( const std::string& templateName );
131 * @copydoc Toolkit::Builder::Create( const std::string& templateName, const Property::Map& map );
133 BaseHandle Create( const std::string& templateName, const Property::Map& map );
136 * @copydoc Toolkit::Builder::CreateFromJson( const std::string& json );
138 BaseHandle CreateFromJson( const std::string& json );
141 * @copydoc Toolkit::Builder::ApplyFromJson( Handle& handle, const std::string& json );
143 bool ApplyFromJson( Handle& handle, const std::string& json );
146 * @copydoc Toolkit::Builder::ApplyStyle
148 bool ApplyStyle( const std::string& styleName, Handle& handle );
151 * @copydoc Toolkit::Builder::AddActors
153 void AddActors( Actor toActor );
156 * @copydoc Toolkit::Builder::AddActors
158 void AddActors( const std::string §ionName, Actor toActor );
161 * @copydoc Toolkit::Builder::CreateRenderTask
163 void CreateRenderTask( const std::string &name );
166 * @copydoc Toolkit::Builder::GetShaderEffect
168 ShaderEffect GetShaderEffect( const std::string &name );
171 * @copydoc Toolkit::Builder::GetShaderEffect
173 ShaderEffect GetShaderEffect( const std::string &name, const Replacement& constant );
176 * @copydoc Toolkit::Builder::GetFrameBufferImage
178 FrameBufferImage GetFrameBufferImage( const std::string &name );
181 * @copydoc Toolkit::Builder::GetFrameBufferImage
183 FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
186 * @copydoc Toolkit::Builder::GetPath
188 Path GetPath( const std::string &name );
191 * @copydoc Toolkit::Builder::GetPathConstrainer
193 Dali::PathConstrainer GetPathConstrainer( const std::string& name );
196 * Check if a given constrainer is of type PathConstrainer
197 * @param[in] name The name of the constrainer
198 * @return True if constainer is of type PathConstrainer, False otherwise
201 bool IsPathConstrainer( const std::string& name );
204 * @copydoc Toolkit::Builder::GetLinearConstrainer
206 Dali::LinearConstrainer GetLinearConstrainer( const std::string& name );
209 * Check if a given constrainer is of type LinearConstrainer
210 * @param[in] name The name of the constrainer
211 * @return True if constainer is of type LinearConstrainer, False otherwise
214 bool IsLinearConstrainer( const std::string& name );
217 * @copydoc Toolkit::Builder::QuitSignal
219 Toolkit::Builder::BuilderSignalType& QuitSignal();
222 * Emits the quit signal
224 void EmitQuitSignal();
232 Builder(const Builder&);
233 Builder& operator=(const Builder& rhs);
235 void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
238 Toolkit::JsonParser mParser;
240 typedef std::map<const std::string, FrameBufferImage> ImageLut;
241 ImageLut mFrameBufferImageLut;
243 typedef std::map<const std::string, ShaderEffect> ShaderEffectLut;
244 ShaderEffectLut mShaderEffectLut;
246 typedef std::map<const std::string, Path> PathLut;
249 typedef struct{ std::string name; Dali::PathConstrainer pathConstrainer; } PathConstrainerEntry;
250 typedef std::vector<PathConstrainerEntry> PathConstrainerLut;
251 PathConstrainerLut mPathConstrainerLut;
253 typedef struct{ std::string name; Dali::LinearConstrainer linearConstrainer; } LinearConstrainerEntry;
254 typedef std::vector<LinearConstrainerEntry> LinearConstrainerLut;
255 LinearConstrainerLut mLinearConstrainerLut;
257 SlotDelegate<Builder> mSlotDelegate;
259 Property::Map mReplacementMap;
261 typedef std::vector< TreeNode::KeyNodePair > MappingsLut;
262 MappingsLut mCompleteMappings;
264 BaseHandle Create( const std::string& templateName, const Replacement& constant );
266 BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
268 void LoadConstants( const TreeNode& root, Property::Map& intoMap );
270 void LoadIncludes( const std::string& data );
272 bool ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
274 Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
276 typedef std::vector<const char*> KeyStack;
279 * Tests if the value is a string delimited by <>. If it is, then it attempts to
280 * change the value to the mapping from a matching key in the mappings table.
281 * @param[in] mappingRoot The JSON node containing the mappings
282 * @param[in,out] keyStack the stack of visited keys
283 * @param[in,out] value The string value to test and write back to.
284 * @return true if the value was converted, false otherwise.
286 bool ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& value );
289 * Find the key in the mapping table, if it's present, then generate a property value for it (of the given type if available), recursing as necessary, and stopping if any cycles
291 * @param[in] mappingRoot The JSON node containing the mappings
292 * @param[in] theKey The key to search for
293 * @param[in,out] keyStack the stack of visited keys
294 * @param[in] propertyType The property type if known, or NONE
295 * @param[in,out] value The string value to test and write back to.
297 bool RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, Property::Value& value );
300 * Find the key in the mapping table, if it's present, then generate a property value for it (of the given type if available), recursing as necessary, and stopping if any cycles
302 * @param[in] mappingRoot The JSON node containing the mappings
303 * @param[in] theKey The key to search for
304 * @param[in] propertyType The property type if known, or NONE
305 * @param[in,out] value The string value to test and write back to.
307 bool GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value );
309 void ApplyProperties( const TreeNode& root, const TreeNode& node,
310 Dali::Handle& handle, const Replacement& constant );
312 void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
313 Dali::Handle& handle, const Replacement& constant );
315 void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
316 Dali::Handle& handle, const Replacement& constant );
318 void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
320 Toolkit::Builder::BuilderSignalType mQuitSignal;
323 } // namespace Internal
325 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
327 DALI_ASSERT_ALWAYS(obj);
329 Dali::BaseObject& handle = obj.GetBaseObject();
331 return static_cast<Internal::Builder&>(handle);
334 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
336 DALI_ASSERT_ALWAYS(obj);
338 const Dali::BaseObject& handle = obj.GetBaseObject();
340 return static_cast<const Internal::Builder&>(handle);
343 } // namespace Toolkit
347 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__