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/common/vector-wrapper.h>
27 #include <dali/public-api/actors/actor.h>
28 #include <dali/public-api/object/base-object.h>
29 #include <dali/public-api/object/property-map.h>
30 #include <dali/public-api/render-tasks/render-task.h>
31 #include <dali/integration-api/debug.h>
34 #include <dali-toolkit/devel-api/builder/json-parser.h>
35 #include <dali-toolkit/devel-api/builder/builder.h>
36 #include <dali-toolkit/internal/builder/builder-declarations.h>
38 // Warning messages usually displayed
39 #define DALI_SCRIPT_WARNING(format, args...) \
40 DALI_LOG_WARNING("Script:" format, ## args)
42 // Info messages are usually debug build
43 #define DALI_SCRIPT_INFO(format, args...) \
44 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ## args)
46 // Info Verbose need to be swiched on in gFilterScript filter constructor (by default set to General)
47 #define DALI_SCRIPT_VERBOSE(format, args...) \
48 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ## args)
64 #if defined(DEBUG_ENABLED)
65 extern Dali::Integration::Log::Filter* gFilterScript;
72 * @copydoc Toolkit::Builder
74 class Builder : public Dali::BaseObject
81 * @copydoc Toolkit::Builder::LoadFromString
83 void LoadFromString( const std::string &data,
84 Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON );
87 * @copydoc Toolkit::Builder::AddConstants
89 void AddConstants( const Property::Map& map );
92 * @copydoc Toolkit::Builder::AddConstant
94 void AddConstant( const std::string& key, const Property::Value& value );
97 * @copydoc Toolkit::Builder::GetConstants
99 const Property::Map& GetConstants() const;
102 * @copydoc Toolkit::Builder::GetConstant
104 const Property::Value& GetConstant( const std::string& key ) const;
107 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
109 Animation CreateAnimation( const std::string& animationName );
112 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const Property::Map& map );
114 Animation CreateAnimation( const std::string& animationName, const Property::Map& map );
117 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
119 Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
122 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const Property::Map&, Dali::Actor);
124 Animation CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor );
127 * @copydoc Toolkit::Builder::Create( const std::string& templateName );
129 BaseHandle Create( const std::string& templateName );
132 * @copydoc Toolkit::Builder::Create( const std::string& templateName, const Property::Map& map );
134 BaseHandle Create( const std::string& templateName, const Property::Map& map );
137 * @copydoc Toolkit::Builder::CreateFromJson( const std::string& json );
139 BaseHandle CreateFromJson( const std::string& json );
142 * @copydoc Toolkit::Builder::ApplyFromJson( Handle& handle, const std::string& json );
144 bool ApplyFromJson( Handle& handle, const std::string& json );
147 * @copydoc Toolkit::Builder::ApplyStyle
149 bool ApplyStyle( const std::string& styleName, Handle& handle );
152 * @copydoc Toolkit::Builder::AddActors
154 void AddActors( Actor toActor );
157 * @copydoc Toolkit::Builder::AddActors
159 void AddActors( const std::string §ionName, Actor toActor );
162 * @copydoc Toolkit::Builder::CreateRenderTask
164 void CreateRenderTask( const std::string &name );
167 * @copydoc Toolkit::Builder::GetFrameBufferImage
169 FrameBufferImage GetFrameBufferImage( const std::string &name );
172 * @copydoc Toolkit::Builder::GetFrameBufferImage
174 FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant );
177 * @copydoc Toolkit::Builder::GetPath
179 Path GetPath( const std::string &name );
182 * @copydoc Toolkit::Builder::GetPathConstrainer
184 Dali::PathConstrainer GetPathConstrainer( const std::string& name );
187 * Check if a given constrainer is of type PathConstrainer
188 * @param[in] name The name of the constrainer
189 * @return True if constainer is of type PathConstrainer, False otherwise
192 bool IsPathConstrainer( const std::string& name );
195 * @copydoc Toolkit::Builder::GetLinearConstrainer
197 Dali::LinearConstrainer GetLinearConstrainer( const std::string& name );
200 * Check if a given constrainer is of type LinearConstrainer
201 * @param[in] name The name of the constrainer
202 * @return True if constainer is of type LinearConstrainer, False otherwise
205 bool IsLinearConstrainer( const std::string& name );
208 * @copydoc Toolkit::Builder::QuitSignal
210 Toolkit::Builder::BuilderSignalType& QuitSignal();
213 * Emits the quit signal
215 void EmitQuitSignal();
223 Builder(const Builder&);
224 Builder& operator=(const Builder& rhs);
226 void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement );
228 void SetCustomProperties( const TreeNode& node, Handle& handle, const Replacement& constant, const std::string& childName, Property::AccessMode accessMode );
231 Toolkit::JsonParser mParser;
233 typedef std::map<const std::string, FrameBufferImage> ImageLut;
234 ImageLut mFrameBufferImageLut;
236 typedef std::map<const std::string, Path> PathLut;
239 typedef struct{ std::string name; Dali::PathConstrainer pathConstrainer; } PathConstrainerEntry;
240 typedef std::vector<PathConstrainerEntry> PathConstrainerLut;
241 PathConstrainerLut mPathConstrainerLut;
243 typedef struct{ std::string name; Dali::LinearConstrainer linearConstrainer; } LinearConstrainerEntry;
244 typedef std::vector<LinearConstrainerEntry> LinearConstrainerLut;
245 LinearConstrainerLut mLinearConstrainerLut;
247 SlotDelegate<Builder> mSlotDelegate;
249 Property::Map mReplacementMap;
251 typedef std::vector< TreeNode::KeyNodePair > MappingsLut;
252 MappingsLut mCompleteMappings;
254 BaseHandle Create( const std::string& templateName, const Replacement& constant );
256 BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements );
258 void LoadConstants( const TreeNode& root, Property::Map& intoMap );
260 void LoadIncludes( const std::string& data );
262 bool ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement);
264 Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor );
266 typedef std::vector<const char*> KeyStack;
269 * Tests if the value is a string delimited by <>. If it is, then it attempts to
270 * change the value to the mapping from a matching key in the mappings table.
271 * @param[in] mappingRoot The JSON node containing the mappings
272 * @param[in,out] keyStack the stack of visited keys
273 * @param[in,out] value The string value to test and write back to.
274 * @return true if the value was converted, false otherwise.
276 bool ConvertChildValue( const TreeNode& mappingRoot, KeyStack& keyStack, Property::Value& value );
279 * 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
281 * @param[in] mappingRoot The JSON node containing the mappings
282 * @param[in] theKey The key to search for
283 * @param[in,out] keyStack the stack of visited keys
284 * @param[in] propertyType The property type if known, or NONE
285 * @param[in,out] value The string value to test and write back to.
287 bool RecursePropertyMap( const TreeNode& mappingRoot, KeyStack& keyStack, const char* theKey, Property::Type propertyType, Property::Value& value );
290 * 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
292 * @param[in] mappingRoot The JSON node containing the mappings
293 * @param[in] theKey The key to search for
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 GetPropertyMap( const TreeNode& mappingRoot, const char* theKey, Property::Type propertyType, Property::Value& value );
299 void ApplyProperties( const TreeNode& root, const TreeNode& node,
300 Dali::Handle& handle, const Replacement& constant );
302 void ApplyStylesByActor( const TreeNode& root, const TreeNode& node,
303 Dali::Handle& handle, const Replacement& constant );
305 void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node,
306 Dali::Handle& handle, const Replacement& constant );
308 void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant );
310 Toolkit::Builder::BuilderSignalType mQuitSignal;
313 } // namespace Internal
315 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
317 DALI_ASSERT_ALWAYS(obj);
319 Dali::BaseObject& handle = obj.GetBaseObject();
321 return static_cast<Internal::Builder&>(handle);
324 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
326 DALI_ASSERT_ALWAYS(obj);
328 const Dali::BaseObject& handle = obj.GetBaseObject();
330 return static_cast<const Internal::Builder&>(handle);
333 } // namespace Toolkit
337 #endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__