From: Kevin Lamonte Date: Wed, 6 Nov 2019 21:38:44 +0000 (-0600) Subject: #65 pad images out to full cell size X-Git-Tag: fanfix-swing-0.0.1~12^2~13^2^2~20 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=3405b554b5a0567b3c22f146fc1ce226e3fa48d2;p=fanfix-swing.git #65 pad images out to full cell size --- diff --git a/src/jexer/TImage.java b/src/jexer/TImage.java index 1463f100..2dfd6a30 100644 --- a/src/jexer/TImage.java +++ b/src/jexer/TImage.java @@ -425,8 +425,21 @@ public class TImage extends TWidget implements EditMenuUser { } Cell cell = new Cell(); - cell.setImage(image.getSubimage(x * textWidth, - y * textHeight, width, height)); + if ((width != textWidth) || (height != textHeight)) { + BufferedImage newImage; + newImage = new BufferedImage(textWidth, textHeight, + BufferedImage.TYPE_INT_ARGB); + + java.awt.Graphics gr = newImage.getGraphics(); + gr.drawImage(image.getSubimage(x * textWidth, + y * textHeight, width, height), + 0, 0, null, null); + gr.dispose(); + cell.setImage(newImage); + } else { + cell.setImage(image.getSubimage(x * textWidth, + y * textHeight, width, height)); + } cells[x][y] = cell; } diff --git a/src/jexer/tterminal/ECMA48.java b/src/jexer/tterminal/ECMA48.java index ce06c36b..369eca93 100644 --- a/src/jexer/tterminal/ECMA48.java +++ b/src/jexer/tterminal/ECMA48.java @@ -7305,8 +7305,21 @@ public class ECMA48 implements Runnable { } Cell cell = new Cell(); - cell.setImage(image.getSubimage(x * textWidth, - y * textHeight, width, height)); + if ((width != textWidth) || (height != textHeight)) { + BufferedImage newImage; + newImage = new BufferedImage(textWidth, textHeight, + BufferedImage.TYPE_INT_ARGB); + + java.awt.Graphics gr = newImage.getGraphics(); + gr.drawImage(image.getSubimage(x * textWidth, + y * textHeight, width, height), + 0, 0, null, null); + gr.dispose(); + cell.setImage(newImage); + } else { + cell.setImage(image.getSubimage(x * textWidth, + y * textHeight, width, height)); + } cells[x][y] = cell; }