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;
23 /// Low level Evas canvas functions. Sub groups will present more high level ones, though.
24 /// Most of these functions deal with low level Evas actions, like:
25 /// create/destroy raw canvases, not bound to any displaying engine
26 /// tell a canvas i got focused(in a windowing context, for example)
27 /// tell a canvas a region should not be calculated anymore in rendering
28 /// tell a canvas to render its contents, immediately
29 /// 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.
30 /// 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.
32 public class EvasCanvas
34 IntPtr _handle = IntPtr.Zero;
35 Dictionary<EventData, Interop.Evas.EvasCallback> _eventDatas = new Dictionary<EventData, Interop.Evas.EvasCallback>();
37 internal EvasCanvas(IntPtr evasObject)
39 _handle = CreateHandle(evasObject);
43 /// Gets or sets the image cache.
44 /// This function returns the image cache size of canvas in bytes.
46 public int ImageCacheSize
50 return Interop.Evas.evas_image_cache_get(_handle);
54 Interop.Evas.evas_image_cache_set(_handle, value);
59 /// Flush the image cache of the canvas.
61 public void FlushImageCache()
63 Interop.Evas.evas_image_cache_flush(_handle);
67 /// Add a damage rectangle.
69 /// <param name="x">The rectangle's top left corner's horizontal coordinate.</param>
70 /// <param name="y">The rectangle's top left corner's vertical coordinate.</param>
71 /// <param name="width">The rectangle's width.</param>
72 /// <param name="height">The rectangle's height.</param>
73 public void AddDamageRectangle(int x, int y, int width, int height)
75 Interop.Evas.evas_damage_rectangle_add(_handle, x, y, width, height);
79 /// Add an "obscured region" to an Evas canvas.
81 /// <param name="x">The rectangle's top left corner's horizontal coordinate.</param>
82 /// <param name="y">The rectangle's top left corner's vertical coordinate.</param>
83 /// <param name="width">The rectangle's width.</param>
84 /// <param name="height">The rectangle's height.</param>
85 public void AddObscuredRectangle(int x, int y, int width, int height)
87 Interop.Evas.evas_obscured_rectangle_add(_handle, x, y, width, height);
91 /// Remove all "obscured regions" from an Evas canvas.
93 public void ClearObscuredRectangle()
95 Interop.Evas.evas_obscured_clear(_handle);
99 /// Adds or registers a event to a given canvas event.
101 /// <param name="type">The type of event that triggers</param>
102 /// <param name="action">The action to be called when the event is triggered</param>
103 public void AddEventAction(EvasObjectCallbackType type, Action action)
107 var eventData = new EventData(type, action);
109 if (!_eventDatas.ContainsKey(eventData))
111 var evasCallback = new Interop.Evas.EvasCallback((d, o, t) => action());
112 Interop.Evas.evas_event_callback_add(_handle, (Interop.Evas.ObjectCallbackType)type, evasCallback, IntPtr.Zero);
113 _eventDatas.Add(eventData, evasCallback);
119 /// Deletes a event to a given canvas event.
121 /// <param name="type">The type of event that triggers</param>
122 /// <param name="action">The action to be called when the event is triggered</param>
123 public void DeleteEventAction(EvasObjectCallbackType type, Action action)
127 var eventData = new EventData(type, action);
128 Interop.Evas.EvasCallback evasCallback = null;
129 _eventDatas.TryGetValue(eventData, out evasCallback);
131 if (evasCallback != null)
133 Interop.Evas.evas_event_callback_del(_handle, (Interop.Evas.ObjectCallbackType)type, evasCallback);
134 _eventDatas.Remove(eventData);
139 IntPtr CreateHandle(IntPtr evasObject)
141 return Interop.Evas.evas_object_evas_get(evasObject);
146 public EvasObjectCallbackType Type { get; set; }
147 public Action Action { get; set; }
149 public EventData(EvasObjectCallbackType type, Action action)
155 public override bool Equals(object obj)
157 EventData e = obj as EventData;
162 return (Type == e.Type) && (Action == e.Action);
165 public override int GetHashCode()
167 int hashCode = Type.GetHashCode();
168 hashCode ^= Action.GetHashCode();