fix bug 556
[org.ibex.core.git] / src / org / ibex / graphics / Surface.java
index e6c5c4e..31ac36e 100644 (file)
@@ -225,8 +225,19 @@ public abstract class Surface extends PixelBuffer implements Task {
 
     public Surface(Box root) {
         this.root = root;
-        root.setWidth(root.minwidth, Math.min(Platform.getScreenWidth(), root.maxwidth));
-        root.setHeight(root.minheight, Math.min(Platform.getScreenHeight(), root.maxheight));
+        // FIXME: document this in the reference
+        if (!root.test(root.HSHRINK) && root.maxwidth == Integer.MAX_VALUE)
+            root.maxwidth = Platform.getScreenWidth() / 2;
+        if (!root.test(root.VSHRINK) && root.maxheight == Integer.MAX_VALUE)
+            root.maxheight = Platform.getScreenHeight() / 2;
+        root.setWidth(root.minwidth,
+                      root.test(root.HSHRINK)
+                      ? Math.max(root.minwidth, root.contentwidth)
+                      : Math.min(Platform.getScreenWidth(), root.maxwidth));
+        root.setHeight(root.minheight,
+                      root.test(root.VSHRINK)
+                      ? Math.max(root.minheight, root.contentheight)
+                      : Math.min(Platform.getScreenHeight(), root.maxheight));
         Surface old = fromBox(root);
         if (old != null) old.dispose(false);
         else root.removeSelf();
@@ -247,13 +258,15 @@ public abstract class Surface extends PixelBuffer implements Task {
                 root.setHeight(root.minheight, pendingHeight);
                 syncRootBoxToSurface = false;
             }
-            if (root.maxwidth != root.width || root.maxheight != root.height) {
+            int rootwidth = root.test(root.HSHRINK) ? root.contentwidth : root.maxwidth;
+            int rootheight = root.test(root.VSHRINK) ? root.contentheight : root.maxheight;
+            if (rootwidth != root.width || rootheight != root.height) {
                 // dirty the place where the scar used to be and where it is now
                 dirty(0, root.height - scarImage.height, scarImage.width, scarImage.height);
-                dirty(0, root.maxheight - scarImage.height, scarImage.width, scarImage.height);
+                dirty(0, rootheight - scarImage.height, scarImage.width, scarImage.height);
             }
             root.reflow();
-            setSize(root.width, root.height);
+            setSize(rootwidth, rootheight);
             /*String oldcursor = cursor;
             cursor = "default";
             root.putAndTriggerTrapsAndCatchExceptions("_Move", JS.T);