1 #ifndef DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
2 #define DALI_TOOLKIT_VISUAL_FACTORY_IMPL_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.
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>
27 #include <dali-toolkit/public-api/styling/style-manager.h>
28 #include <dali-toolkit/devel-api/styling/style-manager-devel.h>
39 class VisualFactoryCache;
40 class ImageVisualShaderFactory;
43 * @copydoc Toolkit::VisualFactory
45 class VisualFactory : public BaseObject
52 * @param[in] debugEnabled If true, use debug renderer to replace all the concrete renderer.
54 VisualFactory( bool debugEnabled );
57 * @brief StyleChanged callback
59 * @param[in] styleManager Handle for style manager.
60 * @param[in] type Style change type.
62 void OnStyleChangedSignal( Toolkit::StyleManager styleManager, StyleChange::Type type );
65 * @copydoc Toolkit::VisualFactory::CreateVisual( const Property::Map& )
67 Toolkit::Visual::Base CreateVisual( const Property::Map& propertyMap );
70 * @copydoc Toolkit::VisualFactory::CreateVisual( const std::string&, ImageDimensions )
72 Toolkit::Visual::Base CreateVisual( const std::string& image, ImageDimensions size );
75 * @copydoc Toolkit::VisualFactory::SetPreMultiplyOnLoad()
77 void SetPreMultiplyOnLoad( bool preMultiply );
80 * @copydoc Toolkit::VisualFactory::GetPreMultiplyOnLoad()
82 bool GetPreMultiplyOnLoad() const;
85 * @return the reference to texture manager
87 Internal::TextureManager& GetTextureManager();
92 * A reference counted object may only be deleted by calling Unreference()
94 virtual ~VisualFactory();
98 * Get the factory cache, creating it if necessary.
100 Internal::VisualFactoryCache& GetFactoryCache();
103 * Get the image visual shader factory, creating it if necessary.
105 ImageVisualShaderFactory& GetImageVisualShaderFactory();
107 VisualFactory(const VisualFactory&) = delete;
109 VisualFactory& operator=(const VisualFactory& rhs) = delete;
112 std::unique_ptr< VisualFactoryCache > mFactoryCache;
113 std::unique_ptr< ImageVisualShaderFactory > mImageVisualShaderFactory;
114 SlotDelegate< VisualFactory > mSlotDelegate;
115 bool mDebugEnabled:1;
116 bool mPreMultiplyOnLoad:1; ///< Local store for this flag
120 * @brief Template to allow discard old visual, get new one and set it on stage if possible
122 * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
123 * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
125 * @param[in] actor Actor for which the visual will be replaced
126 * @param[in,out] visual The visual to be replaced
127 * @param[in] param0 First template based argument passed to the visual factory
128 * @param[in] param1 Second template based argument passed to the visual factory
130 template< class ParameterType0, class ParameterType1 >
131 void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1 )
135 Toolkit::GetImplementation(visual).SetOffStage( actor );
137 visual = Toolkit::VisualFactory::Get().CreateVisual( param0, param1 );
138 if( visual && actor && actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
140 Toolkit::GetImplementation(visual).SetOnStage(actor);
145 * @brief Template to allow discard old visual, get new one and set it on stage if possible
147 * @tparam ParameterType The type of argument passed to the CreateVisual()
149 * @param[in] actor Actor for which the visual will be replaced
150 * @param[in,out] visual The visual to be replaced
151 * @param[in] param Template based argument passed to the visual factory
153 template< class ParameterType >
154 void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param )
156 if( actor && visual )
158 Toolkit::GetImplementation(visual).SetOffStage( actor );
160 visual = Toolkit::VisualFactory::Get().CreateVisual( param );
161 if( visual && actor && actor.GetProperty< bool >( Actor::Property::CONNECTED_TO_SCENE ) )
163 Toolkit::GetImplementation(visual).SetOnStage(actor);
167 } // namespace Internal
169 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)
171 DALI_ASSERT_ALWAYS( factory && "VisualFactory handle is empty" );
173 const BaseObject& handle = factory.GetBaseObject();
175 return static_cast<const Internal::VisualFactory&>(handle);
178 inline Internal::VisualFactory& GetImplementation(Toolkit::VisualFactory& factory)
180 DALI_ASSERT_ALWAYS( factory && "VisualFactory handle is empty" );
182 BaseObject& handle = factory.GetBaseObject();
184 return static_cast<Internal::VisualFactory&>(handle);
187 } // namespace Toolkit
191 #endif /* DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H */