Changed button to use ImageView instead of ImageActor and enabled custom fragment...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / image-view / image-view-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__
2 #define __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__
3
4 /*
5  * Copyright (c) 2014 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/object/property-map.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/controls/renderers/image/image-renderer.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 class ImageView;
36
37 namespace Internal
38 {
39 class ImageView : public Control
40 {
41  protected:
42
43   /**
44    * Construct a new ImageView.
45    */
46   ImageView();
47
48   /**
49    * A reference counted object may only be deleted by calling Unreference()
50    */
51   virtual ~ImageView();
52
53
54
55 public:
56   /**
57    * Create a new ImageView.
58    * @return A smart-pointer to the newly allocated ImageView.
59    */
60   static Toolkit::ImageView New();
61
62   /**
63    * @copydoc Dali::Toolkit::SetImage
64    */
65   void SetImage( Image image );
66
67   /**
68    * @brief Sets this ImageView from an Dali::Property::Map
69    *
70    * If the handle is empty, ImageView will display nothing
71    * @param[in] map The Dali::Property::Map to use for to display.
72    */
73   void SetImage( Dali::Property::Map map );
74
75   /**
76    * @copydoc Dali::Toolkit::SetImage
77    */
78   void SetImage( const std::string& imageUrl, ImageDimensions size );
79
80   // Properties
81   /**
82    * Called when a property of an object of this type is set.
83    * @param[in] object The object whose property is set.
84    * @param[in] index The property index.
85    * @param[in] value The new property value.
86    */
87   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
88
89   /**
90    * Called to retrieve a property of an object of this type.
91    * @param[in] object The object whose property is to be retrieved.
92    * @param[in] index The property index.
93    * @return The current value of the property.
94    */
95   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
96
97   /**
98    * @brief Set the depth index of this image renderer
99    *
100    * Renderer with higher depth indices are rendered in front of other renderers with smaller values
101    *
102    * @param[in] depthIndex The depth index of this renderer
103    */
104   void SetDepthIndex( int depthIndex );
105
106 private: // From Control
107
108   /**
109    * @copydoc Toolkit::Control::OnStageConnect()
110    */
111   virtual void OnStageConnection( int depth );
112
113   /**
114    * @copydoc Toolkit::Control::OnStageDisconnection()
115    */
116   virtual void OnStageDisconnection();
117
118   /**
119    * @copydoc Toolkit::Control::GetNaturalSize
120    */
121   virtual Vector3 GetNaturalSize();
122
123   /**
124    * @copydoc Toolkit::Control::GetHeightForWidth()
125    */
126   virtual float GetHeightForWidth( float width );
127
128   /**
129    * @copydoc Toolkit::Control::GetWidthForHeight()
130    */
131   virtual float GetWidthForHeight( float height );
132
133 private:
134   /**
135    * Attaches mImage member to the renderer, creating the renderers, samplers, meshes and materials if needed
136    *
137    * @pre mImage has been initialised
138    */
139   void AttachImage();
140
141 private:
142   // Undefined
143   ImageView( const ImageView& );
144   ImageView& operator=( const ImageView& );
145
146 private:
147   Toolkit::ControlRenderer  mRenderer;
148   ImageDimensions  mImageSize;
149
150   std::string      mUrl;          ///< the url for the image if the image came from a URL, empty otherwise
151   Image            mImage;        ///< the Image if the image came from a Image, null otherwise
152   Property::Map    mPropertyMap;  ///< the Property::Map if the image came from a Property::Map, empty otherwise
153 };
154
155 } // namespace Internal
156
157 // Helpers for public-api forwarding methods
158 inline Toolkit::Internal::ImageView& GetImpl( Toolkit::ImageView& obj )
159 {
160   DALI_ASSERT_ALWAYS(obj);
161   Dali::RefObject& handle = obj.GetImplementation();
162   return static_cast<Toolkit::Internal::ImageView&>(handle);
163 }
164
165 inline const Toolkit::Internal::ImageView& GetImpl( const Toolkit::ImageView& obj )
166 {
167   DALI_ASSERT_ALWAYS(obj);
168   const Dali::RefObject& handle = obj.GetImplementation();
169   return static_cast<const Toolkit::Internal::ImageView&>(handle);
170 }
171
172 } // namespace Toolkit
173
174 } // namespace Dali
175
176 #endif // __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__