diff options
Diffstat (limited to 'src/com/fourisland/fourpuzzle/window/Window.java')
| -rw-r--r-- | src/com/fourisland/fourpuzzle/window/Window.java | 116 |
1 files changed, 116 insertions, 0 deletions
| diff --git a/src/com/fourisland/fourpuzzle/window/Window.java b/src/com/fourisland/fourpuzzle/window/Window.java new file mode 100644 index 0000000..fa40cba --- /dev/null +++ b/src/com/fourisland/fourpuzzle/window/Window.java | |||
| @@ -0,0 +1,116 @@ | |||
| 1 | /* | ||
| 2 | * To change this template, choose Tools | Templates | ||
| 3 | * and open the template in the editor. | ||
| 4 | */ | ||
| 5 | |||
| 6 | package com.fourisland.fourpuzzle.window; | ||
| 7 | |||
| 8 | import com.fourisland.fourpuzzle.util.TransparentPixelFilter; | ||
| 9 | import java.awt.Graphics2D; | ||
| 10 | import java.awt.Image; | ||
| 11 | import java.awt.Rectangle; | ||
| 12 | import java.awt.Toolkit; | ||
| 13 | import java.awt.image.BufferedImage; | ||
| 14 | import java.awt.image.FilteredImageSource; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * | ||
| 18 | * @author hatkirby | ||
| 19 | */ | ||
| 20 | public enum Window | ||
| 21 | { | ||
| 22 | Default(32), | ||
| 23 | Selector(64); | ||
| 24 | |||
| 25 | private enum SystemArea | ||
| 26 | { | ||
| 27 | TOP(15, 0, 1, 9), | ||
| 28 | TOP_RIGHT(24, 0, 8, 9), | ||
| 29 | RIGHT(24, 15, 8, 1), | ||
| 30 | BOTTOM_RIGHT(24, 25, 8, 9), | ||
| 31 | BOTTOM(15, 24, 1, 9), | ||
| 32 | BOTTOM_LEFT(0, 24, 11, 9), | ||
| 33 | LEFT(0, 15, 11, 1), | ||
| 34 | TOP_LEFT(0, 0, 8, 8); | ||
| 35 | |||
| 36 | private final int x; | ||
| 37 | private final int y; | ||
| 38 | private final int width; | ||
| 39 | private final int height; | ||
| 40 | private SystemArea(int x, int y, int width, int height) | ||
| 41 | { | ||
| 42 | this.x = x; | ||
| 43 | this.y = y; | ||
| 44 | this.width = width; | ||
| 45 | this.height = height; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | private int x; | ||
| 50 | private Window(int x) | ||
| 51 | { | ||
| 52 | this.x = x; | ||
| 53 | } | ||
| 54 | |||
| 55 | private int getX(SystemArea sa) | ||
| 56 | { | ||
| 57 | return x+sa.x; | ||
| 58 | } | ||
| 59 | |||
| 60 | private int getY(SystemArea sa) | ||
| 61 | { | ||
| 62 | return sa.y; | ||
| 63 | } | ||
| 64 | |||
| 65 | private int getWidth(SystemArea sa) | ||
| 66 | { | ||
| 67 | return sa.width; | ||
| 68 | } | ||
| 69 | |||
| 70 | private int getHeight(SystemArea sa) | ||
| 71 | { | ||
| 72 | return sa.height; | ||
| 73 | } | ||
| 74 | |||
| 75 | private Rectangle getBounds(SystemArea sa) | ||
| 76 | { | ||
| 77 | return new Rectangle(getX(sa), getY(sa), getWidth(sa), getHeight(sa)); | ||
| 78 | } | ||
| 79 | |||
| 80 | public int getFullWidth(int width) | ||
| 81 | { | ||
| 82 | return getWidth(SystemArea.TOP_LEFT) + getWidth(SystemArea.TOP_RIGHT) + width; | ||
| 83 | } | ||
| 84 | |||
| 85 | public int getFullHeight(int height) | ||
| 86 | { | ||
| 87 | return getHeight(SystemArea.TOP_LEFT) + getHeight(SystemArea.BOTTOM_LEFT) + height; | ||
| 88 | } | ||
| 89 | |||
| 90 | public int getLeftX() | ||
| 91 | { | ||
| 92 | return getWidth(SystemArea.TOP_LEFT); | ||
| 93 | } | ||
| 94 | |||
| 95 | public int getTopY() | ||
| 96 | { | ||
| 97 | return getHeight(SystemArea.TOP_LEFT); | ||
| 98 | } | ||
| 99 | |||
| 100 | public Image getImage(int width, int height) | ||
| 101 | { | ||
| 102 | BufferedImage temp = new BufferedImage(getFullWidth(width), getFullHeight(height), BufferedImage.TYPE_INT_ARGB); | ||
| 103 | Graphics2D g = temp.createGraphics(); | ||
| 104 | |||
| 105 | g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP_LEFT)), 0, 0, null); | ||
| 106 | g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP)), getWidth(SystemArea.TOP_LEFT), 0, width, getHeight(SystemArea.TOP), null); | ||
| 107 | g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP_RIGHT)), getWidth(SystemArea.TOP_LEFT)+width, 0, null); | ||
| 108 | g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.LEFT)), 0, getHeight(SystemArea.TOP_LEFT), getWidth(SystemArea.LEFT),height, null); | ||
| 109 | g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.BOTTOM_LEFT)), 0, getHeight(SystemArea.TOP_LEFT)+height, null); | ||
| 110 | g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.BOTTOM)), getWidth(SystemArea.BOTTOM_LEFT), (height+getHeight(SystemArea.TOP_LEFT)+getHeight(SystemArea.BOTTOM_LEFT))-getHeight(SystemArea.BOTTOM), width, getHeight(SystemArea.BOTTOM), null); | ||
| 111 | g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.BOTTOM_RIGHT)), getWidth(SystemArea.BOTTOM_RIGHT)+width, getHeight(SystemArea.TOP_RIGHT)+height, null); | ||
| 112 | g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.RIGHT)), (width+getWidth(SystemArea.TOP_LEFT)+getWidth(SystemArea.TOP_RIGHT))-getWidth(SystemArea.RIGHT), getHeight(SystemArea.TOP_RIGHT), getWidth(SystemArea.RIGHT), height, null); | ||
| 113 | |||
| 114 | return Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(temp.getSource(), new TransparentPixelFilter(SystemGraphic.getTransparentColor().getRGB()))); | ||
| 115 | } | ||
| 116 | } \ No newline at end of file | ||
