comparison game/IDMWidget.java @ 75:b586ce4f6d97

Large GUI code cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Mar 2011 04:04:57 +0200
parents f81f76458b92
children 4c0dec72e2f0
comparison
equal deleted inserted replaced
74:b7adeae80363 75:b586ce4f6d97
8 import java.awt.event.*; 8 import java.awt.event.*;
9 9
10 10
11 public class IDMWidget 11 public class IDMWidget
12 { 12 {
13 IDMPoint pos, scale; 13 IDMWidget parent;
14 IDMPoint pos, size, scale;
14 int keyCode; 15 int keyCode;
15 16
16 public IDMWidget() 17 public IDMWidget()
17 { 18 {
18 keyCode = -1; 19 keyCode = -1;
19 this.scale = new IDMPoint(1, 1); 20 this.scale = new IDMPoint(1, 1);
20 this.pos = new IDMPoint(0, 0); 21 this.pos = new IDMPoint(0, 0);
22 this.size = new IDMPoint(0, 0);
21 } 23 }
22 24
23 public IDMWidget(IDMPoint pos) 25 public IDMWidget(IDMPoint pos)
24 { 26 {
25 this(); 27 this();
26 this.pos = pos; 28 this.pos = pos;
27 } 29 }
28 30
29 public void move(IDMPoint pos) 31 public IDMWidget(IDMPoint pos, IDMPoint size)
32 {
33 this();
34 this.pos = pos;
35 this.size = size;
36 }
37
38 public void setParent(IDMWidget par)
39 {
40 this.parent = par;
41 }
42
43 public void add(IDMWidget widget)
44 {
45 }
46
47 public void remove(IDMWidget widget)
48 {
49 }
50
51 public void setPos(IDMPoint pos)
30 { 52 {
31 this.pos = pos; 53 this.pos = pos;
32 } 54 }
33 55
34 public void move(float x, float y) 56 public void setPos(float x, float y)
35 { 57 {
36 this.pos = new IDMPoint(x, y); 58 this.pos = new IDMPoint(x, y);
59 }
60
61 public void setSize(IDMPoint size)
62 {
63 this.size = size;
64 }
65
66 public void setSize(float w, float h)
67 {
68 this.size = new IDMPoint(w, h);
37 } 69 }
38 70
39 public void setScale(IDMPoint scale) 71 public void setScale(IDMPoint scale)
40 { 72 {
41 this.scale = scale; 73 this.scale = scale;
46 this.setScale(new IDMPoint(x, y)); 78 this.setScale(new IDMPoint(x, y));
47 } 79 }
48 80
49 public int getScaledX() 81 public int getScaledX()
50 { 82 {
51 return (int) (this.pos.x * this.scale.x); 83 return (int) (pos.x * scale.x);
52 } 84 }
53 85
54 public int getScaledY() 86 public int getScaledY()
55 { 87 {
56 return (int) (this.pos.y * this.scale.y); 88 return (int) (pos.y * scale.y);
57 } 89 }
58 90
91 public int getScaledWidth()
92 {
93 return (int) (size.x * scale.x);
94 }
95
96 public int getScaledHeight()
97 {
98 return (int) (size.y * scale.y);
99 }
100
101 public boolean contains(float x, float y)
102 {
103 return (x >= getScaledX() &&
104 y >= getScaledY() &&
105 x < getScaledX() + getScaledWidth() &&
106 y < getScaledY() + getScaledHeight());
107 }
108
109 public boolean contains(Point where)
110 {
111 return contains(where.x, where.y);
112 }
113
114 public boolean contains(IDMPoint where)
115 {
116 return contains(where.x, where.y);
117 }
118
59 public void paint(Graphics2D g) 119 public void paint(Graphics2D g)
60 { 120 {
61 } 121 }
62 122
63 public boolean contains(Point pos) 123 public boolean mousePressed(MouseEvent e)
64 { 124 {
65 return false; 125 return false;
66 } 126 }
67 127
68 public void mousePressed(MouseEvent e) 128 public boolean mouseReleased(MouseEvent e)
69 { 129 {
130 if (contains(e.getPoint()))
131 {
132 clicked();
133 return true;
134 }
135 return false;
70 } 136 }
71 137
72 public void mouseReleased(MouseEvent e) 138 public boolean mouseEntered(MouseEvent e)
73 { 139 {
74 if (contains(e.getPoint())) 140 return false;
75 clicked();
76 } 141 }
77 142
78 public void mouseEntered(MouseEvent e) 143 public boolean mouseExited(MouseEvent e)
79 { 144 {
80 } 145 return false;
81
82 public void mouseExited(MouseEvent e)
83 {
84 } 146 }
85 147
86 // Generic key handler 148 // Generic key handler
87 public boolean keyPressed(KeyEvent e) 149 public boolean keyPressed(KeyEvent e)
88 { 150 {