Rev | Line | |
---|
[9b6a069] | 1 | package utils;
|
---|
| 2 |
|
---|
| 3 | import java.awt.*;
|
---|
| 4 | import java.awt.image.*;
|
---|
| 5 |
|
---|
| 6 | public class DynamicImage {
|
---|
| 7 | private String filePath;
|
---|
| 8 | private BufferedImage img;
|
---|
| 9 | private Color bg, shadow;
|
---|
| 10 |
|
---|
| 11 | public DynamicImage(String filePath) {
|
---|
| 12 | this.filePath = filePath;
|
---|
| 13 | img = null;
|
---|
| 14 | bg = shadow = null;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | public DynamicImage(String filePath, Color bg, Color shadow) {
|
---|
| 18 | this.filePath = filePath;
|
---|
| 19 | img = null;
|
---|
| 20 | this.bg = bg;
|
---|
| 21 | this.shadow = shadow;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | private void loadImg() {
|
---|
| 25 | if(bg == null)
|
---|
| 26 | img = Utils.loadImg(filePath);
|
---|
| 27 | else
|
---|
| 28 | img = Utils.loadTransImg(filePath, bg, shadow);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | public int getHeight() {
|
---|
| 32 | if(img == null)
|
---|
| 33 | loadImg();
|
---|
| 34 | return img.getHeight();
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public int getWidth() {
|
---|
| 38 | if(img == null)
|
---|
| 39 | loadImg();
|
---|
| 40 | return img.getWidth();
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public void draw(Graphics g, int x, int y) {
|
---|
| 44 | if(img == null)
|
---|
| 45 | loadImg();
|
---|
| 46 | g.drawImage(img, x, y, null);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public void draw(Graphics g, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) {
|
---|
| 50 | if(img == null)
|
---|
| 51 | loadImg();
|
---|
| 52 | g.drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.