propose-patch
[org.ibex.core.git] / src / org / xwt / builtin / splash.xwt
index dcbc66c..b0fc151 100644 (file)
@@ -1,66 +1,79 @@
 <xwt>
 
-    <template thisbox="window" orient="vertical">
+    <template orient="vertical" color="white">
 
-        minwidth = maxwidth = $inner.width;
-        minheight = maxheight = $inner.height;
-        x = (xwt.screenWidth - width) / 2;
-        y = (xwt.screenHeight - height) / 2;
+        KeyPressed += function(k) { if (k == "escape") thisbox = null; }
 
-        _KeyPressed = function(k) {
-            if (k == "escape") thisbox = null;
+        var settext = function(t) {
+            $text.text = t;
+            $text1.text = t;
+            $text2.text = t;
+            $text3.text = t;
+            $text4.text = t;
         }
 
-        xwt.thread = function() {
-            try {
-                var origin = xwt.origin;
-                if (origin.substring(0, 21) == "http://launch.xwt.org") {
-                    origin = origin.substring(22);
-                    origin = "http://" + origin.substring(origin.indexOf('/') + 1);
-                }
-                xwt.println("origin is " + origin);
-    
-                xwt.loadArchive(origin, function(num, den) {
-                        $left.flex = 50 * (num / den);
-                        $right.flex = 50 + 50 * (1.0 - num /den);
-                        var pct = xwt.math.ceil(num * 100 / den);
-                        if (1024 > num) {
-                            num = "" + num + " bytes";
-                        } else if (1024 * 1024 > num) {
-                            num = "" + xwt.math.ceil(num / 1024) + "kb";
-                        } else {
-                            num = "" + xwt.math.ceil(num / (1024 * 1024)) + "Mb";
-                        }
-                        $status.text = "Downloading: " + pct + "% [" + num + "]";
-                    });
-    
-                    xwt.newBox().apply("main", function(num, den) {
-                        $left.flex = 50 + 50 * (num / den);
-                        $right.flex = 50 * (1.0 - num / den);
-                        if ($right.flex == 0) $right.width = 0;
-                        $status.text = "Initializing: " + xwt.math.ceil(num * 100 / den) + "%";
-                    });
-                    thisbox = null;
+        var progress = function(n, d) {
+            var t = "downloaded " + xwt.math.ceil(100 * n/d) + "%";
+            xwt.log.println("downloaded " + t);
+            $innerbar.width = $bar.width * n / d + 1;
+            settext(t);
+       } 
 
-            } catch (e) {
-                $status.text = "Error: " + e;
-                if ($status.text.substring(0, 13) == "Error: Error:") {
-                    $status.text = $status.text.substring(7) +
-                                   " (press Esc to quit)";
-                }
+        xwt.thread = function() {
+            $text.font = xwt.font.sansserif;
+            $text.fontsize = 14;
+            $text1.font = xwt.font.sansserif;
+            $text1.fontsize = 14;
+            $text2.font = xwt.font.sansserif;
+            $text2.fontsize = 14;
+            $text3.font = xwt.font.sansserif;
+            $text3.fontsize = 14;
+            $text4.font = xwt.font.sansserif;
+            $text4.fontsize = 14;
+            settext("downloading...");
+            fill = .org.xwt.builtin["splash.png"];
+            xwt.ui.window = thisbox;
+            thisbox.width=394;
+            thisbox.height=276;
+            x = (xwt.ui.screen.width - width) / 2;
+            y = (xwt.ui.screen.height - height) / 2;
+            var origin = xwt.origin;
+            if (origin.substring(0, 21) == "http://launch.xwt.org") {
+                origin = origin.substring(22);
+                origin = "http://" + origin.substring(origin.indexOf('/') + 1);
             }
+            xwt.log.println("origin is " + origin);
+            var new_rr = xwt.res.unzip(xwt.res.watch(xwt.res.url(origin), progress));
+            var new_xwt = xwt.clone(new_rr);
 
+            xwt.thread = function() {
+                for(var i=0; 100>i; i++) {
+                progress(i, 100);
+                xwt.thread.yield();
+            }
+            new_xwt.apply(xwt.box, new_xwt["main.xwt"]);
+            thisbox = null;
+        }
+xwt.log.println("leaving");
         }
 
-        <box absolute="true" sizetoimage="true" id="inner" image="org.xwt.builtin.lithium"/>
-
-        <box/>
-        <box text="Downloading user interface..." vshrink="true" hpad="4" vpad="3" id="status" textcolor="white"/>
-        <box hpad="4" height="10">
-            <box flex="0.0" image="org.xwt.builtin.progress" tile="true" id="left"/>
-            <box flex="100.0" id="right"/>
+        <box height="236" align="bottomleft" packed="false" x="20" y="0">
+            <box vshrink="true">
+                <box packed="false" textcolor="black" x="2" y="2" id="text1"/>
+                <box packed="false" textcolor="black" x="0" y="2" id="text2"/>
+                <box packed="false" textcolor="black" x="2" y="0" id="text3"/>
+                <box packed="false" textcolor="black" x="0" y="0" id="text4"/>
+                <box cols="2">
+                    <box height="1" colspan="2"/>
+                    <box width="1"/>
+                    <box textcolor="white" id="text"/>
+                </box>
+            </box>
+        </box>
+        <box packed="false" id="bar" x="20" y="236" width="354" height="20" align="left">
+            <box id="innerbar" fill="blue" width="10" height="20"/>
         </box>
-        <box height="5"/>
 
     </template>
 
+</xwt>
\ No newline at end of file