From 3405b554b5a0567b3c22f146fc1ce226e3fa48d2 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Wed, 6 Nov 2019 15:38:44 -0600 Subject: [PATCH] #65 pad images out to full cell size --- src/jexer/TImage.java | 17 +++++++++++++++-- src/jexer/tterminal/ECMA48.java | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) 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; } -- 2.27.0