Render control background without creating extra actor
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / renderers / control-renderer-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H__
2 #define __DALI_TOOLKIT_INTERNAL_CONTROL_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
22 // EXTERNAL INCLUDES
23 #include <dali/public-api/object/base-object.h>
24
25 #include <dali-toolkit/devel-api/controls/renderer-factory/renderer-factory.h>
26 #include <dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 class RendererFactoryCache;
38
39 /**
40  * Base class for all Control rendering logic. A control may have multiple control renderers.
41  *
42  * Note: The control renderer responds to the the Actor::COLOR by blending it with the 'Multiply' operator.
43  */
44 class ControlRenderer : public BaseObject
45 {
46 public:
47
48   /**
49    * Initialisation of the renderer, this API should only called by the RendererFactory:
50    *  request the geometry and shader from the cache, if not available, create and save to the cache for sharing;
51    *  record the property values.
52    *
53    * @param[in] factoryCache A pointer pointing to the RendererFactoryCache object
54    * @param[in] propertyMap The properties for the requested ControlRenderer object.
55    */
56   virtual void Initialize( RendererFactoryCache& factoryCache, const Property::Map& propertyMap ) = 0;
57
58   /**
59    * @copydoc Toolkit::ControlRenderer::SetSize
60    */
61   virtual void SetSize( const Vector2& size );
62
63   /**
64    * @copydoc Toolkit::ControlRenderer::GetSize
65    */
66   const Vector2& GetSize() const;
67
68   /**
69    * @copydoc Toolkit::ControlRenderer::GetNaturalSize
70    */
71   virtual void GetNaturalSize( Vector2& naturalSize ) const;
72
73   /**
74    * ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
75    *
76    * Set the clip rectangular of this renderer.
77    * The contents of the renderer will not be visible outside this rectangular.
78    *
79    * @param [in] clipRect The clipping rectangular.
80    */
81   virtual void SetClipRect( const Rect<int>& clipRect );
82
83   /**
84    *ToDo: Add this function to Toolkit::ControlRenderer when it is fully implemented.
85    *
86    * Reposition this renderer with a 2D offset.
87    *
88    * @param[in] offset The offset to reposition the renderer.
89    */
90   virtual void SetOffset( const Vector2& offset );
91
92   /**
93    * @copydoc Toolkit::ControlRenderer::SetDepthIndex
94    */
95   void SetDepthIndex( float index );
96
97   /**
98    * @copydoc Toolkit::ControlRenderer::GetDepthIndex
99    */
100   float GetDepthIndex() const;
101
102   /**
103    * @copydoc Toolkit::ControlRenderer::SetOnStage
104    * @pre Impl->mGeometry must be created before this method is called
105    */
106   void SetOnStage( Actor& actor );
107
108   /**
109    * @copydoc Toolkit::ControlRenderer::SetOffStage
110    */
111   void SetOffStage( Actor& actor );
112
113   /**
114    * @copydoc Toolkit::ControlRenderer::CreatePropertyMap
115    */
116   virtual void CreatePropertyMap( Property::Map& map ) const = 0;
117
118 protected:
119
120   /**
121    * @brief Constructor.
122    */
123   ControlRenderer();
124
125   /**
126    * @brief A reference counted object may only be deleted by calling Unreference().
127    */
128   virtual ~ControlRenderer();
129
130 protected:
131
132   /**
133    * Called by SetOnStage() allowing sub classes to respond to the SetOnStage event
134    *
135    * @param[in] actor The actor applying this renderer.
136    */
137   virtual void DoSetOnStage( Actor& actor );
138
139   /**
140    * Called by SetOffStage() allowing sub classes to respond to the SetOffStage event
141    *
142    * @param[in] actor The actor applying this renderer.
143    */
144   virtual void DoSetOffStage( Actor& actor );
145
146 private:
147
148   // Undefined
149   ControlRenderer( const ControlRenderer& renderer );
150
151   // Undefined
152   ControlRenderer& operator=( const ControlRenderer& renderer );
153
154 protected:
155
156   struct Impl;
157   Impl* mImpl;
158 };
159
160 } // namespace Internal
161
162 inline const Internal::ControlRenderer& GetImplementation(const Toolkit::ControlRenderer& renderer)
163 {
164   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
165
166   const BaseObject& handle = renderer.GetBaseObject();
167
168   return static_cast<const Internal::ControlRenderer&>(handle);
169 }
170
171 inline Internal::ControlRenderer& GetImplementation(Toolkit::ControlRenderer& renderer)
172 {
173   DALI_ASSERT_ALWAYS( renderer && "ControlRenderer handle is empty" );
174
175   BaseObject& handle = renderer.GetBaseObject();
176
177   return static_cast<Internal::ControlRenderer&>(handle);
178 }
179
180 } // namespace Toolkit
181
182 } // namespace Dali
183
184 #endif /* __DALI_TOOLKIT_INTERNAL_CONTROL_RENDERER_H___ */