using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using NUIGroup.MultitouchFramework.Engines; using System.Diagnostics; //structure done namespace NUIGroup { namespace MultitouchFramework { namespace Controls { /// /// Button class that responds to touch events /// public class TouchButton : Button { #region Properties //no drag/scale/rotate properties for a button as it can only be touched to press it /// /// Returns the amount of fingers on the element /// public int fingerCount { get { return _fingerList.Count; } } #endregion #region Private Members //list of fingers on this canvas private TouchList _fingerList = new TouchList(); #endregion #region Public Members //eventhandler variables public static readonly RoutedEvent fingerDownEvent = EventManager.RegisterRoutedEvent("fingerDown", RoutingStrategy.Bubble, typeof(fingerDownHandler), typeof(TouchButton)); public static readonly RoutedEvent fingerUpEvent = EventManager.RegisterRoutedEvent("fingerUp", RoutingStrategy.Bubble, typeof(fingerUpHandler), typeof(TouchButton)); public static readonly RoutedEvent fingerUpdateEvent = EventManager.RegisterRoutedEvent("fingerUpdate", RoutingStrategy.Bubble, typeof(fingerUpdateHandler), typeof(TouchButton)); public delegate void fingerDownHandler(object sender, TouchEventArgs e); public delegate void fingerUpdateHandler(object sender, TouchEventArgs e); public delegate void fingerUpHandler(object sender, TouchEventArgs e); #endregion #region Contructors /// /// Standard Public Constructor /// /// Sets up the event handlers /// public TouchButton() { try { TouchEngine.Instance.registerClass(typeof(TouchButton)); _fingerList = new TouchList(); this.fingerDown += new fingerDownHandler(TouchButton_fingerDown); this.fingerUp += new fingerUpHandler(TouchButton_fingerUp); this.fingerUpdate += new fingerUpdateHandler(TouchButton_fingerUpdate); } catch (Exception e) { Debug.WriteLine(e.Message + "\nStackTrace:\n" + e.StackTrace); } } /// /// Contructor that sets the button text /// /// Text to put in the button public TouchButton(String content) { try { TouchEngine.Instance.registerClass(typeof(TouchButton)); _fingerList = new TouchList(); this.fingerDown += new fingerDownHandler(TouchButton_fingerDown); this.fingerUp += new fingerUpHandler(TouchButton_fingerUp); this.fingerUpdate += new fingerUpdateHandler(TouchButton_fingerUpdate); } catch (Exception e) { Debug.WriteLine(e.Message + "\nStackTrace:\n" + e.StackTrace); } this.Content = content; } #endregion #region Event Handlers /// /// This is called on the instance when it gets touched /// /// The button that sent the event /// The Custom touch event arguments void TouchButton_fingerDown(object sender, TouchEventArgs e) { _fingerList.Add(e.data); } /// /// This is called on the instance when it a finger is lifted from it /// /// The button that sent the event /// The Custom touch event arguments void TouchButton_fingerUp(object sender, TouchEventArgs e) { _fingerList.Remove(e.data); } /// /// This is called on the instance when it has been touched, and the finger /// was moved /// /// The button that sent the event /// The Custom touch event arguments void TouchButton_fingerUpdate(object sender, TouchEventArgs e) { //no need to update the finger as it can only be pressed not dragged } #endregion #region Add/Remove Event Handlers /// /// Add the fingerDown event to the class /// public event fingerDownHandler fingerDown { add { AddHandler(fingerDownEvent, value); } remove { RemoveHandler(fingerDownEvent, value); } } /// /// Add the fingerUpdate event to the class /// public event fingerUpdateHandler fingerUpdate { add { AddHandler(fingerUpdateEvent, value); } remove { RemoveHandler(fingerUpdateEvent, value); } } /// /// Add the fingerUp event to the class /// public event fingerUpHandler fingerUp { add { AddHandler(fingerUpEvent, value); } remove { RemoveHandler(fingerUpEvent, value); } } #endregion } } } }