1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
5 * Copyright (c) 2017 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.
21 #include <dali/public-api/object/base-object.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
37 class VisualFactoryCache;
38 typedef IntrusivePtr<VisualFactoryCache> VisualFactoryCachePtr;
41 * @copydoc Toolkit::VisualFactory
43 class VisualFactory : public BaseObject
50 * @param[in] debugEnabled If true, use debug renderer to replace all the concrete renderer.
52 VisualFactory( bool debugEnabled );
55 * @copydoc Toolkit::VisualFactory::CreateVisual( const Property::Map& )
57 Toolkit::Visual::Base CreateVisual( const Property::Map& propertyMap );
60 * @copydoc Toolkit::VisualFactory::CreateVisual( const Image& )
62 Toolkit::Visual::Base CreateVisual( const Image& image );
65 * @copydoc Toolkit::VisualFactory::CreateVisual( const std::string&, ImageDimensions )
67 Toolkit::Visual::Base CreateVisual( const std::string& image, ImageDimensions size );
70 * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
72 void SetPreMultiplyOnLoad( bool preMultiply );
75 * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
77 bool GetPreMultiplyOnLoad() const;
80 * @return the reference to texture manager
82 Internal::TextureManager& GetTextureManager();
87 * A reference counted object may only be deleted by calling Unreference()
89 virtual ~VisualFactory();
93 * Get the factory cache, creating it if necessary.
95 Internal::VisualFactoryCache& GetFactoryCache();
97 VisualFactory(const VisualFactory&) = delete;
99 VisualFactory& operator=(const VisualFactory& rhs) = delete;
103 VisualFactoryCachePtr mFactoryCache;
104 bool mDebugEnabled:1;
105 bool mPreMultiplyOnLoad:1; ///< Local store for this flag ( as mFactoryCache is lazy laoded )
109 * @brief Template to allow discard old visual, get new one and set it on stage if possible
111 * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
112 * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
114 * @param[in] actor Actor for which the visual will be replaced
115 * @param[in,out] visual The visual to be replaced
116 * @param[in] param0 First template based argument passed to the visual factory
117 * @param[in] param1 Second template based argument passed to the visual factory
119 template< class ParameterType0, class ParameterType1 >
120 void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1 )
124 Toolkit::GetImplementation(visual).SetOffStage( actor );
126 visual = Toolkit::VisualFactory::Get().CreateVisual( param0, param1 );
127 if( visual && actor && actor.OnStage() )
129 Toolkit::GetImplementation(visual).SetOnStage(actor);
134 * @brief Template to allow discard old visual, get new one and set it on stage if possible
136 * @tparam ParameterType The type of argument passed to the CreateVisual()
138 * @param[in] actor Actor for which the visual will be replaced
139 * @param[in,out] visual The visual to be replaced
140 * @param[in] param Template based argument passed to the visual factory
142 template< class ParameterType >
143 void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param )
145 if( actor && visual )
147 Toolkit::GetImplementation(visual).SetOffStage( actor );
149 visual = Toolkit::VisualFactory::Get().CreateVisual( param );
150 if( visual && actor && actor.OnStage() )
152 Toolkit::GetImplementation(visual).SetOnStage(actor);
156 } // namespace Internal
158 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
160 DALI_ASSERT_ALWAYS( factory && "VisualFactory handle is empty" );
162 const BaseObject& handle = factory.GetBaseObject();
164 return static_cast<const Internal::VisualFactory&>(handle);
167 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
169 DALI_ASSERT_ALWAYS( factory && "VisualFactory handle is empty" );
171 BaseObject& handle = factory.GetBaseObject();
173 return static_cast<Internal::VisualFactory&>(handle);
176 } // namespace Toolkit
180 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */