|
10
|
1 |
/* |
|
|
2 |
TUIO Java Demo - part of the reacTIVision project |
|
|
3 |
http://reactivision.sourceforge.net/ |
|
|
4 |
|
|
|
5 |
Copyright (c) 2005-2009 Martin Kaltenbrunner <mkalten@iua.upf.edu> |
|
|
6 |
|
|
|
7 |
This program is free software; you can redistribute it and/or modify |
|
|
8 |
it under the terms of the GNU General Public License as published by |
|
|
9 |
the Free Software Foundation; either version 2 of the License, or |
|
|
10 |
(at your option) any later version. |
|
|
11 |
|
|
|
12 |
This program is distributed in the hope that it will be useful, |
|
|
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
15 |
GNU General Public License for more details. |
|
|
16 |
|
|
|
17 |
You should have received a copy of the GNU General Public License |
|
|
18 |
along with this program; if not, write to the Free Software |
|
|
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
20 |
*/ |
|
|
21 |
|
|
|
22 |
import javax.swing.*; |
|
|
23 |
import java.awt.geom.*; |
|
|
24 |
import java.awt.*; |
|
|
25 |
import java.awt.event.*; |
|
|
26 |
import java.util.*; |
|
|
27 |
import TUIO.*; |
|
|
28 |
|
|
|
29 |
public class TuioDemoObject extends TuioObject { |
|
|
30 |
|
|
|
31 |
private Shape square; |
|
|
32 |
|
|
|
33 |
public TuioDemoObject(TuioObject tobj) { |
|
|
34 |
super(tobj); |
|
|
35 |
int size = TuioDemoComponent.object_size; |
|
|
36 |
square = new Rectangle2D.Float(-size/2,-size/2,size,size); |
|
|
37 |
|
|
|
38 |
AffineTransform transform = new AffineTransform(); |
|
|
39 |
transform.translate(xpos,ypos); |
|
|
40 |
transform.rotate(angle,xpos,ypos); |
|
|
41 |
square = transform.createTransformedShape(square); |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
public void paint(Graphics2D g, int width, int height) { |
|
|
45 |
|
|
|
46 |
float Xpos = xpos*width; |
|
|
47 |
float Ypos = ypos*height; |
|
|
48 |
float scale = height/(float)TuioDemoComponent.table_size; |
|
|
49 |
|
|
|
50 |
AffineTransform trans = new AffineTransform(); |
|
|
51 |
trans.translate(-xpos,-ypos); |
|
|
52 |
trans.translate(Xpos,Ypos); |
|
|
53 |
trans.scale(scale,scale); |
|
|
54 |
Shape s = trans.createTransformedShape(square); |
|
|
55 |
|
|
|
56 |
g.setPaint(Color.black); |
|
|
57 |
g.fill(s); |
|
|
58 |
g.setPaint(Color.white); |
|
|
59 |
g.drawString(symbol_id+"",Xpos-10,Ypos); |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
public void update(TuioObject tobj) { |
|
|
63 |
|
|
|
64 |
float dx = tobj.getX() - xpos; |
|
|
65 |
float dy = tobj.getY() - ypos; |
|
|
66 |
float da = tobj.getAngle() - angle; |
|
|
67 |
|
|
|
68 |
if ((dx!=0) || (dy!=0)) { |
|
|
69 |
AffineTransform trans = AffineTransform.getTranslateInstance(dx,dy); |
|
|
70 |
square = trans.createTransformedShape(square); |
|
|
71 |
} |
|
|
72 |
|
|
|
73 |
if (da!=0) { |
|
|
74 |
AffineTransform trans = AffineTransform.getRotateInstance(da,tobj.getX(),tobj.getY()); |
|
|
75 |
square = trans.createTransformedShape(square); |
|
|
76 |
} |
|
|
77 |
|
|
|
78 |
super.update(tobj); |
|
|
79 |
} |
|
|
80 |
|
|
|
81 |
} |