Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / VisualObject / ColorVisual.cs
1 // Copyright (c) 2024 Samsung Electronics Co., Ltd.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15
16 using System.Runtime.InteropServices;
17 using System.Collections.Generic;
18 using System.Linq;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI.Visuals
22 {
23     /// <summary>
24     /// Simple visual to render a solid color.
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class ColorVisual : VisualBase
28     {
29         #region Constructor
30         /// <summary>
31         /// Creates an visual object.
32         /// </summary>
33         [EditorBrowsable(EditorBrowsableState.Never)]
34         public ColorVisual() : this(Interop.VisualObject.VisualObjectNew(), true)
35         {
36             NDalicPINVOKE.ThrowExceptionIfExists();
37         }
38
39         internal ColorVisual(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
40         {
41         }
42
43         internal ColorVisual(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister)
44         {
45             Type = (int)Tizen.NUI.Visual.Type.Color;
46         }
47         #endregion
48
49         #region Visual Properties
50         /// <summary>
51         /// Blur radius for this visual
52         /// </summary>
53         /// <remarks>
54         /// This property will ignore BorderlineWidth property when we set BlurRadius property at least one time.
55         /// </remarks>
56         [EditorBrowsable(EditorBrowsableState.Never)]
57         public float BlurRadius
58         {
59             set
60             {
61                 UpdateVisualProperty((int)Tizen.NUI.ColorVisualProperty.BlurRadius, new PropertyValue(value), false);
62             }
63             get
64             {
65                 float ret = 0.0f;
66                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.ColorVisualProperty.BlurRadius);
67                 propertyValue?.Get(out ret);
68                 return ret;
69             }
70         }
71         #endregion
72
73         #region Decorated Visual Properties
74         /// <summary>
75         /// The radius for the rounded corners of the visual.
76         /// The values in Vector4 are used in clockwise order from top-left to bottom-left : Vector4(top-left-corner, top-right-corner, bottom-right-corner, bottom-left-corner).
77         /// Each radius will clamp internally to the half of smaller of the visual's width or height.
78         /// </summary>
79         [EditorBrowsable(EditorBrowsableState.Never)]
80         public Vector4 CornerRadius
81         {
82             set
83             {
84                 UpdateVisualProperty((int)Tizen.NUI.Visual.Property.CornerRadius, new PropertyValue(value), false);
85             }
86             get
87             {
88                 Vector4 ret = new Vector4();
89                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.Visual.Property.CornerRadius);
90                 propertyValue?.Get(ret);
91                 return ret;
92             }
93         }
94
95         /// <summary>
96         /// Whether the CornerRadius property value is relative (percentage [0.0f to 0.5f] of the visual size) or absolute (in world units).
97         /// It is absolute by default.
98         /// When the policy is relative, the corner radius is relative to the smaller of the visual's width and height.
99         /// </summary>
100         [EditorBrowsable(EditorBrowsableState.Never)]
101         public VisualTransformPolicyType CornerRadiusPolicy
102         {
103             set
104             {
105                 UpdateVisualProperty((int)Tizen.NUI.Visual.Property.CornerRadiusPolicy, new PropertyValue((int)value), false);
106             }
107             get
108             {
109                 int ret = (int)VisualTransformPolicyType.Absolute;
110                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.Visual.Property.CornerRadiusPolicy);
111                 propertyValue?.Get(out ret);
112                 return (VisualTransformPolicyType)ret;
113             }
114         }
115
116         /// <summary>
117         /// The width for the borderline of the visual.
118         /// </summary>
119         [EditorBrowsable(EditorBrowsableState.Never)]
120         public float BorderlineWidth
121         {
122             set
123             {
124                 UpdateVisualProperty((int)Tizen.NUI.Visual.Property.BorderlineWidth, new PropertyValue(value), false);
125             }
126             get
127             {
128                 float ret = 0.0f;
129                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.Visual.Property.BorderlineWidth);
130                 propertyValue?.Get(out ret);
131                 return ret;
132             }
133         }
134
135         /// <summary>
136         /// The color for the borderline of the visual.
137         /// It is Color.Black by default.
138         /// </summary>
139         [EditorBrowsable(EditorBrowsableState.Never)]
140         public Color BorderlineColor
141         {
142             set
143             {
144                 UpdateVisualProperty((int)Tizen.NUI.Visual.Property.BorderlineColor, new PropertyValue(value), false);
145             }
146             get
147             {
148                 Color ret = new Color(0.0f, 0.0f, 0.0f, 1.0f);
149                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.Visual.Property.BorderlineColor);
150                 propertyValue?.Get(ret);
151                 return ret;
152             }
153         }
154
155         /// <summary>
156         /// The Relative offset for the borderline of the visual.
157         /// Recommended range : [-1.0f to 1.0f].
158         /// If -1.0f, draw borderline inside of the visual.
159         /// If 1.0f, draw borderline outside of the visual.
160         /// If 0.0f, draw borderline half inside and half outside.
161         /// It is 0.0f by default.
162         /// </summary>
163         [EditorBrowsable(EditorBrowsableState.Never)]
164         public float BorderlineOffset
165         {
166             set
167             {
168                 UpdateVisualProperty((int)Tizen.NUI.Visual.Property.BorderlineOffset, new PropertyValue(value), false);
169             }
170             get
171             {
172                 float ret = 0.0f;
173                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.Visual.Property.BorderlineOffset);
174                 propertyValue?.Get(out ret);
175                 return ret;
176             }
177         }
178         #endregion
179     }
180 }