/* * 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 { /// /// EcoreAnimator is a helper class. It provides the functions to manage animations. /// /// preview [Obsolete("This has been deprecated in API12")] public static class EcoreAnimator { static readonly Dictionary> _taskMap = new Dictionary>(); static readonly Object _taskLock = new Object(); static int _newTaskId = 0; static Interop.Ecore.EcoreTaskCallback _nativeHandler; static EcoreAnimator() { _nativeHandler = NativeHandler; } /// /// Gets the current system time as a floating point value in seconds. /// /// Current system time /// preview [Obsolete("This has been deprecated in API12")] public static double GetCurrentTime() { return Interop.Ecore.ecore_time_get(); } /// /// Adds an animator to call at every animation tick during the main loop execution. /// /// The function to call when it ticks off. /// A handle to the new animator. /// preview [Obsolete("This has been deprecated in API12")] public static IntPtr AddAnimator(Func handler) { int id = RegistHandler(handler); return Interop.Ecore.ecore_animator_add(_nativeHandler, (IntPtr)id); } /// /// Removes the specified animator from the animator list. /// /// The specified animator handle. /// preview [Obsolete("This has been deprecated in API12")] public static void RemoveAnimator(IntPtr anim) { int taskId = (int)Interop.Ecore.ecore_animator_del(anim); _taskMap.Remove(taskId); } static int RegistHandler(Func task) { int taskId; lock (_taskLock) { taskId = _newTaskId++; } _taskMap[taskId] = task; return taskId; } static bool NativeHandler(IntPtr userData) { int task_id = (int)userData; Func userAction = null; _taskMap.TryGetValue(task_id, out userAction); return (userAction != null) ? userAction() : false; } } }