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