/* * @author Valentin Simonov / http://va.lent.in/ */ using System; using System.Collections.Generic; using TouchScript.Devices.Display; using TouchScript.InputSources; using TouchScript.Layers; using TouchScript.Pointers; namespace TouchScript { /// /// Core manager of all pointer input in TouchScript. It is responsible for assigning unique pointer ids and keeping the list of active pointers. Controls pointer frames and dispatches pointer events. /// /// /// Every frame pointer events are dispatched in this order: /// /// FrameStarted /// PointersAdded /// PointersUpdated /// PointersPressed /// PointersReleased /// PointersRemoved /// PointersCancelled /// FrameFinished /// /// FrameStarted and FrameFinished events mark the start and the end of current pointer frame and allow to implement specific logic at these moments. /// Current instance of an active object implementing can be obtained via . /// /// /// /// This sample shows how to get TouchManager instance and subscribe to events. /// /// TouchManager.Instance.PointersPressed += /// (sender, args) => { foreach (var pointer in args.Pointers) Debug.Log("Pressed: " + pointer.Id); }; /// TouchManager.Instance.PointersReleased += /// (sender, args) => { foreach (var pointer in args.Pointers) Debug.Log("Released: " + pointer.Id); }; /// /// public interface ITouchManager { /// /// Occurs when a new frame is started before all other events. /// event EventHandler FrameStarted; /// /// Occurs when a frame is finished. After all other events. /// event EventHandler FrameFinished; /// /// Occurs when new hovering pointers are added. /// event EventHandler PointersAdded; /// /// Occurs when pointers are updated. /// event EventHandler PointersUpdated; /// /// Occurs when pointers touch the surface. /// event EventHandler PointersPressed; /// /// Occurs when pointers are released. /// event EventHandler PointersReleased; /// /// Occurs when pointers are removed from the system. /// event EventHandler PointersRemoved; /// /// Occurs when pointers are cancelled. /// event EventHandler PointersCancelled; /// /// Gets or sets current display device. /// /// Object which holds properties of current display device, like DPI and others. IDisplayDevice DisplayDevice { get; set; } /// /// Gets current DPI. /// /// Shortcut for . float DPI { get; } /// /// Indicates if TouchScript should create a for you if no layers present in a scene. /// /// true if a CameraLayer should be created on startup; otherwise, false. /// This is usually a desired behavior but sometimes you would want to turn this off if you are using TouchScript only to get pointer input from some device. bool ShouldCreateCameraLayer { get; set; } /// /// Gets or sets a value indicating whether a should be created in scene if no inputs present. /// /// true if StandardInput should be created; otherwise, false. /// This is usually a desired behavior but sometimes you would want to turn this off. bool ShouldCreateStandardInput { get; set; } /// /// Gets the list of /// /// A sorted list of input sources. IList Inputs { get; } /// /// Gets number of pixels in a cm with current DPI. /// float DotsPerCentimeter { get; } /// /// Gets number of pointers in the system. /// int PointersCount { get; } /// /// Gets the number of pressed pointer in the system. /// int PressedPointersCount { get; } /// /// Gets the list of pointers. /// /// An unsorted list of all pointers. IList Pointers { get; } /// /// Gets the list of pressed pointers. /// /// An unsorted list of all pointers which were pressed but not released yet. IList PressedPointers { get; } /// /// Indicates that execution is currently inside a TouchScript Pointer Frame, i.e. before and after events. /// /// /// true if execution is inside a TouchScript Pointer Frame; otherwise, false. /// bool IsInsidePointerFrame { get; } /// /// Adds an input source. /// /// Input source to add. /// true if the input source wasn't in the list and was added; false otherwise. bool AddInput(IInputSource input); /// /// Removes the input. /// /// Input source to remove. /// true if the input source was removed; false otherwise. bool RemoveInput(IInputSource input); /// /// Cancels a pointer and returns it to the system of need. /// /// Pointer id to cancel. /// If the pointer should be redispatched to the system. void CancelPointer(int id, bool shouldReturn); /// /// Cancels a pointer. /// /// Pointer id to cancel. void CancelPointer(int id); /// /// Tells TouchScript to update internal state after a resolution change. /// void UpdateResolution(); } /// /// Arguments dispatched with TouchManager events. /// public class PointerEventArgs : EventArgs { /// /// Gets list of pointers participating in the event. /// /// List of pointers added, changed or removed this frame. public IList Pointers { get; private set; } private static PointerEventArgs instance; /// /// Initializes a new instance of the class. /// private PointerEventArgs() {} /// /// Returns cached instance of EventArgs. /// This cached EventArgs is reused throughout the library not to alocate new ones on every call. /// /// A list of pointers for event. /// Cached EventArgs object. public static PointerEventArgs GetCachedEventArgs(IList pointers) { if (instance == null) instance = new PointerEventArgs(); instance.Pointers = pointers; return instance; } } }