middleware/extern/TuioServer/Tuio.Test/MainWindow.xaml.cs
author bastiena
Fri, 09 Mar 2012 14:52:11 +0100
changeset 0 6fefd4afe506
child 28 9ccef81f02ab
permissions -rw-r--r--
First Import

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Tuio;

namespace Tuio.Test
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private TuioServer _server;

        public MainWindow()
        {
            InitializeComponent();
            _server = new TuioServer();
            ThreadPool.QueueUserWorkItem(ThreadPoolCallback);
        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            _server.AddTuioCursor(0, AbsoluteToRelativePosition(e.GetPosition(this)));            
        }

        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            _server.UpdateTuioCursor(0, AbsoluteToRelativePosition(e.GetPosition(this)));
        }

        private void Window_MouseUp(object sender, MouseButtonEventArgs e)
        {
            _server.DeleteTuioCursor(0);
        }

        private System.Drawing.PointF AbsoluteToRelativePosition(Point p)
        {
            return new System.Drawing.PointF(
                (float)(p.X / Width),
                (float)(p.Y / Height));
        }

        private void ThreadPoolCallback(Object threadContext)
        {
            while (true)
            {
                _server.InitFrame();
                _server.CommitFrame();
                Thread.Sleep(25);
            }
        }
    }
}