Merge "Changed NPatchRenderer and ImageRenderer to use an "broken image" if they...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / image / image-renderer.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/internal/controls/renderers/control-renderer-impl.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/public-api/images/image.h>
26 #include <dali/public-api/images/image-operations.h>
27 #include <dali/public-api/images/resource-image.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 class ImageRenderer;
39 typedef IntrusivePtr< ImageRenderer > ImageRendererPtr;
40
41 /**
42  * The renderer which renders an image to the control's quad
43  *
44  * The following properties are optional
45  *
46  * | %Property Name            | Type             |
47  * |---------------------------|------------------|
48  * | image-url                 | STRING           |
49  * | image-fitting-mode        | STRING           |
50  * | image-sampling-mode       | STRING           |
51  * | image-desired-width       | INT              |
52  * | image-desired-height      | INT              |
53  *
54  * where image-fitting-mode should be one of the following fitting modes:
55  *   "shrink-to-fit"
56  *   "scale-to-fill"
57  *   "fit-width"
58  *   "fit-height"
59  *   "default"
60  *
61  * where image-sampling-mode should be one of the following sampling modes:
62  *   "box"
63  *   "nearest"
64  *   "linear"
65  *   "box-then-nearest"
66  *   "box-then-linear"
67  *   "no-filter"
68  *   "dont-care"
69  *   "default"
70  *
71  */
72 class ImageRenderer: public ControlRenderer, public ConnectionTracker
73 {
74 public:
75
76   /**
77    * @brief Constructor.
78    *
79    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
80    */
81   ImageRenderer( RendererFactoryCache& factoryCache );
82
83   /**
84    * @brief A reference counted object may only be deleted by calling Unreference().
85    */
86   ~ImageRenderer();
87
88 public:  // from ControlRenderer
89
90   /**
91    * @copydoc ControlRenderer::SetSize
92    */
93   virtual void SetSize( const Vector2& size );
94
95   /**
96    * @copydoc ControlRenderer::GetNaturalSize
97    */
98   virtual void GetNaturalSize( Vector2& naturalSize ) const;
99
100   /**
101    * @copydoc ControlRenderer::SetClipRect
102    */
103   virtual void SetClipRect( const Rect<int>& clipRect );
104
105   /**
106    * @copydoc ControlRenderer::SetOffset
107    */
108   virtual void SetOffset( const Vector2& offset );
109
110   /**
111    * @copydoc ControlRenderer::CreatePropertyMap
112    */
113   virtual void DoCreatePropertyMap( Property::Map& map ) const;
114
115 protected:
116   /**
117    * @copydoc ControlRenderer::DoInitialize
118    */
119   virtual void DoInitialize( const Property::Map& propertyMap );
120
121   /**
122    * @copydoc ControlRenderer::DoSetOnStage
123    */
124   virtual void DoSetOnStage( Actor& actor );
125
126   /**
127    * @copydoc ControlRenderer::DoSetOffStage
128    */
129   virtual void DoSetOffStage( Actor& actor );
130
131   /**
132    * @copydoc ControlRenderer::InitializeRenderer
133    */
134   virtual void InitializeRenderer( Renderer& renderer );
135
136 public:
137
138   /**
139    * @brief Sets the image of this renderer to the resource at imageUrl
140    * The renderer will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
141    *
142    * @param[in] imageUrl The URL to to image resource to use
143    */
144   void SetImage( const std::string& imageUrl );
145
146   /**
147    * @brief Sets the image of this renderer to the resource at imageUrl
148    * The renderer will load the Image asynchronously when the associated actor is put on stage, and destroy the image when it is off stage
149    *
150    * @param[in] imageUrl The URL to to image resource to use
151    * @param[in] desiredWidth The desired width of the resource to load
152    * @param[in] desiredHeight The desired height of the resource to load
153    * @param[in] fittingMode The FittingMode of the resource to load
154    * @param[in] samplingMode The SamplingMode of the resource to load
155    */
156   void SetImage( const std::string& imageUrl, int desiredWidth, int desiredHeight, Dali::FittingMode::Type fittingMode, Dali::SamplingMode::Type samplingMode );
157
158   /**
159    * @brief Sets the image of this renderer to use
160    *
161    * @param[in] image The image to use
162    */
163   void SetImage( Image image );
164
165   /**
166    * @brief Gets the image this renderer uses
167    *
168    * @return The image this renderer uses, which may be null if the image is set from a URL string and the renderer is not set as onstage
169    */
170   Image GetImage() const;
171
172 private:
173
174   /**
175    * @brief Applies this renderer's image to the sampler to the material used for this renderer
176    */
177   void ApplyImageToSampler();
178
179   /**
180    * Callback function of image resource loading succeed
181    * @param[in] image The Image content that we attempted to load from mImageUrl
182    */
183   void OnImageLoaded( ResourceImage image );
184
185 private:
186   Image mImage;
187
188   std::string mImageUrl;
189   Dali::ImageDimensions mDesiredSize;
190   Dali::FittingMode::Type mFittingMode;
191   Dali::SamplingMode::Type mSamplingMode;
192
193 };
194
195 } // namespace Internal
196
197 } // namespace Toolkit
198
199 } // namespace Dali
200
201 #endif /* __DALI_TOOLKIT_INTERNAL_IMAGE_RENDERER_H__ */