/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Text; namespace ElmSharp { /// /// This group provides the functions for image objects. /// /// preview public class EvasImage : EvasObject { EvasObject _source = null; IntPtr _handle = IntPtr.Zero; /// /// Creates and initializes a new instance of the EvasImage class. /// /// The parent is a given container, which will be attached by EvasImage as a child. It's type. /// preview public EvasImage(EvasObject parent) : base(parent) { } internal EvasImage(EvasObject parent, IntPtr handle) : base() { _handle = handle; Realize(parent); } /// /// Sets or gets the source file from where an image object must fetch the real image data. /// /// preview public string File { get { string file, key; Interop.Evas.evas_object_image_file_get(RealHandle, out file, out key); return file; } set { Interop.Evas.evas_object_image_file_set(RealHandle, value, null); } } /// /// Sets or gets the source object to be visible. /// /// preview public bool IsSourceVisible { get { return Interop.Evas.evas_object_image_source_visible_get(RealHandle); } set { Interop.Evas.evas_object_image_source_visible_set(RealHandle, value); } } /// /// Sets or gets whether an object is clipped by the source object's clipper. /// /// preview public bool IsSourceClipped { get { return Interop.Evas.evas_object_image_source_clip_get(RealHandle); } set { Interop.Evas.evas_object_image_source_clip_set(RealHandle, value); } } /// /// Sets or gets if the center part of the given image object (not the border) should be drawn. /// /// /// When rendering, the image may be scaled to fit the size of the image object. /// This function sets if the center part of the scaled image is to be drawn or left completely blank, or forced to be solid. /// Very useful for frames and decorations. /// /// preview public ImageBorderFillMode BorderCenterFillMode { get { return (ImageBorderFillMode)Interop.Evas.evas_object_image_border_center_fill_get(RealHandle); } set { Interop.Evas.evas_object_image_border_center_fill_set(RealHandle, (int)value); } } /// /// Sets or gets whether the image object's fill property should track the object's size. /// /// preview public bool IsFilled { get { return Interop.Evas.evas_object_image_filled_get(RealHandle); } set { Interop.Evas.evas_object_image_filled_set(RealHandle, value); } } /// /// Sets or gets the scaling factor (multiplier) for the borders of the image object. /// /// preview public double BorderScale { get { return Interop.Evas.evas_object_image_border_scale_get(RealHandle); } set { Interop.Evas.evas_object_image_border_scale_set(RealHandle, value); } } /// /// Sets or gets the size of the given image object. /// /// preview public Size Size { get { int w, h; Interop.Evas.evas_object_image_size_get(RealHandle, out w, out h); return new Size(w, h); } set { Interop.Evas.evas_object_image_size_set(RealHandle, value.Width, value.Height); } } /// /// Gets the row stride of the given image object. /// /// preview public int Stride { get { return Interop.Evas.evas_object_image_stride_get(RealHandle); } } /// /// Sets or gets whether the alpha channel data is being used on the given image object. /// /// preview public bool IsOpaque { get { return !Interop.Evas.evas_object_image_alpha_get(RealHandle); } set { Interop.Evas.evas_object_image_alpha_set(RealHandle, !value); } } /// /// Sets or gets whether to use a high-quality image scaling algorithm on the given image object. /// /// preview public bool IsSmoothScaled { get { return Interop.Evas.evas_object_image_smooth_scale_get(RealHandle); } set { Interop.Evas.evas_object_image_smooth_scale_set(RealHandle, value); } } /// /// Sets how to fill an image object's drawing rectangle given the (real) image bound to it. /// /// The rectangle of the given image object that the image will be drawn to. /// preview public void SetFill(Rect geometry) { Interop.Evas.evas_object_image_fill_set(RealHandle, geometry.X, geometry.Y, geometry.Width, geometry.Height); } /// /// 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). /// /// The image file path. /// The image key in file (if its an Eet one), otherwise set null. /// preview public void SetFile(string file, string key) { Interop.Evas.evas_object_image_file_set(RealHandle, file, key); } /// /// Sets the data for an image from the memory to be loaded. /// /// memory stream /// preview public void SetStream(Stream stream) { if (stream == null) throw new ArgumentNullException("stream"); MemoryStream memstream = new MemoryStream(); stream.CopyTo(memstream); unsafe { byte[] dataArr = memstream.ToArray(); fixed (byte* data = &dataArr[0]) { Interop.Evas.evas_object_image_memfile_set(RealHandle, data, dataArr.Length, IntPtr.Zero, IntPtr.Zero); } } memstream.Dispose(); } /// /// Sets the source object on an image object to be used as a proxy. /// /// The proxy (image) object. /// true if the source object is set successfully, otherwise false on error. /// preview public bool SetSource(EvasObject source) { bool result = false; _source = source; result = Interop.Evas.evas_object_image_source_set(RealHandle, IntPtr.Zero); if (source != null) result = result && Interop.Evas.evas_object_image_source_set(RealHandle, source.Handle); return result; } /// /// Set the native surface of a given image of the canvas. /// /// The surface. /// preview [EditorBrowsable(EditorBrowsableState.Never)] public void SetNativeSurface(IntPtr surface) { Interop.Evas.evas_object_image_native_surface_set(RealHandle, surface); } /// /// Sets the dimensions for an image object's border, a region which is not scaled together with its center ever. /// /// The border's left width. /// The border's right width. /// The border's top width. /// The border's bottom width. /// preview public void SetBorder(int left, int right, int top, int bottom) { Interop.Evas.evas_object_image_border_set(RealHandle, left, right, top, bottom); } /// /// Save the given image object's contents to an (image) file. /// /// The extension suffix on file will determine which saver module Evas is to use when saving, thus the final file's format. If the file supports multiple data stored in it (Eet ones), you can specify the key to be used as the index of the image in it. /// /// You can specify some flags when saving the image.Currently acceptable flags are quality and compress.Eg.: "quality=100 compress=9" /// /// The filename to be used to save the image (extension obligatory). /// The image key in the file (if an Eet one), or null, otherwise. /// String containing the flags to be used (null for none). public void Save(string file, string key, string flags) { Interop.Evas.evas_object_image_save(RealHandle, file, key, flags); } /// /// Sets the content at a part of a given container widget. /// /// The parent is a given container, which will be attached by the image as a child. It's type. /// The new object, otherwise null if it cannot be created. /// preview protected override IntPtr CreateHandle(EvasObject parent) { return _handle != IntPtr.Zero ? _handle : Interop.Evas.evas_object_image_add(Interop.Evas.evas_object_evas_get(parent.Handle)); } } }