1 #ifndef DALI_TOOLKIT_INTERNAL_BUILDER_H
2 #define DALI_TOOLKIT_INTERNAL_BUILDER_H
5 * Copyright (c) 2019 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>
37 #include <dali-toolkit/internal/builder/style.h>
39 // Warning messages usually displayed
40 #define DALI_SCRIPT_WARNING(format, ...) \
41 DALI_LOG_WARNING("Script:" format, ## __VA_ARGS__)
43 // Info messages are usually debug build
44 #define DALI_SCRIPT_INFO(format, ...) \
45 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ## __VA_ARGS__)
47 // Info Verbose need to be swiched on in gFilterScript filter constructor (by default set to General)
48 #define DALI_SCRIPT_VERBOSE(format, ...) \
49 DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ## __VA_ARGS__)
65 #if defined(DEBUG_ENABLED)
66 extern Dali::Integration::Log::Filter* gFilterScript;
73 * @copydoc Toolkit::Builder
75 class Builder : public Dali::BaseObject
82 * @copydoc Toolkit::Builder::LoadFromString
84 void LoadFromString( const std::string &data,
85 Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON );
88 * @copydoc Toolkit::Builder::AddConstants
90 void AddConstants( const Property::Map& map );
93 * @copydoc Toolkit::Builder::AddConstant
95 void AddConstant( const std::string& key, const Property::Value& value );
98 * @copydoc Toolkit::Builder::GetConfigurations
100 const Property::Map& GetConfigurations() const;
103 * @copydoc Toolkit::Builder::GetConstants
105 const Property::Map& GetConstants() const;
108 * @copydoc Toolkit::Builder::GetConstant
110 const Property::Value& GetConstant( const std::string& key ) const;
113 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName );
115 Animation CreateAnimation( const std::string& animationName );
118 * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const Property::Map& map );
120 Animation CreateAnimation( const std::string& animationName, const Property::Map& map );
123 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor);
125 Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor );
128 * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const Property::Map&, Dali::Actor);
130 Animation CreateAnimation( const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor );
133 * @copydoc Toolkit::Builder::Create( const std::string& templateName );
135 BaseHandle Create( const std::string& templateName );
138 * @copydoc Toolkit::Builder::Create( const std::string& templateName, const Property::Map& map );
140 BaseHandle Create( const std::string& templateName, const Property::Map& map );
143 * @copydoc Toolkit::Builder::CreateFromJson( const std::string& json );
145 BaseHandle CreateFromJson( const std::string& json );
148 * @copydoc Toolkit::Builder::ApplyFromJson( Handle& handle, const std::string& json );
150 bool ApplyFromJson( Handle& handle, const std::string& json );
153 * @copydoc Toolkit::Builder::ApplyStyle
155 bool ApplyStyle( const std::string& styleName, Handle& handle );
158 * Lookup the stylename in builder. If it's found in the parse tree,
160 * @param[in] styleName The style name to search for
161 * @return true if the stylename exists
163 bool LookupStyleName( const std::string& styleName );
166 * Lookup the stylename in the recorded Styles - if it exists,
167 * performs a shallow copy to the passed in style and returns true.
168 * Otherwise it returns false.
170 * @param[in] styleName The stylename to search for
171 * @return A const pointer to the style object
173 const StylePtr GetStyle( const std::string& styleName );
176 * @copydoc Toolkit::Builder::AddActors
178 void AddActors( Actor toActor );
181 * @copydoc Toolkit::Builder::AddActors
183 void AddActors( const std::string §ionName, Actor toActor );
186 * @copydoc Toolkit::Builder::CreateRenderTask
188 void CreateRenderTask( const std::string &name );
191 * @copydoc Toolkit::Builder::GetPath
193 Path GetPath( const std::string &name );
196 * @copydoc Toolkit::Builder::GetPathConstrainer
198 Dali::PathConstrainer GetPathConstrainer( const std::string& name );
201 * Check if a given constrainer is of type PathConstrainer
202 * @param[in] name The name of the constrainer
203 * @return True if constainer is of type PathConstrainer, False otherwise
206 bool IsPathConstrainer( const std::string& name );
209 * @copydoc Toolkit::Builder::GetLinearConstrainer
211 Dali::LinearConstrainer GetLinearConstrainer( const std::string& name );
214 * Check if a given constrainer is of type LinearConstrainer
215 * @param[in] name The name of the constrainer
216 * @return True if constainer is of type LinearConstrainer, False otherwise
219 bool IsLinearConstrainer( const std::string& name );
222 * @copydoc Toolkit::Builder::QuitSignal
224 Toolkit::Builder::BuilderSignalType& QuitSignal();
227 * Emits the quit signal
229 void EmitQuitSignal();
237 typedef std::vector<const char*> KeyStack;
238 typedef std::vector< TreeNode::KeyNodePair > MappingsLut;
239 typedef struct{ std::string name; Dali::LinearConstrainer linearConstrainer; } LinearConstrainerEntry;
240 typedef std::vector<LinearConstrainerEntry> LinearConstrainerLut;
241 typedef struct{ std::string name; Dali::PathConstrainer pathConstrainer; } PathConstrainerEntry;
242 typedef std::vector<PathConstrainerEntry> PathConstrainerLut;
243 typedef std::map<const std::string, Path> PathLut;
247 Builder(const Builder&);
250 Builder& operator=(const Builder& rhs);
252 void LoadConstants( const TreeNode& root, Property::Map& intoMap );
254 void LoadConfiguration( const TreeNode& root, Property::Map& intoMap );
256 Animation CreateAnimation( const std::string& animationName,
257 const Replacement& replacement,
258 Dali::Actor sourceActor );
260 BaseHandle Create( const std::string& templateName,
261 const Replacement& constant );
263 BaseHandle DoCreate( const TreeNode& root,
264 const TreeNode& node,
266 const Replacement& replacements );
268 void SetupTask( RenderTask& task,
269 const Toolkit::TreeNode& node,
270 const Replacement& replacement );
272 bool ApplyStyle( const std::string& styleName,
274 const Replacement& replacement);
276 void ApplyAllStyleProperties( const TreeNode& root,
277 const TreeNode& node,
278 Dali::Handle& handle,
279 const Replacement& constant );
281 void RecordStyles( const char* styleName,
282 const TreeNode& node,
283 Dali::Handle& handle,
284 const Replacement& replacements );
286 void RecordStyle( StylePtr style,
287 const TreeNode& node,
288 Dali::Handle& handle,
289 const Replacement& replacements );
291 void RecordTransitions( const TreeNode::KeyNodePair& keyValue,
292 Property::Array& transitions,
293 const Replacement& replacements );
295 void RecordTransitionData( const TreeNode::KeyNodePair& keyNode,
296 Toolkit::TransitionData& transitionData,
297 const Replacement& replacements );
299 void ApplyProperties( const TreeNode& root,
300 const TreeNode& node,
301 Dali::Handle& handle,
302 const Replacement& constant );
304 void ApplySignals( const TreeNode& root,
305 const TreeNode& node,
306 Dali::Handle& handle );
308 void ApplyStylesByActor( const TreeNode& root,
309 const TreeNode& node,
310 Dali::Handle& handle,
311 const Replacement& constant );
313 void SetProperties( const TreeNode& node,
315 const Replacement& constant );
317 bool MapToTargetProperty( Handle& propertyObject,
318 const std::string& key,
319 const TreeNode& node,
320 const Replacement& constant,
321 Property::Index& index,
322 Property::Value& value );
325 * Find the key in the mapping table, if it's present, then generate
326 * a property value for it (of the given type if available),
327 * recursing as necessary, and stopping if any cycles are detected.
329 * @param[in] mappingRoot The JSON node containing the mappings
330 * @param[in] theKey The key to search for
331 * @param[in] propertyType The property type if known, or NONE
332 * @param[in,out] value The string value to test and write back to.
334 bool GetPropertyMap( const TreeNode& mappingRoot,
336 Property::Type propertyType,
337 Property::Value& value );
339 void SetCustomProperties( const TreeNode& node,
341 const Replacement& constant,
342 const std::string& childName,
343 Property::AccessMode accessMode );
346 * Find the key in the mapping table, if it's present, then generate
347 * a property value for it (of the given type if available),
348 * recursing as necessary, and stopping if any cycles are detected.
350 * @param[in] mappingRoot The JSON node containing the mappings
351 * @param[in] theKey The key to search for
352 * @param[in,out] keyStack the stack of visited keys
353 * @param[in] propertyType The property type if known, or NONE
354 * @param[in,out] value The string value to test and write back to.
356 bool RecursePropertyMap( const TreeNode& mappingRoot,
359 Property::Type propertyType,
360 Property::Value& value );
364 * Tests if the value is a string delimited by <>. If it is, then it attempts to
365 * change the value to the mapping from a matching key in the mappings table.
366 * @param[in] mappingRoot The JSON node containing the mappings
367 * @param[in,out] keyStack the stack of visited keys
368 * @param[in,out] value The string value to test and write back to.
369 * @return true if the value was converted, false otherwise.
371 bool ConvertChildValue( const TreeNode& mappingRoot,
373 Property::Value& value );
376 Toolkit::JsonParser mParser;
378 PathConstrainerLut mPathConstrainerLut;
379 LinearConstrainerLut mLinearConstrainerLut;
380 SlotDelegate<Builder> mSlotDelegate;
381 Property::Map mReplacementMap;
382 Property::Map mConfigurationMap;
383 MappingsLut mCompleteMappings;
384 Dictionary<StylePtr> mStyles; // State based styles
385 Toolkit::Builder::BuilderSignalType mQuitSignal;
388 } // namespace Internal
390 inline Internal::Builder& GetImpl(Dali::Toolkit::Builder& obj)
392 DALI_ASSERT_ALWAYS(obj);
394 Dali::BaseObject& handle = obj.GetBaseObject();
396 return static_cast<Internal::Builder&>(handle);
399 inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj)
401 DALI_ASSERT_ALWAYS(obj);
403 const Dali::BaseObject& handle = obj.GetBaseObject();
405 return static_cast<const Internal::Builder&>(handle);
408 } // namespace Toolkit
412 #endif // DALI_TOOLKIT_INTERNAL_BUILDER_H