473080bc38f6ae2834214c836dce670519b999cc
[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    * @param[in] properties A Property::Map containing settings for this visual
60    * @return A smart-pointer to the newly allocated visual.
61    */
62   static BorderVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties );
63
64 protected:
65
66   /**
67    * @brief Constructor.
68    *
69    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
70    */
71   BorderVisual( VisualFactoryCache& factoryCache );
72
73   /**
74    * @brief A reference counted object may only be deleted by calling Unreference().
75    */
76   virtual ~BorderVisual();
77
78   /**
79    * @copydoc Visual::Base::DoSetProperties
80    */
81   virtual void DoSetProperties( const Property::Map& propertyMap );
82
83   /**
84    * @copydoc Visual::Base::DoSetOnStage
85    */
86   virtual void DoSetOnStage( Actor& actor );
87
88   /**
89    * @copydoc Visual::Base::CreatePropertyMap
90    */
91   virtual void DoCreatePropertyMap( Property::Map& map ) const;
92
93   /**
94    * @copydoc Visual::Base::CreateInstancePropertyMap
95    */
96   virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
97
98   /**
99    * @copydoc Visual::Base::OnSetTransform
100    */
101   virtual void OnSetTransform();
102
103 public:
104
105   /**
106    * Set the color of the border.
107    * @param[in] color The border color.
108    */
109   void SetBorderColor( const Vector4& color);
110
111   /**
112    * Set the size of the border.
113    * @param[in] size The border size.
114    */
115   void SetBorderSize( float size );
116
117   /**
118    * Enable/Disable the anti-aliasing.
119    * @param[in] enable Whether the anti-aliasing be enabled or not.
120    */
121   void RequireAntiAliasing( bool antiAliasing );
122
123 private:
124
125   /**
126    * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
127    */
128   void InitializeRenderer();
129
130   /**
131    * Request the border shader from the factory cache. If fail, create tha shader and add it to cache.
132    * @return The border shader.
133    */
134   Shader GetBorderShader();
135
136   /**
137    * Create the geometry which presents the border.
138    * @return The border geometry
139    */
140   Geometry CreateBorderGeometry();
141
142   /**
143    * Helper method to set individual values by index key.
144    * @param[in] index The index key of the value
145    * @param[in] value The value
146    */
147   void DoSetProperty( Property::Index index, const Property::Value& value );
148
149   // Undefined
150   BorderVisual( const BorderVisual& borderRenderer );
151
152   // Undefined
153   BorderVisual& operator=( const BorderVisual& borderRenderer );
154
155 private:
156
157   Vector4 mBorderColor;
158   float   mBorderSize;
159
160   Property::Index mBorderColorIndex;
161   Property::Index mBorderSizeIndex;
162
163   bool mAntiAliasing;
164 };
165
166 } // namespace Internal
167
168 } // namespace Toolkit
169
170 } // namespace Dali
171
172 #endif // DALI_TOOLKIT_INTERNAL_BORDER_VISUAL_H