2 * Copyright (c) 2016 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/devel-api/visuals/image-visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
32 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
33 #include <dali-toolkit/internal/visuals/border/border-visual.h>
34 #include <dali-toolkit/internal/visuals/color/color-visual.h>
35 #include <dali-toolkit/internal/visuals/gradient/gradient-visual.h>
36 #include <dali-toolkit/internal/visuals/image/image-visual.h>
37 #include <dali-toolkit/internal/visuals/mesh/mesh-visual.h>
38 #include <dali-toolkit/internal/visuals/npatch/npatch-visual.h>
39 #include <dali-toolkit/internal/visuals/primitive/primitive-visual.h>
40 #include <dali-toolkit/internal/visuals/svg/svg-visual.h>
41 #include <dali-toolkit/internal/visuals/text/text-visual.h>
42 #include <dali-toolkit/internal/visuals/animated-image/animated-image-visual.h>
43 #include <dali-toolkit/internal/visuals/wireframe/wireframe-visual.h>
44 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
45 #include <dali-toolkit/internal/visuals/visual-url.h>
46 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
62 BaseHandle handle = Toolkit::VisualFactory::Get();
67 DALI_TYPE_REGISTRATION_BEGIN_CREATE( Toolkit::VisualFactory, Dali::BaseHandle, Create, true )
68 DALI_TYPE_REGISTRATION_END()
72 VisualFactory::VisualFactory( bool debugEnabled )
73 :mDebugEnabled( debugEnabled )
77 VisualFactory::~VisualFactory()
81 Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& propertyMap )
83 // Create factory cache if it hasn't already been
86 mFactoryCache = new VisualFactoryCache();
89 Visual::BasePtr visualPtr;
91 Property::Value* typeValue = propertyMap.Find( Toolkit::DevelVisual::Property::TYPE, VISUAL_TYPE );
92 Toolkit::DevelVisual::Type visualType = Toolkit::DevelVisual::IMAGE; // Default to IMAGE type.
95 Scripting::GetEnumerationProperty( *typeValue, VISUAL_TYPE_TABLE, VISUAL_TYPE_TABLE_COUNT, visualType );
100 case Toolkit::Visual::BORDER:
102 visualPtr = BorderVisual::New( *( mFactoryCache.Get() ), propertyMap );
106 case Toolkit::Visual::COLOR:
108 visualPtr = ColorVisual::New( *( mFactoryCache.Get() ), propertyMap );
112 case Toolkit::Visual::GRADIENT:
114 visualPtr = GradientVisual::New( *( mFactoryCache.Get() ), propertyMap );
118 case Toolkit::Visual::IMAGE:
120 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
121 std::string imageUrl;
124 if( imageURLValue->Get( imageUrl ) )
126 VisualUrl visualUrl( imageUrl );
128 switch( visualUrl.GetType() )
130 case VisualUrl::N_PATCH:
132 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
137 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
142 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
145 case VisualUrl::REGULAR_IMAGE:
147 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
154 Property::Array* array = imageURLValue->GetArray();
157 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), *array, propertyMap );
164 case Toolkit::Visual::MESH:
166 visualPtr = MeshVisual::New( *( mFactoryCache.Get() ), propertyMap );
170 case Toolkit::Visual::PRIMITIVE:
172 visualPtr = PrimitiveVisual::New( *( mFactoryCache.Get() ), propertyMap );
176 case Toolkit::Visual::WIREFRAME:
178 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), propertyMap );
182 case Toolkit::DevelVisual::TEXT:
184 visualPtr = TextVisual::New( *( mFactoryCache.Get() ), propertyMap );
188 case Toolkit::DevelVisual::N_PATCH:
190 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
191 std::string imageUrl;
192 if( imageURLValue && imageURLValue->Get( imageUrl ) )
194 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
199 case Toolkit::DevelVisual::SVG:
201 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
202 std::string imageUrl;
203 if( imageURLValue && imageURLValue->Get( imageUrl ) )
205 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
210 case Toolkit::DevelVisual::ANIMATED_IMAGE:
212 Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
213 std::string imageUrl;
216 if( imageURLValue->Get( imageUrl ) )
218 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
222 Property::Array* array = imageURLValue->GetArray();
225 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), *array, propertyMap );
235 DALI_LOG_ERROR( "Renderer type unknown\n" );
238 if( mDebugEnabled && visualType != Toolkit::DevelVisual::WIREFRAME )
240 //Create a WireframeVisual if we have debug enabled
241 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr, propertyMap );
244 return Toolkit::Visual::Base( visualPtr.Get() );
247 Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image )
251 mFactoryCache = new VisualFactoryCache();
254 Visual::BasePtr visualPtr;
256 NinePatchImage npatchImage = NinePatchImage::DownCast( image );
259 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage );
263 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image );
268 //Create a WireframeVisual if we have debug enabled
269 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr );
272 return Toolkit::Visual::Base( visualPtr.Get() );
275 Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, ImageDimensions size )
279 mFactoryCache = new VisualFactoryCache();
282 Visual::BasePtr visualPtr;
284 // first resolve url type to know which visual to create
285 VisualUrl visualUrl( url );
286 switch( visualUrl.GetType() )
288 case VisualUrl::N_PATCH:
290 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl );
295 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl );
300 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl );
303 case VisualUrl::REGULAR_IMAGE:
305 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size );
312 //Create a WireframeVisual if we have debug enabled
313 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr );
316 return Toolkit::Visual::Base( visualPtr.Get() );
319 } // namespace Internal
321 } // namespace Toolkit