[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Background.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// The Background is a widget that use for setting (solid) background decorations to a window (unless it has transparency enabled)
23     /// or to any container object.
24     /// </summary>
25     /// <since_tizen> preview </since_tizen>
26     public class Background : Layout
27     {
28         /// <summary>
29         /// Creates and initializes a new instance of the Background class.
30         /// </summary>
31         /// <param name="parent">The EvasObject to which the new background will be attached as a child.</param>
32         /// <since_tizen> preview </since_tizen>
33         public Background(EvasObject parent) : base(parent)
34         {
35             Style = "transparent";
36         }
37
38         /// <summary>
39         /// Sets or gets the color to the background.
40         /// </summary>
41         /// <since_tizen> preview </since_tizen>
42         public override Color Color
43         {
44             get
45             {
46                 return BackgroundColor;
47             }
48             set
49             {
50                 BackgroundColor = value;
51             }
52         }
53
54         /// <summary>
55         /// Sets or gets the image to the background.
56         /// </summary>
57         /// <since_tizen> preview </since_tizen>
58         public string File
59         {
60             get
61             {
62                 return Interop.Elementary.BackgroundFileGet(RealHandle);
63             }
64             set
65             {
66                 Interop.Elementary.elm_bg_file_set(RealHandle, value, IntPtr.Zero);
67             }
68         }
69
70         /// <summary>
71         /// Sets or gets the mode of display for a given background widget's image.
72         /// </summary>
73         /// <remarks>
74         /// This sets how the background widget will display its image.
75         /// This will only work if the file was previously set with an image file on object.
76         /// The image can be display tiled, scaled, centered, or stretched. Scaled by default.
77         /// </remarks>
78         /// <since_tizen> preview </since_tizen>
79         public BackgroundOptions BackgroundOption
80         {
81             get
82             {
83                 return (BackgroundOptions)Interop.Elementary.elm_bg_option_get(RealHandle);
84             }
85             set
86             {
87                 Interop.Elementary.elm_bg_option_set(RealHandle, (Interop.Elementary.BackgroundOptions)value);
88             }
89         }
90
91         /// <summary>
92         /// Sets the size of the pixmap representation of the image set on a given background widget.
93         /// This method just makes sense if an image file was set.
94         /// This is just a hint for the underlying system.
95         /// The real size of the pixmap may differ depending on the type of image being loaded, being bigger than requested.
96         /// </summary>
97         /// <param name="w">The new width of the image pixmap representation.</param>
98         /// <param name="h">The new height of the image pixmap representation.</param>
99         /// <since_tizen> preview </since_tizen>
100         public void SetFileLoadSize(int w, int h)
101         {
102             if (File != null)
103             {
104                 Interop.Elementary.elm_bg_load_size_set(RealHandle, w, h);
105             }
106             else
107             {
108                 throw new InvalidOperationException("This method just makes sense if an image file was set.");
109             }
110         }
111
112         /// <summary>
113         /// Creates a widget handle.
114         /// </summary>
115         /// <param name="parent">Parent EvasObject.</param>
116         /// <returns>Handle IntPtr.</returns>
117         /// <since_tizen> preview </since_tizen>
118         protected override IntPtr CreateHandle(EvasObject parent)
119         {
120             return Interop.Elementary.elm_bg_add(parent.Handle);
121         }
122     }
123
124     /// <summary>
125     /// Enumeration for the background types.
126     /// </summary>
127     /// <since_tizen> preview </since_tizen>
128     public enum BackgroundOptions
129     {
130         /// <summary>
131         /// Centers the background image.
132         /// </summary>
133         Center,
134
135         /// <summary>
136         /// Scales the background image, retaining the aspect ratio.
137         /// </summary>
138         Scale,
139
140         /// <summary>
141         /// Stretches the background image to fill the UI component's area.
142         /// </summary>
143         Stretch,
144
145         /// <summary>
146         /// Tiles the background image at its original size.
147         /// </summary>
148         Tile
149     }
150 }