Automatically dis/connect registered visuals to stage
[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 protected:
82
83   /**
84    * @copydoc Visual::Base::DoInitialize
85    */
86   virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
87
88   /**
89    * @copydoc Visual::Base::DoSetOnStage
90    */
91   virtual void DoSetOnStage( Actor& actor );
92
93   /**
94    * @copydoc Visual::Base::DoSetOffStage
95    */
96   virtual void DoSetOffStage( Actor& actor );
97
98 public:
99
100   /**
101    * @brief Sets the svg image of this visual to the resource at imageUrl
102    * The visual will parse the svg image once it is set.
103    * And rasterize it into BufferImage synchronously when the associated actor is put on stage, and destroy the BufferImage when it is off stage
104    *
105    * @param[in] imageUrl The URL to svg resource to use
106    */
107   void SetImage( const std::string& imageUrl, ImageDimensions size = ImageDimensions() );
108
109   /**
110    * @bried Apply the rasterized image to the visual.
111    *
112    * @param[in] rasterizedPixelData The pixel buffer with the rasterized pixels
113    */
114   void ApplyRasterizedImage( PixelData rasterizedPixelData );
115
116 private:
117   /**
118    * @bried Rasterize the svg with the given size, and add it to the visual.
119    *
120    * @param[in] size The target size of the SVG rasterization.
121    */
122   void AddRasterizationTask( const Vector2& size );
123
124
125   // Undefined
126   SvgVisual( const SvgVisual& svgRenderer );
127
128   // Undefined
129   SvgVisual& operator=( const SvgVisual& svgRenderer );
130
131 private:
132   Vector4              mAtlasRect;
133   std::string          mImageUrl;
134   NSVGimage*           mParsedImage;
135   WeakHandle<Actor>    mPlacementActor;
136
137 };
138
139 } // namespace Internal
140
141 } // namespace Toolkit
142
143 } // namespace Dali
144
145 #endif /* DALI_TOOLKIT_INTERNAL_SVG_VISUAL_H */