From da4f68e8acbcb4b7cce64c9fdd93226b50efc9df Mon Sep 17 00:00:00 2001 From: Seunghyun Choi Date: Thu, 15 Jun 2017 17:32:14 +0900 Subject: Enhance EvasCanvas Change-Id: Id169ecc5d29ac237534b4062e8a9b6bb56c94623 --- ElmSharp/ElmSharp/EvasCanvas.cs | 173 ++++++++++++++++++++++++++++++++++++++++ ElmSharp/ElmSharp/EvasObject.cs | 14 ++++ 2 files changed, 187 insertions(+) create mode 100644 ElmSharp/ElmSharp/EvasCanvas.cs diff --git a/ElmSharp/ElmSharp/EvasCanvas.cs b/ElmSharp/ElmSharp/EvasCanvas.cs new file mode 100644 index 0000000..6f778c6 --- /dev/null +++ b/ElmSharp/ElmSharp/EvasCanvas.cs @@ -0,0 +1,173 @@ +/* + * 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; + } + } + } +} \ No newline at end of file diff --git a/ElmSharp/ElmSharp/EvasObject.cs b/ElmSharp/ElmSharp/EvasObject.cs index 9236ba6..598789a 100644 --- a/ElmSharp/ElmSharp/EvasObject.cs +++ b/ElmSharp/ElmSharp/EvasObject.cs @@ -49,6 +49,7 @@ namespace ElmSharp public abstract class EvasObject { private IntPtr _realHandle = IntPtr.Zero; + private EvasCanvas _evasCanvas; private event EventHandler _backButtonPressed; @@ -234,6 +235,19 @@ namespace ElmSharp /// public bool IsRealized { get { return Handle != IntPtr.Zero; } } + /// + /// Gets EvasCanvas + /// + public EvasCanvas EvasCanvas + { + get + { + if (_evasCanvas == null) + _evasCanvas = new EvasCanvas(Handle); + return _evasCanvas; + } + } + /// /// Gets the current class's Name. /// -- cgit v1.2.3