2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
21 #include <dali/integration-api/debug.h>
22 #include <dali/public-api/images/image.h>
23 #include <dali/public-api/object/property-array.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/object/type-registry-helper.h>
26 #include <dali/devel-api/scripting/scripting.h>
29 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
30 #include <dali-toolkit/public-api/visuals/text-visual-properties.h>
31 #include <dali-toolkit/public-api/visuals/visual-properties.h>
32 #include <dali-toolkit/internal/visuals/border/border-visual.h>
33 #include <dali-toolkit/internal/visuals/color/color-visual.h>
34 #include <dali-toolkit/internal/visuals/gradient/gradient-visual.h>
35 #include <dali-toolkit/internal/visuals/image/image-visual.h>
36 #include <dali-toolkit/internal/visuals/mesh/mesh-visual.h>
37 #include <dali-toolkit/internal/visuals/npatch/npatch-visual.h>
38 #include <dali-toolkit/internal/visuals/primitive/primitive-visual.h>
39 #include <dali-toolkit/internal/visuals/svg/svg-visual.h>
40 #include <dali-toolkit/internal/visuals/text/text-visual.h>
41 #include <dali-toolkit/internal/visuals/animated-image/animated-image-visual.h>
42 #include <dali-toolkit/internal/visuals/wireframe/wireframe-visual.h>
43 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
44 #include <dali-toolkit/internal/visuals/visual-url.h>
45 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
61 BaseHandle handle = Toolkit::VisualFactory::Get();
66 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::VisualFactory, Dali::BaseHandle, Create, true )
67 DALI_TYPE_REGISTRATION_END()
71 VisualFactory::VisualFactory( bool debugEnabled )
72 :mDebugEnabled( debugEnabled )
76 VisualFactory::~VisualFactory()
80 Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& propertyMap )
82 // Create factory cache if it hasn't already been
85 mFactoryCache = new VisualFactoryCache();
88 Visual::BasePtr visualPtr;
90 Property::Value* typeValue = propertyMap.Find( Toolkit::Visual::Property::TYPE, VISUAL_TYPE );
91 Toolkit::Visual::Type visualType = Toolkit::Visual::IMAGE; // Default to IMAGE type.
94 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, visualType );
99 case Toolkit::Visual::BORDER:
101 visualPtr = BorderVisual::New( *( mFactoryCache.Get() ), propertyMap );
105 case Toolkit::Visual::COLOR:
107 visualPtr = ColorVisual::New( *( mFactoryCache.Get() ), propertyMap );
111 case Toolkit::Visual::GRADIENT:
113 visualPtr = GradientVisual::New( *( mFactoryCache.Get() ), propertyMap );
117 case Toolkit::Visual::IMAGE:
119 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
120 std::string imageUrl;
123 if( imageURLValue->Get( imageUrl ) )
125 if( !imageUrl.empty() )
127 VisualUrl visualUrl( imageUrl );
129 switch( visualUrl.GetType() )
131 case VisualUrl::N_PATCH:
133 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
138 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
143 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
146 case VisualUrl::REGULAR_IMAGE:
148 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
156 Property::Array* array = imageURLValue->GetArray();
159 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), *array, propertyMap );
166 case Toolkit::Visual::MESH:
168 visualPtr = MeshVisual::New( *( mFactoryCache.Get() ), propertyMap );
172 case Toolkit::Visual::PRIMITIVE:
174 visualPtr = PrimitiveVisual::New( *( mFactoryCache.Get() ), propertyMap );
178 case Toolkit::Visual::WIREFRAME:
180 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), propertyMap );
184 case Toolkit::Visual::TEXT:
186 visualPtr = TextVisual::New( *( mFactoryCache.Get() ), propertyMap );
190 case Toolkit::Visual::N_PATCH:
192 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
193 std::string imageUrl;
194 if( imageURLValue && imageURLValue->Get( imageUrl ) )
196 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
201 case Toolkit::Visual::SVG:
203 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
204 std::string imageUrl;
205 if( imageURLValue && imageURLValue->Get( imageUrl ) )
207 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
212 case Toolkit::Visual::ANIMATED_IMAGE:
214 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
215 std::string imageUrl;
218 if( imageURLValue->Get( imageUrl ) )
220 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
224 Property::Array* array = imageURLValue->GetArray();
227 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), *array, propertyMap );
237 DALI_LOG_ERROR( "Renderer type unknown\n" );
240 if( mDebugEnabled && visualType != Toolkit::Visual::WIREFRAME )
242 //Create a WireframeVisual if we have debug enabled
243 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr, propertyMap );
246 return Toolkit::Visual::Base( visualPtr.Get() );
249 Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image )
253 mFactoryCache = new VisualFactoryCache();
256 Visual::BasePtr visualPtr;
260 NinePatchImage npatchImage = NinePatchImage::DownCast( image );
263 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage );
267 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image );
273 //Create a WireframeVisual if we have debug enabled
274 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr );
277 return Toolkit::Visual::Base( visualPtr.Get() );
280 Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, ImageDimensions size )
284 mFactoryCache = new VisualFactoryCache();
287 Visual::BasePtr visualPtr;
291 // first resolve url type to know which visual to create
292 VisualUrl visualUrl( url );
293 switch( visualUrl.GetType() )
295 case VisualUrl::N_PATCH:
297 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl );
302 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl );
307 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl );
310 case VisualUrl::REGULAR_IMAGE:
312 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size );
320 //Create a WireframeVisual if we have debug enabled
321 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr );
324 return Toolkit::Visual::Base( visualPtr.Get() );
327 Internal::TextureManager& VisualFactory::GetTextureManager()
331 mFactoryCache = new VisualFactoryCache();
333 return mFactoryCache->GetTextureManager();
336 } // namespace Internal
338 } // namespace Toolkit