Revision: 2336
          http://vexi.svn.sourceforge.net/vexi/?rev=2336&view=rev
Author:   clrg
Date:     2007-09-26 17:09:06 -0700 (Wed, 26 Sep 2007)

Log Message:
-----------
Overhaul handling of the way Surface size is handled

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
    trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
    trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2007-09-26 10:05:00 UTC 
(rev 2335)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2007-09-27 00:09:06 UTC 
(rev 2336)
@@ -324,7 +324,7 @@
     }
 
     /** attempt to resize box and dirty appropriate areas */
-    private void tryResize(int width, int height) {
+    protected void tryResize(int width, int height) {
         if (width == this.width && height == this.height) return;
         dirty();
         //#repeat width/height WIDTH/HEIGHT
@@ -383,9 +383,15 @@
     /** should only be invoked on the root box */
     public void reflow() {
         if ((flags & REFLOW) == 0) return;
+       reflow(width, height);
+    }
+
+    /** should only be invoked on the root box */
+    public void reflow(int w, int h) {
         constrain();
-        tryResize(test(HSHRINK) ? contentwidth : maxwidth,
-                  test(VSHRINK) ? contentheight : maxheight);
+        //tryResize(test(HSHRINK) ? contentwidth : maxwidth,
+        //        test(VSHRINK) ? contentheight : maxheight);
+        tryResize(w, h);
         place();
     }
 
@@ -781,7 +787,7 @@
 
     //#repeat Width/Height width/height 
     /** set minwidth/maxwidth according to min/max */
-    public void setMinMaxWidth(int min, int max) {
+    private void setMinMaxWidth(int min, int max) {
         if (this.minwidth == min && this.maxwidth == max) return;
         if (this.minwidth != min) {
             PUT_BOX_FIELD(SC_minwidth,JSU.N(min),this.minwidth = 
min,MINMAX_TRAPS)
@@ -794,22 +800,21 @@
         setConstrain();
 
         // in box tree
-        if (parent != null) {
-            parent.set(CONSTRAIN);
-
+        if (parent != null) parent.set(CONSTRAIN);
         // root of box tree
-        } else {
-            reconstrainRoot();
-        }
+        else reconstrainRoot();
     }
     //#end
 
     // REMARK - moved to own function to avoid the preprocessor in 
setMinMax(Width|Height)
     private void reconstrainRoot() {
         Surface s = getSurface();
-        if (s != null && !s.syncRootWithSurface) {
-            s.pendingWidth = maxwidth;
+        if (s != null) {
             s.setMinimumSize(minwidth, minheight, minwidth != maxwidth || 
minheight != maxheight);
+            int mw = maxwidth, mh = maxheight;
+            if (mw == Integer.MAX_VALUE) mw = s.pendingWidth;
+            if (mh == Integer.MAX_VALUE) mh = s.pendingHeight;
+            s.setSize(mw, mh);
         }
     }
     

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Surface.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Surface.java     2007-09-26 
10:05:00 UTC (rev 2335)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Surface.java     2007-09-27 
00:09:06 UTC (rev 2336)
@@ -200,10 +200,9 @@
 
     /** subclasses should invoke this method when the user resizes the window 
*/
     protected final void SizeChange(final int width, final int height) {
-        if (syncSurfaceWithRoot || (pendingWidth == width && pendingHeight == 
height)) return;
+        if (pendingWidth == width && pendingHeight == height) return;
         pendingWidth = width;
         pendingHeight = height;
-        syncRootWithSurface = true;
         abort = true;
         Refresh();
         // FEATURE: notify root box of x/y change if align is not topleft 
@@ -281,12 +280,20 @@
     protected final void Maximized(boolean b) { maximized = b; new 
Message("Maximized", b ? T : F, root, false); }
     protected final void Focused(boolean b) { new Message("Focused", b ? T : 
F, root, false); }
 
+    /** refresh handles interacting with the scheduler - it needs
+     * to be synchronized to prevent scheduled 
+     */
     private boolean scheduled = false;
-    public void Refresh() { if (!scheduled) Scheduler.add(this); scheduled = 
true; }
+    final public synchronized void Refresh() {
+        if (!scheduled) {
+               Scheduler.add(this);
+               scheduled = true;
+        }
+    }
 
     /** only run if scheduled */
     public Object run(Object o) {
-       if (scheduled) render();
+       render();
        return null;
     }
 
@@ -349,10 +356,12 @@
             Log.warn(this, jse);
         }
         // TODO: document this in the reference
-        if (root.maxwidth == Integer.MAX_VALUE)
-            root.setMinMaxWidth(root.minwidth, Platform.getScreenWidth() / 2);
-        if (root.maxheight == Integer.MAX_VALUE)
-            root.setMinMaxHeight(root.minheight, Platform.getScreenHeight() / 
2);
+        pendingWidth = root.maxwidth;
+        pendingHeight = root.maxheight;
+        if (pendingWidth == Integer.MAX_VALUE)
+               pendingWidth = Platform.getScreenWidth() / 2;
+        if (pendingHeight == Integer.MAX_VALUE)
+               pendingHeight = Platform.getScreenHeight() / 2;
         // set frame specific box properties
         try {
             JS icon = root.get(SC_icon);
@@ -370,30 +379,29 @@
 
     /** runs the prerender() and render() pipelines in the root Box to 
regenerate the backbuffer, then blits it to the screen */
     public synchronized void render() {
-        scheduled = false;
+       scheduled = false;
+        // do nothing if we are minimized
+        if (minimized) return;
         // make sure the root is properly sized
         do {
             abort = false;
-            if (syncRootWithSurface) {
-                root.setMinMaxWidth(root.minwidth, pendingWidth);
-                root.setMinMaxHeight(root.minheight, pendingHeight);
-                syncRootWithSurface = false;
-            }
-            int rootwidth = root.getSurfaceWidth();
-            int rootheight = root.getSurfaceHeight();
-            if (rootwidth != root.width || rootheight != root.height) {
+            // pending size update means the user resized the window
+            if (pendingWidth != root.width || pendingHeight != root.height) {
+                // ensure scar is always shown
                 if (scarImage != null) {
                     // 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, rootheight - scarImage.height, scarImage.width, 
scarImage.height);
+                    dirty(0, root.height - scarImage.height, scarImage.width, 
scarImage.height);
                 }
-            }
-            // set frame size according to root box size
-            if (!maximized && !minimized && syncSurfaceWithRoot) {
-                setSize(rootwidth, rootheight);
-                syncSurfaceWithRoot = false;
-            }
-            root.reflow();
+                // reflow to new size as set by the frame
+                root.reflow(pendingWidth, pendingHeight);
+                // root rejects new sizes
+                /*if (root.width != pendingWidth || root.height != 
pendingHeight) {
+                       pendingWidth = root.width;
+                       pendingHeight = root.height;
+                       setSize(pendingWidth, pendingHeight);
+                }*/
+            } else root.reflow();
         } while(abort);
 
         int numregions = dirtyRegions.num();
@@ -415,7 +423,7 @@
                 if(scarImage.width > x && yscarstart < y+h)
                        buff.drawPicture(scarImage, 0, yscarstart, x, y, x+w, 
y+h);
             }
-            
+            /*
             if (abort) {
                 // x,y,w,h is only partially reconstructed, so we must be 
careful not to re-blit it
                 dirtyRegions.dirty(x, y, w, h);
@@ -425,6 +433,7 @@
                         dirtyRegions.dirty(dirt[j][0], dirt[j][1], dirt[j][2], 
dirt[j][3]);
                 return;
             }
+            */
         }
     }
 
@@ -519,7 +528,7 @@
 
         public void render() {
             super.render();
-            if (abort) return;
+            //if (abort) { System.err.println("early abort"); return; }
             int numregions = screenDirtyRegions.num();
             int[][] dirt = screenDirtyRegions.flush();
             for(int i = 0; dirt != null && i < numregions; i++) {
@@ -533,7 +542,7 @@
                 if (x+w > root.width) w = root.width - x;
                 if (y+h > root.height) h = root.height - y;
                 if (w <= 0 || h <= 0) continue;
-                if (abort) return;
+                //if (abort) { System.err.println("aborting render ("+i+")"); 
return; }
                 blit(backbuffer, x, y, x, y, w + x, h + y);
             }
         }

Modified: trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java 2007-09-26 10:05:00 UTC 
(rev 2335)
+++ trunk/core/org.vexi.core/src/org/vexi/plat/AWT.java 2007-09-27 00:09:06 UTC 
(rev 2336)
@@ -446,6 +446,7 @@
                 if (framed) window = frame = new InnerFrame();
                 else window = new InnerWindow();
                 setLocation();
+                setSize(pendingWidth, pendingHeight);
 
             // this is here to catch HeadlessException on jdk1.4
             } catch (java.lang.UnsupportedOperationException e) {
@@ -553,10 +554,14 @@
                buf.g.setColor(new java.awt.Color((root.fillcolor >> 16) & 0xff,
                     (root.fillcolor >> 8) & 0xff,
                     (root.fillcolor) & 0xff));
-               if (oldwidth < newwidth)
-                       buf.g.fillRect(oldwidth, 0, newwidth, 
oldheight>newheight?oldheight:newheight);
-               if (oldheight < newheight)
-                       buf.g.fillRect(0, oldheight, 
oldwidth>newwidth?oldwidth:newwidth, newheight);
+               if (oldwidth < newwidth) {
+                       buf.g.fillRect(oldwidth, 0, newwidth, newheight);
+                       dirty(oldwidth, 0, newwidth-oldwidth, newheight);
+               }
+               if (oldheight < newheight) {
+                       buf.g.fillRect(0, oldheight, newwidth, newheight);
+                       dirty(0, oldheight, newwidth, newheight-oldheight);
+               }
                oldwidth = newwidth;
                oldheight = newheight;
                SizeChange(newwidth, newheight);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to