[dali_2.3.20] Merge branch 'devel/master'
[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) 2021 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/common/intrusive-ptr.h>
23 #include <dali/public-api/rendering/geometry.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal
33 {
34 class BorderVisual;
35 typedef IntrusivePtr<BorderVisual> BorderVisualPtr;
36
37 /**
38  * The visual which renders a solid color to the control's quad border fixed to a specified size.
39  *
40  * The following properties are required for create a BorderRender
41  *
42  * | %Property Name  | Type        |
43  * |-----------------|-------------|
44  * | borderColor     | VECTOR4     |
45  * | borderSize      | FLOAT       |
46  * | antiAliasing    | BOOLEAN     |
47  */
48 class BorderVisual : public Visual::Base
49 {
50 public:
51   /**
52    * @brief Create a new border visual.
53    *
54    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
55    * @param[in] properties A Property::Map containing settings for this visual
56    * @return A smart-pointer to the newly allocated visual.
57    */
58   static BorderVisualPtr New(VisualFactoryCache& factoryCache, const Property::Map& properties);
59
60 protected:
61   /**
62    * @brief Constructor.
63    *
64    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
65    */
66   BorderVisual(VisualFactoryCache& factoryCache);
67
68   /**
69    * @brief A reference counted object may only be deleted by calling Unreference().
70    */
71   virtual ~BorderVisual();
72
73   /**
74    * @copydoc Visual::Base::OnInitialize
75    */
76   void OnInitialize() override;
77
78   /**
79    * @copydoc Visual::Base::DoSetProperties
80    */
81   void DoSetProperties(const Property::Map& propertyMap) override;
82
83   /**
84    * @copydoc Visual::Base::DoSetOnScene
85    */
86   void DoSetOnScene(Actor& actor) override;
87
88   /**
89    * @copydoc Visual::Base::CreatePropertyMap
90    */
91   void DoCreatePropertyMap(Property::Map& map) const override;
92
93   /**
94    * @copydoc Visual::Base::CreateInstancePropertyMap
95    */
96   void DoCreateInstancePropertyMap(Property::Map& map) const override;
97
98   /**
99    * @copydoc Visual::Base::OnSetTransform
100    */
101   void OnSetTransform() override;
102
103 private:
104   /**
105    * Request the border shader from the factory cache. If fail, create tha shader and add it to cache.
106    * @return The border shader.
107    */
108   Shader GetBorderShader();
109
110   /**
111    * Create the geometry which presents the border.
112    * @return The border geometry
113    */
114   Geometry CreateBorderGeometry();
115
116   /**
117    * Helper method to set individual values by index key.
118    * @param[in] index The index key of the value
119    * @param[in] value The value
120    */
121   void DoSetProperty(Property::Index index, const Property::Value& value);
122
123   // Undefined
124   BorderVisual(const BorderVisual& borderRenderer);
125
126   // Undefined
127   BorderVisual& operator=(const BorderVisual& borderRenderer);
128
129 private:
130   Vector4 mBorderColor;
131   float   mBorderSize;
132
133   Property::Index mBorderColorIndex;
134   Property::Index mBorderSizeIndex;
135
136   bool mAntiAliasing;
137 };
138
139 } // namespace Internal
140
141 } // namespace Toolkit
142
143 } // namespace Dali
144
145 #endif // DALI_TOOLKIT_INTERNAL_BORDER_VISUAL_H