Merge "Simple implementation of ImageView." into devel/master
[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/devel-api/rendering/renderer.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 class ImageView;
35
36 namespace Internal
37 {
38 class ImageView : public Control
39 {
40  protected:
41
42   /**
43    * Construct a new ImageView.
44    */
45   ImageView();
46
47   /**
48    * A reference counted object may only be deleted by calling Unreference()
49    */
50   virtual ~ImageView();
51
52 public:
53   /**
54    * Create a new ImageView.
55    * @return A smart-pointer to the newly allocated ImageView.
56    */
57   static Toolkit::ImageView New();
58
59   /**
60    * @copydoc Dali::Toolkit::SetImage( Image image )
61    */
62   void SetImage( Image image );
63
64   /**
65    * @copydoc Dali::Toolkit::Image GetImage() const
66    */
67   Image GetImage() const;
68
69   // Properties
70   /**
71    * Called when a property of an object of this type is set.
72    * @param[in] object The object whose property is set.
73    * @param[in] index The property index.
74    * @param[in] value The new property value.
75    */
76   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
77
78   /**
79    * Called to retrieve a property of an object of this type.
80    * @param[in] object The object whose property is to be retrieved.
81    * @param[in] index The property index.
82    * @return The current value of the property.
83    */
84   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
85
86 private: // From Control
87
88   /**
89    * @copydoc Toolkit::Control::OnRelayout()
90    */
91   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
92
93   /**
94    * @copydoc Toolkit::Control::OnStageConnect()
95    */
96   virtual void OnStageConnection( int depth );
97
98   /**
99    * @copydoc Toolkit::Control::GetNaturalSize
100    */
101   virtual Vector3 GetNaturalSize();
102
103   /**
104    * @copydoc Toolkit::Control::GetHeightForWidth()
105    */
106   virtual float GetHeightForWidth( float width );
107
108   /**
109    * @copydoc Toolkit::Control::GetWidthForHeight()
110    */
111   virtual float GetWidthForHeight( float height );
112
113 private:
114   /**
115    * Attaches mImage member to the renderer, creating the renderers, samplers, meshes and materials if needed
116    *
117    * @pre mImage has been initialised
118    */
119   void AttachImage();
120
121 private:
122
123   Sampler mSampler;
124   Material mMaterial;
125   Geometry mMesh;
126   Renderer mRenderer;
127   Image mImage;
128   std::string mImageUrl;
129 };
130
131 } // namespace Internal
132
133 // Helpers for public-api forwarding methods
134 inline Toolkit::Internal::ImageView& GetImpl( Toolkit::ImageView& obj )
135 {
136   DALI_ASSERT_ALWAYS(obj);
137   Dali::RefObject& handle = obj.GetImplementation();
138   return static_cast<Toolkit::Internal::ImageView&>(handle);
139 }
140
141 inline const Toolkit::Internal::ImageView& GetImpl( const Toolkit::ImageView& obj )
142 {
143   DALI_ASSERT_ALWAYS(obj);
144   const Dali::RefObject& handle = obj.GetImplementation();
145   return static_cast<const Toolkit::Internal::ImageView&>(handle);
146 }
147
148 } // namespace Toolkit
149
150 } // namespace Dali
151
152 #endif // __DALI_TOOLKIT_INTERNAL_IMAGE_VIEW_H__