|
28
|
1 |
using System; |
|
0
|
2 |
using System.Collections.Generic; |
|
|
3 |
using System.Linq; |
|
|
4 |
using System.Text; |
|
|
5 |
using System.Threading; |
|
|
6 |
using System.Windows; |
|
|
7 |
using System.Windows.Controls; |
|
|
8 |
using System.Windows.Data; |
|
|
9 |
using System.Windows.Documents; |
|
|
10 |
using System.Windows.Input; |
|
|
11 |
using System.Windows.Media; |
|
|
12 |
using System.Windows.Media.Imaging; |
|
|
13 |
using System.Windows.Navigation; |
|
|
14 |
using System.Windows.Shapes; |
|
|
15 |
|
|
|
16 |
using Tuio; |
|
|
17 |
|
|
|
18 |
namespace Tuio.Test |
|
|
19 |
{ |
|
|
20 |
/// <summary> |
|
|
21 |
/// Interaction logic for MainWindow.xaml |
|
|
22 |
/// </summary> |
|
|
23 |
public partial class MainWindow : Window |
|
|
24 |
{ |
|
|
25 |
private TuioServer _server; |
|
|
26 |
|
|
|
27 |
public MainWindow() |
|
|
28 |
{ |
|
|
29 |
InitializeComponent(); |
|
|
30 |
_server = new TuioServer(); |
|
|
31 |
ThreadPool.QueueUserWorkItem(ThreadPoolCallback); |
|
|
32 |
} |
|
|
33 |
|
|
|
34 |
private void Window_MouseDown(object sender, MouseButtonEventArgs e) |
|
|
35 |
{ |
|
|
36 |
_server.AddTuioCursor(0, AbsoluteToRelativePosition(e.GetPosition(this))); |
|
|
37 |
} |
|
|
38 |
|
|
|
39 |
private void Window_MouseMove(object sender, MouseEventArgs e) |
|
|
40 |
{ |
|
|
41 |
_server.UpdateTuioCursor(0, AbsoluteToRelativePosition(e.GetPosition(this))); |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
private void Window_MouseUp(object sender, MouseButtonEventArgs e) |
|
|
45 |
{ |
|
|
46 |
_server.DeleteTuioCursor(0); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
private System.Drawing.PointF AbsoluteToRelativePosition(Point p) |
|
|
50 |
{ |
|
|
51 |
return new System.Drawing.PointF( |
|
|
52 |
(float)(p.X / Width), |
|
|
53 |
(float)(p.Y / Height)); |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
private void ThreadPoolCallback(Object threadContext) |
|
|
57 |
{ |
|
|
58 |
while (true) |
|
|
59 |
{ |
|
|
60 |
_server.InitFrame(); |
|
|
61 |
_server.CommitFrame(); |
|
|
62 |
Thread.Sleep(25); |
|
|
63 |
} |
|
|
64 |
} |
|
|
65 |
} |
|
|
66 |
} |