Skip to content

Commit

Permalink
Remove jar based theme infrastructure
Browse files Browse the repository at this point in the history
To be replaced by featurecat#378
  • Loading branch information
OlivierBlanvillain committed Oct 3, 2018
1 parent f9086bb commit 7a109df
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 165 deletions.
19 changes: 0 additions & 19 deletions doc/theme.md

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ private JSONObject createDefaultConfig() {
JSONObject ui = new JSONObject();

ui.put("board-color", new JSONArray("[217, 152, 77]"));
ui.put("theme", "DefaultTheme");
ui.put("shadows-enabled", true);
ui.put("fancy-stones", true);
ui.put("fancy-board", true);
Expand Down
64 changes: 40 additions & 24 deletions src/main/java/featurecat/lizzie/gui/BoardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
import featurecat.lizzie.rules.BoardHistoryNode;
import featurecat.lizzie.rules.Stone;
import featurecat.lizzie.rules.Zobrist;

import java.awt.*;
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.io.IOException;
import java.util.List;
import java.util.Map;

import featurecat.lizzie.theme.DefaultTheme;
import featurecat.lizzie.theme.ITheme;
import javax.imageio.ImageIO;

public class BoardRenderer {
private static final double MARGIN = 0.03; // percentage of the boardLength to offset before drawing black lines
Expand All @@ -43,6 +41,8 @@ public class BoardRenderer {
private int cachedX, cachedY;

private BufferedImage cachedStonesImage = null;
private BufferedImage cachedBoardImage = null;
private BufferedImage cachedWallpaperImage = null;
private BufferedImage cachedStonesShadowImage = null;
private Zobrist cachedZhash = new Zobrist(); // defaults to an empty board

Expand All @@ -54,7 +54,6 @@ public class BoardRenderer {

private boolean lastInScoreMode = false;

public ITheme theme;
public List<String> variation;

// special values of displayedBranchLength
Expand All @@ -70,10 +69,6 @@ public class BoardRenderer {

public BoardRenderer(boolean isMainBoard) {
uiConfig = Lizzie.config.config.getJSONObject("ui");
theme = ITheme.loadTheme(uiConfig.getString("theme"));
if (theme == null) {
theme = new DefaultTheme();
}
uiPersist = Lizzie.config.persisted.getJSONObject("ui-persist");
try {
maxAlpha = uiPersist.getInt("max-alpha");
Expand All @@ -91,7 +86,7 @@ public void draw(Graphics2D g) {
setupSizeParameters();

// Stopwatch timer = new Stopwatch();
drawBackground(g);
drawGoban(g);
// timer.lap("background");
drawStones();
// timer.lap("stones");
Expand Down Expand Up @@ -161,7 +156,7 @@ private void setupSizeParameters() {
/**
* Draw the green background and go board with lines. We cache the image for a performance boost.
*/
private void drawBackground(Graphics2D g0) {
private void drawGoban(Graphics2D g0) {
// draw the cached background image if frame size changes
if (cachedBackgroundImage == null || cachedBackgroundImage.getWidth() != Lizzie.frame.getWidth() ||
cachedBackgroundImage.getHeight() != Lizzie.frame.getHeight() ||
Expand Down Expand Up @@ -606,14 +601,14 @@ private void drawLeelazSuggestions(Graphics2D g) {
g.setColor(Color.BLACK);
if (branch != null && Lizzie.board.getData().blackToPlay)
g.setColor(Color.WHITE);

String text;
if (Lizzie.config.handicapInsteadOfWinrate) {
text=String.format("%.2f", Lizzie.leelaz.winrateToHandicap(move.winrate));
} else {
text=String.format("%.1f", roundedWinrate);
}

drawString(g, suggestionX, suggestionY, LizzieFrame.OpenSansSemiboldBase, Font.PLAIN, text, stoneRadius, stoneRadius * 1.5, 1);
drawString(g, suggestionX, suggestionY + stoneRadius * 2 / 5, LizzieFrame.OpenSansRegularBase, getPlayoutsString(move.playouts), (float) (stoneRadius * 0.8), stoneRadius * 1.4);
}
Expand Down Expand Up @@ -650,11 +645,16 @@ private void drawNextMoves(Graphics2D g) {

private void drawWoodenBoard(Graphics2D g) {
if (uiConfig.getBoolean("fancy-board")) {
// fancy version
if (cachedBoardImage == null) {
try {
cachedBoardImage = ImageIO.read(getClass().getResourceAsStream("/assets/board.png"));
} catch (IOException e) {
e.printStackTrace();
}
}

int shadowRadius = (int) (boardLength * MARGIN / 6);
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);
drawTextureImage(g, cachedBoardImage, x - 2 * shadowRadius, y - 2 * shadowRadius, boardLength + 4 * shadowRadius, boardLength + 4 * shadowRadius);

g.setStroke(new BasicStroke(shadowRadius * 2));
// draw border
Expand All @@ -663,7 +663,6 @@ private void drawWoodenBoard(Graphics2D g) {
g.setStroke(new BasicStroke(1));

} else {
// simple version
JSONArray boardColor = uiConfig.getJSONArray("board-color");
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
g.setColor(new Color(boardColor.getInt(0), boardColor.getInt(1), boardColor.getInt(2)));
Expand Down Expand Up @@ -766,9 +765,8 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
boolean isGhost = (color == Stone.BLACK_GHOST || color == Stone.WHITE_GHOST);
if (uiConfig.getBoolean("fancy-stones")) {
drawShadow(gShadow, centerX, centerY, isGhost);
Image stone = isBlack ? theme.getBlackStone(new int[]{x, y}) : theme.getWhiteStone(new int[]{x, y});
int size = stoneRadius * 2 + 1;
g.drawImage(getScaleStone(stone, isBlack, size, size), centerX - stoneRadius, centerY - stoneRadius, size, size, null);
g.drawImage(getScaleStone(isBlack, size), centerX - stoneRadius, centerY - stoneRadius, size, size, null);
} else {
drawShadow(gShadow, centerX, centerY, true);
g.setColor(isBlack ? (isGhost ? new Color(0, 0, 0) : Color.BLACK) : (isGhost ? new Color(255, 255, 255) : Color.WHITE));
Expand All @@ -784,12 +782,19 @@ private void drawStone(Graphics2D g, Graphics2D gShadow, int centerX, int center
/**
* Get scaled stone, if cached then return cached
*/
public BufferedImage getScaleStone(Image img, boolean isBlack, int width, int height) {
private BufferedImage getScaleStone(boolean isBlack, int size) {
BufferedImage stone = isBlack ? cachedBlackStoneImage : cachedWhiteStoneImage;
if (stone == null || stone.getWidth() != width || stone.getHeight() != height) {
stone = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
if (stone == null) {
stone = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
String imgPath = isBlack ? "/assets/black0.png" : "/assets/white0.png";
Image img = null;
try {
img = ImageIO.read(getClass().getResourceAsStream(imgPath));
} catch (IOException e) {
e.printStackTrace();
}
Graphics2D g2 = stone.createGraphics();
g2.drawImage(img.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
g2.drawImage(img.getScaledInstance(size, size, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
g2.dispose();
if (isBlack) {
cachedBlackStoneImage = stone;
Expand All @@ -800,6 +805,17 @@ public BufferedImage getScaleStone(Image img, boolean isBlack, int width, int he
return stone;
}

public BufferedImage getWallpaper() {
if (cachedWallpaperImage == null) {
try {
cachedWallpaperImage = ImageIO.read(getClass().getResourceAsStream("/assets/background.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
}
return cachedWallpaperImage;
}

/**
* Draw scale smooth image, enhanced display quality (Not use, for future)
* This function use the traditional Image.getScaledInstance() method
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ private Graphics2D createBackground() {

Graphics2D g = cachedBackground.createGraphics();

BufferedImage background = boardRenderer.theme.getBackground();
int drawWidth = Math.max(background.getWidth(), getWidth());
int drawHeight = Math.max(background.getHeight(), getHeight());
BufferedImage wallpaper = boardRenderer.getWallpaper();
int drawWidth = Math.max(wallpaper.getWidth(), getWidth());
int drawHeight = Math.max(wallpaper.getHeight(), getHeight());
// Support seamless texture
boardRenderer.drawTextureImage(g, background, 0, 0, drawWidth, drawHeight);
boardRenderer.drawTextureImage(g, wallpaper, 0, 0, drawWidth, drawHeight);

return g;
}
Expand Down
66 changes: 0 additions & 66 deletions src/main/java/featurecat/lizzie/theme/DefaultTheme.java

This file was deleted.

51 changes: 0 additions & 51 deletions src/main/java/featurecat/lizzie/theme/ITheme.java

This file was deleted.

0 comments on commit 7a109df

Please sign in to comment.