[NUI] Implement shadow in View (#1223)
[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 : TransformablePropertyMap
28     {
29         private string url;
30
31         private Rectangle border;
32
33         /// <summary>
34         /// Constructor
35         /// </summary>
36         [EditorBrowsable(EditorBrowsableState.Never)]
37         public ImageShadow() : base()
38         {
39         }
40
41         private void OnBorderChanged(int x, int y, int width, int height)
42         {
43             UpdateBorder();
44         }
45
46         private void UpdateUrl()
47         {
48             propertyMap[ImageVisualProperty.URL] = PropertyValue.CreateWithGuard(url);
49             OnPropertyChanged?.Invoke(this);
50         }
51
52         private void UpdateBorder()
53         {
54             propertyMap[ImageVisualProperty.Border] = PropertyValue.CreateWithGuard(border);
55             OnPropertyChanged?.Invoke(this);
56         }
57
58         /// <summary>
59         /// The url for the shadow image to load.
60         /// </summary>
61         [EditorBrowsable(EditorBrowsableState.Never)]
62         public string Url
63         {
64             get
65             {
66                 return url;
67             }
68             set
69             {
70                 url = value;
71                 UpdateUrl();
72             }
73         }
74
75         /// <summary>
76         /// Optional.<br />
77         /// The border area of the n-patch image.
78         /// Set left, right, bottom, top length of the border you don't want to stretch in the image.
79         /// </summary>
80         [EditorBrowsable(EditorBrowsableState.Never)]
81         public Rectangle Border
82         {
83             get
84             {
85                 return border;
86             }
87             set
88             {
89                 border = value == null? null : new Rectangle(OnBorderChanged, value);
90                 UpdateBorder();
91             }
92         }
93
94         override internal string ToDebugString()
95         {
96             string result = "";
97             // TODO
98             return result;
99         }
100
101         override internal bool IsValid()
102         {
103             return url != null;
104         }
105
106         static internal new PropertyValue ToPropertyValue(TransformablePropertyMap instance)
107         {
108             if (instance == null || !instance.IsValid())
109             {
110                 return new PropertyValue();
111             }
112
113             instance.propertyMap.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
114
115             return new PropertyValue(instance.propertyMap);
116         }
117     }
118 }
119
120