bd60a2410c28df29a2008c400e4372c5246ac143
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / ViewProperty / ImageShadow.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18  using System.ComponentModel;
19
20 namespace Tizen.NUI
21 {
22
23     /// <summary>
24     /// The Shadow composed of image for View
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class ImageShadow : ShadowBase, Tizen.NUI.Internal.ICloneable
28     {
29         private static readonly Rectangle noBorder = new Rectangle();
30
31         private string url;
32
33         private Rectangle border;
34
35         /// <summary>
36         /// Constructor
37         /// </summary>
38         [EditorBrowsable(EditorBrowsableState.Never)]
39         public ImageShadow() : base()
40         {
41             propertyMap[Visual.Property.Type] = new PropertyValue((int)Visual.Type.NPatch);
42         }
43
44         internal ImageShadow(ImageShadow other, PropertyChangedCallback callback = null) : base(other)
45         {
46             propertyMap[Visual.Property.Type] = new PropertyValue((int)Visual.Type.NPatch);
47
48             Url = other.Url;
49             Border = other.Border;
50             OnPropertyChanged = callback;
51         }
52
53         /// <summary>
54         /// The string conversion
55         /// </summary>
56         [EditorBrowsable(EditorBrowsableState.Never)]
57         public static implicit operator ImageShadow(string value)
58         {
59             ImageShadow imageShadow = new ImageShadow()
60             {
61                 Url = value ?? "",
62             };
63             return imageShadow;
64         }
65
66         /// <summary>
67         /// Deep copy method
68         /// </summary>
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         public object Clone()
71         {
72             return new ImageShadow() {
73                 Offset = offset,
74                 Extents = extents,
75                 Url = url,
76                 Border = border
77             };
78         }
79
80         /// <summary>
81         /// Deep copy method (static)
82         /// This provides nullity check.
83         /// </summary>
84         [EditorBrowsable(EditorBrowsableState.Never)]
85         static public object Clone(ImageShadow instance)
86         {
87             return instance == null ? null : new ImageShadow() {
88                 Offset = instance.offset,
89                 Extents = instance.extents,
90                 Url = instance.url,
91                 Border = instance.border
92             };
93         }
94
95         private void OnBorderChanged(int x, int y, int width, int height)
96         {
97             UpdateBorder();
98         }
99
100         private void UpdateUrl()
101         {
102             propertyMap[ImageVisualProperty.URL] = PropertyValue.CreateWithGuard(url);
103             OnPropertyChanged?.Invoke(this);
104         }
105
106         private void UpdateBorder()
107         {
108             propertyMap[ImageVisualProperty.Border] = PropertyValue.CreateWithGuard(border);
109             OnPropertyChanged?.Invoke(this);
110         }
111
112         /// <summary>
113         /// The url for the shadow image to load.
114         /// </summary>
115         [EditorBrowsable(EditorBrowsableState.Never)]
116         public string Url
117         {
118             get
119             {
120                 return url;
121             }
122             set
123             {
124                 url = value;
125                 UpdateUrl();
126             }
127         }
128
129         /// <summary>
130         /// Optional.<br />
131         /// The border area of the n-patch image.
132         /// Set left, right, bottom, top length of the border you don't want to stretch in the image.
133         /// </summary>
134         [EditorBrowsable(EditorBrowsableState.Never)]
135         public Rectangle Border
136         {
137             get
138             {
139                 return border;
140             }
141             set
142             {
143                 border = new Rectangle(OnBorderChanged, value ?? noBorder);
144                 UpdateBorder();
145             }
146         }
147
148         override internal bool IsValid()
149         {
150             return !string.IsNullOrEmpty(url);
151         }
152     }
153 }
154
155