Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is a subclass of Display_T35 that allows a LongTouch gesture
public class GestureEnabledDisplay_T35 : Gadgeteer.Modules.GHIElectronics.Display_T35
{
private long _touchdownTicks;
private const long NanosecondsInMilliseconds = 10000;
public delegate void LongTouchEventHandler(object sender, EventArgs args);
public event LongTouchEventHandler LongTouch;
/// <summary>
/// The number of milliseconds a touch needs before it raises a longtouch event
/// </summary>
public long LongTouchRegisterInterval { get; private set; }
public GestureEnabledDisplay_T35(int socket1, int socket2, int socket3, long longTouchRegisterInterval = 5000)
: base(socket1, socket2, socket3)
{
Initialise(longTouchRegisterInterval);
}
public GestureEnabledDisplay_T35(int socket1, int socket2, int socket3, int socket4, long longTouchRegisterInterval = 5000)
: base(socket1, socket2, socket3, socket4)
{
Initialise(longTouchRegisterInterval);
}
private void Initialise(long longTouchRegisterInterval)
{
base.WPFWindow.TouchDown += new Microsoft.SPOT.Input.TouchEventHandler(WPFWindow_TouchDown);
base.WPFWindow.TouchUp += new Microsoft.SPOT.Input.TouchEventHandler(WPFWindow_TouchUp);
LongTouchRegisterInterval = longTouchRegisterInterval;
}
void WPFWindow_TouchDown(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
{
_touchdownTicks = DateTime.Now.Ticks;
}
void WPFWindow_TouchUp(object sender, Microsoft.SPOT.Input.TouchEventArgs e)
{
var touchupTicks = DateTime.Now.Ticks;
if (touchupTicks - _touchdownTicks > (NanosecondsInMilliseconds * LongTouchRegisterInterval))
{
OnLongTouch();
}
}
private void OnLongTouch()
{
if (LongTouch != null)
{
LongTouch(this, EventArgs.Empty);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.