annotate game/IDMWidget.java @ 51:f81f76458b92

Work on widgets.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 23 Feb 2011 02:49:07 +0200
parents 496e616ff09d
children b586ce4f6d97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Ristipolku IDM base widget
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 */
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 package game;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 import java.awt.*;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 import java.awt.event.*;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 public class IDMWidget
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 {
51
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
13 IDMPoint pos, scale;
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 int keyCode;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 public IDMWidget()
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 keyCode = -1;
51
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
19 this.scale = new IDMPoint(1, 1);
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
20 this.pos = new IDMPoint(0, 0);
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
21 }
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
22
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
23 public IDMWidget(IDMPoint pos)
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
24 {
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
25 this();
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
26 this.pos = pos;
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
27 }
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
28
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
29 public void move(IDMPoint pos)
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
30 {
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
31 this.pos = pos;
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
32 }
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
33
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
34 public void move(float x, float y)
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
35 {
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
36 this.pos = new IDMPoint(x, y);
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
37 }
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
38
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
39 public void setScale(IDMPoint scale)
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
40 {
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
41 this.scale = scale;
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
42 }
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
43
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
44 public void setScale(float x, float y)
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
45 {
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
46 this.setScale(new IDMPoint(x, y));
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
47 }
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
48
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
49 public int getScaledX()
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
50 {
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
51 return (int) (this.pos.x * this.scale.x);
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
52 }
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
53
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
54 public int getScaledY()
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
55 {
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
56 return (int) (this.pos.y * this.scale.y);
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 public void paint(Graphics2D g)
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 public boolean contains(Point pos)
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 return false;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 public void mousePressed(MouseEvent e)
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 public void mouseReleased(MouseEvent e)
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 if (contains(e.getPoint()))
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 clicked();
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
76 }
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
77
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
78 public void mouseEntered(MouseEvent e)
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
79 {
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
80 }
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
81
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
82 public void mouseExited(MouseEvent e)
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
83 {
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 // Generic key handler
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 public boolean keyPressed(KeyEvent e)
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 if (e.getKeyCode() == keyCode)
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 clicked();
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 return true;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 else
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 return false;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 public void clicked()
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 }