summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/window/Window.java
blob: db1bfabe87304f4ad1ae92d09af4b9699272afeb (plain) (blame)
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
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.fourisland.fourpuzzle.window;

import com.fourisland.fourpuzzle.Display;
import com.fourisland.fourpuzzle.util.Interval;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

/**
 *
 * @author hatkirby
 */
public enum Window
{
    Default(32)
    {
        protected BufferedImage getBackground()
        {
            return SystemGraphic.getMessageBackground();
        }
    },
    Selector(64)
    {
        Interval in = Interval.createTickInterval(4);
        boolean isFlashing = false;
        
        @Override
        protected int getX(SystemArea sa)
        {
            if (in.isElapsed())
            {
                isFlashing = !isFlashing;
            }
            
            if (isFlashing)
            {
                return (super.getX(sa)+32);
            } else {
                return super.getX(sa);
            }
        }
        
        protected BufferedImage getBackground()
        {
            if (in.isElapsed())
            {
                isFlashing = !isFlashing;
            }
            
            return SystemGraphic.getSelectionBackground(isFlashing);
        }
    };
    
    protected enum SystemArea
    {
        TOP(15, 0, 1, 8),
        TOP_RIGHT(24, 0, 8, 8),
        RIGHT(24, 15, 8, 1),
        BOTTOM_RIGHT(24, 24, 8, 8),
        BOTTOM(15, 24, 1, 8),
        BOTTOM_LEFT(0, 24, 8, 8),
        LEFT(0, 15, 8, 1),
        TOP_LEFT(0, 0, 8, 8);

        private final int x;
        private final int y;
        private final int width;
        private final int height;
        private SystemArea(int x, int y, int width, int height)
        {
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
        }
    }
    
    private int x;
    private Window(int x)
    {
        this.x = x;
    }
    
    protected int getX(SystemArea sa)
    {
        return x+sa.x;
    }
    
    protected int getY(SystemArea sa)
    {
        return sa.y;
    }
    
    protected int getWidth(SystemArea sa)
    {
        return sa.width;
    }
    
    protected int getHeight(SystemArea sa)
    {
        return sa.height;
    }
    
    private Rectangle getBounds(SystemArea sa)
    {
        return new Rectangle(getX(sa), getY(sa), getWidth(sa), getHeight(sa));
    }
    
    public int getFullWidth(int width)
    {
        return getWidth(SystemArea.TOP_LEFT) + getWidth(SystemArea.TOP_RIGHT) + width;
    }
    
    public int getFullHeight(int height)
    {
        return getHeight(SystemArea.TOP_LEFT) + getHeight(SystemArea.BOTTOM_LEFT) + height;
    }
    
    public int getLeftX()
    {
        return getWidth(SystemArea.TOP_LEFT);
    }
    
    public int getTopY()
    {
        return getHeight(SystemArea.TOP_LEFT);
    }
    
    protected abstract BufferedImage getBackground();
    
    public BufferedImage getImage(int width, int height)
    {
        BufferedImage temp = Display.createCanvas(getFullWidth(width), getFullHeight(height));
        Graphics2D g = temp.createGraphics();
        
        g.drawImage(getBackground(), 3, 3, getFullWidth(width)-6, getFullHeight(height)-6, null);
        
        g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP_LEFT)), 0, 0, null);
        g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP)), getWidth(SystemArea.TOP_LEFT), 0, width, getHeight(SystemArea.TOP), null);
        g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.TOP_RIGHT)), getWidth(SystemArea.TOP_LEFT)+width, 0, null);
        g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.LEFT)), 0, getHeight(SystemArea.TOP_LEFT), getWidth(SystemArea.LEFT),height, null);
        g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.BOTTOM_LEFT)), 0, getHeight(SystemArea.TOP_LEFT)+height, null);
        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);
        g.drawImage(SystemGraphic.getChoiceArea(getBounds(SystemArea.BOTTOM_RIGHT)), getWidth(SystemArea.BOTTOM_RIGHT)+width, getHeight(SystemArea.TOP_RIGHT)+height, null);
        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);
        
        return temp;
    }
}