-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphicsScallable.java
448 lines (369 loc) · 16 KB
/
GraphicsScallable.java
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
package asteroidymodyfikacja;
//martapalka
import java.awt.Color;
import java.awt.Composite;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Image;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
import java.text.AttributedCharacterIterator;
import java.util.Map;
/**
*KLASA:GraphicsScallable
* OPIS:Określa jak zachodzi skalowanie grafiki
* Konstruktor jest wywoływany w klasie Game do stworzenia obiektu buffGraphics
* Klasa zaopatrzona w szereg metod wbudowanych określających parametry obiektów różnych typów po skalowaniu
*/
public class GraphicsScallable extends Graphics2D {
private Graphics2D graphics;
private double scaleW;
private double scaleH;
GraphicsScallable( Graphics2D newGraphics, double newScaleW, double newScaleH )
{
graphics = newGraphics;
scaleW = newScaleW;
scaleH = newScaleH;
}
@Override
public void copyArea(int x, int y, int width, int height, int dx, int dy) {
graphics.copyArea(x, y, width, height, dx, dy);
}
@Override
public void drawLine(int x1, int y1, int x2, int y2) {
graphics.drawLine(x1, y1, x2, y2);
}
@Override
public void fillRect(int x, int y, int width, int height) {
graphics.fillRect(x, y, (int)(1000.0*width*scaleW)/1000, (int)(1000.0*height*scaleH)/1000);
}
@Override
public void clearRect(int x, int y, int width, int height) {
graphics.clearRect(x, y, width, height);
}
@Override
public void drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
graphics.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
}
@Override
public void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight) {
graphics.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
}
@Override
public void drawOval(int x, int y, int width, int height) {
double widthS = width*scaleW;
double heightS = height*scaleH;
double xS = (widthS-width)/2 + x*scaleW;
double yS = (heightS-height)/2 + y*scaleH;
graphics.drawOval((int)xS, (int)yS, (int)widthS, (int)heightS);
}
@Override
public void fillOval(int x, int y, int width, int height) {
double widthS = width*scaleW;
double heightS = height*scaleH;
double xS = (widthS-width)/2 + x*scaleW;
double yS = (heightS-height)/2 + y*scaleH;
graphics.fillOval((int)xS, (int)yS, (int)widthS, (int)heightS);
}
@Override
public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
graphics.drawArc(x, y, width, height, startAngle, arcAngle);
}
@Override
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
graphics.fillArc(x, y, width, height, startAngle, arcAngle);
}
@Override
public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) {
graphics.drawPolyline(xPoints, yPoints, nPoints);
}
@Override
public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) {
double xCenter = 0, yCenter = 0;
double xCenterS = 0, yCenterS = 0;
// Środek wielokąta
for( int x:xPoints )
xCenter += x;
for( int y:yPoints )
yCenter += y;
xCenter /= xPoints.length;
yCenter /= yPoints.length;
xCenterS = xCenter*scaleW;
yCenterS = yCenter*scaleH;
// przesunięcie do zera, przeskalowanie i ponowne przesuniecie zwrotne
for( int n=0; n<xPoints.length; n++)
{
xPoints[n] = (int)((xPoints[n]-xCenter)*scaleW+xCenterS);
yPoints[n] = (int)((yPoints[n]-yCenter)*scaleH+yCenterS);
}
graphics.drawPolygon(xPoints, yPoints, nPoints);
}
@Override
public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) {
double xCenter = 0, yCenter = 0;
double xCenterS = 0, yCenterS = 0;
// Środek wielokąta
for( int x:xPoints )
xCenter += x;
for( int y:yPoints )
yCenter += y;
xCenter /= xPoints.length;
yCenter /= yPoints.length;
xCenterS = xCenter*scaleW;
yCenterS = yCenter*scaleH;
// przesunięcie do zera, przeskalowanie i ponowne przesuniecie zwrotne
for( int n=0; n<xPoints.length; n++)
{
xPoints[n] = (int)((xPoints[n]-xCenter)*scaleW+xCenterS);
yPoints[n] = (int)((yPoints[n]-yCenter)*scaleH+yCenterS);
}
graphics.fillPolygon(xPoints, yPoints, nPoints);
}
@Override
public void drawString(String str, int x, int y) {
x = (int)((1000.0*x*scaleW)/1000);
y = (int)((1000.0*y*scaleH)/1000);
graphics.drawString(str, x, y);
}
@Override
public void drawString(AttributedCharacterIterator iterator, int x, int y) {
x = (int)((1000.0*x*scaleW)/1000);
y = (int)((1000.0*y*scaleH)/1000);
graphics.drawString(iterator, x, y);
}
@Override
public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
return graphics.drawImage(img, x, y, observer);
}
@Override
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
return graphics.drawImage(img, x, y, width, height, observer);
}
@Override
public boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer) {
return graphics.drawImage(img, x, y, bgcolor, observer);
}
@Override
public boolean drawImage(Image img, int x, int y, int width, int height, Color bgcolor, ImageObserver observer) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void dispose() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Graphics create() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void translate(int x, int y) {
graphics.translate(x, y);
}
@Override
public Color getColor() {
return graphics.getColor();
}
@Override
public void setColor(Color c) {
graphics.setColor(c);
}
@Override
public void setPaintMode() {
graphics.setPaintMode();
}
@Override
public void setXORMode(Color c1) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Font getFont() {
return graphics.getFont();
}
@Override
public void setFont(Font font) {
font = font.deriveFont( (float)(1000.0*font.getSize2D()*(scaleH*1.0/10.0+scaleW*9.0/10.0))/1000 );
graphics.setFont(font);
}
@Override
public FontMetrics getFontMetrics(Font f) {
return graphics.getFontMetrics(f);
}
@Override
public Rectangle getClipBounds() {
return graphics.getClipBounds();
}
@Override
public void clipRect(int x, int y, int width, int height) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setClip(int x, int y, int width, int height) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Shape getClip() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setClip(Shape clip) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void draw(Shape s) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean drawImage(Image img, AffineTransform xform, ImageObserver obs) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void drawRenderableImage(RenderableImage img, AffineTransform xform) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void drawString(String str, float x, float y) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void drawGlyphVector(GlyphVector g, float x, float y) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void fill(Shape s) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public GraphicsConfiguration getDeviceConfiguration() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setComposite(Composite comp) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setPaint(Paint paint) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setStroke(Stroke s) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setRenderingHint(RenderingHints.Key hintKey, Object hintValue) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Object getRenderingHint(RenderingHints.Key hintKey) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setRenderingHints(Map<?, ?> hints) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void addRenderingHints(Map<?, ?> hints) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public RenderingHints getRenderingHints() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void translate(double tx, double ty) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void rotate(double theta) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void rotate(double theta, double x, double y) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void scale(double sx, double sy) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void shear(double shx, double shy) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void transform(AffineTransform Tx) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setTransform(AffineTransform Tx) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public AffineTransform getTransform() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Paint getPaint() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Composite getComposite() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setBackground(Color color) {
graphics.setBackground(color);
}
@Override
public Color getBackground() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Stroke getStroke() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void clip(Shape s) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public FontRenderContext getFontRenderContext() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}