#35 fix demo
[fanfix.git] / src / jexer / TApplication.java
index 7c96258b4405c00a5660788262a235a3c69c74d9..ec93629b0b17f9584336ff855f0d1010660121be 100644 (file)
@@ -48,6 +48,7 @@ import java.util.ResourceBundle;
 import jexer.bits.Cell;
 import jexer.bits.CellAttributes;
 import jexer.bits.ColorTheme;
+import jexer.bits.StringUtils;
 import jexer.event.TCommandEvent;
 import jexer.event.TInputEvent;
 import jexer.event.TKeypressEvent;
@@ -293,6 +294,11 @@ public class TApplication implements Runnable {
      */
     private List<Runnable> invokeLaters = new LinkedList<Runnable>();
 
+    /**
+     * The last time the screen was resized.
+     */
+    private long screenResizeTime = 0;
+
     /**
      * WidgetEventHandler is the main event consumer loop.  There are at most
      * two such threads in existence: the primary for normal case and a
@@ -518,9 +524,7 @@ public class TApplication implements Runnable {
                     }
                 } // while (!application.quit)
 
-                assert (dirty == true);
-
-                // Flush the screen contents
+                 // Flush the screen contents
                 if (debugThreads) {
                     System.err.printf("%d %s backend.flushScreen()\n",
                         System.currentTimeMillis(), Thread.currentThread());
@@ -925,7 +929,7 @@ public class TApplication implements Runnable {
             openImage();
             return true;
         }
-        if (menu.getId() == TMenu.MID_CHANGE_FONT) {
+        if (menu.getId() == TMenu.MID_SCREEN_OPTIONS) {
             new TFontChooserWindow(this);
             return true;
         }
@@ -1026,8 +1030,14 @@ public class TApplication implements Runnable {
             if (event instanceof TResizeEvent) {
                 TResizeEvent resize = (TResizeEvent) event;
                 synchronized (getScreen()) {
-                    getScreen().setDimensions(resize.getWidth(),
-                        resize.getHeight());
+                    if ((System.currentTimeMillis() - screenResizeTime >= 15)
+                        || (resize.getWidth() < getScreen().getWidth())
+                        || (resize.getHeight() < getScreen().getHeight())
+                    ) {
+                        getScreen().setDimensions(resize.getWidth(),
+                            resize.getHeight());
+                        screenResizeTime = System.currentTimeMillis();
+                    }
                     desktopBottom = getScreen().getHeight() - 1;
                     mouseX = 0;
                     mouseY = 0;
@@ -1713,12 +1723,12 @@ public class TApplication implements Runnable {
                 }
             }
         }
-        assert (cell.getWidth() == Cell.Width.RIGHT);
-
-        if (x > 0) {
-            Cell leftHalf = getScreen().getCharXY(x - 1, y);
-            if (leftHalf.getWidth() == Cell.Width.LEFT) {
-                invertCell(x - 1, y, true);
+        if (cell.getWidth() == Cell.Width.RIGHT) {
+            if (x > 0) {
+                Cell leftHalf = getScreen().getCharXY(x - 1, y);
+                if (leftHalf.getWidth() == Cell.Width.LEFT) {
+                    invertCell(x - 1, y, true);
+                }
             }
         }
     }
@@ -1842,7 +1852,7 @@ public class TApplication implements Runnable {
                 menuMnemonicColor = theme.getColor("tmenu.mnemonic");
             }
             // Draw the menu title
-            getScreen().hLineXY(x, 0, menu.getTitle().length() + 2, ' ',
+            getScreen().hLineXY(x, 0, StringUtils.width(menu.getTitle()) + 2, ' ',
                 menuColor);
             getScreen().putStringXY(x + 1, 0, menu.getTitle(), menuColor);
             // Draw the highlight character
@@ -1854,7 +1864,7 @@ public class TApplication implements Runnable {
                 // Reset the screen clipping so we can draw the next title.
                 getScreen().resetClipping();
             }
-            x += menu.getTitle().length() + 2;
+            x += StringUtils.width(menu.getTitle()) + 2;
         }
 
         for (TMenu menu: subMenus) {
@@ -2729,7 +2739,7 @@ public class TApplication implements Runnable {
             for (TMenu menu: menus) {
                 if ((mouse.getAbsoluteX() >= menu.getTitleX())
                     && (mouse.getAbsoluteX() < menu.getTitleX()
-                        + menu.getTitle().length() + 2)
+                        + StringUtils.width(menu.getTitle()) + 2)
                 ) {
                     menu.setActive(true);
                     activeMenu = menu;
@@ -2757,7 +2767,7 @@ public class TApplication implements Runnable {
             for (TMenu menu: menus) {
                 if ((mouse.getAbsoluteX() >= menu.getTitleX())
                     && (mouse.getAbsoluteX() < menu.getTitleX()
-                        + menu.getTitle().length() + 2)
+                        + StringUtils.width(menu.getTitle()) + 2)
                 ) {
                     menu.setActive(true);
                     activeMenu = menu;
@@ -3042,7 +3052,7 @@ public class TApplication implements Runnable {
         for (TMenu menu: menus) {
             menu.setX(x);
             menu.setTitleX(x);
-            x += menu.getTitle().length() + 2;
+            x += StringUtils.width(menu.getTitle()) + 2;
 
             // Don't let the menu window exceed the screen width
             int rightEdge = menu.getX() + menu.getWidth();
@@ -3122,7 +3132,7 @@ public class TApplication implements Runnable {
         TMenu toolMenu = addMenu(i18n.getString("toolMenuTitle"));
         toolMenu.addDefaultItem(TMenu.MID_REPAINT);
         toolMenu.addDefaultItem(TMenu.MID_VIEW_IMAGE);
-        toolMenu.addDefaultItem(TMenu.MID_CHANGE_FONT);
+        toolMenu.addDefaultItem(TMenu.MID_SCREEN_OPTIONS);
         TStatusBar toolStatusBar = toolMenu.newStatusBar(i18n.
             getString("toolMenuStatus"));
         toolStatusBar.addShortcutKeypress(kbF1, cmHelp, i18n.getString("Help"));