mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
GUI, performance: fixed memory/resources leaks on some components rendering
This commit is contained in:
parent
1f3fad6594
commit
83823acec7
18 changed files with 341 additions and 248 deletions
|
|
@ -1487,9 +1487,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
if (!liteMode) {
|
||||
final SplashScreen splash = SplashScreen.getSplashScreen();
|
||||
if (splash != null) {
|
||||
Graphics2D g = splash.createGraphics();
|
||||
if (g != null) {
|
||||
renderSplashFrame(g);
|
||||
Graphics2D g2 = splash.createGraphics();
|
||||
try {
|
||||
renderSplashFrame(g2);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
splash.update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -330,12 +330,15 @@ public class CardIconsPanel extends JPanel {
|
|||
JLabel label = new JLabel();
|
||||
label.setToolTipText("<html>" + ManaSymbols.replaceSymbolsWithHTML(icon.getHint(), ManaSymbols.Type.CARD_ICON_HINT));
|
||||
if (!icon.getText().isEmpty()) {
|
||||
Graphics2D g2d = iconImageWithText.createGraphics();
|
||||
g2d.setColor(PreferencesDialog.getCurrentTheme().getCardIconsTextColor(this.color));
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
Rectangle rect = CardRendererUtils.reduceRect(new Rectangle(0, 0, iconImageWithText.getWidth(), iconImageWithText.getHeight()), 0.8f);
|
||||
CardRendererUtils.drawCenteredText(g2d, icon.getText(), rect, this.font, true);
|
||||
g2d.dispose();
|
||||
Graphics2D g2 = iconImageWithText.createGraphics();
|
||||
try {
|
||||
g2.setColor(PreferencesDialog.getCurrentTheme().getCardIconsTextColor(this.color));
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
Rectangle rect = CardRendererUtils.reduceRect(new Rectangle(0, 0, iconImageWithText.getWidth(), iconImageWithText.getHeight()), 0.8f);
|
||||
CardRendererUtils.drawCenteredText(g2, icon.getText(), rect, this.font, true);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// the stretch icon can occupy all space (full grid's cell)
|
||||
|
|
|
|||
|
|
@ -144,37 +144,40 @@ public class MageRoundPane extends JPanel {
|
|||
|
||||
BufferedImage image = GraphicsUtilities.createCompatibleTranslucentImage(key.width, key.height);
|
||||
Graphics2D g2 = image.createGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
try {
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
BufferedImage shadow = ROUND_PANEL_SHADOW_IMAGES_CACHE.getOrThrow(new ShadowKey(w, h));
|
||||
BufferedImage shadow = ROUND_PANEL_SHADOW_IMAGES_CACHE.getOrThrow(new ShadowKey(w, h));
|
||||
|
||||
{
|
||||
int xOffset = (shadow.getWidth() - w) / 2;
|
||||
int yOffset = (shadow.getHeight() - h) / 2;
|
||||
g2.drawImage(shadow, x - xOffset, y - yOffset, null);
|
||||
{
|
||||
int xOffset = (shadow.getWidth() - w) / 2;
|
||||
int yOffset = (shadow.getHeight() - h) / 2;
|
||||
g2.drawImage(shadow, x - xOffset, y - yOffset, null);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// fill content
|
||||
/**
|
||||
* Add white translucent substrate
|
||||
*/
|
||||
/*if (ALPHA != 0) {
|
||||
g2.setColor(new Color(255, 255, 255, ALPHA));
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
}*/
|
||||
g2.setColor(key.backgroundColor);
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// draw border
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRoundRect(x, y, w, h, arc, arc);
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// fill content
|
||||
/**
|
||||
* Add white translucent substrate
|
||||
*/
|
||||
/*if (ALPHA != 0) {
|
||||
g2.setColor(new Color(255, 255, 255, ALPHA));
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
}*/
|
||||
g2.setColor(key.backgroundColor);
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// draw border
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRoundRect(x, y, w, h, arc, arc);
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
|
||||
g2.dispose();
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
@ -194,9 +197,12 @@ public class MageRoundPane extends JPanel {
|
|||
|
||||
BufferedImage base = GraphicsUtilities.createCompatibleTranslucentImage(w, h);
|
||||
Graphics2D g2 = base.createGraphics();
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.fillRoundRect(0, 0, w, h, arc, arc);
|
||||
g2.dispose();
|
||||
try {
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.fillRoundRect(0, 0, w, h, arc, arc);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
ShadowRenderer renderer = new ShadowRenderer(shadowSize, 0.5f,
|
||||
Color.GRAY);
|
||||
|
|
|
|||
|
|
@ -273,10 +273,13 @@ public class StretchIcon extends ImageIcon {
|
|||
* BEGIN CHANGES
|
||||
*/
|
||||
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
Graphics2D g2d = bi.createGraphics();
|
||||
g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
|
||||
g2d.drawImage(image, 0, 0, w, h, io == null ? c : io);
|
||||
g2d.dispose();
|
||||
Graphics2D g2 = bi.createGraphics();
|
||||
try {
|
||||
g2.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
|
||||
g2.drawImage(image, 0, 0, w, h, io == null ? c : io);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
/*
|
||||
* END CHANGES
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -112,44 +112,46 @@ public class DialogContainer extends JPanel {
|
|||
int arc = 30;
|
||||
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
try {
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
if (shadow != null) {
|
||||
int xOffset = (shadow.getWidth() - w) / 2;
|
||||
int yOffset = (shadow.getHeight() - h) / 2;
|
||||
g2.drawImage(shadow, x - xOffset, y - yOffset, null);
|
||||
if (shadow != null) {
|
||||
int xOffset = (shadow.getWidth() - w) / 2;
|
||||
int yOffset = (shadow.getHeight() - h) / 2;
|
||||
g2.drawImage(shadow, x - xOffset, y - yOffset, null);
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
// fill content
|
||||
|
||||
/**
|
||||
* Add white translucent substrate
|
||||
*/
|
||||
if (alpha != 0) {
|
||||
g2.setColor(new Color(255, 255, 255, alpha));
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
}
|
||||
|
||||
if (!isGradient) {
|
||||
g2.setColor(backgroundColor);
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
} else {
|
||||
RoundRectangle2D r = new RoundRectangle2D.Float(x, y, w, h, arc, arc);
|
||||
g2.setPaint(tp);
|
||||
g2.fill(r);
|
||||
}
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
// draw border
|
||||
g2.setStroke(new BasicStroke(3f));
|
||||
g2.setColor(Color.BLACK);
|
||||
//g2.setColor(Color.GRAY);
|
||||
g2.drawRoundRect(x, y, w, h, arc, arc);
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
// fill content
|
||||
|
||||
/**
|
||||
* Add white translucent substrate
|
||||
*/
|
||||
if (alpha != 0) {
|
||||
g2.setColor(new Color(255, 255, 255, alpha));
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
}
|
||||
|
||||
if (!isGradient) {
|
||||
g2.setColor(backgroundColor);
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
} else {
|
||||
RoundRectangle2D r = new RoundRectangle2D.Float(x, y, w, h, arc, arc);
|
||||
g2.setPaint(tp);
|
||||
g2.fill(r);
|
||||
}
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
// draw border
|
||||
g2.setStroke(new BasicStroke(3f));
|
||||
g2.setColor(Color.BLACK);
|
||||
//g2.setColor(Color.GRAY);
|
||||
g2.drawRoundRect(x, y, w, h, arc, arc);
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
public void showDialog(boolean bShow) {
|
||||
|
|
|
|||
|
|
@ -83,20 +83,27 @@ public final class TransformedImageCache {
|
|||
GraphicsConfiguration gc = gs.getDefaultConfiguration();
|
||||
|
||||
BufferedImage result = gc.createCompatibleImage(newWidth, newHeight, Transparency.TRANSLUCENT);
|
||||
Graphics2D g = result.createGraphics();
|
||||
g.translate((newWidth - width) / 2, (newHeight - height) / 2);
|
||||
g.rotate(angle, width / 2, height / 2);
|
||||
g.drawRenderedImage(image, null);
|
||||
g.dispose();
|
||||
Graphics2D g2 = result.createGraphics();
|
||||
try {
|
||||
g2.translate((newWidth - width) / 2, (newHeight - height) / 2);
|
||||
g2.rotate(angle, width / 2, height / 2);
|
||||
g2.drawRenderedImage(image, null);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static BufferedImage resizeImage(BufferedImage original, int width, int height) {
|
||||
Image scaled = original.getScaledInstance(width, height, Image.SCALE_SMOOTH);
|
||||
BufferedImage output = new BufferedImage(width, height, original.getType());
|
||||
Graphics2D graphics = output.createGraphics();
|
||||
graphics.drawImage(scaled, 0, 0, null);
|
||||
graphics.dispose();
|
||||
Graphics2D g2 = output.createGraphics();
|
||||
try {
|
||||
g2.drawImage(scaled, 0, 0, null);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,9 +30,12 @@ public class BufferedImageBuilder {
|
|||
return null;
|
||||
}
|
||||
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
|
||||
Graphics2D g = bufferedImage.createGraphics();
|
||||
g.drawImage(image, null, null);
|
||||
//waitForImage(bufferedImage);
|
||||
Graphics2D g2 = bufferedImage.createGraphics();
|
||||
try {
|
||||
g2.drawImage(image, null, null);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
|
|
@ -41,10 +44,14 @@ public class BufferedImageBuilder {
|
|||
return null;
|
||||
}
|
||||
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
|
||||
Graphics2D g = bufferedImage.createGraphics();
|
||||
g.drawImage(image, null, null);
|
||||
g.setColor(color);
|
||||
g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
|
||||
Graphics2D g2 = bufferedImage.createGraphics();
|
||||
try {
|
||||
g2.drawImage(image, null, null);
|
||||
g2.setColor(color);
|
||||
g2.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -375,13 +375,12 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen
|
|||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) (g.create());
|
||||
|
||||
// Defer to subclasses
|
||||
paintCard(g2d);
|
||||
|
||||
// Done, dispose of the context
|
||||
g2d.dispose();
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
try {
|
||||
paintCard(g2);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -183,50 +183,52 @@ public class CardPanelRenderModeImage extends CardPanel {
|
|||
int cardYOffset = key.cardYOffset;
|
||||
|
||||
BufferedImage image = GraphicsUtilities.createCompatibleTranslucentImage(renderWidth, renderHeight);
|
||||
Graphics2D g2d = image.createGraphics();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
Graphics2D g2 = image.createGraphics();
|
||||
try {
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
// card full size = select border + black border + real card
|
||||
CardSizes sizes = new CardSizes(componentBorder, cardXOffset, cardYOffset, renderWidth, renderHeight);
|
||||
// card full size = select border + black border + real card
|
||||
CardSizes sizes = new CardSizes(componentBorder, cardXOffset, cardYOffset, renderWidth, renderHeight);
|
||||
|
||||
// corners for selection and for border
|
||||
int cornerSizeSelection = Math.max(4, Math.round(sizes.rectSelection.width * ROUNDED_CORNER_SIZE));
|
||||
int cornerSizeBorder = Math.max(4, Math.round(sizes.rectBorder.width * ROUNDED_CORNER_SIZE));
|
||||
// corners for selection and for border
|
||||
int cornerSizeSelection = Math.max(4, Math.round(sizes.rectSelection.width * ROUNDED_CORNER_SIZE));
|
||||
int cornerSizeBorder = Math.max(4, Math.round(sizes.rectBorder.width * ROUNDED_CORNER_SIZE));
|
||||
|
||||
// DRAW ORDER from big to small: select -> select info -> border -> card
|
||||
// DRAW ORDER from big to small: select -> select info -> border -> card
|
||||
|
||||
// draw selection
|
||||
if (key.isSelected) {
|
||||
// TODO: add themes color support
|
||||
g2d.setColor(Color.green);
|
||||
g2d.fillRoundRect(sizes.rectSelection.x + 1, sizes.rectSelection.y + 1, sizes.rectSelection.width - 2, sizes.rectSelection.height - 2, cornerSizeSelection, cornerSizeSelection);
|
||||
} else if (key.isChoosable) {
|
||||
g2d.setColor(new Color(250, 250, 0, 230));
|
||||
g2d.fillRoundRect(sizes.rectSelection.x + 1, sizes.rectSelection.y + 1, sizes.rectSelection.width - 2, sizes.rectSelection.height - 2, cornerSizeSelection, cornerSizeSelection);
|
||||
} else if (key.isPlayable) {
|
||||
g2d.setColor(new Color(153, 102, 204, 200));
|
||||
g2d.fillRoundRect(sizes.rectSelection.x, sizes.rectSelection.y, sizes.rectSelection.width, sizes.rectSelection.height, cornerSizeSelection, cornerSizeSelection);
|
||||
}
|
||||
// draw selection
|
||||
if (key.isSelected) {
|
||||
// TODO: add themes color support
|
||||
g2.setColor(Color.green);
|
||||
g2.fillRoundRect(sizes.rectSelection.x + 1, sizes.rectSelection.y + 1, sizes.rectSelection.width - 2, sizes.rectSelection.height - 2, cornerSizeSelection, cornerSizeSelection);
|
||||
} else if (key.isChoosable) {
|
||||
g2.setColor(new Color(250, 250, 0, 230));
|
||||
g2.fillRoundRect(sizes.rectSelection.x + 1, sizes.rectSelection.y + 1, sizes.rectSelection.width - 2, sizes.rectSelection.height - 2, cornerSizeSelection, cornerSizeSelection);
|
||||
} else if (key.isPlayable) {
|
||||
g2.setColor(new Color(153, 102, 204, 200));
|
||||
g2.fillRoundRect(sizes.rectSelection.x, sizes.rectSelection.y, sizes.rectSelection.width, sizes.rectSelection.height, cornerSizeSelection, cornerSizeSelection);
|
||||
}
|
||||
|
||||
// draw attack or block border (?inner part of a selection?)
|
||||
if (key.canAttack || key.canBlock) {
|
||||
g2d.setColor(new Color(255, 50, 50, 230));
|
||||
g2d.fillRoundRect(sizes.rectSelection.x + 1, sizes.rectSelection.y + 1, sizes.rectSelection.width - 2, sizes.rectSelection.height - 2, cornerSizeSelection, cornerSizeSelection);
|
||||
}
|
||||
// draw attack or block border (?inner part of a selection?)
|
||||
if (key.canAttack || key.canBlock) {
|
||||
g2.setColor(new Color(255, 50, 50, 230));
|
||||
g2.fillRoundRect(sizes.rectSelection.x + 1, sizes.rectSelection.y + 1, sizes.rectSelection.width - 2, sizes.rectSelection.height - 2, cornerSizeSelection, cornerSizeSelection);
|
||||
}
|
||||
|
||||
// draw empty card with border
|
||||
if (!key.hasImage) {
|
||||
// gray 1 px border
|
||||
g2d.setColor(new Color(125, 125, 125, 255));
|
||||
g2d.fillRoundRect(sizes.rectBorder.x, sizes.rectBorder.y, sizes.rectBorder.width, sizes.rectBorder.height, cornerSizeBorder, cornerSizeBorder);
|
||||
// color plate
|
||||
g2d.setColor(new Color(30, 200, 200, 200));
|
||||
g2d.fillRoundRect(sizes.rectBorder.x + 1, sizes.rectBorder.y + 1, sizes.rectBorder.width - 2, sizes.rectBorder.height - 2, cornerSizeBorder, cornerSizeBorder);
|
||||
// draw empty card with border
|
||||
if (!key.hasImage) {
|
||||
// gray 1 px border
|
||||
g2.setColor(new Color(125, 125, 125, 255));
|
||||
g2.fillRoundRect(sizes.rectBorder.x, sizes.rectBorder.y, sizes.rectBorder.width, sizes.rectBorder.height, cornerSizeBorder, cornerSizeBorder);
|
||||
// color plate
|
||||
g2.setColor(new Color(30, 200, 200, 200));
|
||||
g2.fillRoundRect(sizes.rectBorder.x + 1, sizes.rectBorder.y + 1, sizes.rectBorder.width - 2, sizes.rectBorder.height - 2, cornerSizeBorder, cornerSizeBorder);
|
||||
}
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
// draw real card by component (see imagePanel and other layout's items)
|
||||
g2d.dispose();
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
@ -241,10 +243,15 @@ public class CardPanelRenderModeImage extends CardPanel {
|
|||
} else {
|
||||
newImage = ImageHelper.getResizedImage(image, 20, 20);
|
||||
}
|
||||
Graphics graphics = newImage.getGraphics();
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.setFont(new Font("Arial Black", amount > 100 ? Font.PLAIN : Font.BOLD, fontSize));
|
||||
graphics.drawString(Integer.toString(amount), xOffset * factor, 11 * factor);
|
||||
Graphics g2 = newImage.createGraphics();
|
||||
try {
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.setFont(new Font("Arial Black", amount > 100 ? Font.PLAIN : Font.BOLD, fontSize));
|
||||
g2.drawString(Integer.toString(amount), xOffset * factor, 11 * factor);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
return new ImageIcon(newImage);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -309,18 +309,19 @@ public class CardPanelRenderModeMTGO extends CardPanel {
|
|||
// Create image to render to
|
||||
BufferedImage image
|
||||
= GraphicsUtilities.createCompatibleTranslucentImage(cardWidth, cardHeight);
|
||||
Graphics2D g2d = image.createGraphics();
|
||||
Graphics2D g2 = image.createGraphics();
|
||||
try {
|
||||
// Render with Antialialsing
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
|
||||
// Render with Antialialsing
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
// Draw card itself
|
||||
cardRenderer.draw(g2, getAttributes(), image);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
// Draw card itself
|
||||
cardRenderer.draw(g2d, getAttributes(), image);
|
||||
|
||||
// Done
|
||||
g2d.dispose();
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -335,18 +335,23 @@ public abstract class CardRenderer {
|
|||
break;
|
||||
}
|
||||
double scale = (0.1 * 0.25 * cardWidth);
|
||||
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
g2.translate(xPos, yPos);
|
||||
g2.scale(scale, scale);
|
||||
g2.setColor(Color.white);
|
||||
g2.fillPolygon(p);
|
||||
g2.setColor(Color.black);
|
||||
g2.drawPolygon(p);
|
||||
g2.setFont(new Font("Arial", Font.BOLD, 7));
|
||||
String cstr = String.valueOf(v.getCount());
|
||||
int strW = g2.getFontMetrics().stringWidth(cstr);
|
||||
g2.drawString(cstr, 5 - strW / 2, 8);
|
||||
g2.dispose();
|
||||
try {
|
||||
g2.translate(xPos, yPos);
|
||||
g2.scale(scale, scale);
|
||||
g2.setColor(Color.white);
|
||||
g2.fillPolygon(p);
|
||||
g2.setColor(Color.black);
|
||||
g2.drawPolygon(p);
|
||||
g2.setFont(new Font("Arial", Font.BOLD, 7));
|
||||
String cstr = String.valueOf(v.getCount());
|
||||
int strW = g2.getFontMetrics().stringWidth(cstr);
|
||||
g2.drawString(cstr, 5 - strW / 2, 8);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
yPos += ((int) (0.30 * cardWidth));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,9 +55,12 @@ public final class CardRendererUtils {
|
|||
BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
// Draw the image on to the buffered image
|
||||
Graphics2D bGr = bimage.createGraphics();
|
||||
bGr.drawImage(img, 0, 0, null);
|
||||
bGr.dispose();
|
||||
Graphics2D g2 = bimage.createGraphics();
|
||||
try {
|
||||
g2.drawImage(img, 0, 0, null);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
// Return the buffered image
|
||||
return bimage;
|
||||
|
|
|
|||
|
|
@ -159,53 +159,58 @@ public class GlowText extends JLabel {
|
|||
private static BufferedImage createGlowImage(Key key) {
|
||||
Dimension size = new Dimension(key.width, key.height);
|
||||
BufferedImage image = GraphicsUtilities.createCompatibleTranslucentImage(size.width, size.height);
|
||||
Graphics2D g2d = image.createGraphics();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
Graphics2D g2 = image.createGraphics();
|
||||
try {
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
int textX = 0, textY = 0;
|
||||
int wrapWidth = Math.max(0, key.wrap ? size.width - key.glowSize : Integer.MAX_VALUE);
|
||||
int textX = 0, textY = 0;
|
||||
int wrapWidth = Math.max(0, key.wrap ? size.width - key.glowSize : Integer.MAX_VALUE);
|
||||
|
||||
AttributedString attributedString = new AttributedString(key.text);
|
||||
attributedString.addAttribute(TextAttribute.FONT, key.getFont());
|
||||
AttributedCharacterIterator charIterator = attributedString.getIterator();
|
||||
FontRenderContext fontContext = g2d.getFontRenderContext();
|
||||
AttributedString attributedString = new AttributedString(key.text);
|
||||
attributedString.addAttribute(TextAttribute.FONT, key.getFont());
|
||||
AttributedCharacterIterator charIterator = attributedString.getIterator();
|
||||
FontRenderContext fontContext = g2.getFontRenderContext();
|
||||
|
||||
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH), fontContext);
|
||||
int lineCount = 0;
|
||||
while (measurer.getPosition() < charIterator.getEndIndex()) {
|
||||
//TextLayout textLayout = measurer.nextLayout(wrapWidth);
|
||||
lineCount++;
|
||||
if (lineCount > 2) {
|
||||
break;
|
||||
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH), fontContext);
|
||||
int lineCount = 0;
|
||||
while (measurer.getPosition() < charIterator.getEndIndex()) {
|
||||
//TextLayout textLayout = measurer.nextLayout(wrapWidth);
|
||||
lineCount++;
|
||||
if (lineCount > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
charIterator.first();
|
||||
// Use char wrap if word wrap would cause more than two lines of text.
|
||||
if (lineCount > 2) {
|
||||
measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext);
|
||||
} else {
|
||||
measurer.setPosition(0);
|
||||
}
|
||||
while (measurer.getPosition() < charIterator.getEndIndex()) {
|
||||
TextLayout textLayout = measurer.nextLayout(wrapWidth);
|
||||
float ascent = textLayout.getAscent();
|
||||
textY += ascent; // Move down to baseline.
|
||||
charIterator.first();
|
||||
// Use char wrap if word wrap would cause more than two lines of text.
|
||||
if (lineCount > 2) {
|
||||
measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext);
|
||||
} else {
|
||||
measurer.setPosition(0);
|
||||
}
|
||||
while (measurer.getPosition() < charIterator.getEndIndex()) {
|
||||
TextLayout textLayout = measurer.nextLayout(wrapWidth);
|
||||
float ascent = textLayout.getAscent();
|
||||
textY += ascent; // Move down to baseline.
|
||||
|
||||
g2d.setColor(key.glowColor);
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
|
||||
int glowSize = key.glowSize;
|
||||
textLayout.draw(g2d, textX + glowSize / 2 + 1, textY + glowSize / 2 - 1);
|
||||
textLayout.draw(g2d, textX + glowSize / 2 + 1, textY + glowSize / 2 + 1);
|
||||
textLayout.draw(g2d, textX + glowSize / 2 - 1, textY + glowSize / 2 - 1);
|
||||
textLayout.draw(g2d, textX + glowSize / 2 - 1, textY + glowSize / 2 + 1);
|
||||
g2.setColor(key.glowColor);
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
|
||||
int glowSize = key.glowSize;
|
||||
textLayout.draw(g2, textX + glowSize / 2 + 1, textY + glowSize / 2 - 1);
|
||||
textLayout.draw(g2, textX + glowSize / 2 + 1, textY + glowSize / 2 + 1);
|
||||
textLayout.draw(g2, textX + glowSize / 2 - 1, textY + glowSize / 2 - 1);
|
||||
textLayout.draw(g2, textX + glowSize / 2 - 1, textY + glowSize / 2 + 1);
|
||||
|
||||
g2d.setColor(key.color);
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
|
||||
textLayout.draw(g2d, textX + glowSize / 2, textY + glowSize / 2);
|
||||
g2.setColor(key.color);
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
|
||||
textLayout.draw(g2, textX + glowSize / 2, textY + glowSize / 2);
|
||||
|
||||
textY += textLayout.getDescent() + textLayout.getLeading(); // Move down to top of next line.
|
||||
textY += textLayout.getDescent() + textLayout.getLeading(); // Move down to top of next line.
|
||||
}
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -488,6 +488,7 @@ public final class ManaSymbols {
|
|||
BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D gg = image.createGraphics();
|
||||
manaPanel.paint(gg);
|
||||
gg.dispose()
|
||||
g.drawImage(image, x, y, null);
|
||||
*/
|
||||
// OLD version with custom draw
|
||||
|
|
@ -539,10 +540,14 @@ public final class ManaSymbols {
|
|||
// render component to new position
|
||||
// need to copy graphics, overvise it draw at top left corner
|
||||
// https://stackoverflow.com/questions/4974268/java-paint-problem
|
||||
Graphics2D labelG = (Graphics2D) g.create(x, y, symbolWidth, symbolWidth);
|
||||
labelG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
labelG.fillOval(x + 1, y + 1, symbolWidth - 2, symbolWidth - 2);
|
||||
labelRender.paint(labelG);
|
||||
Graphics2D g2 = (Graphics2D) g.create(x, y, symbolWidth, symbolWidth);
|
||||
try {
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.fillOval(x + 1, y + 1, symbolWidth - 2, symbolWidth - 2);
|
||||
labelRender.paint(g2);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
} else {
|
||||
// ICON draw
|
||||
g.drawImage(image, x, y, null);
|
||||
|
|
|
|||
|
|
@ -355,24 +355,48 @@ public class ModernSplitCardRenderer extends ModernCardRenderer {
|
|||
totalContentInset + 3, typeLineY + boxHeight * 3 - 1,
|
||||
contentWidth / 2 - 8, cardHeight - borderWidth * 3 - typeLineY - boxHeight * 3 + 2, false);
|
||||
} else if (isAftermath()) {
|
||||
drawSplitHalfFrame(getUnmodifiedHalfContext(g), attribs, leftHalf, (int) (leftHalf.ch * TYPE_LINE_Y_FRAC));
|
||||
drawSplitHalfFrame(getAftermathHalfContext(g), attribs, rightHalf, (rightHalf.ch - boxHeight) / 2);
|
||||
Graphics2D g2 = getUnmodifiedHalfContext(g);
|
||||
try {
|
||||
drawSplitHalfFrame(g2, attribs, leftHalf, (int) (leftHalf.ch * TYPE_LINE_Y_FRAC));
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
g2 = getAftermathHalfContext(g);
|
||||
try {
|
||||
drawSplitHalfFrame(g2, attribs, rightHalf, (rightHalf.ch - boxHeight) / 2);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
} else {
|
||||
drawSplitHalfFrame(getLeftHalfContext(g), attribs, leftHalf, (int) (leftHalf.ch * TYPE_LINE_Y_FRAC));
|
||||
drawSplitHalfFrame(getRightHalfContext(g), attribs, rightHalf, (int) (rightHalf.ch * TYPE_LINE_Y_FRAC));
|
||||
Graphics2D g2 = getLeftHalfContext(g);
|
||||
try {
|
||||
drawSplitHalfFrame(g2, attribs, leftHalf, (int) (leftHalf.ch * TYPE_LINE_Y_FRAC));
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
g2 = getRightHalfContext(g);
|
||||
try {
|
||||
drawSplitHalfFrame(g2, attribs, rightHalf, (int) (rightHalf.ch * TYPE_LINE_Y_FRAC));
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
if (isFuse()) {
|
||||
Graphics2D g2 = getRightHalfContext(g);
|
||||
int totalFuseBoxWidth = rightHalf.cw * 2 + 2 * borderWidth + dividerSize;
|
||||
Paint boxColor = getTextboxPaint(cardView.getColor(), ONLY_LAND_TYPE, totalFuseBoxWidth, false);
|
||||
Paint borderPaint = getBorderPaint(cardView.getColor(), ONLY_LAND_TYPE, totalFuseBoxWidth);
|
||||
CardRendererUtils.drawRoundedBox(g2,
|
||||
-borderWidth, rightHalf.ch,
|
||||
totalFuseBoxWidth, boxHeight,
|
||||
contentInset,
|
||||
borderPaint, boxColor);
|
||||
drawNameLine(g2, attribs, SplitCard.FUSE_RULE, "",
|
||||
0, rightHalf.ch,
|
||||
totalFuseBoxWidth - 2 * borderWidth, boxHeight);
|
||||
g2 = getRightHalfContext(g);
|
||||
try {
|
||||
int totalFuseBoxWidth = rightHalf.cw * 2 + 2 * borderWidth + dividerSize;
|
||||
Paint boxColor = getTextboxPaint(cardView.getColor(), ONLY_LAND_TYPE, totalFuseBoxWidth, false);
|
||||
Paint borderPaint = getBorderPaint(cardView.getColor(), ONLY_LAND_TYPE, totalFuseBoxWidth);
|
||||
CardRendererUtils.drawRoundedBox(g2,
|
||||
-borderWidth, rightHalf.ch,
|
||||
totalFuseBoxWidth, boxHeight,
|
||||
contentInset,
|
||||
borderPaint, boxColor);
|
||||
drawNameLine(g2, attribs, SplitCard.FUSE_RULE, "",
|
||||
0, rightHalf.ch,
|
||||
totalFuseBoxWidth - 2 * borderWidth, boxHeight);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,11 +185,15 @@ public class SvgUtils {
|
|||
Image shadow = Toolkit.getDefaultToolkit().createImage(prod);
|
||||
// result
|
||||
BufferedImage result = new BufferedImage(originImage.getWidth() + shadowX, originImage.getHeight() + shadowY, originImage.getType());
|
||||
Graphics2D g = (Graphics2D) result.getGraphics();
|
||||
// draw shadow with offset (left bottom)
|
||||
g.drawImage(shadow, -1 * shadowX, shadowY, null);
|
||||
// draw original image
|
||||
g.drawImage(originImage, 0, 0, null);
|
||||
Graphics2D g2 = result.createGraphics();
|
||||
try {
|
||||
// draw shadow with offset (left bottom)
|
||||
g2.drawImage(shadow, -1 * shadowX, shadowY, null);
|
||||
// draw original image
|
||||
g2.drawImage(originImage, 0, 0, null);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
// return origin image without shadow
|
||||
|
|
|
|||
|
|
@ -131,16 +131,19 @@ public final class ImageCache {
|
|||
int cornerSizeBorder = Math.max(4, Math.round(image.getWidth() * ROUNDED_CORNER_SIZE));
|
||||
|
||||
// corner mask
|
||||
Graphics2D gg = cornerImage.createGraphics();
|
||||
gg.setComposite(AlphaComposite.Src);
|
||||
gg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
gg.setColor(Color.white);
|
||||
gg.fill(new RoundRectangle2D.Float(0, 0, cornerImage.getWidth(), cornerImage.getHeight(), cornerSizeBorder, cornerSizeBorder));
|
||||
Graphics2D g2 = cornerImage.createGraphics();
|
||||
try {
|
||||
g2.setComposite(AlphaComposite.Src);
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2.setColor(Color.white);
|
||||
g2.fill(new RoundRectangle2D.Float(0, 0, cornerImage.getWidth(), cornerImage.getHeight(), cornerSizeBorder, cornerSizeBorder));
|
||||
|
||||
// image draw to buffer
|
||||
gg.setComposite(AlphaComposite.SrcAtop);
|
||||
gg.drawImage(image, 0, 0, null);
|
||||
gg.dispose();
|
||||
// image draw to buffer
|
||||
g2.setComposite(AlphaComposite.SrcAtop);
|
||||
g2.drawImage(image, 0, 0, null);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
return cornerImage;
|
||||
} else {
|
||||
|
|
@ -152,9 +155,12 @@ public final class ImageCache {
|
|||
// TODO: can be removed?
|
||||
if (image != null && image.getWidth() == 265 && image.getHeight() == 370) {
|
||||
BufferedImage crop = new BufferedImage(256, 360, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics2D = crop.createGraphics();
|
||||
graphics2D.drawImage(image, 0, 0, 255, 360, 5, 5, 261, 365, null);
|
||||
graphics2D.dispose();
|
||||
Graphics2D g2 = crop.createGraphics();
|
||||
try {
|
||||
g2.drawImage(image, 0, 0, 255, 360, 5, 5, 261, 365, null);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
return crop;
|
||||
} else {
|
||||
return image;
|
||||
|
|
|
|||
|
|
@ -38,14 +38,18 @@ public final class Transparency {
|
|||
BufferedImage target = new BufferedImage(source.getWidth(), source
|
||||
.getHeight(), java.awt.Transparency.TRANSLUCENT);
|
||||
// Get the images graphics
|
||||
Graphics2D g = target.createGraphics();
|
||||
// Set the Graphics composite to Alpha
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
(float) alpha));
|
||||
// Draw the image into the prepared reciver image
|
||||
g.drawImage(source, null, 0, 0);
|
||||
// let go of all system resources in this Graphics
|
||||
g.dispose();
|
||||
Graphics2D g2 = target.createGraphics();
|
||||
try {
|
||||
// Set the Graphics composite to Alpha
|
||||
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
|
||||
(float) alpha));
|
||||
// Draw the image into the prepared reciver image
|
||||
g2.drawImage(source, null, 0, 0);
|
||||
} finally {
|
||||
// let go of all system resources in this Graphics
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
// Return the image
|
||||
return target;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue