mirror of
https://gitlab.com/AutumnMeowMeow/jexer
synced 2024-09-19 11:50:19 -06:00
#83 imagesOverText in TImage
This commit is contained in:
parent
6c7628b01d
commit
f513485b9e
4 changed files with 56 additions and 59 deletions
|
@ -31,6 +31,7 @@ package jexer;
|
|||
import java.awt.image.BufferedImage;
|
||||
|
||||
import jexer.bits.Cell;
|
||||
import jexer.bits.ImageUtils;
|
||||
import jexer.event.TCommandEvent;
|
||||
import jexer.event.TKeypressEvent;
|
||||
import jexer.event.TMouseEvent;
|
||||
|
@ -422,23 +423,14 @@ public class TImage extends TWidget implements EditMenuUser {
|
|||
}
|
||||
|
||||
Cell cell = new Cell();
|
||||
|
||||
// Always re-render the image against the cell
|
||||
// background, so that alpha in the image does not lead
|
||||
// to bleed-through artifacts.
|
||||
BufferedImage newImage;
|
||||
newImage = new BufferedImage(textWidth, textHeight,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
java.awt.Graphics gr = newImage.getGraphics();
|
||||
gr.setColor(cell.getBackground());
|
||||
gr.fillRect(0, 0, textWidth, textHeight);
|
||||
gr.drawImage(image.getSubimage(x * textWidth,
|
||||
y * textHeight, width, height),
|
||||
0, 0, null, null);
|
||||
gr.dispose();
|
||||
cell.setImage(newImage);
|
||||
|
||||
cell.setTo(getWindow().getBackground());
|
||||
|
||||
BufferedImage subImage = image.getSubimage(x * textWidth,
|
||||
y * textHeight, width, height);
|
||||
if (!ImageUtils.isFullyTransparent(subImage)) {
|
||||
cell.setImage(subImage);
|
||||
cell.flattenImage(false);
|
||||
}
|
||||
cells[x][y] = cell;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2257,7 +2257,6 @@ public class ECMA48Terminal extends LogicalScreen
|
|||
ArrayList<Cell> cellsToDraw = new ArrayList<Cell>();
|
||||
for (int i = 0; i < (right - x); i++) {
|
||||
assert (logical[x + i][y].isImage());
|
||||
GlyphMaker glyphMaker = null;
|
||||
BufferedImage newImage;
|
||||
BufferedImage textImage;
|
||||
|
||||
|
@ -2271,47 +2270,9 @@ public class ECMA48Terminal extends LogicalScreen
|
|||
// continue on. Otherwise render a text character
|
||||
// under the image.
|
||||
if (imagesOverText == true) {
|
||||
// Render this cell to a flat image. The bad
|
||||
// news is that we don't get to use the actual
|
||||
// terminal's font, because putting image data
|
||||
// over text is really iffy depending on
|
||||
// terminal. So we render it here instead.
|
||||
BufferedImage image = logical[x + i][y].getImage();
|
||||
int textWidth = image.getWidth();
|
||||
int textHeight = image.getHeight();
|
||||
if (glyphMaker == null) {
|
||||
glyphMaker = GlyphMaker.getInstance(textHeight);
|
||||
}
|
||||
newImage = new BufferedImage(textWidth,
|
||||
textHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
textImage = glyphMaker.getImage(logical[x + i][y],
|
||||
textWidth, textHeight);
|
||||
|
||||
java.awt.Graphics gr = newImage.getGraphics();
|
||||
gr.setColor(jexer.backend.SwingTerminal.
|
||||
attrToBackgroundColor(logical[x + i][y]));
|
||||
gr.drawImage(textImage, 0, 0, null, null);
|
||||
gr.drawImage(logical[x + i][y].getImage(), 0, 0,
|
||||
null, null);
|
||||
gr.dispose();
|
||||
logical[x + i][y].setImage(newImage);
|
||||
logical[x + i][y].flattenImage(true);
|
||||
} else {
|
||||
// Put the cell's background color behind the
|
||||
// pixels.
|
||||
BufferedImage image = logical[x + i][y].getImage();
|
||||
int textWidth = image.getWidth();
|
||||
int textHeight = image.getHeight();
|
||||
newImage = new BufferedImage(textWidth,
|
||||
textHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
java.awt.Graphics gr = newImage.getGraphics();
|
||||
gr.setColor(jexer.backend.SwingTerminal.
|
||||
attrToBackgroundColor(logical[x + i][y]));
|
||||
gr.fillRect(0, 0, newImage.getWidth(),
|
||||
newImage.getHeight());
|
||||
gr.drawImage(logical[x + i][y].getImage(), 0, 0,
|
||||
null, null);
|
||||
gr.dispose();
|
||||
logical[x + i][y].setImage(newImage);
|
||||
logical[x + i][y].flattenImage(false);
|
||||
}
|
||||
}
|
||||
assert (!logical[x + i][y].isTransparentImage());
|
||||
|
|
|
@ -323,7 +323,7 @@ public class GlyphMaker {
|
|||
/**
|
||||
* The mono font resource filename (terminus).
|
||||
*/
|
||||
private static final String MONO = "terminus-ttf-4.39/TerminusTTF-Bold-4.39.ttf";
|
||||
private static final String MONO = "terminus-ttf-4.49.1/TerminusTTF-Bold-4.49.1.ttf";
|
||||
|
||||
/**
|
||||
* The CJK font resource filename.
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
package jexer.bits;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import jexer.backend.GlyphMaker;
|
||||
|
||||
/**
|
||||
* This class represents a single text cell or bit of image on the screen.
|
||||
|
@ -198,6 +199,49 @@ public class Cell extends CellAttributes {
|
|||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten the image on this cell by rendering it either onto the
|
||||
* background color, or generating the glyph and rendering over that.
|
||||
*
|
||||
* @param overGlyph if true, render over the glyph
|
||||
*/
|
||||
public void flattenImage(final boolean overGlyph) {
|
||||
if (!isImage()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasTransparentPixels == 2) {
|
||||
// The image already covers the entire cell.
|
||||
return;
|
||||
}
|
||||
|
||||
// We will be opaque when done.
|
||||
hasTransparentPixels = 2;
|
||||
|
||||
int textWidth = image.getWidth();
|
||||
int textHeight = image.getHeight();
|
||||
BufferedImage newImage = new BufferedImage(textWidth,
|
||||
textHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
java.awt.Graphics gr = newImage.getGraphics();
|
||||
gr.setColor(jexer.backend.SwingTerminal.
|
||||
attrToBackgroundColor(this));
|
||||
|
||||
if (overGlyph) {
|
||||
// Render this cell to a flat image. The bad news is that we
|
||||
// won't get to use the actual terminal's font.
|
||||
GlyphMaker glyphMaker = GlyphMaker.getInstance(textHeight);
|
||||
gr.drawImage(glyphMaker.getImage(this, textWidth, textHeight),
|
||||
0, 0, null, null);
|
||||
} else {
|
||||
// Put the background color behind the pixels.
|
||||
gr.fillRect(0, 0, newImage.getWidth(),
|
||||
newImage.getHeight());
|
||||
}
|
||||
gr.drawImage(image, 0, 0, null, null);
|
||||
gr.dispose();
|
||||
setImage(newImage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blit another cell's image on top of the image data for this cell.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue