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

Last change on this file since 1198 was 1198, checked in by bln4, 5 years ago

org.expeditee.gio.GraphicsManager ->
org.expeditee.gio.javafx.JavaFXGraphicsManager ->
org.expeditee.gio.swing.SwingGraphicsManager ->

Graphics managers can be now consulted to obtain the height of a character in a given font.

File size: 8.8 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.EnforcedClipStack.EnforcedClipKey;
12import org.expeditee.core.Fill;
13import org.expeditee.core.Font;
14import org.expeditee.core.Image;
15import org.expeditee.core.Line;
16import org.expeditee.core.Point;
17import org.expeditee.core.Stroke;
18import org.expeditee.core.TextLayout;
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 == "") {
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 /** Sets the default font for the current rendering surface. */
159 public abstract void setFont(Font font);
160
161 /*
162 *
163 * Image-drawing methods.
164 *
165 */
166
167 /** Draws the given image at its natural size at the given location. */
168 public void drawImage(Image image, Point topLeft)
169 {
170 drawImage(image, topLeft, null);
171 }
172
173 /** Draws the given image at the given size. */
174 public void drawImage(Image image, Point topLeft, Dimension size)
175 {
176 drawImage(image, topLeft, size, 0.0f);
177 }
178
179 /** Draws the given image rotated about its top-left corner by the given angle. */
180 public void drawImage(Image image, Point topLeft, Dimension size, double angle)
181 {
182 drawImage(image, topLeft, size, angle, null, null);
183 }
184
185 /** Draws the given cropped area of the given image. */
186 public abstract void drawImage(Image image, Point topLeft, Dimension size, double angle, Point cropTopLeft, Dimension cropSize);
187
188 /*
189 *
190 * Shape-drawing methods.
191 *
192 */
193
194 /** Completely fills the current surface with the specified colour. */
195 public void clear(Colour colour)
196 {
197 // Can't clear to no colour
198 if (colour == null) {
199 return;
200 }
201
202 Dimension fullSurface = getCurrentDrawingSurfaceSize();
203 Fill fill = new Fill(colour);
204
205 drawRectangle(new Point(0, 0), fullSurface, 0.0, fill, null, null, null);
206 }
207
208 /** Draws the given rectangle. */
209 public void drawRectangle(AxisAlignedBoxBounds rect, double angle, Fill fill, Colour borderColour, Stroke borderStroke, Dimension cornerRadius)
210 {
211 if (rect == null) {
212 return;
213 }
214
215 drawRectangle(rect.getTopLeft(), rect.getSize(), angle, fill, borderColour, borderStroke, cornerRadius);
216 }
217
218 /** Draws a rectangle specified by the given top-left corner and dimensions. */
219 public abstract void drawRectangle(Point topLeft, Dimension size, double angle, Fill fill, Colour borderColour, Stroke borderStroke, Dimension cornerRadius);
220
221 /** Draws the given ellipse. */
222 public void drawOval(EllipticalBounds oval, double angle, Fill fill, Colour borderColour, Stroke borderStroke)
223 {
224 if (oval == null) {
225 return;
226 }
227
228 drawOval(oval.getCentre(), oval.getDiameters(), angle, fill, borderColour, borderStroke);
229 }
230
231 /** Draws an oval defined by the given centre-point and diameters. */
232 public abstract void drawOval(Point centre, Dimension diameters, double angle, Fill fill, Colour borderColour, Stroke borderStroke);
233
234 /** Draws a polygon. Fills the closed area but strokes the open line. */
235 public abstract void drawPolygon(PolygonBounds points, Point offset, Dimension scale, double angle, Fill fill, Colour borderColour, Stroke borderStroke);
236
237 /** Draws the given line. */
238 public void drawLine(Line line, Colour colour, Stroke stroke)
239 {
240 if (line == null) {
241 return;
242 }
243
244 drawLine(line.getFirstEnd(), line.getSecondEnd(), colour, stroke);
245 }
246
247 /** Draws a line defined by two end points. */
248 public void drawLine(Point p1, Point p2, Colour colour, Stroke stroke)
249 {
250 if (p1 == null || p2 == null) {
251 return;
252 }
253
254 drawLine(p1.getX(), p1.getY(), p2.getX(), p2.getY(), colour, stroke);
255 }
256
257 /** Draws a line defined by two end points. */
258 public abstract void drawLine(int x1, int y1, int x2, int y2, Colour colour, Stroke stroke);
259
260 /*
261 *
262 * Text-drawing methods.
263 *
264 */
265
266 /** Draws the given string. */
267 public abstract void drawString(String string, Point position, Font font, Colour colour);
268
269 /** Draws the text in the given text-layout. */
270 public void drawTextLayout(TextLayout layout, Point position, Colour colour)
271 {
272 drawString(layout.getLine(), position, layout.getFont(), colour);
273 }
274
275 /*
276 *
277 * Cursor-graphics methods.
278 *
279 */
280
281 /** TODO: Comment. cts16 */
282 public abstract void setCursor(Cursor cursor);
283
284 /** TODO: Comment. cts16 */
285 public abstract Dimension getBestCursorSize(Dimension desiredSize);
286
287 /*
288 *
289 * Dialog box methods.
290 *
291 */
292
293 /** TODO: Comment. cts16 */
294 public abstract boolean showDialog(String title, String message);
295
296 /*
297 *
298 * Widget methods.
299 *
300 */
301
302 /** TODO: Comment. cts16 */
303 protected List<Widget> _widgets;
304
305 /** TODO: Comment. cts16 */
306 public boolean addInteractiveWidget(Widget iw)
307 {
308 if (iw == null) {
309 return false;
310 }
311
312 return _widgets.add(iw);
313 }
314
315 /** TODO: Comment. cts16 */
316 public boolean removeInteractiveWidget(Widget iw)
317 {
318 if (iw == null) {
319 return false;
320 }
321
322 return _widgets.remove(iw);
323 }
324
325 /**
326 * Acquire the height of text produced using this font.
327 * @param font
328 * @return
329 */
330 public abstract int getFontHeight(final Font font);
331}
Note: See TracBrowser for help on using the repository browser.