2003/10/28 10:10:18
[org.ibex.core.git] / src / org / xwt / plat / AWT.java
index 771bdbb..fd9703b 100644 (file)
@@ -126,11 +126,11 @@ 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);
+            mediatracker.removeImage(i);
             synchronized(AWTPixelBuffer.class) { 
                 if (AWTPixelBuffer.component == null) {
                     AWTPixelBuffer.component = new Frame();
@@ -138,8 +138,6 @@ public class AWT extends JVM {
                     AWTPixelBuffer.component.addNotify();
                 }
             }
-            this.i = AWTPixelBuffer.component.createImage(w, h);
-            this.i.getGraphics().drawImage(img, 0, 0, null);
         }
     }
     
@@ -166,24 +164,32 @@ 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 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);
-        }
-        
-        public void drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2,
-                                         int sx1, int sy1, int sx2, int sy2, int rgb) {
-            AWTPicture p = (AWTPicture)source;
-            Graphics g = p.i.getGraphics();
-            g.setXORMode(new Color(rgb));
-            g.fillRect(0, 0, p.i.getWidth(null), p.i.getHeight(null));
-            drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);
-            g.fillRect(0, 0, p.i.getWidth(null), p.i.getHeight(null));
+        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 fillRect(int x, int y, int x2, int y2, int argb) {
-            // FEATURE: use an LRU cache for Color objects
+        /** 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();
         }
 
         // FIXME: try to use os acceleration
@@ -235,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) {