Mercurial > hg > ristipolku
annotate game/IDMWidget.java @ 171:5070e57ebbfc
Move text drawing stuff to IDMWidget class.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Mar 2017 10:19:04 +0200 |
parents | b9bc493ae53c |
children | 55ea5821c802 |
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 |
151 | 3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
49
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 { |
75 | 13 IDMWidget parent; |
14 IDMPoint pos, size, scale; | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 int keyCode; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
16 |
171
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
17 IDMPoint textCurrPos, textCurrOffs; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
18 Paint textPaint; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
19 Font textFont; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
20 FontMetrics textMetrics; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
21 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
22 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 public IDMWidget() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 keyCode = -1; |
51 | 26 this.scale = new IDMPoint(1, 1); |
27 this.pos = new IDMPoint(0, 0); | |
75 | 28 this.size = new IDMPoint(0, 0); |
51 | 29 } |
30 | |
31 public IDMWidget(IDMPoint pos) | |
32 { | |
33 this(); | |
34 this.pos = pos; | |
35 } | |
36 | |
75 | 37 public IDMWidget(IDMPoint pos, IDMPoint size) |
38 { | |
39 this(); | |
40 this.pos = pos; | |
41 this.size = size; | |
42 } | |
43 | |
44 public void setParent(IDMWidget par) | |
45 { | |
46 this.parent = par; | |
47 } | |
48 | |
49 public void add(IDMWidget widget) | |
50 { | |
51 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
52 |
75 | 53 public void remove(IDMWidget widget) |
54 { | |
55 } | |
56 | |
57 public void setPos(IDMPoint pos) | |
51 | 58 { |
59 this.pos = pos; | |
60 } | |
61 | |
75 | 62 public void setPos(float x, float y) |
51 | 63 { |
64 this.pos = new IDMPoint(x, y); | |
65 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
66 |
75 | 67 public void setSize(IDMPoint size) |
68 { | |
69 this.size = size; | |
70 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
71 |
75 | 72 public void setSize(float w, float h) |
73 { | |
74 this.size = new IDMPoint(w, h); | |
75 } | |
51 | 76 |
77 public void setScale(IDMPoint scale) | |
78 { | |
79 this.scale = scale; | |
80 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
81 |
51 | 82 public void setScale(float x, float y) |
83 { | |
84 this.setScale(new IDMPoint(x, y)); | |
85 } | |
86 | |
87 public int getScaledX() | |
88 { | |
75 | 89 return (int) (pos.x * scale.x); |
51 | 90 } |
91 | |
92 public int getScaledY() | |
93 { | |
75 | 94 return (int) (pos.y * scale.y); |
95 } | |
96 | |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
97 public int getScaledX(float x) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
98 { |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
99 return (int) (x * scale.x); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
100 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
101 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
102 public int getScaledY(float y) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
103 { |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
104 return (int) (y * scale.y); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
105 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
106 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
107 public int getScaledRelX(float x) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
108 { |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
109 return (int) ((pos.x + x) * scale.x); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
110 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
111 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
112 public int getScaledRelY(float y) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
113 { |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
114 return (int) ((pos.y + y) * scale.y); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
115 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
116 |
75 | 117 public int getScaledWidth() |
118 { | |
119 return (int) (size.x * scale.x); | |
120 } | |
121 | |
122 public int getScaledHeight() | |
123 { | |
124 return (int) (size.y * scale.y); | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 |
75 | 127 public boolean contains(float x, float y) |
128 { | |
129 return (x >= getScaledX() && | |
130 y >= getScaledY() && | |
131 x < getScaledX() + getScaledWidth() && | |
132 y < getScaledY() + getScaledHeight()); | |
133 } | |
134 | |
135 public boolean contains(Point where) | |
136 { | |
137 return contains(where.x, where.y); | |
138 } | |
139 | |
140 public boolean contains(IDMPoint where) | |
141 { | |
142 return contains(where.x, where.y); | |
143 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
144 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 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
|
146 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
148 |
75 | 149 public boolean mousePressed(MouseEvent e) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 return false; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 |
75 | 154 public boolean mouseReleased(MouseEvent e) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 if (contains(e.getPoint())) |
75 | 157 { |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 clicked(); |
75 | 159 return true; |
160 } | |
161 return false; | |
50 | 162 } |
163 | |
75 | 164 public boolean mouseEntered(MouseEvent e) |
50 | 165 { |
75 | 166 return false; |
50 | 167 } |
168 | |
75 | 169 public boolean mouseExited(MouseEvent e) |
50 | 170 { |
75 | 171 return false; |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 // Generic key handler |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 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
|
176 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 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
|
178 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 clicked(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 return true; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 else |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 return false; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
185 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 public void clicked() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
187 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
188 } |
171
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
189 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
190 public void setTextFont(Font font, FontMetrics metrics) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
191 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
192 textFont = font; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
193 textMetrics = metrics; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
194 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
195 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
196 public void setTextPaint(Paint paint) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
197 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
198 textPaint = paint; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
199 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
200 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
201 public void setCurrPos(IDMPoint npos) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
202 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
203 textCurrPos = npos; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
204 textCurrOffs = new IDMPoint(0, 0); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
205 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
206 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
207 public void setCurrPos(float x, float y) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
208 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
209 setCurrPos(new IDMPoint(x, y)); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
210 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
211 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
212 public void setCurrPosScaledRel(float x, float y) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
213 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
214 setCurrPos(new IDMPoint(getScaledRelX(x), getScaledRelY(y))); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
215 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
216 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
217 public void drawString(Graphics2D g, String text) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
218 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
219 Paint savePaint = g.getPaint(); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
220 g.setPaint(textPaint); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
221 g.setFont(textFont); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
222 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
223 int i = 0; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
224 while (i < text.length()) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
225 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
226 int p = text.indexOf("\n", i); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
227 boolean linefeed; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
228 String str; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
229 if (p >= i) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
230 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
231 str = text.substring(i, p); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
232 i = p + 1; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
233 linefeed = true; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
234 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
235 else |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
236 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
237 str = text.substring(i); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
238 i += str.length(); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
239 linefeed = false; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
240 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
241 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
242 g.drawString(str, textCurrPos.x + textCurrOffs.x, textCurrPos.y + textCurrOffs.y); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
243 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
244 if (linefeed) |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
245 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
246 textCurrOffs.x = 0; |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
247 textCurrOffs.y += textMetrics.getHeight(); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
248 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
249 else |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
250 { |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
251 textCurrOffs.x += textMetrics.stringWidth(str); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
252 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
253 } |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
254 |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
255 g.setPaint(savePaint); |
5070e57ebbfc
Move text drawing stuff to IDMWidget class.
Matti Hamalainen <ccr@tnsp.org>
parents:
170
diff
changeset
|
256 } |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 } |