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

Increase/decrease alpha value by ctrl-shift-pgup/pgdown #290

Merged
merged 2 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 11 additions & 8 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Config {
private String configFilename = "config.txt";
private String persistFilename = "persist";

private JSONObject loadAndMergeConfig(JSONObject defaultCfg, String fileName) throws IOException {
private JSONObject loadAndMergeConfig(JSONObject defaultCfg, String fileName, boolean needValidation) throws IOException {
File file = new File(fileName);
if (!file.canRead()) {
System.err.printf("Creating config file %s\n", fileName);
Expand All @@ -59,7 +59,7 @@ private JSONObject loadAndMergeConfig(JSONObject defaultCfg, String fileName) th
fp.close();

// Validate and correct settings
if (validateAndCorrectSettings(mergedcfg)) {
if (needValidation && validateAndCorrectSettings(mergedcfg)) {
modified = true;
}

Expand All @@ -82,8 +82,7 @@ private JSONObject loadAndMergeConfig(JSONObject defaultCfg, String fileName) th
* @return if any correction has been made.
*/
private boolean validateAndCorrectSettings(JSONObject config) {
// We don't care persisted settings. They are managed automatically.
if (config == null || !config.has("ui")) {
if (config == null) {
return false;
}

Expand Down Expand Up @@ -125,9 +124,9 @@ public Config() throws IOException {
JSONObject persistConfig = createPersistConfig();

// Main properties
this.config = loadAndMergeConfig(defaultConfig, configFilename);
this.config = loadAndMergeConfig(defaultConfig, configFilename, true);
// Persisted properties
this.persisted = loadAndMergeConfig(persistConfig, persistFilename);
this.persisted = loadAndMergeConfig(persistConfig, persistFilename, false);

leelazConfig = config.getJSONObject("leelaz");
uiConfig = config.getJSONObject("ui");
Expand Down Expand Up @@ -274,12 +273,16 @@ private JSONObject createPersistConfig() {
config.put("filesystem", filesys);

// About User Interface display
//JSONObject ui = new JSONObject();
JSONObject ui = new JSONObject();

//ui.put("window-height", 657);
//ui.put("window-width", 687);
//ui.put("max-alpha", 240);

//config.put("ui", ui);
// Avoid the key "ui" because it was used to distinguish "config" and "persist"
// in old version of validateAndCorrectSettings().
// If we use "ui" here, we will have trouble to run old lizzie.
config.put("ui-persist", ui);
return config;
}

Expand Down
16 changes: 14 additions & 2 deletions src/main/java/featurecat/lizzie/gui/BoardRenderer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package featurecat.lizzie.gui;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import featurecat.lizzie.Lizzie;
import featurecat.lizzie.analysis.Branch;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class BoardRenderer {
private int x, y;
private int boardLength;

private JSONObject uiConfig;
private JSONObject uiConfig, uiPersist;

private int scaledMargin, availableLength, squareLength, stoneRadius;
private Branch branch;
Expand Down Expand Up @@ -61,12 +62,18 @@ public class BoardRenderer {
private boolean showingBranch = false;
private boolean isMainBoard = false;

private int maxAlpha = 240;

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");
} catch (JSONException e) {}
this.isMainBoard = isMainBoard;
}

Expand Down Expand Up @@ -497,7 +504,7 @@ private void drawLeelazSuggestions(Graphics2D g) {

final int MIN_ALPHA = 32;
final int MIN_ALPHA_TO_DISPLAY_TEXT = 64;
final int MAX_ALPHA = 240;
final int MAX_ALPHA = maxAlpha = Math.max(maxAlpha, MIN_ALPHA_TO_DISPLAY_TEXT);
final double HUE_SCALING_FACTOR = 3.0;
final double ALPHA_SCALING_FACTOR = 5.0;
final float GREEN_HUE = Color.RGBtoHSB(0,1,0,null)[0];
Expand Down Expand Up @@ -1002,4 +1009,9 @@ public boolean isInside(int x1, int y1) {
private boolean showCoordinates() {
return isMainBoard && Lizzie.frame.showCoordinates;
}

public void increaseMaxAlpha(int k) {
maxAlpha = Math.min(maxAlpha + k, 255);
uiPersist.put("max-alpha", maxAlpha);
}
}
12 changes: 10 additions & 2 deletions src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ public void keyPressed(KeyEvent e) {
break;

case VK_PAGE_DOWN:
redo(10);
if (controlIsPressed(e) && e.isShiftDown()) {
Lizzie.frame.increaseMaxAlpha(-5);
} else {
redo(10);
}
break;

case VK_DOWN:
Expand Down Expand Up @@ -245,7 +249,11 @@ public void keyPressed(KeyEvent e) {
break;

case VK_PAGE_UP:
undo(10);
if (controlIsPressed(e) && e.isShiftDown()) {
Lizzie.frame.increaseMaxAlpha(5);
} else {
undo(10);
}
break;

case VK_I:
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -896,4 +896,8 @@ public void pasteSgf() {
e.printStackTrace();
}
}

public void increaseMaxAlpha(int k) {
boardRenderer.increaseMaxAlpha(k);
}
}