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
{
///
/// Window class that responds to touch events
///
public class TouchWindow : Window
{
#region Properties
//no need for resizing the window as it is the main container
///
/// 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(TouchWindow));
public static readonly RoutedEvent fingerUpEvent = EventManager.RegisterRoutedEvent("fingerUp", RoutingStrategy.Bubble, typeof(fingerUpHandler), typeof(TouchWindow));
public static readonly RoutedEvent fingerUpdateEvent = EventManager.RegisterRoutedEvent("fingerUpdate", RoutingStrategy.Bubble, typeof(fingerUpdateHandler), typeof(TouchWindow));
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 Constructor
///
/// Standard public constructor for the window
///
public TouchWindow()
{
try
{
TouchEngine.Instance.registerClass(typeof(TouchWindow));
_fingerList = new TouchList();
this.fingerDown += new fingerDownHandler(TouchWindow_fingerDown);
this.fingerUp += new fingerUpHandler(TouchWindow_fingerUp);
this.fingerUpdate += new fingerUpdateHandler(TouchWindow_fingerUpdate);
}
catch(Exception e)
{
Debug.WriteLine(e.Message + "\nStackTrace:\n" + e.StackTrace);
}
this.ContentRendered += new EventHandler(TouchWindow_ContentRendered);
}
#endregion
#region Other
void TouchWindow_ContentRendered(object sender, EventArgs e)
{
//starts touchlib when everything onscreen has been rendered
TouchEngine.Instance.startTracking(this);
this.Close();
}
#endregion
#region Event Handlers
///
/// This is called on the instance when it gets touched
///
/// The window that sent the event
/// The Custom touch event arguments
void TouchWindow_fingerDown( object sender, TouchEventArgs e )
{
_fingerList.Add(e.data);
}
///
/// This is called on the instance when it a finger is lifted from it
///
/// The window that sent the event
/// The Custom touch event arguments
void TouchWindow_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 window that sent the event
/// The Custom touch event arguments
void TouchWindow_fingerUpdate( object sender, TouchEventArgs e )
{
}
#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
}
}
}