source: trunk/src/org/expeditee/gio/GraphicsManager.java@ 1097

Last change on this file since 1097 was 1097, checked in by davidb, 6 years ago

Newly structured files from Corey's work on logic/graphics separation

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