Review Elmsharp API cs files
[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                 int r = 0;
47                 int g = 0;
48                 int b = 0;
49                 int a = 0;
50                 var swallowContent = GetPartContent("elm.swallow.rectangle");
51                 if (swallowContent != IntPtr.Zero)
52                 {
53                     Interop.Evas.evas_object_color_get(swallowContent, out r, out g, out b, out a);
54                 }
55                 return new Color(r, g, b, a);
56             }
57             set
58             {
59                 var swallowContent = GetPartContent("elm.swallow.rectangle");
60                 if (swallowContent == IntPtr.Zero)
61                 {
62                     Interop.Elementary.elm_bg_color_set(RealHandle, value.R, value.G, value.B);
63                     swallowContent = GetPartContent("elm.swallow.rectangle");
64                 }
65                 Interop.Evas.evas_object_color_set(swallowContent, value.R, value.G, value.B, value.A);
66             }
67         }
68
69         /// <summary>
70         /// Sets or gets the image to the background.
71         /// </summary>
72         /// <since_tizen> preview </since_tizen>
73         public string File
74         {
75             get
76             {
77                 return Interop.Elementary.BackgroundFileGet(RealHandle);
78             }
79             set
80             {
81                 Interop.Elementary.elm_bg_file_set(RealHandle, value, IntPtr.Zero);
82             }
83         }
84
85         /// <summary>
86         /// Sets or gets the mode of display for a given background widget's image.
87         /// </summary>
88         /// <remarks>
89         /// This sets how the background widget will display its image.
90         /// This will only work if the file was previously set with an image file on object.
91         /// The image can be display tiled, scaled, centered, or stretched. Scaled by default.
92         /// </remarks>
93         /// <since_tizen> preview </since_tizen>
94         public BackgroundOptions BackgroundOption
95         {
96             get
97             {
98                 return (BackgroundOptions)Interop.Elementary.elm_bg_option_get(RealHandle);
99             }
100             set
101             {
102                 Interop.Elementary.elm_bg_option_set(RealHandle, (Interop.Elementary.BackgroundOptions)value);
103             }
104         }
105
106         /// <summary>
107         /// Sets the size of the pixmap representation of the image set on a given background widget.
108         /// This method just makes sense if an image file was set.
109         /// This is just a hint for the underlying system.
110         /// The real size of the pixmap may differ depending on the type of image being loaded, being bigger than requested.
111         /// </summary>
112         /// <param name="w">The new width of the image pixmap representation.</param>
113         /// <param name="h">The new height of the image pixmap representation.</param>
114         /// <since_tizen> preview </since_tizen>
115         public void SetFileLoadSize(int w, int h)
116         {
117             if (File != null)
118             {
119                 Interop.Elementary.elm_bg_load_size_set(RealHandle, w, h);
120             }
121             else
122             {
123                 throw new Exception("This method just makes sense if an image file was set.");
124             }
125         }
126
127         /// <summary>
128         /// Creates a widget handle.
129         /// </summary>
130         /// <param name="parent">Parent EvasObject.</param>
131         /// <returns>Handle IntPtr.</returns>
132         /// <since_tizen> preview </since_tizen>
133         protected override IntPtr CreateHandle(EvasObject parent)
134         {
135             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
136             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
137
138             RealHandle = Interop.Elementary.elm_bg_add(handle);
139             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
140
141             return handle;
142         }
143     }
144
145     /// <summary>
146     /// Enumeration for the background types.
147     /// </summary>
148     /// <since_tizen> preview </since_tizen>
149     public enum BackgroundOptions
150     {
151         /// <summary>
152         /// Centers the background image.
153         /// </summary>
154         Center,
155
156         /// <summary>
157         /// Scales the background image, retaining the aspect ratio.
158         /// </summary>
159         Scale,
160
161         /// <summary>
162         /// Stretches the background image to fill the UI component's area.
163         /// </summary>
164         Stretch,
165
166         /// <summary>
167         /// Tiles the background image at its original size.
168         /// </summary>
169         Tile
170     }
171 }