Release 4.0.0-preview1-00235
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / EvasImage.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.IO;
5 using System.Text;
6
7 namespace ElmSharp
8 {
9     /// <summary>
10     /// This group provides functions for image objects.
11     /// </summary>
12     public class EvasImage : EvasObject
13     {
14         EvasObject _source = null;
15         IntPtr _handle = IntPtr.Zero;
16
17         /// <summary>
18         /// Creates and initializes a new instance of EvasImage class.
19         /// </summary>
20         /// <param name="parent">The parent is a given container which will be attached by EvasImage as a child. It's <see cref="EvasObject"/> type.</param>
21         public EvasImage(EvasObject parent) : base(parent)
22         {
23         }
24
25         internal EvasImage(EvasObject parent, IntPtr handle) : base()
26         {
27             _handle = handle;
28             Realize(parent);
29         }
30
31         /// <summary>
32         /// Sets or gets the source file from where an image object must fetch the real image data
33         /// </summary>
34         public string File
35         {
36             get
37             {
38                 string file, key;
39                 Interop.Evas.evas_object_image_file_get(RealHandle, out file, out key);
40                 return file;
41             }
42             set
43             {
44                 Interop.Evas.evas_object_image_file_set(RealHandle, value, null);
45             }
46         }
47
48         /// <summary>
49         /// Sets or gets the source object to be visible.
50         /// </summary>
51         public bool IsSourceVisible
52         {
53             get
54             {
55                 return Interop.Evas.evas_object_image_source_visible_get(RealHandle);
56             }
57             set
58             {
59                 Interop.Evas.evas_object_image_source_visible_set(RealHandle, value);
60             }
61         }
62
63         /// <summary>
64         /// Sets or gets whether an object is clipped by source object's clipper.
65         /// </summary>
66         public bool IsSourceClipped
67         {
68             get
69             {
70                 return Interop.Evas.evas_object_image_source_clip_get(RealHandle);
71             }
72             set
73             {
74                 Interop.Evas.evas_object_image_source_clip_set(RealHandle, value);
75             }
76         }
77
78         /// <summary>
79         /// Sets or gets if the center part of the given image object (not the border) should be drawn.
80         /// </summary>
81         /// <remarks>
82         /// When rendering, the image may be scaled to fit the size of the image object.
83         /// This function sets if the center part of the scaled image is to be drawn or left completely blank, or forced to be solid.
84         /// Very useful for frames and decorations.
85         /// </remarks>
86         public ImageBorderFillMode BorderCenterFillMode
87         {
88             get
89             {
90                 return (ImageBorderFillMode)Interop.Evas.evas_object_image_border_center_fill_get(RealHandle);
91             }
92             set
93             {
94                 Interop.Evas.evas_object_image_border_center_fill_set(RealHandle, (int)value);
95             }
96         }
97
98         /// <summary>
99         /// Sets or gets whether the image object's fill property should track the object's size.
100         /// </summary>
101         public bool IsFilled
102         {
103             get
104             {
105                 return Interop.Evas.evas_object_image_filled_get(RealHandle);
106             }
107             set
108             {
109                 Interop.Evas.evas_object_image_filled_set(RealHandle, value);
110             }
111         }
112
113         /// <summary>
114         /// Sets or gets the scaling factor (multiplier) for the borders of an image object.
115         /// </summary>
116         public double BorderScale
117         {
118             get
119             {
120                 return Interop.Evas.evas_object_image_border_scale_get(RealHandle);
121             }
122             set
123             {
124                 Interop.Evas.evas_object_image_border_scale_set(RealHandle, value);
125             }
126         }
127
128         /// <summary>
129         /// Sets or gets the size of the given image object.
130         /// </summary>
131         public Size Size
132         {
133             get
134             {
135                 int w, h;
136                 Interop.Evas.evas_object_image_size_get(RealHandle, out w, out h);
137                 return new Size(w, h);
138             }
139             set
140             {
141                 Interop.Evas.evas_object_image_size_set(RealHandle, value.Width, value.Height);
142             }
143         }
144
145         /// <summary>
146         /// Gets the row stride of the given image object.
147         /// </summary>
148         public int Stride
149         {
150             get
151             {
152                 return Interop.Evas.evas_object_image_stride_get(RealHandle);
153             }
154         }
155
156         /// <summary>
157         /// Sets or gets whether alpha channel data is being used on the given image object.
158         /// </summary>
159         public bool IsOpaque
160         {
161             get
162             {
163                 return !Interop.Evas.evas_object_image_alpha_get(RealHandle);
164             }
165             set
166             {
167                 Interop.Evas.evas_object_image_alpha_set(RealHandle, !value);
168
169             }
170         }
171
172         /// <summary>
173         /// Sets or gets whether to use high-quality image scaling algorithm on the given image object.
174         /// </summary>
175         public bool IsSmoothScaled
176         {
177             get
178             {
179                 return Interop.Evas.evas_object_image_smooth_scale_get(RealHandle);
180             }
181             set
182             {
183                 Interop.Evas.evas_object_image_smooth_scale_set(RealHandle, value);
184             }
185         }
186
187         /// <summary>
188         /// Sets how to fill an image object's drawing rectangle given the (real) image bound to it.
189         /// </summary>
190         /// <param name="geometry"></param>
191         public void SetFill(Rect geometry)
192         {
193             Interop.Evas.evas_object_image_fill_set(RealHandle, geometry.X, geometry.Y, geometry.Width, geometry.Height);
194         }
195
196         /// <summary>
197         /// Sets the source file from where an image object must fetch the real image data (it may be an Eet file, besides pure image ones).
198         /// </summary>
199         /// <param name="file">The image file path</param>
200         /// <param name="key">The image key in file (if its an Eet one), otherwise set null</param>
201         public void SetFile(string file, string key)
202         {
203             Interop.Evas.evas_object_image_file_set(RealHandle, file, key);
204         }
205
206         /// <summary>
207         /// Sets the data for an image from memory to be loaded.
208         /// </summary>
209         /// <param name="stream">memory stream</param>
210         public void SetStream(Stream stream)
211         {
212             if (stream == null)
213                 throw new ArgumentNullException("stream");
214
215             MemoryStream memstream = new MemoryStream();
216             stream.CopyTo(memstream);
217             unsafe
218             {
219                 byte[] dataArr = memstream.ToArray();
220                 fixed (byte* data = &dataArr[0])
221                 {
222                     Interop.Evas.evas_object_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
223                 }
224             }
225             memstream.Dispose();
226         }
227
228         /// <summary>
229         /// Sets the source object on an image object to used as a proxy.
230         /// </summary>
231         /// <param name="source">The proxy (image) object</param>
232         /// <returns>true if the source object is set successfully, ortherwise false on error</returns>
233         public bool SetSource(EvasObject source)
234         {
235             bool result = false;
236             _source = source;
237             result = Interop.Evas.evas_object_image_source_set(RealHandle, IntPtr.Zero);
238             if (source != null)
239                 result = result && Interop.Evas.evas_object_image_source_set(RealHandle, source.Handle);
240             return result;
241         }
242
243         [EditorBrowsable(EditorBrowsableState.Never)]
244         public void SetNativeSurface(IntPtr surface)
245         {
246             Interop.Evas.evas_object_image_native_surface_set(RealHandle, surface);
247         }
248
249         /// <summary>
250         /// Sets the dimensions for an image object's border, a region which is not scaled together with its center ever.
251         /// </summary>
252         /// <param name="left">The border's left width</param>
253         /// <param name="right">The border's right width</param>
254         /// <param name="top">The border's top width</param>
255         /// <param name="bottom">The border's bottom width</param>
256         public void SetBorder(int left, int right, int top, int bottom)
257         {
258             Interop.Evas.evas_object_image_border_set(RealHandle, left, right, top, bottom);
259         }
260
261         /// <summary>
262         /// Sets the content at a part of a given container widget.
263         /// </summary>
264         /// <param name="parent">The parent is a given container which will be attached by Image as a child. It's <see cref="EvasObject"/> type.</param>
265         /// <returns>The new object, otherwise null if it cannot be created</returns>
266         protected override IntPtr CreateHandle(EvasObject parent)
267         {
268             return _handle != IntPtr.Zero ? _handle : Interop.Evas.evas_object_image_add(Interop.Evas.evas_object_evas_get(parent.Handle));
269         }
270     }
271 }