summaryrefslogtreecommitdiff
path: root/Backup/Anoto/Form1.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Backup/Anoto/Form1.cs')
-rw-r--r--Backup/Anoto/Form1.cs143
1 files changed, 143 insertions, 0 deletions
diff --git a/Backup/Anoto/Form1.cs b/Backup/Anoto/Form1.cs
new file mode 100644
index 0000000..c3f97a9
--- /dev/null
+++ b/Backup/Anoto/Form1.cs
@@ -0,0 +1,143 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using Anoto;
+using System.Threading;
+
+
+namespace Anoto
+{
+ public struct Stroke
+ {
+ List<Point> Points;
+ }
+
+ public partial class Form1 : Form
+ {
+
+ Anoto.GenericStreamer.PenManagerClass PenManager;
+
+ Dictionary<string, Stroke> PensStrocks;
+
+ Dictionary<string, List<Point>> PensPoints;
+ Dictionary<string, Brush> PensColor;
+ Mutex mutex;
+ Random Rnd;
+
+ public Form1()
+ {
+ InitializeComponent();
+ }
+
+ private void Form1_Load(object sender, EventArgs e)
+ {
+ PenManager = new Anoto.GenericStreamer.PenManagerClass();
+
+ PenManager.PenConnected += new Anoto.GenericStreamer._IPenManagerEvents_PenConnectedEventHandler(pm_PenConnected);
+ PenManager.NewCoordinate += new Anoto.GenericStreamer._IPenManagerEvents_NewCoordinateEventHandler(PenManager_NewCoordinate);
+ PenManager.PenDown += new Anoto.GenericStreamer._IPenManagerEvents_PenDownEventHandler(PenManager_PenDown);
+ PenManager.PenUp += new Anoto.GenericStreamer._IPenManagerEvents_PenUpEventHandler(PenManager_PenUp);
+ PenManager.Start();
+
+ mutex = new Mutex();
+
+ InitDictionary();
+
+ Rnd = new Random();
+ }
+
+ private void InitDictionary()
+ {
+ PensPoints = new Dictionary<string, List<Point>>();
+ PensColor = new Dictionary<string, Brush>();
+
+ PensStrocks = new Dictionary<string, Stroke>();
+ }
+
+ void PenManager_PenUp(string penSerial, Anoto.GenericStreamer.PenType PenType, ulong time, byte penDownSeqNbr, int isSpcdGenerated)
+ {
+ Console.WriteLine("Pen Up " + penSerial + " time " + time);
+ }
+
+ void PenManager_PenDown(string penSerial, Anoto.GenericStreamer.PenType PenType, ulong time, byte penDownSeqNbr, Anoto.GenericStreamer.PenTipType PenTipType, int isValidColor, byte r, byte g, byte b, int isSpcdGenerated)
+ {
+ Console.WriteLine("Pen Down " + penSerial + " time " + time);
+ // PensStrocks[penSerial].
+ }
+
+ void PenManager_NewCoordinate(string penSerial, Anoto.GenericStreamer.PenType PenType, ulong time, string page, int x, int y, byte imgSeqNbr, byte force)
+ {
+ mutex.WaitOne();
+ PensPoints[penSerial].Add(new Point(x, y));
+ mutex.ReleaseMutex();
+ Console.WriteLine("Pen NewCoordinate " + penSerial + " time " + time + " x " + x + " y " + y);
+ pictureBox1.Invalidate();
+ }
+
+ void pm_PenConnected(string penSerial, Anoto.GenericStreamer.PenType PenType, ulong time, string productName, ushort pid)
+ {
+
+ // Consol("Pen connected ");
+ // listBox1.Items.Add("Pen connected " + penSerial + " " + PenType.ToString() + " " + productName + "\n\r");
+ Console.WriteLine("Pen connected " + penSerial + " " + PenType.ToString() + " " + productName);
+ PensPoints.Add(penSerial, new List<Point>());
+ PensColor.Add(penSerial,new SolidBrush( Color.FromArgb(255,Rnd.Next(255),Rnd.Next(255),Rnd.Next(255))));
+ // listBox1.Invalidate();
+ }
+
+ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
+ {
+
+
+ PenManager.Stop();
+
+ }
+
+ private void pictureBox1_Paint(object sender, PaintEventArgs e)
+ {
+ //draw the dots
+ Graphics g = e.Graphics;
+ g.FillRectangle(Brushes.White, new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height));
+ mutex.WaitOne();
+ foreach (var pen in PensPoints)
+ {
+ foreach (var point in pen.Value)
+ {
+ g.FillEllipse(PensColor[pen.Key], (float)(point.X) / 10.0f, (float)(point.Y) / 10.0f, 2, 2);
+ }
+ }
+ mutex.ReleaseMutex();
+ }
+
+ private void timer1_Tick(object sender, EventArgs e)
+ {
+ pictureBox1.Invalidate();
+ }
+
+ private void clearToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ mutex.WaitOne();
+
+ foreach (var pen in PensPoints)
+ {
+ // pen.Value = new List<Point>();
+
+ }
+
+ mutex.ReleaseMutex();
+ }
+
+ private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
+ {
+ if (e.Button == MouseButtons.Right)
+ {
+ contextMenuStrip1.Show();
+ }
+ }
+ }
+}