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 the current known default pointer coordinates.
44 /// This function returns the current known canvas unit coordinates of the mouse pointer.
51 Interop.Evas.evas_pointer_canvas_xy_get(_handle, out mx, out my);
52 return new Point { X = mx, Y = my };
57 /// Gets or sets the image cache.
58 /// This function returns the image cache size of canvas in bytes.
60 public int ImageCacheSize
64 return Interop.Evas.evas_image_cache_get(_handle);
68 Interop.Evas.evas_image_cache_set(_handle, value);
73 /// Flush the image cache of the canvas.
75 public void FlushImageCache()
77 Interop.Evas.evas_image_cache_flush(_handle);
81 /// Add a damage rectangle.
83 /// <param name="x">The rectangle's top left corner's horizontal coordinate.</param>
84 /// <param name="y">The rectangle's top left corner's vertical coordinate.</param>
85 /// <param name="width">The rectangle's width.</param>
86 /// <param name="height">The rectangle's height.</param>
87 public void AddDamageRectangle(int x, int y, int width, int height)
89 Interop.Evas.evas_damage_rectangle_add(_handle, x, y, width, height);
93 /// Add an "obscured region" to an Evas canvas.
95 /// <param name="x">The rectangle's top left corner's horizontal coordinate.</param>
96 /// <param name="y">The rectangle's top left corner's vertical coordinate.</param>
97 /// <param name="width">The rectangle's width.</param>
98 /// <param name="height">The rectangle's height.</param>
99 public void AddObscuredRectangle(int x, int y, int width, int height)
101 Interop.Evas.evas_obscured_rectangle_add(_handle, x, y, width, height);
105 /// Remove all "obscured regions" from an Evas canvas.
107 public void ClearObscuredRectangle()
109 Interop.Evas.evas_obscured_clear(_handle);
113 /// Adds or registers a event to a given canvas event.
115 /// <param name="type">The type of event that triggers</param>
116 /// <param name="action">The action to be called when the event is triggered</param>
117 public void AddEventAction(EvasObjectCallbackType type, Action action)
121 var eventData = new EventData(type, action);
123 if (!_eventDatas.ContainsKey(eventData))
125 var evasCallback = new Interop.Evas.EvasCallback((d, o, t) => action());
126 Interop.Evas.evas_event_callback_add(_handle, (Interop.Evas.ObjectCallbackType)type, evasCallback, IntPtr.Zero);
127 _eventDatas.Add(eventData, evasCallback);
133 /// Deletes a event to a given canvas event.
135 /// <param name="type">The type of event that triggers</param>
136 /// <param name="action">The action to be called when the event is triggered</param>
137 public void DeleteEventAction(EvasObjectCallbackType type, Action action)
141 var eventData = new EventData(type, action);
142 Interop.Evas.EvasCallback evasCallback = null;
143 _eventDatas.TryGetValue(eventData, out evasCallback);
145 if (evasCallback != null)
147 Interop.Evas.evas_event_callback_del(_handle, (Interop.Evas.ObjectCallbackType)type, evasCallback);
148 _eventDatas.Remove(eventData);
154 /// Creates an Evas canvas handle.
156 /// <param name="evasObject">EvasObject</param>
157 /// <returns>Handle IntPtr</returns>
158 IntPtr CreateHandle(IntPtr evasObject)
160 return Interop.Evas.evas_object_evas_get(evasObject);
165 public EvasObjectCallbackType Type { get; set; }
166 public Action Action { get; set; }
168 public EventData(EvasObjectCallbackType type, Action action)
175 /// Indicates whether this instance and a specified object are equal.
177 /// <param name="obj">The object to compare with the current instance.</param>
179 /// true if obj and this instance are the same type and represent the same value.
180 /// otherwise, false.
182 public override bool Equals(object obj)
184 EventData e = obj as EventData;
189 return (Type == e.Type) && (Action == e.Action);
192 public override int GetHashCode()
194 int hashCode = Type.GetHashCode();
195 hashCode ^= Action.GetHashCode();