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::GetFrameBufferImage
168 FrameBufferImage GetFrameBufferImage( const std::string &name );
171 * @copydoc Toolkit::Builder::GetFrameBufferImage
173 FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
176 * @copydoc Toolkit::Builder::GetPath
178 Path GetPath( const std::string &name );
181 * @copydoc Toolkit::Builder::GetPathConstrainer
183 Dali::PathConstrainer GetPathConstrainer( const std::string& name );
186 * Check if a given constrainer is of type PathConstrainer
187 * @param[in] name The name of the constrainer
188 * @return True if constainer is of type PathConstrainer, False otherwise
191 bool IsPathConstrainer( const std::string& name );
194 * @copydoc Toolkit::Builder::GetLinearConstrainer
196 Dali::LinearConstrainer GetLinearConstrainer( const std::string& name );
199 * Check if a given constrainer is of type LinearConstrainer
200 * @param[in] name The name of the constrainer
201 * @return True if constainer is of type LinearConstrainer, False otherwise
204 bool IsLinearConstrainer( const std::string& name );
207 * @copydoc Toolkit::Builder::QuitSignal
209 Toolkit::Builder::BuilderSignalType& QuitSignal();
212 * Emits the quit signal
214 void EmitQuitSignal();
222 Builder(const Builder&);
223 Builder& operator=(const Builder& rhs);
225 void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
227 void SetCustomProperties( const TreeNode& node, Handle& handle, const Replacement& constant, const std::string& childName, Property::AccessMode accessMode );
230 Toolkit::JsonParser mParser;
232 typedef std::map<const std::string, FrameBufferImage> ImageLut;
233 ImageLut mFrameBufferImageLut;
235 typedef std::map<const std::string, Path> PathLut;
238 typedef struct{ std::string name; Dali::PathConstrainer pathConstrainer; } PathConstrainerEntry;
239 typedef std::vector<PathConstrainerEntry> PathConstrainerLut;
240 PathConstrainerLut mPathConstrainerLut;
242 typedef struct{ std::string name; Dali::LinearConstrainer linearConstrainer; } LinearConstrainerEntry;
243 typedef std::vector<LinearConstrainerEntry> LinearConstrainerLut;
244 LinearConstrainerLut mLinearConstrainerLut;
246 SlotDelegate<Builder> mSlotDelegate;
248 Property::Map mReplacementMap;
250 typedef std::vector< TreeNode::KeyNodePair > MappingsLut;
251 MappingsLut mCompleteMappings;
253 BaseHandle Create( const std::string& templateName, const Replacement& constant );
255 BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
257 void LoadConstants( const TreeNode& root, Property::Map& intoMap );
259 void LoadIncludes( const std::string& data );
261 bool ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
263 Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
265 typedef std::vector<const char*> KeyStack;
268 * Tests if the value is a string delimited by <>. If it is, then it attempts to
269 * change the value to the mapping from a matching key in the mappings table.
270 * @param[in] mappingRoot The JSON node containing the mappings
271 * @param[in,out] keyStack the stack of visited keys
272 * @param[in,out] value The string value to test and write back to.
273 * @return true if the value was converted, false otherwise.
275 bool ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& value );
278 * 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
280 * @param[in] mappingRoot The JSON node containing the mappings
281 * @param[in] theKey The key to search for
282 * @param[in,out] keyStack the stack of visited keys
283 * @param[in] propertyType The property type if known, or NONE
284 * @param[in,out] value The string value to test and write back to.
286 bool RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, 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] propertyType The property type if known, or NONE
294 * @param[in,out] value The string value to test and write back to.
296 bool GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value );
298 void ApplyProperties( const TreeNode& root, const TreeNode& node,
299 Dali::Handle& handle, const Replacement& constant );
301 void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
302 Dali::Handle& handle, const Replacement& constant );
304 void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
305 Dali::Handle& handle, const Replacement& constant );
307 void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
309 Toolkit::Builder::BuilderSignalType mQuitSignal;
312 } // namespace Internal
314 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
316 DALI_ASSERT_ALWAYS(obj);
318 Dali::BaseObject& handle = obj.GetBaseObject();
320 return static_cast<Internal::Builder&>(handle);
323 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
325 DALI_ASSERT_ALWAYS(obj);
327 const Dali::BaseObject& handle = obj.GetBaseObject();
329 return static_cast<const Internal::Builder&>(handle);
332 } // namespace Toolkit
336 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__