fix bug that prevented scar image from loading
authoradam <adam@megacz.com>
Sun, 16 Jan 2005 07:07:50 +0000 (07:07 +0000)
committeradam <adam@megacz.com>
Sun, 16 Jan 2005 07:07:50 +0000 (07:07 +0000)
darcs-hash:20050116070750-5007d-49ca5aed20c1421b4a60393f51f4604ed9046ca8.gz

src/org/ibex/core/Box.java
src/org/ibex/core/Ibex.java
src/org/ibex/core/Main.java
src/org/ibex/graphics/Picture.java

index 0ccd421..5133251 100644 (file)
@@ -60,11 +60,7 @@ public final class Box extends JS.Obj implements Callable {
     // FIXME memory leak
     static Basket.Map boxToCursor = new Basket.Hash(500, 3);
 
     // FIXME memory leak
     static Basket.Map boxToCursor = new Basket.Hash(500, 3);
 
-    static final Font DEFAULT_FONT;
-    static {
-        try { DEFAULT_FONT = Font.getFont((JS)Main.builtin.get(JSU.S("fonts/vera/Vera.ttf")), 10); }
-        catch(JSExn e) { throw new Error("Error loading default font: " + e); }
-    }
+    public static final Font DEFAULT_FONT = Font.getFont(Main.vera, 10);
 
 
     // Flags //////////////////////////////////////////////////////////////////////
 
 
     // Flags //////////////////////////////////////////////////////////////////////
index 4110a8d..5efc608 100644 (file)
@@ -74,9 +74,9 @@ public final class Ibex extends JS.Obj implements JS.Cloneable {
         case "ui.font.wait": return METHOD;
         case "ui.font.width": return METHOD;
         case "ui.font.height": return METHOD;
         case "ui.font.wait": return METHOD;
         case "ui.font.width": return METHOD;
         case "ui.font.height": return METHOD;
-        case "ui.font.sansserif": return Main.builtin.get(JSU.S("fonts/vera/Vera.ttf"));
-        case "ui.font.monospace": return Main.builtin.get(JSU.S("fonts/vera/VeraMono.ttf"));
-        case "ui.font.serif": return Main.builtin.get(JSU.S("fonts/vera/VeraSe.ttf"));
+        case "ui.font.sansserif": return Main.vera;
+        case "ui.font.monospace": return Main.vera;
+        case "ui.font.serif": return Main.vera;
         case "ui.browser": return METHOD;
         case "ui.mouse": return getSub(name);
         case "ui.mouse.button":
         case "ui.browser": return METHOD;
         case "ui.mouse": return getSub(name);
         case "ui.mouse.button":
@@ -370,7 +370,7 @@ public final class Ibex extends JS.Obj implements JS.Cloneable {
     // FEATURE: move this into builtin.xwar
     public Blessing bless(JS b) throws JSExn { return new Ibex.Blessing(b, this, null, null); }
     // JS:FIXME: This doesn't properly handle traps
     // FEATURE: move this into builtin.xwar
     public Blessing bless(JS b) throws JSExn { return new Ibex.Blessing(b, this, null, null); }
     // JS:FIXME: This doesn't properly handle traps
-    public static class Blessing extends JS.Obj {
+    public static class Blessing extends JS.Clone {
         private Ibex ibex;
         private Template t = null;
         public JS parentkey = null;
         private Ibex ibex;
         private Template t = null;
         public JS parentkey = null;
@@ -378,16 +378,15 @@ public final class Ibex extends JS.Obj implements JS.Cloneable {
         public JS clonee;
         private Basket.Map cache = new Basket.Hash(); 
         public Blessing(JS clonee, Ibex ibex, Blessing parent, JS parentkey) throws JSExn {
         public JS clonee;
         private Basket.Map cache = new Basket.Hash(); 
         public Blessing(JS clonee, Ibex ibex, Blessing parent, JS parentkey) throws JSExn {
-            this.clonee = clonee; this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; }
+            super(clonee); this.clonee = clonee; this.ibex = ibex; this.parentkey = parentkey; this.parent = parent; }
         public JS get(JS key) throws JSExn {
             if (JSU.isString(key) && JSU.toString(key).equals("")) return getStatic();
             if (cache.get(key) != null) return (JS)cache.get(key);
         public JS get(JS key) throws JSExn {
             if (JSU.isString(key) && JSU.toString(key).equals("")) return getStatic();
             if (cache.get(key) != null) return (JS)cache.get(key);
-            JS ret = new Blessing(clonee.get(key), ibex, this, key);
+            JS ret = new Blessing(super.get(key), ibex, this, key);
             cache.put(key, ret);
             return ret;
         }
         public static Blessing getBlessing(JS js) {
             cache.put(key, ret);
             return ret;
         }
         public static Blessing getBlessing(JS js) {
-            // CHECKME: is unclone() good enough or do we need getClonee() in Cloneable?
             while (js instanceof JS.Clone && !(js instanceof Blessing)) js = js.unclone();
             if (!(js instanceof Blessing)) return null;
             return (Blessing)js;
             while (js instanceof JS.Clone && !(js instanceof Blessing)) js = js.unclone();
             if (!(js instanceof Blessing)) return null;
             return (Blessing)js;
@@ -440,8 +439,6 @@ public final class Ibex extends JS.Obj implements JS.Cloneable {
             if (t == null) throw new JSExn("No such template " + JSU.str(parentkey));
             return t;
         }
             if (t == null) throw new JSExn("No such template " + JSU.str(parentkey));
             return t;
         }
-        // JS:FIXME: Blessing shouldn't need to roll its own JS.Clone implementation
-        //public InputStream getInputStream() throws JSExn, IOException { return clonee.getInputStream(); }
     }
 
 }
     }
 
 }
index a9c35df..4fd76f0 100644 (file)
@@ -11,7 +11,6 @@ import org.ibex.js.*;
 import org.ibex.util.*;
 import org.ibex.plat.*;
 import org.ibex.graphics.*;
 import org.ibex.util.*;
 import org.ibex.plat.*;
 import org.ibex.graphics.*;
-import org.ibex.core.builtin.*;
 
 /** Entry point for the Ibex Engine; handles splash screen, initial xwar loading, and argument processing */
 public class Main {
 
 /** Entry point for the Ibex Engine; handles splash screen, initial xwar loading, and argument processing */
 public class Main {
@@ -29,7 +28,15 @@ public class Main {
     public static String origin = null;
     public static String initialTemplate = null;
     
     public static String origin = null;
     public static String initialTemplate = null;
     
-    public static final Fountain builtin = new Fountain.Zip(new Fountain.FromInputStream(Platform.getBuiltinInputStream()));
+    //public static final Fountain builtin = new Fountain.Zip(new Fountain.FromInputStream(Platform.getBuiltinInputStream()));
+    public static final Fountain vera;
+    static {
+        Fountain temp = null;
+        try {
+            temp = new Fountain.FromInputStream(Encode.JavaSourceCode.decode(Vera.data));
+        } catch (Exception e) { Log.error(Main.class, e); }
+        vera = temp;
+    }
 
     public static void printUsage() {
         System.err.println("Usage: ibex [-lawp] [ url | file | directory ]");
 
     public static void printUsage() {
         System.err.println("Usage: ibex [-lawp] [ url | file | directory ]");
@@ -99,19 +106,24 @@ public class Main {
         if (Log.on) Log.info(Main.class, "loading xwar");
         final Ibex ibex = new Ibex(rr);
 
         if (Log.on) Log.info(Main.class, "loading xwar");
         final Ibex ibex = new Ibex(rr);
 
-        org.ibex.graphics.Surface.scarImage =
-            Picture.load(new Fountain.FromInputStream(Encode.JavaSourceCode.decode(Scar.data)),
-                         new Callable() {
-                             private final JS[] callargs = new JS[1];
-                             public Object run(Object o) throws JSExn,UnknownHostException {
-                                 if (Log.on) Log.info(Main.class, "invoking initial template");
-                                 try {
-                                     callargs[0] = new Box(); 
-                                     ibex.resolveString(startupTemplate, false).call(null, callargs);
-                                 } finally { callargs[0] = null; }
-                                 return null;
-                         } });
+        try {
+            JS blessed = ibex.bless(new Fountain.FromInputStream(Encode.JavaSourceCode.decode(org.ibex.core.builtin.Scar.data)));
+            org.ibex.graphics.Surface.scarImage = Platform.createPicture(blessed);
+        } catch (Exception e) {
+            Log.error(Main.class, e);
+        }
 
 
+        Platform.Scheduler.add(new Callable() {
+            private final JS[] callargs = new JS[1];
+            public Object run(Object o) throws JSExn,UnknownHostException {
+                if (Log.on) Log.info(Main.class, "invoking initial template");
+                try {
+                    callargs[0] = new Box(); 
+                    ibex.resolveString(startupTemplate, false).call(null, callargs);
+                } finally { callargs[0] = null; }
+                return null;
+            } });
+    
         Platform.Scheduler.init();
     }
 }
         Platform.Scheduler.init();
     }
 }
index ce7b20b..fb236ea 100644 (file)
@@ -29,6 +29,20 @@ public class Picture {
     public int[] data = null;                      ///< argb samples
     public boolean isLoaded = false;               ///< true iff the image is fully loaded
 
     public int[] data = null;                      ///< argb samples
     public boolean isLoaded = false;               ///< true iff the image is fully loaded
 
+    public Picture(InputStream is) throws IOException { load(this, is); }
+
+    public static void load(Picture p, InputStream in) throws IOException {
+        PushbackInputStream pbis = new PushbackInputStream(in);
+        int firstByte = pbis.read();
+        if (firstByte == -1) throw new IOException("empty stream reading image");
+        pbis.unread(firstByte);
+        if ((firstByte & 0xff) == 'G') GIF.load(pbis, p);
+        else if ((firstByte & 0xff) == 137)  PNG.load(pbis, p);
+        else if ((firstByte & 0xff) == 0xff) Platform.decodeJPEG(pbis, p);
+        else throw new IOException("couldn't figure out image type from first byte");
+        p.loaded();
+    }
+
     /** invoked when an image is fully loaded; subclasses can use this to initialize platform-specific constructs */
     protected void loaded() { isLoaded = true; }
 
     /** invoked when an image is fully loaded; subclasses can use this to initialize platform-specific constructs */
     protected void loaded() { isLoaded = true; }
 
@@ -52,15 +66,7 @@ public class Picture {
                 }
                 if (in == null) { Log.warn(Picture.class, "couldn't load image for stream " + stream.unclone()); return; }
                 try {
                 }
                 if (in == null) { Log.warn(Picture.class, "couldn't load image for stream " + stream.unclone()); return; }
                 try {
-                    PushbackInputStream pbis = new PushbackInputStream(in);
-                    int firstByte = pbis.read();
-                    if (firstByte == -1) throw new JSExn("empty stream reading image");
-                    pbis.unread(firstByte);
-                    if ((firstByte & 0xff) == 'G') GIF.load(pbis, p);
-                    else if ((firstByte & 0xff) == 137)  PNG.load(pbis, p);
-                    else if ((firstByte & 0xff) == 0xff) Platform.decodeJPEG(pbis, p);
-                    else throw new JSExn("couldn't figure out image type from first byte");
-                    p.loaded();
+                    load(p, in);
                     Platform.Scheduler.add(callback);
                 } catch (Exception e) {
                     Log.info(this, "exception while loading image");
                     Platform.Scheduler.add(callback);
                 } catch (Exception e) {
                     Log.info(this, "exception while loading image");