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/text-visual-properties.h>
31 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.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-factory-resolve-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::DevelVisual::Property::TYPE, VISUAL_TYPE );
91 Toolkit::DevelVisual::Type visualType = Toolkit::DevelVisual::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;
121 if( imageURLValue && imageURLValue->Get( imageUrl ) )
123 // first resolve url type to know which visual to create
124 UrlType::Type type = ResolveUrlType( imageUrl );
125 if( UrlType::N_PATCH == type )
127 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
129 else if( UrlType::SVG == type )
131 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
133 else if( UrlType::GIF == type )
135 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
137 else // Regular image
139 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
146 case Toolkit::Visual::MESH:
148 visualPtr = MeshVisual::New( *( mFactoryCache.Get() ), propertyMap );
152 case Toolkit::Visual::PRIMITIVE:
154 visualPtr = PrimitiveVisual::New( *( mFactoryCache.Get() ), propertyMap );
158 case Toolkit::Visual::WIREFRAME:
160 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), propertyMap );
164 case Toolkit::DevelVisual::TEXT:
166 visualPtr = TextVisual::New( *( mFactoryCache.Get() ), propertyMap );
173 DALI_LOG_ERROR( "Renderer type unknown\n" );
176 if( mDebugEnabled && visualType != Toolkit::DevelVisual::WIREFRAME )
178 //Create a WireframeVisual if we have debug enabled
179 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr, propertyMap );
182 return Toolkit::Visual::Base( visualPtr.Get() );
185 Toolkit::Visual::Base VisualFactory::CreateVisual( const Image& image )
189 mFactoryCache = new VisualFactoryCache();
192 Visual::BasePtr visualPtr;
194 NinePatchImage npatchImage = NinePatchImage::DownCast( image );
197 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), npatchImage );
201 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), image );
206 //Create a WireframeVisual if we have debug enabled
207 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr );
210 return Toolkit::Visual::Base( visualPtr.Get() );
213 Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, ImageDimensions size )
217 mFactoryCache = new VisualFactoryCache();
220 Visual::BasePtr visualPtr;
222 // first resolve url type to know which visual to create
223 UrlType::Type type = ResolveUrlType( url );
224 if( UrlType::N_PATCH == type )
226 visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), url );
228 else if( UrlType::SVG == type )
230 visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url );
232 else if( UrlType::GIF == type )
234 visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), url );
236 else // Regular image
238 visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), url, size );
243 //Create a WireframeVisual if we have debug enabled
244 visualPtr = WireframeVisual::New( *( mFactoryCache.Get() ), visualPtr );
247 return Toolkit::Visual::Base( visualPtr.Get() );
250 } // namespace Internal
252 } // namespace Toolkit