X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FCell.java;h=c949c3e36c147efb830f019f988225df966974cf;hb=027de5ae322ef58d3bc74051d3aa20847455361a;hp=d4c816f41ee88e202bf9e509af30b47630a97482;hpb=a69ed767c9c07cf35cf1c5f7821fc009cfe79cd2;p=fanfix.git diff --git a/src/jexer/bits/Cell.java b/src/jexer/bits/Cell.java index d4c816f..c949c3e 100644 --- a/src/jexer/bits/Cell.java +++ b/src/jexer/bits/Cell.java @@ -40,6 +40,26 @@ public final class Cell extends CellAttributes { // Constants -------------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * How this cell needs to be displayed if it is part of a larger glyph. + */ + public enum Width { + /** + * This cell is an entire glyph on its own. + */ + SINGLE, + + /** + * This cell is the left half of a wide glyph. + */ + LEFT, + + /** + * This cell is the right half of a wide glyph. + */ + RIGHT, + } + /** * The special "this cell is unset" (null) value. This is the Unicode * "not a character" value. @@ -53,7 +73,12 @@ public final class Cell extends CellAttributes { /** * The character at this cell. */ - private char ch; + private char ch = ' '; + + /** + * The display width of this cell. + */ + private Width width = Width.SINGLE; /** * The image at this cell. @@ -69,7 +94,7 @@ public final class Cell extends CellAttributes { * The background color used for the area the image portion might not * cover. */ - private Color background = null; + private Color background = Color.BLACK; /** * hashCode() needs to call image.hashCode(), which can get quite @@ -94,7 +119,7 @@ public final class Cell extends CellAttributes { * @see #reset() */ public Cell() { - reset(); + // NOP } /** @@ -105,15 +130,33 @@ public final class Cell extends CellAttributes { * @see #reset() */ public Cell(final char ch) { - reset(); this.ch = ch; } + /** + * Public constructor sets the character and attributes. + * + * @param ch character to set to + * @param attr attributes to use + */ + public Cell(final char ch, final CellAttributes attr) { + super(attr); + this.ch = ch; + } + + /** + * Public constructor creates a duplicate. + * + * @param cell the instance to copy + */ + public Cell(final Cell cell) { + setTo(cell); + } + // ------------------------------------------------------------------------ // Cell ------------------------------------------------------------------- // ------------------------------------------------------------------------ - /** * Set the image data for this cell. * @@ -122,6 +165,7 @@ public final class Cell extends CellAttributes { public void setImage(final BufferedImage image) { this.image = image; imageHashCode = image.hashCode(); + width = Width.SINGLE; } /** @@ -223,6 +267,25 @@ public final class Cell extends CellAttributes { this.ch = ch; } + /** + * Getter for cell width. + * + * @return Width.SINGLE, Width.LEFT, or Width.RIGHT + */ + public Width getWidth() { + return width; + } + + /** + * Setter for cell width. + * + * @param width new cell width, one of Width.SINGLE, Width.LEFT, or + * Width.RIGHT + */ + public void setWidth(final Width width) { + this.width = width; + } + /** * Reset this cell to a blank. */ @@ -230,6 +293,7 @@ public final class Cell extends CellAttributes { public void reset() { super.reset(); ch = ' '; + width = Width.SINGLE; image = null; imageHashCode = 0; invertedImage = null; @@ -244,6 +308,7 @@ public final class Cell extends CellAttributes { public void unset() { super.reset(); ch = UNSET_VALUE; + width = Width.SINGLE; image = null; imageHashCode = 0; invertedImage = null; @@ -271,6 +336,7 @@ public final class Cell extends CellAttributes { && !isProtect() && !isRGB() && !isImage() + && (width == Width.SINGLE) && (ch == ' ') ) { return true; @@ -327,7 +393,7 @@ public final class Cell extends CellAttributes { } // Normal case: character and attributes must match. - if (ch == that.ch) { + if ((ch == that.ch) && (width == that.width)) { return super.equals(rhs); } return false; @@ -345,6 +411,7 @@ public final class Cell extends CellAttributes { int hash = A; hash = (B * hash) + super.hashCode(); hash = (B * hash) + (int)ch; + hash = (B * hash) + width.hashCode(); if (image != null) { /* hash = (B * hash) + image.hashCode(); @@ -371,11 +438,13 @@ public final class Cell extends CellAttributes { this.image = null; this.imageHashCode = 0; this.backgroundHashCode = 0; + this.width = Width.SINGLE; super.setTo(thatAttr); if (rhs instanceof Cell) { Cell that = (Cell) rhs; this.ch = that.ch; + this.width = that.width; this.image = that.image; this.invertedImage = that.invertedImage; this.background = that.background;