2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
19 using System.ComponentModel;
26 /// This group provides functions for image objects.
28 /// <since_tizen> preview </since_tizen>
29 public class EvasImage : EvasObject
31 EvasObject _source = null;
32 IntPtr _handle = IntPtr.Zero;
35 /// Creates and initializes a new instance of EvasImage class.
37 /// <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>
38 /// <since_tizen> preview </since_tizen>
39 public EvasImage(EvasObject parent) : base(parent)
43 internal EvasImage(EvasObject parent, IntPtr handle) : base()
50 /// Sets or gets the source file from where an image object must fetch the real image data
52 /// <since_tizen> preview </since_tizen>
58 Interop.Evas.evas_object_image_file_get(RealHandle, out file, out key);
63 Interop.Evas.evas_object_image_file_set(RealHandle, value, null);
68 /// Sets or gets the source object to be visible.
70 /// <since_tizen> preview </since_tizen>
71 public bool IsSourceVisible
75 return Interop.Evas.evas_object_image_source_visible_get(RealHandle);
79 Interop.Evas.evas_object_image_source_visible_set(RealHandle, value);
84 /// Sets or gets whether an object is clipped by source object's clipper.
86 /// <since_tizen> preview </since_tizen>
87 public bool IsSourceClipped
91 return Interop.Evas.evas_object_image_source_clip_get(RealHandle);
95 Interop.Evas.evas_object_image_source_clip_set(RealHandle, value);
100 /// Sets or gets if the center part of the given image object (not the border) should be drawn.
103 /// When rendering, the image may be scaled to fit the size of the image object.
104 /// This function sets if the center part of the scaled image is to be drawn or left completely blank, or forced to be solid.
105 /// Very useful for frames and decorations.
107 /// <since_tizen> preview </since_tizen>
108 public ImageBorderFillMode BorderCenterFillMode
112 return (ImageBorderFillMode)Interop.Evas.evas_object_image_border_center_fill_get(RealHandle);
116 Interop.Evas.evas_object_image_border_center_fill_set(RealHandle, (int)value);
121 /// Sets or gets whether the image object's fill property should track the object's size.
123 /// <since_tizen> preview </since_tizen>
128 return Interop.Evas.evas_object_image_filled_get(RealHandle);
132 Interop.Evas.evas_object_image_filled_set(RealHandle, value);
137 /// Sets or gets the scaling factor (multiplier) for the borders of an image object.
139 /// <since_tizen> preview </since_tizen>
140 public double BorderScale
144 return Interop.Evas.evas_object_image_border_scale_get(RealHandle);
148 Interop.Evas.evas_object_image_border_scale_set(RealHandle, value);
153 /// Sets or gets the size of the given image object.
155 /// <since_tizen> preview </since_tizen>
161 Interop.Evas.evas_object_image_size_get(RealHandle, out w, out h);
162 return new Size(w, h);
166 Interop.Evas.evas_object_image_size_set(RealHandle, value.Width, value.Height);
171 /// Gets the row stride of the given image object.
173 /// <since_tizen> preview </since_tizen>
178 return Interop.Evas.evas_object_image_stride_get(RealHandle);
183 /// Sets or gets whether alpha channel data is being used on the given image object.
185 /// <since_tizen> preview </since_tizen>
190 return !Interop.Evas.evas_object_image_alpha_get(RealHandle);
194 Interop.Evas.evas_object_image_alpha_set(RealHandle, !value);
199 /// Sets or gets whether to use high-quality image scaling algorithm on the given image object.
201 /// <since_tizen> preview </since_tizen>
202 public bool IsSmoothScaled
206 return Interop.Evas.evas_object_image_smooth_scale_get(RealHandle);
210 Interop.Evas.evas_object_image_smooth_scale_set(RealHandle, value);
215 /// Sets how to fill an image object's drawing rectangle given the (real) image bound to it.
217 /// <param name="geometry"></param>
218 /// <since_tizen> preview </since_tizen>
219 public void SetFill(Rect geometry)
221 Interop.Evas.evas_object_image_fill_set(RealHandle, geometry.X, geometry.Y, geometry.Width, geometry.Height);
225 /// 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).
227 /// <param name="file">The image file path</param>
228 /// <param name="key">The image key in file (if its an Eet one), otherwise set null</param>
229 /// <since_tizen> preview </since_tizen>
230 public void SetFile(string file, string key)
232 Interop.Evas.evas_object_image_file_set(RealHandle, file, key);
236 /// Sets the data for an image from memory to be loaded.
238 /// <param name="stream">memory stream</param>
239 /// <since_tizen> preview </since_tizen>
240 public void SetStream(Stream stream)
243 throw new ArgumentNullException("stream");
245 MemoryStream memstream = new MemoryStream();
246 stream.CopyTo(memstream);
249 byte[] dataArr = memstream.ToArray();
250 fixed (byte* data = &dataArr[0])
252 Interop.Evas.evas_object_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
259 /// Sets the source object on an image object to used as a proxy.
261 /// <param name="source">The proxy (image) object</param>
262 /// <returns>true if the source object is set successfully, ortherwise false on error</returns>
263 /// <since_tizen> preview </since_tizen>
264 public bool SetSource(EvasObject source)
268 result = Interop.Evas.evas_object_image_source_set(RealHandle, IntPtr.Zero);
270 result = result && Interop.Evas.evas_object_image_source_set(RealHandle, source.Handle);
275 /// Set the native surface of a given image of the canvas
277 /// <param name="surface">The surface.</param>
278 /// <since_tizen> preview </since_tizen>
279 [EditorBrowsable(EditorBrowsableState.Never)]
280 public void SetNativeSurface(IntPtr surface)
282 Interop.Evas.evas_object_image_native_surface_set(RealHandle, surface);
286 /// Sets the dimensions for an image object's border, a region which is not scaled together with its center ever.
288 /// <param name="left">The border's left width</param>
289 /// <param name="right">The border's right width</param>
290 /// <param name="top">The border's top width</param>
291 /// <param name="bottom">The border's bottom width</param>
292 /// <since_tizen> preview </since_tizen>
293 public void SetBorder(int left, int right, int top, int bottom)
295 Interop.Evas.evas_object_image_border_set(RealHandle, left, right, top, bottom);
299 /// Sets the content at a part of a given container widget.
301 /// <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>
302 /// <returns>The new object, otherwise null if it cannot be created</returns>
303 /// <since_tizen> preview </since_tizen>
304 protected override IntPtr CreateHandle(EvasObject parent)
306 return _handle != IntPtr.Zero ? _handle : Interop.Evas.evas_object_image_add(Interop.Evas.evas_object_evas_get(parent.Handle));