1 #ifndef DALI_TOOLKIT_INTERNAL_BUILDER_H
2 #define DALI_TOOLKIT_INTERNAL_BUILDER_H
5 * Copyright (c) 2020 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/vector-wrapper.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>
36 #include <dali-toolkit/internal/builder/style.h>
38 // Warning messages usually displayed
39 #define DALI_SCRIPT_WARNING(format, ...) \
40 DALI_LOG_WARNING("Script:" format, ## __VA_ARGS__)
42 // Info messages are usually debug build
43 #define DALI_SCRIPT_INFO(format, ...) \
44 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ## __VA_ARGS__)
46 // Info Verbose need to be swiched on in gFilterScript filter constructor (by default set to General)
47 #define DALI_SCRIPT_VERBOSE(format, ...) \
48 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ## __VA_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::GetConfigurations
99 const Property::Map& GetConfigurations() const;
102 * @copydoc Toolkit::Builder::GetConstants
104 const Property::Map& GetConstants() const;
107 * @copydoc Toolkit::Builder::GetConstant
109 const Property::Value& GetConstant( const std::string& key ) const;
112 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
114 Animation CreateAnimation( const std::string& animationName );
117 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const Property::Map& map );
119 Animation CreateAnimation( const std::string& animationName, const Property::Map& map );
122 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
124 Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
127 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const Property::Map&, Dali::Actor);
129 Animation CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor );
132 * @copydoc Toolkit::Builder::Create( const std::string& templateName );
134 BaseHandle Create( const std::string& templateName );
137 * @copydoc Toolkit::Builder::Create( const std::string& templateName, const Property::Map& map );
139 BaseHandle Create( const std::string& templateName, const Property::Map& map );
142 * @copydoc Toolkit::Builder::CreateFromJson( const std::string& json );
144 BaseHandle CreateFromJson( const std::string& json );
147 * @copydoc Toolkit::Builder::ApplyFromJson( Handle& handle, const std::string& json );
149 bool ApplyFromJson( Handle& handle, const std::string& json );
152 * @copydoc Toolkit::Builder::ApplyStyle
154 bool ApplyStyle( const std::string& styleName, Handle& handle );
157 * Lookup the stylename in builder. If it's found in the parse tree,
159 * @param[in] styleName The style name to search for
160 * @return true if the stylename exists
162 bool LookupStyleName( const std::string& styleName );
165 * Lookup the stylename in the recorded Styles - if it exists,
166 * performs a shallow copy to the passed in style and returns true.
167 * Otherwise it returns false.
169 * @param[in] styleName The stylename to search for
170 * @return A const pointer to the style object
172 const StylePtr GetStyle( const std::string& styleName );
175 * @copydoc Toolkit::Builder::AddActors
177 void AddActors( Actor toActor );
180 * @copydoc Toolkit::Builder::AddActors
182 void AddActors( const std::string §ionName, Actor toActor );
185 * @copydoc Toolkit::Builder::CreateRenderTask
187 void CreateRenderTask( const std::string &name );
190 * @copydoc Toolkit::Builder::GetPath
192 Path GetPath( const std::string &name );
195 * @copydoc Toolkit::Builder::GetPathConstrainer
197 Dali::PathConstrainer GetPathConstrainer( const std::string& name );
200 * Check if a given constrainer is of type PathConstrainer
201 * @param[in] name The name of the constrainer
202 * @return True if constainer is of type PathConstrainer, False otherwise
205 bool IsPathConstrainer( const std::string& name );
208 * @copydoc Toolkit::Builder::GetLinearConstrainer
210 Dali::LinearConstrainer GetLinearConstrainer( const std::string& name );
213 * Check if a given constrainer is of type LinearConstrainer
214 * @param[in] name The name of the constrainer
215 * @return True if constainer is of type LinearConstrainer, False otherwise
218 bool IsLinearConstrainer( const std::string& name );
221 * @copydoc Toolkit::Builder::QuitSignal
223 Toolkit::Builder::BuilderSignalType& QuitSignal();
226 * Emits the quit signal
228 void EmitQuitSignal();
236 typedef std::vector<const char*> KeyStack;
237 typedef std::vector< TreeNode::KeyNodePair > MappingsLut;
238 typedef struct{ std::string name; Dali::LinearConstrainer linearConstrainer; } LinearConstrainerEntry;
239 typedef std::vector<LinearConstrainerEntry> LinearConstrainerLut;
240 typedef struct{ std::string name; Dali::PathConstrainer pathConstrainer; } PathConstrainerEntry;
241 typedef std::vector<PathConstrainerEntry> PathConstrainerLut;
242 typedef std::map<const std::string, Path> PathLut;
246 Builder(const Builder&);
249 Builder& operator=(const Builder& rhs);
251 void LoadConstants( const TreeNode& root, Property::Map& intoMap );
253 void LoadConfiguration( const TreeNode& root, Property::Map& intoMap );
255 Animation CreateAnimation( const std::string& animationName,
256 const Replacement& replacement,
257 Dali::Actor sourceActor );
259 BaseHandle Create( const std::string& templateName,
260 const Replacement& constant );
262 BaseHandle DoCreate( const TreeNode& root,
263 const TreeNode& node,
265 const Replacement& replacements );
267 void SetupTask( RenderTask& task,
268 const Toolkit::TreeNode& node,
269 const Replacement& replacement );
271 bool ApplyStyle( const std::string& styleName,
273 const Replacement& replacement);
275 void ApplyAllStyleProperties( const TreeNode& root,
276 const TreeNode& node,
277 Dali::Handle& handle,
278 const Replacement& constant );
280 void RecordStyles( const char* styleName,
281 const TreeNode& node,
282 Dali::Handle& handle,
283 const Replacement& replacements );
285 void RecordStyle( StylePtr style,
286 const TreeNode& node,
287 Dali::Handle& handle,
288 const Replacement& replacements );
290 void RecordTransitions( const TreeNode::KeyNodePair& keyValue,
291 Property::Array& transitions,
292 const Replacement& replacements );
294 void RecordTransitionData( const TreeNode::KeyNodePair& keyNode,
295 Toolkit::TransitionData& transitionData,
296 const Replacement& replacements );
298 void ApplyProperties( const TreeNode& root,
299 const TreeNode& node,
300 Dali::Handle& handle,
301 const Replacement& constant );
303 void ApplySignals( const TreeNode& root,
304 const TreeNode& node,
305 Dali::Handle& handle );
307 void ApplyStylesByActor( const TreeNode& root,
308 const TreeNode& node,
309 Dali::Handle& handle,
310 const Replacement& constant );
312 void SetProperties( const TreeNode& node,
314 const Replacement& constant );
316 bool MapToTargetProperty( Handle& propertyObject,
317 const std::string& key,
318 const TreeNode& node,
319 const Replacement& constant,
320 Property::Index& index,
321 Property::Value& value );
324 * Find the key in the mapping table, if it's present, then generate
325 * a property value for it (of the given type if available),
326 * recursing as necessary, and stopping if any cycles are detected.
328 * @param[in] mappingRoot The JSON node containing the mappings
329 * @param[in] theKey The key to search for
330 * @param[in] propertyType The property type if known, or NONE
331 * @param[in,out] value The string value to test and write back to.
333 bool GetPropertyMap( const TreeNode& mappingRoot,
335 Property::Type propertyType,
336 Property::Value& value );
338 void SetCustomProperties( const TreeNode& node,
340 const Replacement& constant,
341 const std::string& childName,
342 Property::AccessMode accessMode );
345 * Find the key in the mapping table, if it's present, then generate
346 * a property value for it (of the given type if available),
347 * recursing as necessary, and stopping if any cycles are detected.
349 * @param[in] mappingRoot The JSON node containing the mappings
350 * @param[in] theKey The key to search for
351 * @param[in,out] keyStack the stack of visited keys
352 * @param[in] propertyType The property type if known, or NONE
353 * @param[in,out] value The string value to test and write back to.
355 bool RecursePropertyMap( const TreeNode& mappingRoot,
358 Property::Type propertyType,
359 Property::Value& value );
363 * Tests if the value is a string delimited by <>. If it is, then it attempts to
364 * change the value to the mapping from a matching key in the mappings table.
365 * @param[in] mappingRoot The JSON node containing the mappings
366 * @param[in,out] keyStack the stack of visited keys
367 * @param[in,out] value The string value to test and write back to.
368 * @return true if the value was converted, false otherwise.
370 bool ConvertChildValue( const TreeNode& mappingRoot,
372 Property::Value& value );
375 Toolkit::JsonParser mParser;
377 PathConstrainerLut mPathConstrainerLut;
378 LinearConstrainerLut mLinearConstrainerLut;
379 SlotDelegate<Builder> mSlotDelegate;
380 Property::Map mReplacementMap;
381 Property::Map mConfigurationMap;
382 MappingsLut mCompleteMappings;
383 Dictionary<StylePtr> mStyles; // State based styles
384 Toolkit::Builder::BuilderSignalType mQuitSignal;
387 } // namespace Internal
389 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
391 DALI_ASSERT_ALWAYS(obj);
393 Dali::BaseObject& handle = obj.GetBaseObject();
395 return static_cast<Internal::Builder&>(handle);
398 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
400 DALI_ASSERT_ALWAYS(obj);
402 const Dali::BaseObject& handle = obj.GetBaseObject();
404 return static_cast<const Internal::Builder&>(handle);
407 } // namespace Toolkit
411 #endif // DALI_TOOLKIT_INTERNAL_BUILDER_H