Merge remote-tracking branch 'origin/master' into tizen
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / VisualObject / NPatchVisual.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     /// The visual which can display an n-patch image resource.
25     /// It will be used when we want to display n-patch image, border only n-patch, or make regular image stretched.
26     /// </summary>
27     /// <remarks>
28     /// Following ImageVisual properties are not supported in NPatchVisual.
29     /// - CornerRadius
30     /// - BorderlineWidth
31     /// - AlphaMaskUrl
32     /// </remarks>
33     /// <remarks>
34     /// We assume that the image is a n-patch image always. So it does not support other image formats, like svg, lottie.
35     /// </remarks>
36     [EditorBrowsable(EditorBrowsableState.Never)]
37     public class NPatchVisual : ImageVisual
38     {
39         #region Constructor
40         /// <summary>
41         /// Creates an visual object.
42         /// </summary>
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public NPatchVisual() : this(Interop.VisualObject.VisualObjectNew(), true)
45         {
46             NDalicPINVOKE.ThrowExceptionIfExists();
47         }
48
49         internal NPatchVisual(global::System.IntPtr cPtr, bool cMemoryOwn) : this(cPtr, cMemoryOwn, cMemoryOwn)
50         {
51         }
52
53         internal NPatchVisual(global::System.IntPtr cPtr, bool cMemoryOwn, bool cRegister) : base(cPtr, cMemoryOwn, cRegister)
54         {
55             Type = (int)Tizen.NUI.Visual.Type.NPatch;
56         }
57         #endregion
58
59         #region Visual Properties
60         /// <summary>
61         /// Gets or sets whether to draw the borders only (If true).<br />
62         /// If not specified, the default is false.<br />
63         /// </summary>
64         [EditorBrowsable(EditorBrowsableState.Never)]
65         public bool BorderOnly
66         {
67             set
68             {
69                 UpdateVisualProperty((int)Tizen.NUI.NpatchImageVisualProperty.BorderOnly, new PropertyValue(value));
70             }
71             get
72             {
73                 bool ret = false;
74                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.NpatchImageVisualProperty.BorderOnly);
75                 propertyValue?.Get(out ret);
76                 return ret;
77             }
78         }
79
80         /// <summary>
81         /// The border of the regular image is in the order: left, right, bottom, top.<br />
82         /// </summary>
83         /// <remarks>
84         /// Note that it is not mean the value from 9 patch image.<br />
85         /// </remarks>
86         [EditorBrowsable(EditorBrowsableState.Never)]
87         public Rectangle Border
88         {
89             set
90             {
91                 UpdateVisualProperty((int)Tizen.NUI.NpatchImageVisualProperty.Border, (value == null) ? null : new PropertyValue(value));
92             }
93             get
94             {
95                 Rectangle ret = new Rectangle();
96                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.NpatchImageVisualProperty.Border);
97                 propertyValue?.Get(ret);
98                 return ret;
99             }
100         }
101
102         /// <summary>
103         /// Overlays the auxiliary image on top of an NPatch image.
104         /// The resulting visual image will be at least as large as the smallest possible n-patch or the auxiliary image, whichever is larger.
105         /// </summary>
106         [EditorBrowsable(EditorBrowsableState.Never)]
107         public string AuxiliaryImageUrl
108         {
109             set
110             {
111                 UpdateVisualProperty((int)Tizen.NUI.ImageVisualProperty.AuxiliaryImageURL, string.IsNullOrEmpty(value) ? null : new PropertyValue(value));
112             }
113             get
114             {
115                 string ret = "";
116                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.ImageVisualProperty.AuxiliaryImageURL);
117                 propertyValue?.Get(out ret);
118                 return ret;
119             }
120         }
121
122         /// <summary>
123         /// An alpha value for mixing between the masked main NPatch image and the auxiliary image.
124         /// </summary>
125         [EditorBrowsable(EditorBrowsableState.Never)]
126         public float AuxiliaryImageAlpha
127         {
128             set
129             {
130                 UpdateVisualProperty((int)Tizen.NUI.ImageVisualProperty.AuxiliaryImageAlpha, new PropertyValue(value));
131             }
132             get
133             {
134                 float ret = 1.0f;
135                 var propertyValue = GetCachedVisualProperty((int)Tizen.NUI.ImageVisualProperty.AuxiliaryImageAlpha);
136                 propertyValue?.Get(out ret);
137                 return ret;
138             }
139         }
140         #endregion
141     }
142 }