X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fplat%2FAWT.java;h=050f9e7ea5a15f657abb1c7bf8dd79bbfc764a5a;hp=d93758874b684fb9212794f463a71c1828c6aa6b;hb=HEAD;hpb=297fdbde87e6db4732448a0950d1141c7265c169 diff --git a/src/org/ibex/plat/AWT.java b/src/org/ibex/plat/AWT.java index d937588..050f9e7 100644 --- a/src/org/ibex/plat/AWT.java +++ b/src/org/ibex/plat/AWT.java @@ -27,8 +27,7 @@ public class AWT extends JVM { protected void postInit() { if (Log.on) Log.diag(Platform.class, " color depth = " + - Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); - } + Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp"); } protected void _criticalAbort(String message) { if (Log.on) Log.info(this, message); @@ -120,8 +119,8 @@ public class AWT extends JVM { protected org.ibex.graphics.Font.Glyph _createGlyph(org.ibex.graphics.Font f, char c) { return new AWTGlyph(f, c); } protected static class AWTGlyph extends org.ibex.graphics.Font.Glyph { - private Image i = null; - private Image i2 = null; + Image i = null; + Image i2 = null; private static ColorModel cmodel = new DirectColorModel(32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); // this doesn't work on Win32 because the JVM is broken @@ -189,6 +188,27 @@ public class AWT extends JVM { protected static class AWTPixelBuffer implements PixelBuffer { + private int[] xpoints = new int[3]; + private int[] ypoints = new int[3]; + public void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int argb) { + xpoints[0] = x1; + xpoints[1] = x2; + xpoints[2] = x3; + ypoints[0] = y1; + ypoints[1] = y2; + ypoints[2] = y3; + Graphics g = getGraphics(); + g.setColor(new java.awt.Color((argb & 0x00ff0000) >> 16, + (argb & 0x0000ff00) >> 8, + argb & 0x000000ff/*, + (argb & 0xff000000) >> 24*/)); + g.fillPolygon(xpoints, ypoints, 3); + } + + public void drawPicture(Picture p, Affine a, Mesh h) { + throw new Error("drawPicture() not implemented"); + } + protected Image i = null; protected Graphics g = null; protected AWTSurface surface = null; @@ -230,8 +250,8 @@ public class AWT extends JVM { g.drawLine(x1, y1, x2, y2); } - public void stroke(org.ibex.graphics.Polygon p, int color) { p.stroke(this, color); } - public void fill(org.ibex.graphics.Polygon p, org.ibex.graphics.Paint paint) { p.fill(this, paint); } + //public void stroke(org.ibex.graphics.Mesh p, int color) { /*p.stroke(this, color);*/ } + //public void fill(org.ibex.graphics.Mesh p, org.ibex.graphics.Paint paint) { /*p.fill(this, paint);*/ } private static int[] xa = new int[4]; private static int[] ya = new int[4]; @@ -251,8 +271,9 @@ public class AWT extends JVM { } // this doens't seem to work on Windows - public void drawGlyph(org.ibex.graphics.Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, - int rgb, int argb) { + public void drawGlyph(org.ibex.graphics.Font.Glyph source, Affine a, Mesh h, int argb, int bg) { + //throw new Error("drawGlyph() not implemented"); + /* Image i = ((AWTGlyph)source).getImage(); if (((AWTGlyph)source).i2 == null) ((AWTGlyph)source).i2 = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_INT_ARGB); @@ -270,11 +291,12 @@ public class AWT extends JVM { g.fillRect(dx+i2.getWidth(null), cy1, cx2 - (dx+i2.getWidth(null)), cy2 - cy1); g.fillRect(cx1, dy+i2.getHeight(null), cx2 - cx1, cy2 - (dy+i2.getHeight(null))); g.setClip(0, 0, 1000, 1000); + */ } } - protected static class AWTSurface extends Surface.DoubleBufferedSurface + protected static class AWTSurface extends Surface // extends Surface.DoubleBufferedSurface implements MouseListener, MouseMotionListener, KeyListener, ComponentListener, WindowListener { protected AWTPixelBuffer pb = null; @@ -282,6 +304,8 @@ public class AWT extends JVM { Frame frame = null; Window window = null; + public PixelBuffer getPixelBuffer() { return pb==null?(pb=new AWTPixelBuffer(this)):pb; } + public void blit(PixelBuffer source, int sx, int sy, int dx, int dy, int dx2, int dy2) { getGraphics().drawImage(((AWTPixelBuffer)source).i, sx, sy, sx+(dx2-dx), sy+(dy2-dy), dx, dy, dx2, dy2, null); } @@ -297,12 +321,13 @@ public class AWT extends JVM { public void setMinimumSize(int minx, int miny, boolean resizable) { if (frame != null) frame.setResizable(resizable); } public void toBack() { if (window != null) window.toBack(); } public void toFront() { if (window != null) window.toFront(); } - public void setLocation() { window.setLocation(root.x, root.y); } + public void setLocation() { /*window.setLocation(root.x, root.y); FIXME */ } public void setTitleBarText(String s) { if (frame != null) frame.setTitle(s); } public void setIcon(Picture i) { if (frame != null) frame.setIconImage(((AWTPicture)i).i); } public void _setSize(int width, int height) { g = null; - window.setSize(width + (insets.left + insets.right), height + (insets.top + insets.bottom)); } + window.setSize(width + (insets.left + insets.right), height + (insets.top + insets.bottom)); + } public void setInvisible(boolean b) { window.setVisible(!b); } protected void _setMinimized(boolean b) { if (Log.on) Log.info(this, "JDK 1.1 platforms cannot minimize or unminimize windows"); } protected void _setMaximized(boolean b) { @@ -317,29 +342,36 @@ public class AWT extends JVM { class InnerFrame extends Frame { public InnerFrame() throws java.lang.UnsupportedOperationException { } - public Dimension getMinimumSize() { return new Dimension(root.minwidth(), root.minheight()); } - public void update(Graphics gr) { paint(gr); } + public Dimension getMinimumSize() { return new Dimension(root.minwidth, root.minheight); } + public void update(Graphics gr) { + Rectangle r = gr.getClipBounds(); + super.update(gr); + dirtify(r); + } public void paint(Graphics gr) { // Mac OS X Jdk1.4 Bug: after a componentResized(), you must wait for the paint() before you redraw Rectangle r = gr.getClipBounds(); - + super.paint(gr); + dirtify(r); + } + private void dirtify(java.awt.Rectangle r) { + if (r != null) { + Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height); + } else { + Dirty(0, 0, + Math.max(getWidth() - insets.left - insets.right, root.getRootWidth()), + Math.min(getHeight() - insets.top - insets.bottom, root.getRootHeight())); + } // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches expansions during smooth resize - 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); - - //Dirty(r.x - insets.left, r.y - insets.top, r.width, r.height); - g = gr; - blit(r.x - insets.left, r.y - insets.top, r.width, r.height); - g.setClip(0, 0, getWidth(), getHeight()); + int newwidth = Math.max(getWidth() - insets.left - insets.right, root.getRootWidth()); + int newheight = Math.max(getHeight() - insets.top - insets.bottom, root.getRootHeight()); + if (newwidth != root.getRootWidth() || newheight != root.getRootHeight()) componentResized(newwidth, newheight); } } class InnerWindow extends Window { public InnerWindow() throws java.lang.UnsupportedOperationException { super(new Frame()); } - public Dimension getMinimumSize() { return new Dimension(root.minwidth(), root.minheight()); } + public Dimension getMinimumSize() { return new Dimension(root.minwidth, root.minheight); } public void update(Graphics gr) { paint(gr); } public void paint(Graphics gr) { g = null; @@ -351,6 +383,7 @@ public class AWT extends JVM { private int oldfill = 0x0; public void render() { // useful optimizatin; + /* if (oldfill != root.fillcolor) { oldfill = root.fillcolor; window.setBackground((root.fillcolor & 0xFF000000) == 0 ? @@ -359,9 +392,16 @@ public class AWT extends JVM { (root.fillcolor >> 8) & 0xff, (root.fillcolor) & 0xff)); } + */ super.render(); } + Insets getInsets() { + Insets ret = window.getInsets(); + if (System.getProperty("os.name", "").equals("Mac OS X")) ret.bottom = -1 * ret.top; + return ret; + } + AWTSurface(Box root, boolean framed) { super(root); try { @@ -374,7 +414,7 @@ public class AWT extends JVM { if (Log.on) Log.info(this, e); } - insets = window.getInsets(); + insets = getInsets(); window.addMouseListener(this); window.addKeyListener(this); @@ -433,21 +473,22 @@ public class AWT extends JVM { public void windowClosed(WindowEvent e) { } public void windowClosing(WindowEvent e) { Close(); } public void windowIconified(WindowEvent e) { Minimized(true); } - public void windowDeiconified(WindowEvent e) { dirty(0, 0, root.width, root.height); Minimized(false); } + public void windowDeiconified(WindowEvent e) { dirty(0, 0, root.getRootWidth(), root.getRootHeight()); Minimized(false); } public void windowActivated(WindowEvent e) { Focused(true); } public void windowDeactivated(WindowEvent e) { Focused(false); } public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x + insets.left, window.getLocation().y + insets.top); } public void componentResized(ComponentEvent e) { // we have to periodically do this; I don't know why - insets = window.getInsets(); + insets = getInsets(); componentResized(window.getWidth() - insets.left - insets.right, window.getHeight() - insets.top - insets.bottom); } public void componentResized(int newwidth, int newheight) { SizeChange(newwidth, newheight); - //if (newwidth > root.width) Dirty(root.width, 0, newwidth-root.width, newheight); - //if (newheight > root.height) Dirty(0, root.height, newwidth, newheight-root.height); + if (newwidth > root.getRootWidth()) Dirty(root.getRootWidth(), 0, newwidth-root.getRootWidth(), newheight); + if (newheight > root.getRootHeight()) Dirty(0, root.getRootHeight(), newwidth, newheight-root.getRootHeight()); + Refresh(); } public void keyTyped(KeyEvent k) { } @@ -461,7 +502,7 @@ public class AWT extends JVM { // ugly hack for Java1.4 dynamicLayout on Win32 -- this catches contractions during smooth resize int newwidth = window.getWidth() - insets.left - insets.right; int newheight = window.getHeight() - insets.top - insets.bottom; - if (newwidth != root.width || newheight != root.height) componentResized(newwidth, newheight); + if (newwidth != root.getRootWidth() || newheight != root.getRootHeight()) componentResized(newwidth, newheight); Move(m.getX() - insets.left, m.getY() - insets.top); }