/* * 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; namespace ElmSharp { /// /// Low level Evas canvas functions. Sub groups will present more high level ones, though. /// Most of these functions deal with low level Evas actions, like: /// create/destroy raw canvases, not bound to any displaying engine /// tell a canvas i got focused(in a windowing context, for example) /// tell a canvas a region should not be calculated anymore in rendering /// tell a canvas to render its contents, immediately /// Most users will be using Evas by means of the Ecore_Evas wrapper, which deals with all the above mentioned issues automatically for them.Thus, you'll be looking at this section only if you're building low level stuff. /// The groups within present you functions that deal with the canvas directly, too, and not yet with its objects.They are the functions you need to use at a minimum to get a working canvas. /// public class EvasCanvas { IntPtr _handle = IntPtr.Zero; Dictionary _eventDatas = new Dictionary(); internal EvasCanvas(IntPtr evasObject) { _handle = CreateHandle(evasObject); } /// /// Gets or sets the image cache. /// This function returns the image cache size of canvas in bytes. /// public int ImageCacheSize { get { return Interop.Evas.evas_image_cache_get(_handle); } set { Interop.Evas.evas_image_cache_set(_handle, value); } } /// /// Flush the image cache of the canvas. /// public void FlushImageCache() { Interop.Evas.evas_image_cache_flush(_handle); } /// /// Add a damage rectangle. /// /// The rectangle's top left corner's horizontal coordinate. /// The rectangle's top left corner's vertical coordinate. /// The rectangle's width. /// The rectangle's height. public void AddDamageRectangle(int x, int y, int width, int height) { Interop.Evas.evas_damage_rectangle_add(_handle, x, y, width, height); } /// /// Add an "obscured region" to an Evas canvas. /// /// The rectangle's top left corner's horizontal coordinate. /// The rectangle's top left corner's vertical coordinate. /// The rectangle's width. /// The rectangle's height. public void AddObscuredRectangle(int x, int y, int width, int height) { Interop.Evas.evas_obscured_rectangle_add(_handle, x, y, width, height); } /// /// Remove all "obscured regions" from an Evas canvas. /// public void ClearObscuredRectangle() { Interop.Evas.evas_obscured_clear(_handle); } /// /// Adds or registers a event to a given canvas event. /// /// The type of event that triggers /// The action to be called when the event is triggered public void AddEventAction(EvasObjectCallbackType type, Action action) { if (action != null) { var eventData = new EventData(type, action); if (!_eventDatas.ContainsKey(eventData)) { var evasCallback = new Interop.Evas.EvasCallback((d, o, t) => action()); Interop.Evas.evas_event_callback_add(_handle, (Interop.Evas.ObjectCallbackType)type, evasCallback, IntPtr.Zero); _eventDatas.Add(eventData, evasCallback); } } } /// /// Deletes a event to a given canvas event. /// /// The type of event that triggers /// The action to be called when the event is triggered public void DeleteEventAction(EvasObjectCallbackType type, Action action) { if (action != null) { var eventData = new EventData(type, action); Interop.Evas.EvasCallback evasCallback = null; _eventDatas.TryGetValue(eventData, out evasCallback); if (evasCallback != null) { Interop.Evas.evas_event_callback_del(_handle, (Interop.Evas.ObjectCallbackType)type, evasCallback); _eventDatas.Remove(eventData); } } } IntPtr CreateHandle(IntPtr evasObject) { return Interop.Evas.evas_object_evas_get(evasObject); } class EventData { public EvasObjectCallbackType Type { get; set; } public Action Action { get; set; } public EventData(EvasObjectCallbackType type, Action action) { Type = type; Action = action; } public override bool Equals(object obj) { EventData e = obj as EventData; if (e == null) { return false; } return (Type == e.Type) && (Action == e.Action); } public override int GetHashCode() { int hashCode = Type.GetHashCode(); hashCode ^= Action.GetHashCode(); return hashCode; } } } }