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 1 commit
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
34 changes: 25 additions & 9 deletions src/main/java/featurecat/lizzie/gui/BoardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,12 @@ 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);
// Support seamless texture
BufferedImage boardImage = theme.getBoard();
TexturePaint paint = new TexturePaint(boardImage, new Rectangle(0, 0, boardImage.getWidth(), boardImage.getHeight()));
g.setPaint(paint);
g.fill(new Rectangle(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 @@ -751,8 +755,11 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
case BLACK_CAPTURED:
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
BufferedImage stone = theme.getBlackStone(new int[]{x, y});
BufferedImage newstone = new BufferedImage(stoneRadius * 2 + 1, stoneRadius * 2 + 1, BufferedImage.TYPE_INT_ARGB);
newstone.getGraphics().drawImage(stone.getScaledInstance(stoneRadius * 2 + 1, stoneRadius * 2 + 1, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
g.drawImage(newstone, 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 +772,10 @@ 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
BufferedImage newstone = new BufferedImage(stoneRadius * 2 + 1, stoneRadius * 2 + 1, BufferedImage.TYPE_INT_ARGB);
newstone.getGraphics().drawImage(stone.getScaledInstance(stoneRadius * 2 + 1, stoneRadius * 2 + 1, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
g.drawImage(newstone, centerX - stoneRadius, centerY - stoneRadius, stoneRadius * 2 + 1, stoneRadius * 2 + 1, null);
} else {
drawShadow(gShadow, centerX, centerY, true);
g.setColor(Color.WHITE);
Expand All @@ -778,8 +788,11 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
case BLACK_GHOST:
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
BufferedImage stone = theme.getBlackStone(new int[]{x, y});
BufferedImage newstone = new BufferedImage(stoneRadius * 2 + 1, stoneRadius * 2 + 1, BufferedImage.TYPE_INT_ARGB);
newstone.getGraphics().drawImage(stone.getScaledInstance(stoneRadius * 2 + 1, stoneRadius * 2 + 1, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
g.drawImage(newstone, 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 @@ -790,8 +803,11 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
case WHITE_GHOST:
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
BufferedImage stone = theme.getWhiteStone(new int[]{x, y});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is copy pasted 4 times in this PR... Do you think you could refactor that method to avoid the duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, of course. I have changed and committed. Thanks.

BufferedImage newstone = new BufferedImage(stoneRadius * 2 + 1, stoneRadius * 2 + 1, BufferedImage.TYPE_INT_ARGB);
newstone.getGraphics().drawImage(stone.getScaledInstance(stoneRadius * 2 + 1, stoneRadius * 2 + 1, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
g.drawImage(newstone, 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 Down
6 changes: 4 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,10 @@ 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
TexturePaint paint = new TexturePaint(background, new Rectangle(0, 0, background.getWidth(), background.getHeight()));
g.setPaint(paint);
g.fill(new Rectangle(0, 0, drawWidth, drawHeight));

return g;
}
Expand Down