GUI: added some docs and experimental code (disabled) for better graphic rendering with HiDPI monitors (part of #969)

This commit is contained in:
Oleg Agafonov 2024-08-14 20:27:59 +04:00
parent 664ac24dfd
commit ce439d7fcf

View file

@ -23,6 +23,10 @@ import java.util.concurrent.TimeUnit;
*/ */
public class CardPanelRenderModeMTGO extends CardPanel { public class CardPanelRenderModeMTGO extends CardPanel {
// TODO: share code and use for all images/rendering (potential injection point - images cache), see #969
private static final boolean MTGO_MODE_RENDER_SMOOTH_IMAGES_ENABLED = false;
private static final int MTGO_MODE_RENDER_SCALED_IMAGES_COEF = 1; // TODO: experiment with scale settings, is it useful to render in x2-x4 sizes?
// https://www.mtg.onl/evolution-of-magic-token-card-frame-design/ // https://www.mtg.onl/evolution-of-magic-token-card-frame-design/
private static final Cache<ImageKey, BufferedImage> MTGO_MODE_RENDERED_CACHE = ImageCaches.register( private static final Cache<ImageKey, BufferedImage> MTGO_MODE_RENDERED_CACHE = ImageCaches.register(
@ -166,8 +170,8 @@ public class CardPanelRenderModeMTGO extends CardPanel {
ImageKey key = new ImageKey( ImageKey key = new ImageKey(
getGameCard(), getGameCard(),
artImage, artImage,
getCardWidth(), getCardWidth() * MTGO_MODE_RENDER_SCALED_IMAGES_COEF,
getCardHeight(), getCardHeight() * MTGO_MODE_RENDER_SCALED_IMAGES_COEF,
isChoosable(), isChoosable(),
isSelected(), isSelected(),
isTransformed() isTransformed()
@ -183,7 +187,25 @@ public class CardPanelRenderModeMTGO extends CardPanel {
// And draw the image we now have // And draw the image we now have
int cardOffsetX = 0; int cardOffsetX = 0;
int cardOffsetY = 0; int cardOffsetY = 0;
g.drawImage(cardImage, cardOffsetX, cardOffsetY, null);
Graphics2D g2 = (Graphics2D) g.create();
try {
// render with antialiasing
if (MTGO_MODE_RENDER_SMOOTH_IMAGES_ENABLED) {
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 scaled
if (MTGO_MODE_RENDER_SCALED_IMAGES_COEF > 1) {
g2.drawImage(cardImage, cardOffsetX, cardOffsetY, getCardWidth(), getCardHeight(), null);
} else {
g2.drawImage(cardImage, cardOffsetX, cardOffsetY, null);
}
} finally {
g2.dispose();
}
} }
@Override @Override