// 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 //////////////////////////////////////////////////////////////////////
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":
// 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;
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);
- 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) {
- // 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;
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(); }
}
}
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 {
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 ]");
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();
}
}
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; }
}
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");