2 using System.Collections.Generic;
3 using System.ComponentModel;
10 /// This group provides functions for image objects.
12 public class EvasImage : EvasObject
14 EvasObject _source = null;
15 IntPtr _handle = IntPtr.Zero;
18 /// Creates and initializes a new instance of EvasImage class.
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)
25 internal EvasImage(EvasObject parent, IntPtr handle) : base()
32 /// Sets or gets the source file from where an image object must fetch the real image data
39 Interop.Evas.evas_object_image_file_get(RealHandle, out file, out key);
44 Interop.Evas.evas_object_image_file_set(RealHandle, value, null);
49 /// Sets or gets the source object to be visible.
51 public bool IsSourceVisible
55 return Interop.Evas.evas_object_image_source_visible_get(RealHandle);
59 Interop.Evas.evas_object_image_source_visible_set(RealHandle, value);
64 /// Sets or gets whether an object is clipped by source object's clipper.
66 public bool IsSourceClipped
70 return Interop.Evas.evas_object_image_source_clip_get(RealHandle);
74 Interop.Evas.evas_object_image_source_clip_set(RealHandle, value);
79 /// Sets or gets if the center part of the given image object (not the border) should be drawn.
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.
86 public ImageBorderFillMode BorderCenterFillMode
90 return (ImageBorderFillMode)Interop.Evas.evas_object_image_border_center_fill_get(RealHandle);
94 Interop.Evas.evas_object_image_border_center_fill_set(RealHandle, (int)value);
99 /// Sets or gets whether the image object's fill property should track the object's size.
105 return Interop.Evas.evas_object_image_filled_get(RealHandle);
109 Interop.Evas.evas_object_image_filled_set(RealHandle, value);
114 /// Sets or gets the scaling factor (multiplier) for the borders of an image object.
116 public double BorderScale
120 return Interop.Evas.evas_object_image_border_scale_get(RealHandle);
124 Interop.Evas.evas_object_image_border_scale_set(RealHandle, value);
129 /// Sets or gets the size of the given image object.
136 Interop.Evas.evas_object_image_size_get(RealHandle, out w, out h);
137 return new Size(w, h);
141 Interop.Evas.evas_object_image_size_set(RealHandle, value.Width, value.Height);
146 /// Gets the row stride of the given image object.
152 return Interop.Evas.evas_object_image_stride_get(RealHandle);
157 /// Sets or gets whether alpha channel data is being used on the given image object.
163 return !Interop.Evas.evas_object_image_alpha_get(RealHandle);
167 Interop.Evas.evas_object_image_alpha_set(RealHandle, !value);
173 /// Sets or gets whether to use high-quality image scaling algorithm on the given image object.
175 public bool IsSmoothScaled
179 return Interop.Evas.evas_object_image_smooth_scale_get(RealHandle);
183 Interop.Evas.evas_object_image_smooth_scale_set(RealHandle, value);
188 /// Sets how to fill an image object's drawing rectangle given the (real) image bound to it.
190 /// <param name="geometry"></param>
191 public void SetFill(Rect geometry)
193 Interop.Evas.evas_object_image_fill_set(RealHandle, geometry.X, geometry.Y, geometry.Width, geometry.Height);
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).
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)
203 Interop.Evas.evas_object_image_file_set(RealHandle, file, key);
207 /// Sets the data for an image from memory to be loaded.
209 /// <param name="stream">memory stream</param>
210 public void SetStream(Stream stream)
213 throw new ArgumentNullException("stream");
215 MemoryStream memstream = new MemoryStream();
216 stream.CopyTo(memstream);
219 byte[] dataArr = memstream.ToArray();
220 fixed (byte* data = &dataArr[0])
222 Interop.Evas.evas_object_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero);
229 /// Sets the source object on an image object to used as a proxy.
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)
237 result = Interop.Evas.evas_object_image_source_set(RealHandle, IntPtr.Zero);
239 result = result && Interop.Evas.evas_object_image_source_set(RealHandle, source.Handle);
243 [EditorBrowsable(EditorBrowsableState.Never)]
244 public void SetNativeSurface(IntPtr surface)
246 Interop.Evas.evas_object_image_native_surface_set(RealHandle, surface);
250 /// Sets the dimensions for an image object's border, a region which is not scaled together with its center ever.
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)
258 Interop.Evas.evas_object_image_border_set(RealHandle, left, right, top, bottom);
262 /// Sets the content at a part of a given container widget.
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)
268 return _handle != IntPtr.Zero ? _handle : Interop.Evas.evas_object_image_add(Interop.Evas.evas_object_evas_get(parent.Handle));