Add SetProperty and GetProperty to Visuals.
[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/devel-api/object/weak-handle.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
26
27 struct NSVGimage;
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * The visual which renders a svg image
40  *
41  * The following property is essential
42  *
43  * | %Property Name           | Type             |
44  * |--------------------------|------------------|
45  * | url                      | STRING           |
46  *
47  */
48 class SvgVisual: public Visual::Base
49 {
50 public:
51
52   /**
53    * @brief Constructor.
54    *
55    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
56    */
57   SvgVisual( VisualFactoryCache& factoryCache );
58
59   /**
60    * @brief A reference counted object may only be deleted by calling Unreference().
61    */
62   ~SvgVisual();
63
64 public:  // from Visual
65
66   /**
67    * @copydoc Visual::Base::GetNaturalSize
68    */
69   virtual void GetNaturalSize( Vector2& naturalSize ) const;
70
71   /**
72    * @copydoc Visual::Base::SetSize
73    */
74   virtual void SetSize( const Vector2& size );
75
76   /**
77    * @copydoc Visual::Base::CreatePropertyMap
78    */
79   virtual void DoCreatePropertyMap( Property::Map& map ) const;
80
81   /**
82    * @copydoc Visual::Base::DoSetProperty
83    */
84   virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
85
86   /**
87    * @copydoc Visual::Base::DoGetProperty
88    */
89   virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
90
91 protected:
92
93   /**
94    * @copydoc Visual::Base::DoInitialize
95    */
96   virtual void DoInitialize( Actor& actor, 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 public:
109
110   /**
111    * @brief Sets the svg image of this visual to the resource at imageUrl
112    * The visual will parse the svg image once it is set.
113    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
114    *
115    * @param[in] imageUrl The URL to svg resource to use
116    */
117   void SetImage( const std::string& imageUrl, ImageDimensions size = ImageDimensions() );
118
119   /**
120    * @bried Apply the rasterized image to the visual.
121    *
122    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
123    */
124   void ApplyRasterizedImage( PixelData rasterizedPixelData );
125
126 private:
127   /**
128    * @bried Rasterize the svg with the given size, and add it to the visual.
129    *
130    * @param[in] size The target size of the SVG rasterization.
131    */
132   void AddRasterizationTask( const Vector2& size );
133
134
135   // Undefined
136   SvgVisual( const SvgVisual& svgRenderer );
137
138   // Undefined
139   SvgVisual& operator=( const SvgVisual& svgRenderer );
140
141 private:
142   Vector4              mAtlasRect;
143   std::string          mImageUrl;
144   NSVGimage*           mParsedImage;
145   WeakHandle<Actor>    mPlacementActor;
146
147 };
148
149 } // namespace Internal
150
151 } // namespace Toolkit
152
153 } // namespace Dali
154
155 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */