1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
| using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows;
using System.ComponentModel;
using System.Collections;
using TUIO;
using System.Threading;
using System.IO;
namespace TUIO_DEMO
{
public class TuioDemo : Form, TuioListener
{
private static TuioClient client;
private static Hashtable objectList;
private static Hashtable cursorList;
private static Song[] song = new Song[400]; //Song List
private static Square[,] square = new Square[1, 1]; //DensitySquares List
private static int h = 0, w = 0; //dimension of windows (640x480, 1024x768)
private static double xv = 0; //zoom vector abs = average of object-->focus vector abs
private static double yv = 0; //zoom vector ord = average of object-->focus vector ord
public static double xf = 0; //focus abs
public static double yf = 0; //focus ord
private static double xvmemory; //zoom vector abs of previous frame
private static double yvmemory; //zoom vector ord of previous frame
private static double xfmemory; //...
private static double yfmemory; //...
private static double alpha = 1; //zoom x-axis added at one frame
private static double beta = 1; //zoom y-axis added at one frame
private static double deltax = 0; //x-translation at one frame
private static double deltay = 0; //y-translation at one frame
public static int[] xbrowser = new int[2]; //polygon x-values for browsing window
public static int[] ybrowser = new int[2]; //polygon y-values for browsing window
public static Random rand = new Random();
public static Random r = new Random();
public static int sizey;
public static int sizex;
public static double movingTangibleAngle;
public static Rectangle Browser; //browsing window polygon
public static Rectangle Wide; //browsing unwindow, around cache
public static Rectangle windowBrowser;
// public static Point[] aroundCircle = new Point[cursorList.Values.Count];
public static Rectangle tinyRect;
public static Rectangle menu, deleteOvalLeft;
public static Rectangle bordExtTable;
public static Rectangle bordIntTable;
public static Region BrowserRegion = new Region();
public static int various2 = 0;
public static int various1 = 0;
public static int various = 0;
public static GraphicsPath pathMenu = new GraphicsPath();
public static GraphicsPath pathMenu2 = new GraphicsPath();
public static GraphicsPath pathBrowser = new GraphicsPath();
public static GraphicsPath pathDelete = new GraphicsPath();
public static GraphicsPath pathOutside = new GraphicsPath();
public static GraphicsPath pathWindow = new GraphicsPath();
public static GraphicsPath pathTable = new GraphicsPath();
public static GraphicsPath bg = new GraphicsPath();
public static GraphicsPath sphere = new GraphicsPath();
public static GraphicsPath squarePath = new GraphicsPath();
public static GraphicsPath anchorCircle = new GraphicsPath();
public static SolidBrush Monome;
public static String criteriaString = "";
public static int crit;
public static int tinyRectColorLevel;
public static SolidBrush tinyMonome;
public static bool delete = false;
public static bool windowing = true;
public static bool browsing = true;
public static bool moving = false;
public static bool movingTangible = false;
public static bool anchoring = false;
public static bool restart = false;
public static bool showDensity = false;
public static bool showCriteria = false;
public static bool resetSongs;
public static bool drawSongsMode = false;
public static Color tableColor;
public static FontFamily myFontFamily = new FontFamily("Arial");
public static Font myFont = new Font("Arial", 8);
public System.Threading.Thread thread;
public TuioDemo(int port,int w,int h) {
//copy from Martin code
ClientSize = new Size(w,h);
Name = "TuioDemo";
Text = "TuioDemo";
Closing+=new CancelEventHandler(Form_Closing);
objectList = new Hashtable();
cursorList = new Hashtable();
client = new TuioClient(port);
client.addTuioListener(this);
client.connect();
//my code
InitializeComponent();
sizey = h;
sizex = w;
Wide = new Rectangle(0, 0, w, h);
xf = 0;
yf = 0;
square = new Square[(int)(sizex / 30) + 1, (int)(sizey / 30) + 1];//30 is the width of an tuio
bg.AddRectangle(new Rectangle(0, 0, sizex, sizey));
/*----define level 0 elements ----*/
String path = getdirectory() + "\\songList.txt";
TextReader tr = new StreamReader(path);
Random rs = new Random();
for (int i = 0; i < 400; i++)
{
song[i] = new Song();
song[i].setCoord((double)(rand.Next(w)), (double)(rand.Next(h)));
song[i].setId(i + 1);
song[i].setCriteria("BPM", i * 250 / 200);
song[i].setCriteria("DCB", i);
song[i].setCriteria("BRK", (int)(i - 0.5 * i));
song[i].setCriteria("TON", (int)(i * 88 / 200));
song[i].setCriteria("TBR", (int)(i * 300 / 200));
song[i].setCriteria("SHP", (int)(i * 50 / 200));
song[i].setCriteria("GNR", rand.Next(0, 10));
String artist = tr.ReadLine();
String titre = tr.ReadLine();
String album = tr.ReadLine();
String genre = tr.ReadLine();
tr.ReadLine();//saut de ligne
song[i].setInfos(artist, titre, album, genre);
}
tr.Close();
resetSongs = false;
/*----define level 1 elements ----*/
for (int i = 0; i < w / 30; i++)
{
for (int j = 0; j < h / 30; j++)
{
square[i, j] = new Square(i * 30, j * 30, 30);
}
}
/*----define level 2 elements ----*/
for (int i = 0; i < 2; i++) { xbrowser[i] = 0; ybrowser[i] = 0; }
tableColor = Color.FromArgb((int)(22 * 3.6), (int)(30 * 3.6), (int)(43 * 3.6));
/*----define level 3 elements----*/
bordExtTable = new Rectangle(0, 0, w, h);
bordIntTable = new Rectangle(75, 0, h, h);
}
private void Form_Closing(object sender, CancelEventArgs e)
{
client.removeTuioListener(this);
client.disconnect();
Application.Exit();
}
aw the song spheres
setsongCatched();
drawSong(g2);
drawSquares(g2);//2.Draw the density squares
windowDrawer(g2);
drawObjects(g2);
drawFinger(g2);
}
}
public static void OnKeyPressEvent(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.ToString() == "d") { showDensity = !showDensity; }
if (e.KeyChar.ToString() == "c") { showCriteria = !showCriteria; }
if (e.KeyChar.ToString() == "f") { drawSongsMode = !drawSongsMode; }
if (e.KeyChar.ToString() == "r") { resetSongs = true; }
//this.Refresh();
}
/*--main--*/
private void InitializeComponent()
{
KeyPress += new KeyPressEventHandler(OnKeyPressEvent);
}
public static void Main(String[] argv)
{
int port = 0;
switch (argv.Length)
{
case 1:
port = int.Parse(argv[0], null);
if (port == 0) goto default;
break;
case 0:
port = 3333;
break;
default:
Console.WriteLine("usage: java TuioDump [port]");
//System.exit(0);
break;
}
Console.WriteLine("Client Port :");
Console.WriteLine(port);
Console.WriteLine();
Console.WriteLine("Keyboard cmd :");
Console.WriteLine("d : swow song density");
Console.WriteLine("c : show average criteria");
Console.WriteLine("f : flip squares/songs");
Console.WriteLine("r : reset songs positions");
TuioDemo demo = new TuioDemo(port, 640, 480);
Application.Run(demo);
}
}
} |