1 | package org.expeditee.gio;
|
---|
2 |
|
---|
3 | import java.net.URL;
|
---|
4 | import java.util.LinkedList;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import org.expeditee.core.Clip;
|
---|
8 | import org.expeditee.core.Colour;
|
---|
9 | import org.expeditee.core.Cursor;
|
---|
10 | import org.expeditee.core.Dimension;
|
---|
11 | import org.expeditee.core.EnforcedClipStack.EnforcedClipKey;
|
---|
12 | import org.expeditee.core.Fill;
|
---|
13 | import org.expeditee.core.Font;
|
---|
14 | import org.expeditee.core.Image;
|
---|
15 | import org.expeditee.core.Line;
|
---|
16 | import org.expeditee.core.Point;
|
---|
17 | import org.expeditee.core.Stroke;
|
---|
18 | import org.expeditee.core.TextLayout;
|
---|
19 | import org.expeditee.core.bounds.AxisAlignedBoxBounds;
|
---|
20 | import org.expeditee.core.bounds.EllipticalBounds;
|
---|
21 | import org.expeditee.core.bounds.PolygonBounds;
|
---|
22 | import org.expeditee.items.widgets.Widget;
|
---|
23 |
|
---|
24 | /** TODO: Comment. cts16 */
|
---|
25 | public abstract class GraphicsManager {
|
---|
26 |
|
---|
27 | /** TODO: Comment. cts16 */
|
---|
28 | protected static String _windowIcon = "";
|
---|
29 |
|
---|
30 | protected GraphicsManager()
|
---|
31 | {
|
---|
32 | _widgets = new LinkedList<Widget>();
|
---|
33 | }
|
---|
34 |
|
---|
35 | /*
|
---|
36 | *
|
---|
37 | * Screen and window methods.
|
---|
38 | *
|
---|
39 | */
|
---|
40 |
|
---|
41 | /** Gets the width and height of the display screen in pixels. */
|
---|
42 | public abstract Dimension getScreenSize();
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Gets the pixel location of the top-left corner of the window drawing area
|
---|
46 | * in screen-relative coordinates.
|
---|
47 | */
|
---|
48 | public abstract Point getWindowLocation();
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Sets the pixel location of the top-left corner of the window drawing area
|
---|
52 | * in screen-relative coordinates.
|
---|
53 | */
|
---|
54 | public abstract void setWindowLocation(Point p);
|
---|
55 |
|
---|
56 | /** Gets the dimensions of window drawing area. */
|
---|
57 | public abstract Dimension getWindowSize();
|
---|
58 |
|
---|
59 | /** Sets the dimensions of window drawing area. */
|
---|
60 | public abstract void setWindowSize(Dimension d);
|
---|
61 |
|
---|
62 | /** Tries to focus the window. */
|
---|
63 | public abstract void requestFocus();
|
---|
64 |
|
---|
65 | /** Tells the GraphicsManager which icon to use for the window. */
|
---|
66 | public static final void setWindowIcon(String filename)
|
---|
67 | {
|
---|
68 | if (_windowIcon == "") {
|
---|
69 | _windowIcon = filename;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | /** Should be called by the platform-specific graphics manager to set the window's icon. */
|
---|
74 | protected void setWindowIcon()
|
---|
75 | {
|
---|
76 | // set up the image used for the icon
|
---|
77 | try
|
---|
78 | {
|
---|
79 | URL iconURL = ClassLoader.getSystemResource(_windowIcon);
|
---|
80 | if (iconURL != null)
|
---|
81 | {
|
---|
82 | Image localImage = Image.getImage(iconURL);
|
---|
83 | setWindowIcon(localImage);
|
---|
84 | }
|
---|
85 | }
|
---|
86 | catch (Exception e)
|
---|
87 | {
|
---|
88 | e.printStackTrace();
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | /** Sets the window's icon to the given image. */
|
---|
93 | protected abstract void setWindowIcon(Image image);
|
---|
94 |
|
---|
95 | /** Sets the title text for the window. */
|
---|
96 | public abstract void setWindowTitle(String title);
|
---|
97 |
|
---|
98 | /** Returns whether or not the window is capable of going fullscreen. */
|
---|
99 | public abstract boolean canGoFullscreen();
|
---|
100 |
|
---|
101 | /** Returns whether or not the window is currently in fullscreen mode. */
|
---|
102 | public abstract boolean isFullscreen();
|
---|
103 |
|
---|
104 | /** Tells the window to enter fullscreen mode. */
|
---|
105 | public abstract void goFullscreen();
|
---|
106 |
|
---|
107 | /** Tells the window to leave fullscreen mode. */
|
---|
108 | public abstract void exitFullscreen();
|
---|
109 |
|
---|
110 | /*
|
---|
111 | *
|
---|
112 | * Drawing-surface methods.
|
---|
113 | *
|
---|
114 | */
|
---|
115 |
|
---|
116 | /** Gets the platform-specific sub-typed surface stack. */
|
---|
117 | protected abstract GraphicsSurfaceStack<?> getGraphicsSurfaceStack();
|
---|
118 |
|
---|
119 | /** Puts the given image on top of the drawing stack, making it the current rendering surface. */
|
---|
120 | public void pushDrawingSurface(Image image)
|
---|
121 | {
|
---|
122 | getGraphicsSurfaceStack().push(image);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /** Removes a rendering surface from the drawing stack. */
|
---|
126 | public Image popDrawingSurface()
|
---|
127 | {
|
---|
128 | return getGraphicsSurfaceStack().pop();
|
---|
129 | }
|
---|
130 |
|
---|
131 | /** Pushes a new clip onto the stack, ensuring that it is a sub-area of the top of the stack. */
|
---|
132 | public EnforcedClipKey pushClip(Clip clip)
|
---|
133 | {
|
---|
134 | return getGraphicsSurfaceStack().pushClip(clip);
|
---|
135 | }
|
---|
136 |
|
---|
137 | /** Pops the top of the current clip-stack if there given key corresponds to it. */
|
---|
138 | public Clip popClip(EnforcedClipKey key)
|
---|
139 | {
|
---|
140 | return getGraphicsSurfaceStack().popClip(key);
|
---|
141 | }
|
---|
142 |
|
---|
143 | /** Returns a copy of the top of the current clip-stack. */
|
---|
144 | public Clip peekClip()
|
---|
145 | {
|
---|
146 | return getGraphicsSurfaceStack().peekClip();
|
---|
147 | }
|
---|
148 |
|
---|
149 | /** Gets the size of the current drawing surface. */
|
---|
150 | public abstract Dimension getCurrentDrawingSurfaceSize();
|
---|
151 |
|
---|
152 | /** Sets the global compositing alpha value for the current rendering surface. */
|
---|
153 | public abstract void setCompositeAlpha(float alpha);
|
---|
154 |
|
---|
155 | /** Sets whether antialiased rendering should be used on the current surface. */
|
---|
156 | public abstract void setAntialiasing(boolean on);
|
---|
157 |
|
---|
158 | public abstract void setTransientAntialiasingOn();
|
---|
159 | public abstract void setTransientAntialiasingOff();
|
---|
160 |
|
---|
161 | /** Sets the default font for the current rendering surface. */
|
---|
162 | public abstract void setFont(Font font);
|
---|
163 |
|
---|
164 | /*
|
---|
165 | *
|
---|
166 | * Image-drawing methods.
|
---|
167 | *
|
---|
168 | */
|
---|
169 |
|
---|
170 | /** Draws the given image at its natural size at the given location. */
|
---|
171 | public void drawImage(Image image, Point topLeft)
|
---|
172 | {
|
---|
173 | drawImage(image, topLeft, null);
|
---|
174 | }
|
---|
175 |
|
---|
176 | /** Draws the given image at the given size. */
|
---|
177 | public void drawImage(Image image, Point topLeft, Dimension size)
|
---|
178 | {
|
---|
179 | drawImage(image, topLeft, size, 0.0f);
|
---|
180 | }
|
---|
181 |
|
---|
182 | /** Draws the given image rotated about its top-left corner by the given angle. */
|
---|
183 | public void drawImage(Image image, Point topLeft, Dimension size, double angle)
|
---|
184 | {
|
---|
185 | drawImage(image, topLeft, size, angle, null, null);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /** Draws the given cropped area of the given image. */
|
---|
189 | public abstract void drawImage(Image image, Point topLeft, Dimension size, double angle, Point cropTopLeft, Dimension cropSize);
|
---|
190 |
|
---|
191 | /*
|
---|
192 | *
|
---|
193 | * Shape-drawing methods.
|
---|
194 | *
|
---|
195 | */
|
---|
196 |
|
---|
197 | /** Completely fills the current surface with the specified colour. */
|
---|
198 | public void clear(Colour colour)
|
---|
199 | {
|
---|
200 | // Can't clear to no colour
|
---|
201 | if (colour == null) {
|
---|
202 | return;
|
---|
203 | }
|
---|
204 |
|
---|
205 | Dimension fullSurface = getCurrentDrawingSurfaceSize();
|
---|
206 | Fill fill = new Fill(colour);
|
---|
207 |
|
---|
208 | drawRectangle(new Point(0, 0), fullSurface, 0.0, fill, null, null, null);
|
---|
209 | }
|
---|
210 |
|
---|
211 | /** Draws the given rectangle. */
|
---|
212 | public void drawRectangle(AxisAlignedBoxBounds rect, double angle, Fill fill, Colour borderColour, Stroke borderStroke, Dimension cornerRadius)
|
---|
213 | {
|
---|
214 | if (rect == null) {
|
---|
215 | return;
|
---|
216 | }
|
---|
217 |
|
---|
218 | drawRectangle(rect.getTopLeft(), rect.getSize(), angle, fill, borderColour, borderStroke, cornerRadius);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /** Draws a rectangle specified by the given top-left corner and dimensions. */
|
---|
222 | public abstract void drawRectangle(Point topLeft, Dimension size, double angle, Fill fill, Colour borderColour, Stroke borderStroke, Dimension cornerRadius);
|
---|
223 |
|
---|
224 | /** Draws the given ellipse. */
|
---|
225 | public void drawOval(EllipticalBounds oval, double angle, Fill fill, Colour borderColour, Stroke borderStroke)
|
---|
226 | {
|
---|
227 | if (oval == null) {
|
---|
228 | return;
|
---|
229 | }
|
---|
230 |
|
---|
231 | drawOval(oval.getCentre(), oval.getDiameters(), angle, fill, borderColour, borderStroke);
|
---|
232 | }
|
---|
233 |
|
---|
234 | /** Draws an oval defined by the given centre-point and diameters. */
|
---|
235 | public abstract void drawOval(Point centre, Dimension diameters, double angle, Fill fill, Colour borderColour, Stroke borderStroke);
|
---|
236 |
|
---|
237 | /** Draws a polygon. Fills the closed area but strokes the open line. */
|
---|
238 | public abstract void drawPolygon(PolygonBounds points, Point offset, Dimension scale, double angle, Fill fill, Colour borderColour, Stroke borderStroke);
|
---|
239 |
|
---|
240 | /** Draws the given line. */
|
---|
241 | public void drawLine(Line line, Colour colour, Stroke stroke)
|
---|
242 | {
|
---|
243 | if (line == null) {
|
---|
244 | return;
|
---|
245 | }
|
---|
246 |
|
---|
247 | drawLine(line.getFirstEnd(), line.getSecondEnd(), colour, stroke);
|
---|
248 | }
|
---|
249 |
|
---|
250 | /** Draws a line defined by two end points. */
|
---|
251 | public void drawLine(Point p1, Point p2, Colour colour, Stroke stroke)
|
---|
252 | {
|
---|
253 | if (p1 == null || p2 == null) {
|
---|
254 | return;
|
---|
255 | }
|
---|
256 |
|
---|
257 | drawLine(p1.getX(), p1.getY(), p2.getX(), p2.getY(), colour, stroke);
|
---|
258 | }
|
---|
259 |
|
---|
260 | /** Draws a line defined by two end points. */
|
---|
261 | public abstract void drawLine(int x1, int y1, int x2, int y2, Colour colour, Stroke stroke);
|
---|
262 |
|
---|
263 | /*
|
---|
264 | *
|
---|
265 | * Text-drawing methods.
|
---|
266 | *
|
---|
267 | */
|
---|
268 |
|
---|
269 | /** Draws the given string. */
|
---|
270 | public abstract void drawString(String string, Point position, Font font, Colour colour);
|
---|
271 |
|
---|
272 | /** Draws the text in the given text-layout. */
|
---|
273 | public void drawTextLayout(TextLayout layout, Point position, Colour colour)
|
---|
274 | {
|
---|
275 | drawString(layout.getLine(), position, layout.getFont(), colour);
|
---|
276 | }
|
---|
277 |
|
---|
278 | /*
|
---|
279 | *
|
---|
280 | * Cursor-graphics methods.
|
---|
281 | *
|
---|
282 | */
|
---|
283 |
|
---|
284 | /** TODO: Comment. cts16 */
|
---|
285 | public abstract void setCursor(Cursor cursor);
|
---|
286 |
|
---|
287 | /** TODO: Comment. cts16 */
|
---|
288 | public abstract Dimension getBestCursorSize(Dimension desiredSize);
|
---|
289 |
|
---|
290 | /*
|
---|
291 | *
|
---|
292 | * Dialog box methods.
|
---|
293 | *
|
---|
294 | */
|
---|
295 |
|
---|
296 | /** TODO: Comment. cts16 */
|
---|
297 | public abstract boolean showDialog(String title, String message);
|
---|
298 |
|
---|
299 | /*
|
---|
300 | *
|
---|
301 | * Widget methods.
|
---|
302 | *
|
---|
303 | */
|
---|
304 |
|
---|
305 | /** TODO: Comment. cts16 */
|
---|
306 | protected List<Widget> _widgets;
|
---|
307 |
|
---|
308 | /** TODO: Comment. cts16 */
|
---|
309 | public boolean addInteractiveWidget(Widget iw)
|
---|
310 | {
|
---|
311 | if (iw == null) {
|
---|
312 | return false;
|
---|
313 | }
|
---|
314 |
|
---|
315 | return _widgets.add(iw);
|
---|
316 | }
|
---|
317 |
|
---|
318 | /** TODO: Comment. cts16 */
|
---|
319 | public boolean removeInteractiveWidget(Widget iw)
|
---|
320 | {
|
---|
321 | if (iw == null) {
|
---|
322 | return false;
|
---|
323 | }
|
---|
324 |
|
---|
325 | return _widgets.remove(iw);
|
---|
326 | }
|
---|
327 |
|
---|
328 | /**
|
---|
329 | * Acquire the height of text produced using this font.
|
---|
330 | * @param font
|
---|
331 | * @return
|
---|
332 | */
|
---|
333 | public abstract int getFontHeight(final Font font);
|
---|
334 | }
|
---|