X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fbuilder%2Fbuilder-impl.h;h=59ff5de956680e8b46ab80c310d760e376daaf1e;hp=87a35b98b86ee9eb0c23bace3cc6c514f69d0fdb;hb=7018f61b640b6fcf9cb576b537bafcb6bb8240e8;hpb=6bd46a2944d89638f1c1a1c609f72c9348db6abb diff --git a/dali-toolkit/internal/builder/builder-impl.h b/dali-toolkit/internal/builder/builder-impl.h index 87a35b9..59ff5de 100644 --- a/dali-toolkit/internal/builder/builder-impl.h +++ b/dali-toolkit/internal/builder/builder-impl.h @@ -1,61 +1,63 @@ -#ifndef __DALI_TOOLKIT_INTERNAL_BUILDER_H__ -#define __DALI_TOOLKIT_INTERNAL_BUILDER_H__ - -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +#ifndef DALI_TOOLKIT_INTERNAL_BUILDER_H +#define DALI_TOOLKIT_INTERNAL_BUILDER_H + +/* + * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ // EXTERNAL INCLUDES -#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include +#include // INTERNAL INCLUDES -#include -#include +#include +#include #include +#include // Warning messages usually displayed -#define DALI_SCRIPT_WARNING(format, args...) \ - DALI_LOG_WARNING("Script:" format, ## args) +#define DALI_SCRIPT_WARNING(format, ...) \ + DALI_LOG_WARNING("Script:" format, ##__VA_ARGS__) // Info messages are usually debug build -#define DALI_SCRIPT_INFO(format, args...) \ - DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ## args) +#define DALI_SCRIPT_INFO(format, ...) \ + DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::General, "Script:" format, ##__VA_ARGS__) // Info Verbose need to be swiched on in gFilterScript filter constructor (by default set to General) -#define DALI_SCRIPT_VERBOSE(format, args...) \ - DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ## args) +#define DALI_SCRIPT_VERBOSE(format, ...) \ + DALI_LOG_INFO(Dali::Toolkit::Internal::gFilterScript, Debug::Verbose, "Script:" format, ##__VA_ARGS__) namespace Dali { - namespace Toolkit { - class TreeNode; +class TreeNode; } namespace Toolkit { - namespace Internal { - #if defined(DEBUG_ENABLED) extern Dali::Integration::Log::Filter* gFilterScript; #endif @@ -69,184 +71,318 @@ class Replacement; class Builder : public Dali::BaseObject { public: - Builder(); /** * @copydoc Toolkit::Builder::LoadFromString */ - void LoadFromString( const std::string &data, - Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON ); + void LoadFromString(const std::string& data, + Dali::Toolkit::Builder::UIFormat rep = Dali::Toolkit::Builder::JSON); /** * @copydoc Toolkit::Builder::AddConstants */ - void AddConstants( const PropertyValueMap& map ); + void AddConstants(const Property::Map& map); /** * @copydoc Toolkit::Builder::AddConstant */ - void AddConstant( const std::string& key, const Property::Value& value ); + void AddConstant(const std::string& key, const Property::Value& value); + + /** + * @copydoc Toolkit::Builder::GetConfigurations + */ + const Property::Map& GetConfigurations() const; /** * @copydoc Toolkit::Builder::GetConstants */ - const PropertyValueMap& GetConstants() const; + const Property::Map& GetConstants() const; /** * @copydoc Toolkit::Builder::GetConstant */ - const Property::Value& GetConstant( const std::string& key ) const; + const Property::Value& GetConstant(const std::string& key) const; /** * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName ); */ - Animation CreateAnimation( const std::string& animationName ); + Animation CreateAnimation(const std::string& animationName); /** - * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const PropertyValueMap& map ); + * @copydoc Toolkit::Builder::CreateAnimation( const std::string& animationName, const Property::Map& map ); */ - Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map ); + Animation CreateAnimation(const std::string& animationName, const Property::Map& map); /** * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,Dali::Actor); */ - Animation CreateAnimation( const std::string& animationName, Dali::Actor sourceActor ); + Animation CreateAnimation(const std::string& animationName, Dali::Actor sourceActor); /** - * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const PropertyValueMap&,Dali::Actor); + * @copydoc Toolkit::Builder::CreateAnimation( const std::string&,const Property::Map&, Dali::Actor); */ - Animation CreateAnimation( const std::string& animationName, const PropertyValueMap& map, Dali::Actor sourceActor ); + Animation CreateAnimation(const std::string& animationName, const Property::Map& map, Dali::Actor sourceActor); /** * @copydoc Toolkit::Builder::Create( const std::string& templateName ); */ - BaseHandle Create( const std::string& templateName ); + BaseHandle Create(const std::string& templateName); /** - * @copydoc Toolkit::Builder::Create( const std::string& templateName, const PropertyValueMap& map ); + * @copydoc Toolkit::Builder::Create( const std::string& templateName, const Property::Map& map ); */ - BaseHandle Create( const std::string& templateName, const PropertyValueMap& map ); + BaseHandle Create(const std::string& templateName, const Property::Map& map); - /** - * @copydoc Toolkit::Builder::GetFont + /** + * @copydoc Toolkit::Builder::CreateFromJson( const std::string& json ); */ - Font GetFont(const std::string &name) const; + BaseHandle CreateFromJson(const std::string& json); /** - * @copydoc Toolkit::Builder::GetTextStyle + * @copydoc Toolkit::Builder::ApplyFromJson( Handle& handle, const std::string& json ); */ - TextStyle GetTextStyle(const std::string &name) const; + bool ApplyFromJson(Handle& handle, const std::string& json); /** - * @copydoc Toolkit::Builder::GetImage + * @copydoc Toolkit::Builder::ApplyStyle */ - Image GetImage(const std::string &name) const; + bool ApplyStyle(const std::string& styleName, Handle& handle); /** - * @copydoc Toolkit::Builder::GetActor + * Lookup the stylename in builder. If it's found in the parse tree, + * then return true. + * @param[in] styleName The style name to search for + * @return true if the stylename exists */ - Actor GetActor( const std::string &name ) const; + bool LookupStyleName(const std::string& styleName); /** - * @copydoc Toolkit::Builder::ApplyStyle - */ - void ApplyStyle( const std::string& styleName, Handle& handle ); + * Lookup the stylename in the recorded Styles - if it exists, + * performs a shallow copy to the passed in style and returns true. + * Otherwise it returns false. - void AnimateTo( const std::string& styleName, Handle& handle ); + * @param[in] styleName The stylename to search for + * @return A const pointer to the style object + */ + const StylePtr GetStyle(const std::string& styleName); /** * @copydoc Toolkit::Builder::AddActors */ - void AddActors( Actor toActor ); + void AddActors(Actor toActor); /** * @copydoc Toolkit::Builder::AddActors */ - void AddActors( const std::string §ionName, Actor toActor ); + void AddActors(const std::string& sectionName, Actor toActor); /** - * @copydoc Toolkit::Builder::GetAnimation + * @copydoc Toolkit::Builder::CreateRenderTask */ - Animation GetAnimation( const std::string &name ) const; + void CreateRenderTask(const std::string& name); /** - * @copydoc Toolkit::Builder::CreateRenderTask + * @copydoc Toolkit::Builder::GetPath */ - void CreateRenderTask( const std::string &name ); + Path GetPath(const std::string& name); /** - * @copydoc Toolkit::Builder::GetShaderEffect + * @copydoc Toolkit::Builder::GetPathConstrainer */ - ShaderEffect GetShaderEffect( const std::string &name ); + Dali::PathConstrainer GetPathConstrainer(const std::string& name); - /** - * @copydoc Toolkit::Builder::GetShaderEffect + /* + * Check if a given constrainer is of type PathConstrainer + * @param[in] name The name of the constrainer + * @return True if constainer is of type PathConstrainer, False otherwise + * */ - ShaderEffect GetShaderEffect( const std::string &name, const Replacement& constant ); + bool IsPathConstrainer(const std::string& name); /** - * @copydoc Toolkit::Builder::GetFrameBufferImage + * @copydoc Toolkit::Builder::GetLinearConstrainer + */ + Dali::LinearConstrainer GetLinearConstrainer(const std::string& name); + + /* + * Check if a given constrainer is of type LinearConstrainer + * @param[in] name The name of the constrainer + * @return True if constainer is of type LinearConstrainer, False otherwise + * */ - FrameBufferImage GetFrameBufferImage( const std::string &name ); + bool IsLinearConstrainer(const std::string& name); /** - * @copydoc Toolkit::Builder::GetFrameBufferImage + * @copydoc Toolkit::Builder::QuitSignal */ - FrameBufferImage GetFrameBufferImage( const std::string &name, const Replacement& constant ); + Toolkit::Builder::BuilderSignalType& QuitSignal(); /** - * @copydoc Toolkit::Builder::GetTopLevelActors + * Emits the quit signal */ - ActorContainer GetTopLevelActors( void ) const; + void EmitQuitSignal(); protected: + ~Builder() override; - virtual ~Builder(); +private: + typedef std::vector KeyStack; + typedef std::vector MappingsLut; + typedef struct + { + std::string name; + Dali::LinearConstrainer linearConstrainer; + } LinearConstrainerEntry; + typedef std::vector LinearConstrainerLut; + typedef struct + { + std::string name; + Dali::PathConstrainer pathConstrainer; + } PathConstrainerEntry; + typedef std::vector PathConstrainerLut; + typedef std::map PathLut; private: // Undefined Builder(const Builder&); + + // Undefined Builder& operator=(const Builder& rhs); - void SetupTask( RenderTask& task, const Toolkit::TreeNode& node, const Replacement& replacement ); + void LoadConstants(const TreeNode& root, Property::Map& intoMap); -private: - Toolkit::JsonParser mParser; + void LoadConfiguration(const TreeNode& root, Property::Map& intoMap); + + Animation CreateAnimation(const std::string& animationName, + const Replacement& replacement, + Dali::Actor sourceActor); - typedef std::map ImageLut; - ImageLut mFrameBufferImageLut; + BaseHandle Create(const std::string& templateName, + const Replacement& constant); - typedef std::map ShaderEffectLut; - ShaderEffectLut mShaderEffectLut; + BaseHandle DoCreate(const TreeNode& root, + const TreeNode& node, + Actor parent, + const Replacement& replacements); - SlotDelegate mSlotDelegate; + void SetupTask(RenderTask& task, + const Toolkit::TreeNode& node, + const Replacement& replacement); - PropertyValueMap mReplacementMap; + bool ApplyStyle(const std::string& styleName, + Handle& handle, + const Replacement& replacement); - BaseHandle Create( const std::string& templateName, const Replacement& constant ); + void ApplyAllStyleProperties(const TreeNode& root, + const TreeNode& node, + Dali::Handle& handle, + const Replacement& constant); - BaseHandle DoCreate( const TreeNode& root, const TreeNode& node, Actor parent, const Replacement& replacements ); + void RecordStyles(const char* styleName, + const TreeNode& node, + Dali::Handle& handle, + const Replacement& replacements); - void LoadConstants( const TreeNode& root, PropertyValueMap& intoMap ); + void RecordStyle(StylePtr style, + const TreeNode& node, + Dali::Handle& handle, + const Replacement& replacements); - void LoadIncludes( const std::string& data ); + void RecordTransitions(const TreeNode::KeyNodePair& keyValue, + Property::Array& transitions, + const Replacement& replacements); - void ApplyStyle( const std::string& styleName, Handle& handle, const Replacement& replacement); + void RecordTransitionData(const TreeNode::KeyNodePair& keyNode, + Toolkit::TransitionData& transitionData, + const Replacement& replacements); - Animation CreateAnimation( const std::string& animationName, const Replacement& replacement, Dali::Actor sourceActor ); + void ApplyProperties(const TreeNode& root, + const TreeNode& node, + Dali::Handle& handle, + const Replacement& constant); - void ApplyProperties( const TreeNode& root, const TreeNode& node, - Dali::Handle& handle, const Replacement& constant ); + void ApplySignals(const TreeNode& root, + const TreeNode& node, + Dali::Handle& handle); - void ApplyStylesByActor( const TreeNode& root, const TreeNode& node, - Dali::Handle& handle, const Replacement& constant ); + void ApplyStylesByActor(const TreeNode& root, + const TreeNode& node, + Dali::Handle& handle, + const Replacement& constant); - void ApplyAllStyleProperties( const TreeNode& root, const TreeNode& node, - Dali::Handle& handle, const Replacement& constant ); + void SetProperties(const TreeNode& node, + Handle& handle, + const Replacement& constant); - void SetProperties( const TreeNode& node, Handle& handle, const Replacement& constant ); + bool MapToTargetProperty(Handle& propertyObject, + const std::string& key, + const TreeNode& node, + const Replacement& constant, + Property::Index& index, + Property::Value& value); + /** + * 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 are detected. + * + * @param[in] mappingRoot The JSON node containing the mappings + * @param[in] theKey The key to search for + * @param[in] propertyType The property type if known, or NONE + * @param[in,out] value The string value to test and write back to. + */ + bool GetPropertyMap(const TreeNode& mappingRoot, + const char* theKey, + Property::Type propertyType, + Property::Value& value); + + void SetCustomProperties(const TreeNode& node, + Handle& handle, + const Replacement& constant, + const std::string& childName, + Property::AccessMode accessMode); + + /** + * 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 are detected. + * + * @param[in] mappingRoot The JSON node containing the mappings + * @param[in] theKey The key to search for + * @param[in,out] keyStack the stack of visited keys + * @param[in] propertyType The property type if known, or NONE + * @param[in,out] value The string value to test and write back to. + */ + bool RecursePropertyMap(const TreeNode& mappingRoot, + KeyStack& keyStack, + const char* theKey, + Property::Type propertyType, + Property::Value& value); + + /** + * Tests if the value is a string delimited by <>. If it is, then it attempts to + * change the value to the mapping from a matching key in the mappings table. + * @param[in] mappingRoot The JSON node containing the mappings + * @param[in,out] keyStack the stack of visited keys + * @param[in,out] value The string value to test and write back to. + * @return true if the value was converted, false otherwise. + */ + bool ConvertChildValue(const TreeNode& mappingRoot, + KeyStack& keyStack, + Property::Value& value); + +private: + Toolkit::JsonParser mParser; + PathLut mPathLut; + PathConstrainerLut mPathConstrainerLut; + LinearConstrainerLut mLinearConstrainerLut; + SlotDelegate mSlotDelegate; + Property::Map mReplacementMap; + Property::Map mConfigurationMap; + MappingsLut mCompleteMappings; + Dictionary mStyles; // State based styles + Toolkit::Builder::BuilderSignalType mQuitSignal; }; } // namespace Internal @@ -273,4 +409,4 @@ inline const Internal::Builder& GetImpl(const Dali::Toolkit::Builder& obj) } // namespace Dali -#endif // __DALI_TOOLKIT_INTERNAL_BUILDER_H__ +#endif // DALI_TOOLKIT_INTERNAL_BUILDER_H