X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbackend%2FMultiScreen.java;h=880ee1888300d12ae936ed2106c927b311cdc5a0;hb=eb0d6c82905932e04acfb4066ab680ef867931ce;hp=77688734fa9179aca6414829a5bc29cdcc91ecf7;hpb=d6ee0801333ff93dffd851f4c1a44519c96c371d;p=fanfix.git diff --git a/src/jexer/backend/MultiScreen.java b/src/jexer/backend/MultiScreen.java index 7768873..880ee18 100644 --- a/src/jexer/backend/MultiScreen.java +++ b/src/jexer/backend/MultiScreen.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2017 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -386,7 +386,20 @@ public class MultiScreen implements Screen { */ public void setDimensions(final int width, final int height) { for (Screen screen: screens) { - screen.setDimensions(width, height); + // Do not blindly call setDimension() on every screen. Instead + // call it only on those screens that do not already have the + // requested dimension. With this very small check, we have the + // ability for ANY screen in the MultiBackend to resize ALL of + // the screens. + if ((screen.getWidth() != width) + || (screen.getHeight() != height) + ) { + screen.setDimensions(width, height); + } else { + // The screen that didn't change is probably the one that + // prompted the resize. Force it to repaint. + screen.clearPhysical(); + } } } @@ -396,7 +409,14 @@ public class MultiScreen implements Screen { * @return current screen height */ public int getHeight() { - return screens.get(0).getHeight(); + // Return the smallest height of the screens. + int height = screens.get(0).getHeight(); + for (Screen screen: screens) { + if (screen.getHeight() < height) { + height = screen.getHeight(); + } + } + return height; } /** @@ -405,7 +425,14 @@ public class MultiScreen implements Screen { * @return current screen width */ public int getWidth() { - return screens.get(0).getWidth(); + // Return the smallest width of the screens. + int width = screens.get(0).getWidth(); + for (Screen screen: screens) { + if (screen.getWidth() < width) { + width = screen.getWidth(); + } + } + return width; } /** @@ -496,6 +523,27 @@ public class MultiScreen implements Screen { } } + /** + * Clear the physical screen. + */ + public void clearPhysical() { + for (Screen screen: screens) { + screen.clearPhysical(); + } + } + + /** + * Unset every image cell on one row of the physical screen, forcing + * images on that row to be redrawn. + * + * @param y row coordinate. 0 is the top-most row. + */ + public final void unsetImageRow(final int y) { + for (Screen screen: screens) { + screen.unsetImageRow(y); + } + } + /** * Classes must provide an implementation to push the logical screen to * the physical device. @@ -590,4 +638,50 @@ public class MultiScreen implements Screen { } } + /** + * Get the width of a character cell in pixels. + * + * @return the width in pixels of a character cell + */ + public int getTextWidth() { + int textWidth = 16; + for (Screen screen: screens) { + int newTextWidth = textWidth; + if (screen instanceof MultiScreen) { + newTextWidth = ((MultiScreen) screen).getTextWidth(); + } else if (screen instanceof ECMA48Terminal) { + newTextWidth = ((ECMA48Terminal) screen).getTextWidth(); + } else if (screen instanceof SwingTerminal) { + newTextWidth = ((SwingTerminal) screen).getTextWidth(); + } + if (newTextWidth < textWidth) { + textWidth = newTextWidth; + } + } + return textWidth; + } + + /** + * Get the height of a character cell in pixels. + * + * @return the height in pixels of a character cell + */ + public int getTextHeight() { + int textHeight = 20; + for (Screen screen: screens) { + int newTextHeight = textHeight; + if (screen instanceof MultiScreen) { + newTextHeight = ((MultiScreen) screen).getTextHeight(); + } else if (screen instanceof ECMA48Terminal) { + newTextHeight = ((ECMA48Terminal) screen).getTextHeight(); + } else if (screen instanceof SwingTerminal) { + newTextHeight = ((SwingTerminal) screen).getTextHeight(); + } + if (newTextHeight < textHeight) { + textHeight = newTextHeight; + } + } + return textHeight; + } + }