protected String getDescriptiveName() { return "Generic JDK 1.1+ with AWT"; }
protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new AWTPixelBuffer(w, h); }
- protected Picture _createPicture(int[] b, int w, int h) { return new AWTPicture(b, w, h); }
+ protected Picture _createPicture(Res r) { return new AWTPicture(r); }
protected int _getScreenWidth() { return Toolkit.getDefaultToolkit().getScreenSize().width; }
protected int _getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().height; }
protected Surface _createSurface(Box b, boolean framed) { return new AWTSurface(b, framed); }
// Inner Classes /////////////////////////////////////////////////////////////////////////////////////
- protected static class AWTPicture extends Picture {
- public int getHeight() { return i.getHeight(null); }
- public int getWidth() { return i.getWidth(null); }
- public int[] getData() { return data; }
+ protected org.xwt.Font.Glyph _createGlyph(org.xwt.Font f, char c) { return new AWTGlyph(f, c); }
+ protected static class AWTGlyph extends org.xwt.Font.Glyph {
+ private Image i = null;
+ static ColorModel cmodel = new DirectColorModel(8, 0x00000000, 0x00000000, 0x00000000, 0xFF);
+ public AWTGlyph(org.xwt.Font f, char c) { super(f, c); }
+ Image getImage() {
+ if (i == null && isLoaded) {
+ i = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(width, height, cmodel, data, 0, width));
+ MediaTracker mediatracker = new MediaTracker(new Canvas());
+ mediatracker.addImage(i, 1);
+ try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
+ mediatracker.removeImage(i);
+ synchronized(AWTPixelBuffer.class) {
+ if (AWTPixelBuffer.component == null) {
+ AWTPixelBuffer.component = new Frame();
+ AWTPixelBuffer.component.setVisible(false);
+ AWTPixelBuffer.component.addNotify();
+ }
+ }
+ data = null;
+ }
+ return i;
+ }
+ }
- int[] data = null;
+ protected static class AWTPicture extends Picture {
public Image i = null;
private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
- public AWTPicture(int[] b, int w, int h) {
- data = b;
- i = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, cmodel, b, 0, w));
+ boolean initialized = false;
+ public AWTPicture(Res r) { super(r); }
+ public void init() {
+ if (initialized) return;
+ initialized = true;
+ i = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(width, height, cmodel, data, 0, width));
MediaTracker mediatracker = new MediaTracker(new Canvas());
mediatracker.addImage(i, 1);
try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
public int getWidth() { return i == null ? 0 : i.getWidth(null); }
public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
+ ((AWTPicture)source).init();
g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
g.drawImage(((AWTPicture)source).i, dx, dy, null);
g.setClip(0, 0, i.getWidth(null), i.getHeight(null));
}
/** implemented with java.awt 1.1's setXORMode() */
- public void drawPictureAlphaOnly(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
+ public void drawGlyph(org.xwt.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int rgb) {
// XOR the target region
g.setXORMode(new Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
// blacken the area we want the glyph to cover
g.setPaintMode();
- drawPicture(source, dx, dy, cx1, cy1, cx2, cy2);
+ g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1);
+ g.drawImage(((AWTGlyph)source).getImage(), dx, dy, null);
+ g.setClip(0, 0, i.getWidth(null), i.getHeight(null));
// XOR back, turning black into the chosen rgb color
g.setXORMode(new Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
}
// FIXME: try to use os acceleration
- public void fillJSTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) {
+ public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int argb) {
g.setColor(new Color((argb & 0x00FF0000) >> 16, (argb & 0x0000FF00) >> 8, (argb & 0x000000FF)));
if (x1 == x3 && x2 == x4) {
g.fillRect(x1, y1, x4 - x1, y2 - y1);
int newwidth = Math.max(r.x - insets.left + r.width, root.width);
int newheight = Math.max(r.y - insets.top + r.height, root.height);
if (newwidth > root.width || newheight > root.height)
- componentResized(window.getWidth() - insets.left - insets.right, window.getHeight() - insets.top - insets.bottom);
+ componentResized(window.getWidth() - insets.left - insets.right,
+ window.getHeight() - insets.top - insets.bottom);
Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height);
}
AWTSurface(Box root, boolean framed) {
super(root);
- System.out.println("Y");
try {
if (framed) window = frame = new InnerFrame();
else window = new InnerWindow();
}
}
- protected Picture _decodeJPEG(InputStream is, String name) {
+ protected void _decodeJPEG(InputStream is, Picture p) {
try {
Image i = Toolkit.getDefaultToolkit().createImage(InputStreamToByteArray.convert(is));
MediaTracker mediatracker = new MediaTracker(new Canvas());
final int[] data = new int[width * height];
PixelGrabber pg = new PixelGrabber(i, 0, 0, width, height, data, 0, width);
pg.grabPixels();
- if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
- Log.log(this, "PixelGrabber reported an error while decoding JPEG image " + name);
- return null;
- }
- return Platform.createPicture(data, width, height);
+ if ((pg.getStatus() & ImageObserver.ABORT) != 0)
+ Log.log(this, "PixelGrabber reported an error while decoding JPEG image");
+ p.width = width;
+ p.height = height;
+ p.data = data;
} catch (Exception e) {
- Log.log(this, "Exception caught while decoding JPEG image " + name);
+ Log.log(this, "Exception caught while decoding JPEG image");
Log.log(this, e);
- return null;
}
}
}