Tnx Steven, Touch is working! code underneath.
At the moment I’m trying to get an on screen keyboard if a TextBox is touched. Since the buttons are working great it should not be so hard… Strange enough textBox.TapEvent += new OnTap(textBox_TapEvent); does not encounter whatever touches I make. How do I make a Tap event? is it indeed a double touch? I think I don’t forward the tab touches correctly to Glide. Anyone any idear? Other sugestions?
xml
<Glide Version="1.0.5">
<Window Name="xmlMainWnd" Width="800" Height="480" BackColor="E08040">
<TextBox Name="textBox" X="300" Y="100" Width="120" Height="32" Alpha="255" Text="" TextAlign="Left" Font="4" FontColor="000000"/>
<Button Name="buttonTestOn" X="580" Y="410" Width="80" Height="32" Alpha="255" Text="On" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
<Button Name="buttonTestOff" X="680" Y="410" Width="80" Height="32" Alpha="255" Text="Off" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
<Button Name="buttonKB" X="480" Y="410" Width="80" Height="32" Alpha="255" Text="Key" Font="4" FontColor="000000" DisabledFontColor="808080" TintColor="000000" TintAmount="0"/>
</Window>
</Glide>
program cs
using System;
using System.Collections;
using System.IO;
using System.IO.Ports;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using GHIElectronics.NETMF.Glide;
using GHIElectronics.NETMF.Glide.Display;
using GHIElectronics.NETMF.Glide.UI;
namespace App42
{
public partial class Program
{
static Window stkMainWnd;
static TextBlock textBlock;
static int timeCnt = 0;
static string outStr;
GT.Timer timer = new GT.Timer(1000);
static Thread wdThread;
void ProgramStarted()
{
Debug.Print("Program Started");
//Watchdog.Enable(5000);
timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
timer.Start();
wdThread = new Thread(wdThreadFunc);
wdThread.Start();
GlideTouch.Initialize();
joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);
joystick.JoystickReleased += new Joystick.JoystickEventHandler(joystick_JoystickReleased);
display_CP7.ScreenPressed += new Display_CP7.TouchEventHandler(display_CP7_ScreenPressed);
// Main window layout
stkMainWnd = GlideLoader.LoadWindow(Resources.GetString(Resources.StringResources.xmlMainWnd));
stkMainWnd.BackImage = Resources.GetBitmap(Resources.BitmapResources.resBgImage);
textBlock = new TextBlock("", 255, 100, 100, 100, 100);
textBlock.Text = "Starting...";
textBlock.FontColor = Colors.White;
stkMainWnd.AddChild(textBlock);
Button buttonTestOn = (Button)stkMainWnd.GetChildByName("buttonTestOn");
buttonTestOn.PressEvent += new OnPress(buttonTestOn_PressEvent);
Button buttonTestOff = (Button)stkMainWnd.GetChildByName("buttonTestOff");
buttonTestOff.PressEvent += new OnPress(buttonTestOff_PressEvent);
Button buttonKB = (Button)stkMainWnd.GetChildByName("buttonKB");
buttonKB.PressEvent += new OnPress(buttonKB_PressEvent);
TextBox textBox = (TextBox)stkMainWnd.GetChildByName("textBox");
textBox.TapEvent += new OnTap(textBox_TapEvent);
// textBox.TapEvent += new OnTap(Glide.OpenKeyboard);
// textBlockNum.ValueChangedEvent += new OnValueChanged(textBox_ValueChangedEvent);
// display active window
Glide.MainWindow = stkMainWnd;
}
static void textBox_ValueChangedEvent(object sender)
{
TextBox textBox = (TextBox)stkMainWnd.GetChildByName("textBox");
Debug.Print(textBox.Text);
}
void textBox_TapEvent(object sender)
{
Debug.Print("textBox_TapEvent!!!!!!!!!");
}
void buttonKB_PressEvent(object sender)
{
Debug.Print("buttonKB_PressEvent!!!!!!!!!");
}
static int lastX = 0;
static int lastY = 0;
static int x;
static int y;
static bool isTouched = false;
void display_CP7_ScreenPressed(Display_CP7 sender, Display_CP7.TouchStatus touchStatus)
{
GHIElectronics.NETMF.Glide.Geom.Point touches;
if (touchStatus.numTouches > 0)
{
touches.X = touchStatus.touchPos[0].xPos;
touches.Y = touchStatus.touchPos[0].yPos;
x = 0;
y = 0;
if (isTouched == false)
{
GlideTouch.RaiseTouchDownEvent(null, new TouchEventArgs(touches));
lastX = x;
lastY = y;
isTouched = true;
}
else
{
if (lastX != touches.X && lastY != touches.Y)
{
touches.X = lastX;
touches.Y = lastY;
GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touches));
isTouched = false;
}
}
}
else
{
if (isTouched == true)
{
touches.X = lastX;
touches.Y = lastY;
GlideTouch.RaiseTouchUpEvent(null, new TouchEventArgs(touches));
isTouched = false;
}
}
}
void wdThreadFunc()
{
while (true)
{
//Thread.Sleep(3000);
//Watchdog.ResetCounter();
}
}
void joystick_JoystickReleased(Joystick sender, Joystick.JoystickState state)
{
led7r.TurnLightOff(7);
}
void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
{
led7r.TurnLightOn(7, false);
}
void timer_Tick(GT.Timer timer)
{
//PulseDebugLED();
timeCnt++;
stkMainWnd.RemoveChild(textBlock);
outStr = "test " + timeCnt.ToString() + " nr";
textBlock.Text = outStr;
stkMainWnd.AddChild(textBlock);
Glide.MainWindow = stkMainWnd;
}
void buttonTestOn_PressEvent(object sender)
{
led7r.TurnLightOn(6, false);
}
void buttonTestOff_PressEvent(object sender)
{
led7r.TurnLightOff(6);
}
}
}