X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fio%2FScreen.java;h=2ac6e2893b5ebdb4a39370edc7e0edc44b2b7e2e;hb=daa4106c096cd4d2b92c3cbae6491edccd25fcc4;hp=6c872b3107ed86a5050d1951d6026806f6ee7771;hpb=48e27807150e00bc9a92844382ebc8cedf1d265f;p=fanfix.git diff --git a/src/jexer/io/Screen.java b/src/jexer/io/Screen.java index 6c872b3..2ac6e28 100644 --- a/src/jexer/io/Screen.java +++ b/src/jexer/io/Screen.java @@ -1,4 +1,4 @@ -/** +/* * Jexer - Java Text User Interface * * License: LGPLv3 or later @@ -53,7 +53,7 @@ public abstract class Screen { /** * Drawing offset for x. */ - protected int offsetX; + private int offsetX; /** * Set drawing offset for x. @@ -67,7 +67,7 @@ public abstract class Screen { /** * Drawing offset for y. */ - protected int offsetY; + private int offsetY; /** * Set drawing offset for y. @@ -77,11 +77,11 @@ public abstract class Screen { public final void setOffsetY(final int offsetY) { this.offsetY = offsetY; } - + /** * Ignore anything drawn right of clipRight. */ - protected int clipRight; + private int clipRight; /** * Get right drawing clipping boundary. @@ -104,7 +104,7 @@ public abstract class Screen { /** * Ignore anything drawn below clipBottom. */ - protected int clipBottom; + private int clipBottom; /** * Get bottom drawing clipping boundary. @@ -127,7 +127,7 @@ public abstract class Screen { /** * Ignore anything drawn left of clipLeft. */ - protected int clipLeft; + private int clipLeft; /** * Get left drawing clipping boundary. @@ -150,7 +150,7 @@ public abstract class Screen { /** * Ignore anything drawn above clipTop. */ - protected int clipTop; + private int clipTop; /** * Get top drawing clipping boundary. @@ -183,7 +183,17 @@ public abstract class Screen { /** * When true, logical != physical. */ - protected boolean dirty; + protected volatile boolean dirty; + + /** + * Get dirty flag. + * + * @return if true, the logical screen is not in sync with the physical + * screen + */ + public final boolean isDirty() { + return dirty; + } /** * Set if the user explicitly wants to redraw everything starting with a @@ -214,9 +224,11 @@ public abstract class Screen { * @param y row coordinate. 0 is the top-most row. * @return attributes at (x, y) */ - public CellAttributes getAttrXY(final int x, final int y) { + public final CellAttributes getAttrXY(final int x, final int y) { CellAttributes attr = new CellAttributes(); - attr.setTo(logical[x][y]); + if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) { + attr.setTo(logical[x][y]); + } return attr; } @@ -227,7 +239,9 @@ public abstract class Screen { * @param y row coordinate. 0 is the top-most row. * @param attr attributes to use (bold, foreColor, backColor) */ - public void putAttrXY(final int x, final int y, final CellAttributes attr) { + public final void putAttrXY(final int x, final int y, + final CellAttributes attr) { + putAttrXY(x, y, attr, true); } @@ -239,8 +253,8 @@ public abstract class Screen { * @param attr attributes to use (bold, foreColor, backColor) * @param clip if true, honor clipping/offset */ - public void putAttrXY(final int x, final int y, final CellAttributes attr, - final boolean clip) { + public final void putAttrXY(final int x, final int y + , final CellAttributes attr, final boolean clip) { int X = x; int Y = y; @@ -261,11 +275,11 @@ public abstract class Screen { dirty = true; logical[X][Y].setForeColor(attr.getForeColor()); logical[X][Y].setBackColor(attr.getBackColor()); - logical[X][Y].setBold(attr.getBold()); - logical[X][Y].setBlink(attr.getBlink()); - logical[X][Y].setReverse(attr.getReverse()); - logical[X][Y].setUnderline(attr.getUnderline()); - logical[X][Y].setProtect(attr.getProtect()); + logical[X][Y].setBold(attr.isBold()); + logical[X][Y].setBlink(attr.isBlink()); + logical[X][Y].setReverse(attr.isReverse()); + logical[X][Y].setUnderline(attr.isUnderline()); + logical[X][Y].setProtect(attr.isProtect()); } } @@ -275,7 +289,8 @@ public abstract class Screen { * @param ch character to draw * @param attr attributes to use (bold, foreColor, backColor) */ - public void putAll(final char ch, final CellAttributes attr) { + public final void putAll(final char ch, final CellAttributes attr) { + for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { putCharXY(x, y, ch, attr); @@ -290,7 +305,7 @@ public abstract class Screen { * @param y row coordinate. 0 is the top-most row. * @param ch character + attributes to draw */ - public void putCharXY(final int x, final int y, final Cell ch) { + public final void putCharXY(final int x, final int y, final Cell ch) { putCharXY(x, y, ch.getChar(), ch); } @@ -302,7 +317,7 @@ public abstract class Screen { * @param ch character to draw * @param attr attributes to use (bold, foreColor, backColor) */ - public void putCharXY(final int x, final int y, final char ch, + public final void putCharXY(final int x, final int y, final char ch, final CellAttributes attr) { if ((x < clipLeft) @@ -328,11 +343,11 @@ public abstract class Screen { logical[X][Y].setChar(ch); logical[X][Y].setForeColor(attr.getForeColor()); logical[X][Y].setBackColor(attr.getBackColor()); - logical[X][Y].setBold(attr.getBold()); - logical[X][Y].setBlink(attr.getBlink()); - logical[X][Y].setReverse(attr.getReverse()); - logical[X][Y].setUnderline(attr.getUnderline()); - logical[X][Y].setProtect(attr.getProtect()); + logical[X][Y].setBold(attr.isBold()); + logical[X][Y].setBlink(attr.isBlink()); + logical[X][Y].setReverse(attr.isReverse()); + logical[X][Y].setUnderline(attr.isUnderline()); + logical[X][Y].setProtect(attr.isProtect()); } } @@ -343,7 +358,8 @@ public abstract class Screen { * @param y row coordinate. 0 is the top-most row. * @param ch character to draw */ - public void putCharXY(final int x, final int y, final char ch) { + public final void putCharXY(final int x, final int y, final char ch) { + if ((x < clipLeft) || (x >= clipRight) || (y < clipTop) @@ -371,7 +387,7 @@ public abstract class Screen { * @param str string to draw * @param attr attributes to use (bold, foreColor, backColor) */ - public void putStrXY(final int x, final int y, final String str, + public final void putStringXY(final int x, final int y, final String str, final CellAttributes attr) { int i = x; @@ -393,7 +409,8 @@ public abstract class Screen { * @param y row coordinate. 0 is the top-most row. * @param str string to draw */ - public void putStrXY(final int x, final int y, final String str) { + public final void putStringXY(final int x, final int y, final String str) { + int i = x; for (int j = 0; j < str.length(); j++) { char ch = str.charAt(j); @@ -414,8 +431,8 @@ public abstract class Screen { * @param ch character to draw * @param attr attributes to use (bold, foreColor, backColor) */ - public void vLineXY(final int x, final int y, final int n, final char ch, - final CellAttributes attr) { + public final void vLineXY(final int x, final int y, final int n, + final char ch, final CellAttributes attr) { for (int i = y; i < y + n; i++) { putCharXY(x, i, ch, attr); @@ -431,8 +448,8 @@ public abstract class Screen { * @param ch character to draw * @param attr attributes to use (bold, foreColor, backColor) */ - public void hLineXY(final int x, final int y, final int n, final char ch, - final CellAttributes attr) { + public final void hLineXY(final int x, final int y, final int n, + final char ch, final CellAttributes attr) { for (int i = x; i < x + n; i++) { putCharXY(i, y, ch, attr); @@ -445,7 +462,7 @@ public abstract class Screen { * @param width new width * @param height new height */ - private void reallocate(final int width, final int height) { + private synchronized void reallocate(final int width, final int height) { if (logical != null) { for (int row = 0; row < this.height; row++) { for (int col = 0; col < this.width; col++) { @@ -490,7 +507,7 @@ public abstract class Screen { * * @param width new screen width */ - public void setWidth(final int width) { + public final synchronized void setWidth(final int width) { reallocate(width, this.height); } @@ -500,7 +517,7 @@ public abstract class Screen { * * @param height new screen height */ - public void setHeight(final int height) { + public final synchronized void setHeight(final int height) { reallocate(this.width, height); } @@ -511,7 +528,7 @@ public abstract class Screen { * @param width new screen width * @param height new screen height */ - public void setDimensions(final int width, final int height) { + public final void setDimensions(final int width, final int height) { reallocate(width, height); } @@ -520,7 +537,7 @@ public abstract class Screen { * * @return current screen height */ - public int getHeight() { + public final synchronized int getHeight() { return this.height; } @@ -529,14 +546,14 @@ public abstract class Screen { * * @return current screen width */ - public int getWidth() { + public final synchronized int getWidth() { return this.width; } /** * Public constructor. Sets everything to not-bold, white-on-black. */ - public Screen() { + protected Screen() { offsetX = 0; offsetY = 0; width = 80; @@ -550,7 +567,7 @@ public abstract class Screen { * Reset screen to not-bold, white-on-black. Also flushes the offset and * clip variables. */ - public void reset() { + public final synchronized void reset() { dirty = true; for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { @@ -563,7 +580,7 @@ public abstract class Screen { /** * Flush the offset and clip variables. */ - public void resetClipping() { + public final void resetClipping() { offsetX = 0; offsetY = 0; clipLeft = 0; @@ -573,12 +590,24 @@ public abstract class Screen { } /** - * Force the screen to be fully cleared and redrawn on the next flush(). + * Clear the logical screen. */ - public void clear() { + public final void clear() { reset(); } + /** + * Clear the physical screen. + */ + public final void clearPhysical() { + dirty = true; + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { + physical[col][row].reset(); + } + } + } + /** * Draw a box with a border and empty background. * @@ -589,7 +618,7 @@ public abstract class Screen { * @param border attributes to use for the border * @param background attributes to use for the background */ - public void drawBox(final int left, final int top, + public final void drawBox(final int left, final int top, final int right, final int bottom, final CellAttributes border, final CellAttributes background) { @@ -610,13 +639,11 @@ public abstract class Screen { * single-line left/right edges (like Qmodem) * @param shadow if true, draw a "shadow" on the box */ - public void drawBox(final int left, final int top, + public final void drawBox(final int left, final int top, final int right, final int bottom, final CellAttributes border, final CellAttributes background, final int borderType, final boolean shadow) { - int boxTop = top; - int boxLeft = left; int boxWidth = right - left; int boxHeight = bottom - top; @@ -684,14 +711,14 @@ public abstract class Screen { } /** - * Draw a box shadow + * Draw a box shadow. * * @param left left column of box. 0 is the left-most row. * @param top top row of the box. 0 is the top-most row. * @param right right column of box * @param bottom bottom row of the box */ - public void drawBoxShadow(final int left, final int top, + public final void drawBoxShadow(final int left, final int top, final int right, final int bottom) { int boxTop = top; @@ -725,7 +752,7 @@ public abstract class Screen { * Subclasses must provide an implementation to push the logical screen * to the physical device. */ - abstract public void flushPhysical(); + public abstract void flushPhysical(); /** * Put the cursor at (x,y). @@ -735,15 +762,16 @@ public abstract class Screen { * @param y row coordinate to put the cursor on */ public void putCursor(final boolean visible, final int x, final int y) { + cursorVisible = visible; cursorX = x; cursorY = y; } /** - * Hide the cursor + * Hide the cursor. */ - public void hideCursor() { + public final void hideCursor() { cursorVisible = false; } }