config/i386/cygming.h (DWARF2_UNWIND_INFO): Handle 64-bit
[official-gcc.git] / libjava / gnu / awt / j2d / IntegerGraphicsState.java
blobbcfacd008f068637a7fd45d8d8ebfd6f336d21b4
1 /* Copyright (C) 2000, 2003 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 package gnu.awt.j2d;
11 import java.awt.Color;
12 import java.awt.Image;
13 import java.awt.Shape;
14 import java.awt.Rectangle;
15 import java.awt.Graphics;
16 import java.awt.Graphics2D;
17 import java.awt.GraphicsConfiguration;
18 import java.awt.Font;
19 import java.awt.FontMetrics;
20 import java.awt.image.BufferedImage;
21 import java.awt.image.ImageObserver;
22 import java.awt.image.Raster;
23 import java.awt.image.WritableRaster;
24 import java.awt.image.ColorModel;
26 /**
27 * IntegerGraphicsState is one of several graphics state
28 * implementations. This graphics state is used when the graphics
29 * object has simple properties, (coordinate translation only, no
30 * transform) and the backend supports integer coordinates (pixel
31 * based). For primitive paint operations, this object translates the
32 * coordinates and forwards the request to the backend. For requests
33 * to draw arbitrary shapes and paths, this object translates the
34 * requests to primitive drawing operations supported by the
35 * backend. IntegerGraphicsState is meant to support the most common
36 * state of an graphics object. The degree of functionality is roughly
37 * equivalent with the old java.awt.Graphics API.
39 public class IntegerGraphicsState extends AbstractGraphicsState
41 int tx;
42 int ty;
44 DirectRasterGraphics directGfx;
45 Shape clip;
47 /** Interface for images which are coupled to a GraphicsConfiguration,
48 * as is typically the case for an off-screen buffer used in
49 * double-buffering. Any image which implements this interface is
50 * rendered directly by DirectRasterGraphics (i.e. by directGfx.drawImage)
52 public interface ScreenCoupledImage
54 /** Get the GraphicsConfiguration to which this image is coupled
55 * @return the GraphicsConfiguration
57 GraphicsConfiguration getGraphicsConfiguration ();
60 public IntegerGraphicsState(DirectRasterGraphics directGfx)
62 this.directGfx = directGfx;
65 public Object clone()
67 IntegerGraphicsState clone = (IntegerGraphicsState) super.clone();
68 clone.directGfx = (DirectRasterGraphics) directGfx.clone();
70 return clone;
73 public void dispose()
75 DirectRasterGraphics lDeviceGfx = directGfx;
77 directGfx = null;
79 if (lDeviceGfx != null)
80 lDeviceGfx.dispose();
82 super.dispose();
85 // -------- Graphics methods:
87 public void setColor(Color color)
89 directGfx.setColor(color);
92 public void setPaintMode()
94 directGfx.setPaintMode();
97 public void setXORMode(Color altColor)
99 directGfx.setXORMode(altColor);
102 public void setFont(Font font)
104 directGfx.setFont(font);
107 public FontMetrics getFontMetrics(Font font)
109 return directGfx.getFontMetrics(font);
112 public void setClip(Shape clip)
114 if (clip instanceof Rectangle)
116 Rectangle clipRect = (Rectangle) ((Rectangle) clip).clone();
117 clipRect.x += tx;
118 clipRect.y += ty;
120 this.clip = clipRect;
122 directGfx.setClip(clipRect);
123 return;
126 String msg =
127 "translating clip shape " + clip + " into device " +
128 "coordinate space has not been implemented yet";
130 throw new UnsupportedOperationException(msg);
133 public Shape getClip()
135 if (clip == null)
136 return null;
137 if (clip instanceof Rectangle)
139 Rectangle clipRect = (Rectangle) ((Rectangle) clip).clone();
140 clipRect.x -= tx;
141 clipRect.y -= ty;
142 return clipRect;
145 String msg =
146 "translating clip shape " + clip + " into user " +
147 "coordinate space has not been implemented yet";
149 throw new UnsupportedOperationException(msg);
152 public Rectangle getClipBounds()
154 if (clip == null)
155 return null;
156 Rectangle clipRect = clip.getBounds();
158 clipRect.x -= tx;
159 clipRect.y -= ty;
160 return clipRect;
163 public void copyArea(int x, int y,
164 int width, int height,
165 int dx, int dy)
167 directGfx.copyArea(x+tx, y+ty, width, height, dx, dy);
170 public void drawLine(int x1, int y1,
171 int x2, int y2)
173 directGfx.drawLine(x1+tx, y1+ty, x2+tx, y2+ty);
176 public void fillRect(int x, int y,
177 int width, int height)
179 directGfx.fillRect(x+tx, y+ty, width, height);
182 public void clearRect(int x, int y,
183 int width, int height)
185 directGfx.setColor(frontend.getBackground());
186 directGfx.fillRect(x+tx, y+ty, width, height);
187 directGfx.setColor(frontend.getColor());
190 public void drawRoundRect(int x, int y,
191 int width, int height,
192 int arcWidth, int arcHeight)
194 throw new UnsupportedOperationException("not implemented yet");
197 public void fillRoundRect(int x, int y,
198 int width, int height,
199 int arcWidth, int arcHeight)
201 throw new UnsupportedOperationException("not implemented yet");
204 public void drawOval(int x, int y,
205 int width, int height)
207 drawArc (x, y, width, height, 0, 360);
210 public void fillOval(int x, int y,
211 int width, int height)
213 fillArc (x, y, width, height, 0, 360);
216 public void drawArc(int x, int y,
217 int width, int height,
218 int startAngle, int arcAngle)
220 directGfx.drawArc(x+tx, y+ty, width, height, startAngle, arcAngle);
223 public void fillArc(int x, int y,
224 int width, int height,
225 int startAngle, int arcAngle)
227 directGfx.fillArc(x+tx, y+ty, width, height, startAngle, arcAngle);
230 public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints)
232 if ((tx == 0) && (ty == 0))
234 directGfx.drawPolyline(xPoints, yPoints, nPoints);
235 return;
238 throw new UnsupportedOperationException("translate not implemented");
241 public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
243 if ((tx == 0) && (ty == 0))
245 directGfx.drawPolygon(xPoints, yPoints, nPoints);
246 return;
249 throw new UnsupportedOperationException("translate not implemented");
252 public void fillPolygon (int[] xPoints, int[] yPoints, int nPoints)
254 // FIXME: remove tx & ty args once translation via AffineTransform
255 // is implemented.
256 directGfx.fillPolygon (xPoints, yPoints, nPoints, tx, ty);
259 public boolean drawImage(Image image, int x, int y,
260 ImageObserver observer)
262 x += tx;
263 y += ty;
265 if (image instanceof ScreenCoupledImage)
267 GraphicsConfiguration config
268 = ((ScreenCoupledImage)image).getGraphicsConfiguration ();
269 if (config == frontend.config)
270 return directGfx.drawImage (image, x, y, observer);
272 if (image instanceof BufferedImage)
274 BufferedImage bImage = (BufferedImage) image;
275 // FIXME: eliminate? ScreenCoupledImage is probably more efficient
276 Object config = bImage.getProperty ("java.awt.GraphicsConfiguration");
277 if (config == frontend.config)
278 return directGfx.drawImage (image, x, y, observer);
280 int width = image.getWidth (null);
281 int height = image.getHeight (null);
283 Rectangle bounds = new Rectangle (x, y, width, height);
285 MappedRaster mr = directGfx.mapRaster (bounds);
287 // manipulate raster here...
288 ColorModel colorModel = mr.getColorModel ();
289 WritableRaster raster = mr.getRaster ();
291 int xEnd = x + width;
292 int yEnd = y + height;
294 // FIXME: Use the following code only as a fallback. It's SLOW!
296 Object rgbElem = null;
297 for (int yy=0; yy<height; yy++)
299 for (int xx=0; xx<width; xx++)
301 int srgb = bImage.getRGB (xx, yy);
302 int sa = ((srgb >>> 24) & 0xff) + 1;
303 int sr = ((srgb >>> 16) & 0xff) + 1;
304 int sg = ((srgb >>> 8) & 0xff) + 1;
305 int sb = (srgb & 0xff) + 1;
307 rgbElem = raster.getDataElements (xx+x, yy+y, rgbElem);
308 int drgb = colorModel.getRGB (rgbElem);
309 int dr = ((drgb >>> 16) & 0xff) + 1;
310 int dg = ((drgb >>> 8) & 0xff) + 1;
311 int db = (drgb & 0xff) + 1;
312 int da = 256 - sa;
314 dr = ((sr*sa + dr*da) >>> 8) - 1;
315 dg = ((sg*sa + dg*da) >>> 8) - 1;
316 db = ((sb*sa + db*da) >>> 8) - 1;
318 drgb = (dr<<16) | (dg<<8) | db;
320 rgbElem = colorModel.getDataElements (drgb, rgbElem);
322 raster.setDataElements (xx+x, yy+y, rgbElem);
325 directGfx.unmapRaster (mr);
326 return true;
329 throw new UnsupportedOperationException ("drawing image " + image +
330 "not implemented");
334 // -------- Graphics2D methods:
336 public void draw(Shape shape)
338 if (shape instanceof Rectangle)
340 Rectangle rect = (Rectangle) shape;
341 directGfx.drawRect(rect.x+tx, rect.y+ty, rect.width, rect.height);
342 return;
345 throw new UnsupportedOperationException("shape not implemented");
348 public void fill(Shape shape)
350 if (shape instanceof Rectangle)
352 Rectangle rect = (Rectangle) shape;
353 directGfx.fillRect(rect.x+tx, rect.y+ty, rect.width, rect.height);
354 return;
357 throw new UnsupportedOperationException("not implemented");
360 public boolean hit(Rectangle rect, Shape text,
361 boolean onStroke)
363 throw new UnsupportedOperationException("not implemented");
366 public void drawString(String text, int x, int y)
368 directGfx.drawString(text, x+tx, y+ty);
371 public void drawString(String text, float x, float y)
373 drawString(text, (int) x, (int) y);
376 public void translate(int x, int y)
378 tx += x;
379 ty += y;
382 public void translate(double tx, double ty)
384 if ((tx == 0) && (ty == 0))
385 return;
387 needAffineTransform();
390 public void rotate(double theta)
392 if (theta == 0)
393 return;
395 needAffineTransform();
398 public void rotate(double theta, double x, double y)
400 if (theta == 0)
401 return;
403 needAffineTransform();
406 public void scale(double scaleX, double scaleY)
408 if ((scaleX == 1) && (scaleY == 1))
409 return;
411 needAffineTransform();
414 public void shear(double shearX, double shearY)
416 if ((shearX == 0) && (shearY == 0))
417 return;
419 needAffineTransform();
422 private void needAffineTransform()
424 throw new UnsupportedOperationException("state with affine " +
425 "transform not implemented");