-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLayerManager.java
157 lines (129 loc) · 3.43 KB
/
LayerManager.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
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) fieldsfirst space
// Source File Name: LayerManager.java
// package javax.microedition.lcdui.game;
// import javax.microedition.lcdui.Graphics;
import java.awt.Graphics;
import java.awt.Shape;
// Referenced classes of package javax.microedition.lcdui.game:
// Layer
public class LayerManager
{
private int nlayers;
private Layer component[];
private int viewX;
private int viewY;
private int viewWidth;
private int viewHeight;
public LayerManager()
{
component = new Layer[4];
setViewWindow(0, 0, 0x7fffffff, 0x7fffffff);
}
public void append(Layer l)
{
removeImpl(l);
addImpl(l, nlayers);
}
public void insert(Layer l, int index)
{
if (index < 0 || index > nlayers)
{
throw new IndexOutOfBoundsException();
} else
{
removeImpl(l);
addImpl(l, index);
return;
}
}
public Layer getLayerAt(int index)
{
if (index < 0 || index >= nlayers)
throw new IndexOutOfBoundsException();
else
return component[index];
}
public int getSize()
{
return nlayers;
}
public void remove(Layer l)
{
removeImpl(l);
}
public void paint(Graphics g, int x, int y)
{
Shape shape = g.getClip();
// int clipX = g.getClipX();
// int clipY = g.getClipY();
// int clipW = g.getClipWidth();
// int clipH = g.getClipHeight();
g.translate(x - viewX, y - viewY);
g.clipRect(viewX, viewY, viewWidth, viewHeight);
int i = nlayers;
while (true)
{
if (--i < 0)
break;
Layer comp = component[i];
if (comp.visible)
comp.paint(g);
}
g.translate(-x + viewX, -y + viewY);
g.setClip(shape);
// g.setClip(clipX, clipY, clipW, clipH);
}
public void setViewWindow(int x, int y, int width, int height)
{
if (width < 0 || height < 0)
{
throw new IllegalArgumentException();
} else
{
viewX = x;
viewY = y;
viewWidth = width;
viewHeight = height;
return;
}
}
private void addImpl(Layer layer, int index)
{
if (nlayers == component.length)
{
Layer newcomponents[] = new Layer[nlayers + 4];
System.arraycopy(component, 0, newcomponents, 0, nlayers);
System.arraycopy(component, index, newcomponents,
index + 1, nlayers - index);
component = newcomponents;
}
else
{
System.arraycopy(component, index, component,
index + 1, nlayers - index);
}
component[index] = layer;
nlayers++;
}
private void removeImpl(Layer l)
{
if (l == null)
throw new NullPointerException();
int i = nlayers;
do
{
if (--i < 0)
break;
if (component[i] == l)
remove(i);
} while (true);
}
private void remove(int index)
{
System.arraycopy(component, index + 1, component,
index, nlayers - index - 1);
component[--nlayers] = null;
}
}