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