Merge "Removed Visual::Base::SetProperty and GetProperty" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / svg / svg-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/intrusive-ptr.h>
23 #include <dali/devel-api/object/weak-handle.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27
28 struct NSVGimage;
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 class SvgVisual;
40 typedef IntrusivePtr< SvgVisual > SvgVisualPtr;
41
42 /**
43  * The visual which renders a svg image
44  *
45  * The following property is essential
46  *
47  * | %Property Name           | Type             |
48  * |--------------------------|------------------|
49  * | url                      | STRING           |
50  *
51  */
52 class SvgVisual: public Visual::Base
53 {
54 public:
55
56   /**
57    * @brief Create the SVG Visual using the image URL.
58    *
59    * The visual will parse the SVG image once it is set.
60    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
61    *
62    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
63    * @param[in] imageUrl The URL to svg resource to use
64    */
65   static SvgVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
66
67 public:  // from Visual
68
69   /**
70    * @copydoc Visual::Base::GetNaturalSize
71    */
72   virtual void GetNaturalSize( Vector2& naturalSize );
73
74   /**
75    * @copydoc Visual::Base::CreatePropertyMap
76    */
77   virtual void DoCreatePropertyMap( Property::Map& map ) const;
78
79 protected:
80
81   /**
82    * @brief Constructor.
83    *
84    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
85    */
86   SvgVisual( VisualFactoryCache& factoryCache );
87
88   /**
89    * @brief A reference counted object may only be deleted by calling Unreference().
90    */
91   virtual ~SvgVisual();
92
93   /**
94    * @copydoc Visual::Base::DoSetProperties
95    */
96   virtual void DoSetProperties( const Property::Map& propertyMap );
97
98   /**
99    * @copydoc Visual::Base::DoSetOnStage
100    */
101   virtual void DoSetOnStage( Actor& actor );
102
103   /**
104    * @copydoc Visual::Base::DoSetOffStage
105    */
106   virtual void DoSetOffStage( Actor& actor );
107
108   /**
109    * @copydoc Visual::Base::OnSetTransform
110    */
111   virtual void OnSetTransform();
112
113 public:
114
115   /**
116    * @bried Apply the rasterized image to the visual.
117    *
118    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
119    */
120   void ApplyRasterizedImage( PixelData rasterizedPixelData );
121
122 private:
123
124   /**
125    * @brief Parses the SVG Image from the set URL.
126    *
127    * @param[in] imageUrl The URL of the image to parse the SVG from.
128    */
129   void ParseFromUrl( const std::string& imageUrl );
130
131   /**
132    * @bried Rasterize the svg with the given size, and add it to the visual.
133    *
134    * @param[in] size The target size of the SVG rasterization.
135    */
136   void AddRasterizationTask( const Vector2& size );
137
138
139   // Undefined
140   SvgVisual( const SvgVisual& svgRenderer );
141
142   // Undefined
143   SvgVisual& operator=( const SvgVisual& svgRenderer );
144
145 private:
146   Vector4              mAtlasRect;
147   std::string          mImageUrl;
148   NSVGimage*           mParsedImage;
149   WeakHandle<Actor>    mPlacementActor;
150   Vector2              mVisualSize;
151 };
152
153 } // namespace Internal
154
155 } // namespace Toolkit
156
157 } // namespace Dali
158
159 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */