[fb4fc67] | 1 | package utils;
|
---|
| 2 |
|
---|
| 3 | import java.awt.image.ImageObserver;
|
---|
| 4 | import java.awt.Image;
|
---|
| 5 | import java.awt.Graphics;
|
---|
| 6 | import java.awt.Color;
|
---|
| 7 | import java.awt.image.BufferedImage;
|
---|
| 8 |
|
---|
| 9 | public class DynamicImage {
|
---|
| 10 | private String filePath;
|
---|
| 11 | private BufferedImage img;
|
---|
| 12 | private Color bg;
|
---|
| 13 | private Color shadow;
|
---|
| 14 |
|
---|
| 15 | public DynamicImage(final String filePath) {
|
---|
| 16 | this.filePath = filePath;
|
---|
| 17 | this.img = null;
|
---|
| 18 | final Color color = null;
|
---|
| 19 | this.shadow = color;
|
---|
| 20 | this.bg = color;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | public DynamicImage(final String filePath, final Color bg, final Color shadow) {
|
---|
| 24 | this.filePath = filePath;
|
---|
| 25 | this.img = null;
|
---|
| 26 | this.bg = bg;
|
---|
| 27 | this.shadow = shadow;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | private void loadImg() {
|
---|
| 31 | if (this.bg == null) {
|
---|
| 32 | this.img = Utils.loadImg(this.filePath);
|
---|
| 33 | }
|
---|
| 34 | else {
|
---|
| 35 | this.img = Utils.loadTransImg(this.filePath, this.bg, this.shadow);
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public int getHeight() {
|
---|
| 40 | if (this.img == null) {
|
---|
| 41 | this.loadImg();
|
---|
| 42 | }
|
---|
| 43 | return this.img.getHeight();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public int getWidth() {
|
---|
| 47 | if (this.img == null) {
|
---|
| 48 | this.loadImg();
|
---|
| 49 | }
|
---|
| 50 | return this.img.getWidth();
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public void draw(final Graphics g, final int x, final int y) {
|
---|
| 54 | if (this.img == null) {
|
---|
| 55 | this.loadImg();
|
---|
| 56 | }
|
---|
| 57 | g.drawImage(this.img, x, y, null);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public void draw(final Graphics g, final int dx1, final int dy1, final int dx2, final int dy2, final int sx1, final int sy1, final int sx2, final int sy2) {
|
---|
| 61 | if (this.img == null) {
|
---|
| 62 | this.loadImg();
|
---|
| 63 | }
|
---|
| 64 | g.drawImage(this.img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|