Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next: Support Seamless Texture & Enhance Stone Quality #366

Merged
merged 6 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/main/java/featurecat/lizzie/gui/BoardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.awt.font.TextAttribute;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -639,8 +640,10 @@ private void drawWoodenBoard(Graphics2D g) {
if (uiConfig.getBoolean("fancy-board")) {
// fancy version
int shadowRadius = (int) (boardLength * MARGIN / 6);
Image boardImage = theme.getBoard();
g.drawImage(boardImage == null ? theme.getBoard() : boardImage, x - 2 * shadowRadius, y - 2 * shadowRadius, boardLength + 4 * shadowRadius, boardLength + 4 * shadowRadius, null);
BufferedImage boardImage = theme.getBoard();
// Support seamless texture
drawTextureImage(g, boardImage == null ? theme.getBoard() : boardImage, x - 2 * shadowRadius, y - 2 * shadowRadius, boardLength + 4 * shadowRadius, boardLength + 4 * shadowRadius);

g.setStroke(new BasicStroke(shadowRadius * 2));
// draw border
g.setColor(new Color(0, 0, 0, 50));
Expand Down Expand Up @@ -752,7 +755,8 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
if (uiConfig.getBoolean("fancy-stones")) {
drawShadow(gShadow, centerX, centerY, false);
Image stone = theme.getBlackStone(new int[]{x, y});
g.drawImage(stone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
// Enhance draw quality
drawScaleSmoothImage(g, stone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
} else {
drawShadow(gShadow, centerX, centerY, true);
g.setColor(Color.BLACK);
Expand All @@ -765,7 +769,8 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
if (uiConfig.getBoolean("fancy-stones")) {
drawShadow(gShadow, centerX, centerY, false);
Image stone = theme.getWhiteStone(new int[]{x, y});
g.drawImage(stone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
// Enhance draw quality
drawScaleSmoothImage(g, stone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
} else {
drawShadow(gShadow, centerX, centerY, true);
g.setColor(Color.WHITE);
Expand All @@ -779,7 +784,8 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
if (uiConfig.getBoolean("fancy-stones")) {
drawShadow(gShadow, centerX, centerY, true);
Image stone = theme.getBlackStone(new int[]{x, y});
g.drawImage(stone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
// Enhance draw quality
drawScaleSmoothImage(g, stone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
} else {
drawShadow(gShadow, centerX, centerY, true);
g.setColor(new Color(0, 0, 0));//, uiConfig.getInt("branch-stone-alpha")));
Expand All @@ -791,7 +797,8 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
if (uiConfig.getBoolean("fancy-stones")) {
drawShadow(gShadow, centerX, centerY, true);
Image stone = theme.getWhiteStone(new int[]{x, y});
g.drawImage(stone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
// Enhance draw quality
drawScaleSmoothImage(g, stone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
} else {
drawShadow(gShadow, centerX, centerY, true);
g.setColor(new Color(255, 255, 255));//, uiConfig.getInt("branch-stone-alpha")));
Expand All @@ -805,6 +812,24 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
}
}

/**
* Draw scale smooth image, enhanced display quality
*/
public void drawScaleSmoothImage(Graphics2D g, Image img, int x, int y, int width, int height, ImageObserver observer) {
BufferedImage newstone = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
newstone.getGraphics().drawImage(img.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH), 0, 0, observer);
g.drawImage(newstone, x, y, width, height, observer);
}

/**
* Draw texture image
*/
public void drawTextureImage(Graphics2D g, BufferedImage img, int x, int y, int width, int height) {
TexturePaint paint = new TexturePaint(img, new Rectangle(0, 0, img.getWidth(), img.getHeight()));
g.setPaint(paint);
g.fill(new Rectangle(x, y, width, height));
}

/**
* Fills in a circle centered at (centerX, centerY) with radius $radius$
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ private Graphics2D createBackground() {
BufferedImage background = boardRenderer.theme.getBackground();
int drawWidth = Math.max(background.getWidth(), getWidth());
int drawHeight = Math.max(background.getHeight(), getHeight());

g.drawImage(background, 0, 0, drawWidth, drawHeight, null);
// Support seamless texture
boardRenderer.drawTextureImage(g, background, 0, 0, drawWidth, drawHeight);

return g;
}
Expand Down