f982561d98ab8015d7bb55c5a72e4469e636709b
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / border / border-visual.h
1 #ifndef DALI_TOOLKIT_INTERNAL_BORDER_VISUAL_H
2 #define DALI_TOOLKIT_INTERNAL_BORDER_VISUAL_H
3
4 /*
5  * Copyright (c) 2016 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/rendering/geometry.h>
23 #include <dali/public-api/common/intrusive-ptr.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 class BorderVisual;
38 typedef IntrusivePtr< BorderVisual > BorderVisualPtr;
39
40 /**
41  * The visual which renders a solid color to the control's quad border fixed to a specified size.
42  *
43  * The following properties are required for create a BorderRender
44  *
45  * | %Property Name  | Type        |
46  * |-----------------|-------------|
47  * | borderColor     | VECTOR4     |
48  * | borderSize      | FLOAT       |
49  * | antiAliasing    | BOOLEAN     |
50  */
51 class BorderVisual : public Visual::Base
52 {
53 public:
54
55   /**
56    * @brief Create a new border visual.
57    *
58    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
59    * @return A smart-pointer to the newly allocated visual.
60    */
61   static BorderVisualPtr New( VisualFactoryCache& factoryCache );
62
63 protected:
64
65   /**
66    * @brief Constructor.
67    *
68    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
69    */
70   BorderVisual( VisualFactoryCache& factoryCache );
71
72   /**
73    * @brief A reference counted object may only be deleted by calling Unreference().
74    */
75   virtual ~BorderVisual();
76
77   /**
78    * @copydoc Visual::Base::DoSetProperties
79    */
80   virtual void DoSetProperties( const Property::Map& propertyMap );
81
82   /**
83    * @copydoc Visual::Base::DoSetOnStage
84    */
85   virtual void DoSetOnStage( Actor& actor );
86
87   /**
88    * @copydoc Visual::Base::CreatePropertyMap
89    */
90   virtual void DoCreatePropertyMap( Property::Map& map ) const;
91
92   /**
93    * @copydoc Visual::Base::DoSetProperty
94    */
95   virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
96
97   /**
98    * @copydoc Visual::Base::DoGetProperty
99    */
100   virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
101
102   /**
103    * @copydoc Visual::Base::OnSetTransform
104    */
105   virtual void OnSetTransform();
106
107 public:
108
109   /**
110    * Set the color of the border.
111    * @param[in] color The border color.
112    */
113   void SetBorderColor( const Vector4& color);
114
115   /**
116    * Set the size of the border.
117    * @param[in] size The border size.
118    */
119   void SetBorderSize( float size );
120
121   /**
122    * Enable/Disable the anti-aliasing.
123    * @param[in] enable Whether the anti-aliasing be enabled or not.
124    */
125   void RequireAntiAliasing( bool antiAliasing );
126
127 private:
128
129   /**
130    * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
131    */
132   void InitializeRenderer();
133
134   /**
135    * Request the border shader from the factory cache. If fail, create tha shader and add it to cache.
136    * @return The border shader.
137    */
138   Shader GetBorderShader();
139
140   /**
141    * Create the geometry which presents the border.
142    * @return The border geometry
143    */
144   Geometry CreateBorderGeometry();
145
146   // Undefined
147   BorderVisual( const BorderVisual& borderRenderer );
148
149   // Undefined
150   BorderVisual& operator=( const BorderVisual& borderRenderer );
151
152 private:
153
154   Vector4 mBorderColor;
155   float   mBorderSize;
156
157   Property::Index mBorderColorIndex;
158   Property::Index mBorderSizeIndex;
159
160   bool mAntiAliasing;
161 };
162
163 } // namespace Internal
164
165 } // namespace Toolkit
166
167 } // namespace Dali
168
169 #endif // DALI_TOOLKIT_INTERNAL_BORDER_VISUAL_H