2003/10/28 10:10:18
[org.ibex.core.git] / src / org / xwt / plat / AWT.java
index 6850927..fd9703b 100644 (file)
@@ -20,9 +20,10 @@ public class AWT extends JVM {
     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); }
-    protected boolean _supressDirtyOnResize() { return false; }
 
     protected void postInit() {
+        System.setProperty("com.apple.mrj.application.live-resize", "true");
+        System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
         if (Log.on) Log.log(Platform.class, "               color depth = " + Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp");
     }
 
@@ -108,7 +109,7 @@ public class AWT extends JVM {
         final Semaphore s = new Semaphore();
         FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, write);
         s.block();
-        return fd.getDirectory() + File.separatorChar + fd.getFile();
+        return fd.getDirectory() == null ? null : (fd.getDirectory() + File.separatorChar + fd.getFile());
     }
 
 
@@ -125,12 +126,18 @@ public class AWT extends JVM {
         
         public AWTPicture(int[] b, int w, int h) {
             data = b;
-            Image img = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, cmodel, b, 0, w));
+            i = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, cmodel, b, 0, w));
             MediaTracker mediatracker = new MediaTracker(new Canvas());
-            mediatracker.addImage(img, 1);
+            mediatracker.addImage(i, 1);
             try { mediatracker.waitForAll(); } catch (InterruptedException e) { }
-            mediatracker.removeImage(img);
-            this.i = img;
+            mediatracker.removeImage(i);
+            synchronized(AWTPixelBuffer.class) { 
+                if (AWTPixelBuffer.component == null) {
+                    AWTPixelBuffer.component = new Frame();
+                    AWTPixelBuffer.component.setVisible(false);
+                    AWTPixelBuffer.component.addNotify();
+                }
+            }
         }
     }
     
@@ -157,22 +164,48 @@ public class AWT extends JVM {
         
         public int getHeight() { return i == null ? 0 : i.getHeight(null); }
         public int getWidth() { return i == null ? 0 : i.getWidth(null); }
-        public void setClip(int x, int y, int x2, int y2) { g.setClip(x, y, x2 - x, y2 - y); }
 
-        public void drawPicture(Picture source, int x, int y) {
-            drawPicture(source, x, y, x + source.getWidth(), y + source.getHeight(), 0, 0, source.getWidth(), source.getHeight());
+        public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
+            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));
         }
 
-        public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) {
-            g.drawImage(((AWTPicture)source).i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, 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) {
+
+            // XOR the target region
+            g.setXORMode(new Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
+            g.setColor(new Color(0x0, 0x0, 0x0));
+            g.fillRect(cx1, cy1, cx2 - cx1, cy2 - cy1);
+
+            // blacken the area we want the glyph to cover
+            g.setPaintMode();
+            drawPicture(source, dx, dy, cx1, cy1, cx2, cy2);
+
+            // XOR back, turning black into the chosen rgb color
+            g.setXORMode(new Color((rgb & 0x00ff0000) >> 16, (rgb & 0x0000ff00) >> 8, rgb & 0x000000ff));
+            g.setColor(new Color(0x0, 0x0, 0x0));
+            g.fillRect(cx1, cy1, cx2 - cx1, cy2 - cy1);
+
+            // restore the graphics context
+            g.setPaintMode();
         }
-        
-        public void fillRect(int x, int y, int x2, int y2, int argb) {
-            // FEATURE: use an LRU cache for Color objects
+
+        // FIXME: try to use os acceleration
+        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)));
-            g.fillRect(x, y, x2 - x, y2 - y);
+            if (x1 == x3 && x2 == x4) {
+                g.fillRect(x1, y1, x4 - x1, y2 - y1);
+            } else for(int y=y1; y<y2; y++) {
+                int _x1 = (int)Math.floor((y - y1) * (x3 - x1) / (y2 - y1) + x1);
+                int _y1 = (int)Math.floor(y);
+                int _x2 = (int)Math.ceil((y - y1) * (x4 - x2) / (y2 - y1) + x2);
+                int _y2 = (int)Math.floor(y) + 1;
+                if (_x1 > _x2) { int _x0 = _x1; _x1 = _x2; _x2 = _x0; }
+                g.fillRect(_x1, _y1, _x2 - _x1, _y2 - _y1);
+            }
         }
-
     }
     
     
@@ -181,7 +214,12 @@ public class AWT extends JVM {
 
         public void blit(PixelBuffer s, int sx, int sy, int dx, int dy, int dx2, int dy2) {
             if (ourGraphics == null) ourGraphics = window.getGraphics();
-            ourGraphics.drawImage(((AWTPixelBuffer)s).i, dx + insets.left, dy + insets.top, dx2 + insets.left, dy2 + insets.top,
+            insets = (frame == null ? window : frame).getInsets();
+            ourGraphics.drawImage(((AWTPixelBuffer)s).i,
+                                  dx + insets.left,
+                                  dy + insets.top,
+                                  dx2 + insets.left,
+                                  dy2 + insets.top,
                                   sx, sy, sx + (dx2 - dx), sy + (dy2 - dy), null);
         }
         
@@ -203,7 +241,7 @@ public class AWT extends JVM {
         public void setLocation() { window.setLocation(root.x, root.y); }
         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) { window.setSize(width + (insets.left + insets.right), height + (insets.top + insets.bottom)); }
+        public void _setSize(int width, int height) { 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.log(this, "JDK 1.1 platforms cannot minimize or unminimize windows"); }
         protected void _setMaximized(boolean b) {
@@ -314,7 +352,7 @@ public class AWT extends JVM {
         public void windowDeiconified(WindowEvent e) { dirty(0, 0, root.width, root.height); 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 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
@@ -374,7 +412,7 @@ public class AWT extends JVM {
             case KeyEvent.VK_F3: return "f3";
             case KeyEvent.VK_F4: return "f4";
             case KeyEvent.VK_F5: return "f5";
-            case KeyEvent.VK_F6: return "f6";
+            case KeyEvent.VK_F6: return "f6"; 
             case KeyEvent.VK_F7: return "f7";
             case KeyEvent.VK_F8: return "f8";
             case KeyEvent.VK_F9: return "f9";