mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-19 12:12:17 +01:00
DroidFish: Use SVG graphics for buttons. Implemented "toggle large buttons" button action.
This commit is contained in:
@@ -121,12 +121,12 @@ public class ButtonActions {
|
||||
}
|
||||
|
||||
/** Get icon resource for button. */
|
||||
public int getIcon(boolean large) {
|
||||
public int getIcon() {
|
||||
int ret = -1;
|
||||
if (mainAction != null)
|
||||
ret = mainAction.getIcon(large);
|
||||
ret = mainAction.getIcon();
|
||||
if (ret == -1)
|
||||
ret = large ? R.drawable.custom_large : R.drawable.custom;
|
||||
ret = R.raw.custom;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ import org.petero.droidfish.gamelogic.PgnToken;
|
||||
import org.petero.droidfish.gamelogic.GameTree.Node;
|
||||
import org.petero.droidfish.gtb.Probe;
|
||||
|
||||
import com.larvalabs.svgandroid.SVG;
|
||||
import com.larvalabs.svgandroid.SVGParser;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
@@ -211,7 +214,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
addAction(new UIAction() {
|
||||
public String getId() { return "flipboard"; }
|
||||
public int getName() { return R.string.flip_board; }
|
||||
public int getIcon(boolean large) { return large ? R.drawable.flip_large : R.drawable.flip; }
|
||||
public int getIcon() { return R.raw.flip; }
|
||||
public boolean enabled() { return true; }
|
||||
public void run() {
|
||||
boardFlipped = !cb.flipped;
|
||||
@@ -222,7 +225,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
addAction(new UIAction() {
|
||||
public String getId() { return "showThinking"; }
|
||||
public int getName() { return R.string.toggle_show_thinking; }
|
||||
public int getIcon(boolean large) { return -1; }
|
||||
public int getIcon() { return -1; }
|
||||
public boolean enabled() { return true; }
|
||||
public void run() {
|
||||
mShowThinking = toggleBooleanPref("showThinking");
|
||||
@@ -232,7 +235,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
addAction(new UIAction() {
|
||||
public String getId() { return "bookHints"; }
|
||||
public int getName() { return R.string.toggle_book_hints; }
|
||||
public int getIcon(boolean large) { return -1; }
|
||||
public int getIcon() { return -1; }
|
||||
public boolean enabled() { return true; }
|
||||
public void run() {
|
||||
mShowBookHints = toggleBooleanPref("bookHints");
|
||||
@@ -242,7 +245,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
addAction(new UIAction() {
|
||||
public String getId() { return "viewVariations"; }
|
||||
public int getName() { return R.string.toggle_pgn_variations; }
|
||||
public int getIcon(boolean large) { return -1; }
|
||||
public int getIcon() { return -1; }
|
||||
public boolean enabled() { return true; }
|
||||
public void run() {
|
||||
pgnOptions.view.variations = toggleBooleanPref("viewVariations");
|
||||
@@ -253,7 +256,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
addAction(new UIAction() {
|
||||
public String getId() { return "viewComments"; }
|
||||
public int getName() { return R.string.toggle_pgn_comments; }
|
||||
public int getIcon(boolean large) { return -1; }
|
||||
public int getIcon() { return -1; }
|
||||
public boolean enabled() { return true; }
|
||||
public void run() {
|
||||
pgnOptions.view.comments = toggleBooleanPref("viewComments");
|
||||
@@ -264,7 +267,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
addAction(new UIAction() {
|
||||
public String getId() { return "viewHeaders"; }
|
||||
public int getName() { return R.string.toggle_pgn_headers; }
|
||||
public int getIcon(boolean large) { return -1; }
|
||||
public int getIcon() { return -1; }
|
||||
public boolean enabled() { return true; }
|
||||
public void run() {
|
||||
pgnOptions.view.headers = toggleBooleanPref("viewHeaders");
|
||||
@@ -275,7 +278,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
addAction(new UIAction() {
|
||||
public String getId() { return "toggleAnalysis"; }
|
||||
public int getName() { return R.string.toggle_analysis; }
|
||||
public int getIcon(boolean large) { return -1; }
|
||||
public int getIcon() { return -1; }
|
||||
public boolean enabled() { return true; }
|
||||
public void run() {
|
||||
int gameModeType = ctrl.analysisMode() ? GameMode.EDIT_GAME : GameMode.ANALYSIS;
|
||||
@@ -288,6 +291,16 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
setBoardFlip(true);
|
||||
}
|
||||
});
|
||||
addAction(new UIAction() {
|
||||
public String getId() { return "largeButtons"; }
|
||||
public int getName() { return R.string.toggle_large_buttons; }
|
||||
public int getIcon() { return -1; }
|
||||
public boolean enabled() { return true; }
|
||||
public void run() {
|
||||
pgnOptions.view.headers = toggleBooleanPref("largeButtons");
|
||||
updateButtons();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -734,30 +747,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
custom1ButtonActions.readPrefs(settings, actionFactory);
|
||||
custom2ButtonActions.readPrefs(settings, actionFactory);
|
||||
|
||||
boolean largeButtons = settings.getBoolean("largeButtons", false);
|
||||
Resources r = getResources();
|
||||
int bWidth = (int)Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, r.getDisplayMetrics()));
|
||||
int bHeight = (int)Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, r.getDisplayMetrics()));
|
||||
if (largeButtons) {
|
||||
bWidth = bWidth * 3 / 2;
|
||||
bHeight = bHeight * 3 / 2;
|
||||
custom1Button.setImageResource(custom1ButtonActions.getIcon(true));
|
||||
custom2Button.setImageResource(custom2ButtonActions.getIcon(true));
|
||||
modeButton.setImageResource(R.drawable.mode_large);
|
||||
undoButton.setImageResource(R.drawable.left_large);
|
||||
redoButton.setImageResource(R.drawable.right_large);
|
||||
} else {
|
||||
custom1Button.setImageResource(custom1ButtonActions.getIcon(false));
|
||||
custom2Button.setImageResource(custom2ButtonActions.getIcon(false));
|
||||
modeButton.setImageResource(R.drawable.mode);
|
||||
undoButton.setImageResource(R.drawable.left);
|
||||
redoButton.setImageResource(R.drawable.right);
|
||||
}
|
||||
custom1Button.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
custom2Button.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
modeButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
undoButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
redoButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
updateButtons();
|
||||
|
||||
bookOptions.filename = settings.getString("bookFile", "");
|
||||
bookOptions.maxLength = getIntSetting("bookMaxLength", 1000000);
|
||||
@@ -803,6 +793,39 @@ public class DroidFish extends Activity implements GUIInterface {
|
||||
ctrl.prefsChanged();
|
||||
}
|
||||
|
||||
private void updateButtons() {
|
||||
boolean largeButtons = settings.getBoolean("largeButtons", false);
|
||||
Resources r = getResources();
|
||||
int bWidth = (int)Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 36, r.getDisplayMetrics()));
|
||||
int bHeight = (int)Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, r.getDisplayMetrics()));
|
||||
if (largeButtons) {
|
||||
bWidth = bWidth * 3 / 2;
|
||||
bHeight = bHeight * 3 / 2;
|
||||
}
|
||||
SVG svg = SVGParser.getSVGFromResource(getResources(),
|
||||
custom1ButtonActions.getIcon());
|
||||
custom1Button.setBackgroundDrawable(new SVGPictureDrawable(svg));
|
||||
|
||||
svg = SVGParser.getSVGFromResource(getResources(),
|
||||
custom2ButtonActions.getIcon());
|
||||
custom2Button.setBackgroundDrawable(new SVGPictureDrawable(svg));
|
||||
|
||||
svg = SVGParser.getSVGFromResource(getResources(), R.raw.right);
|
||||
redoButton.setBackgroundDrawable(new SVGPictureDrawable(svg));
|
||||
|
||||
svg = SVGParser.getSVGFromResource(getResources(), R.raw.left);
|
||||
undoButton.setBackgroundDrawable(new SVGPictureDrawable(svg));
|
||||
|
||||
svg = SVGParser.getSVGFromResource(getResources(), R.raw.mode);
|
||||
modeButton.setBackgroundDrawable(new SVGPictureDrawable(svg));
|
||||
|
||||
custom1Button.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
custom2Button.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
modeButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
undoButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
redoButton.setLayoutParams(new LinearLayout.LayoutParams(bWidth, bHeight));
|
||||
}
|
||||
|
||||
private synchronized final void setWakeLock(boolean enableLock) {
|
||||
WakeLock wl = wakeLock;
|
||||
if (wl != null) {
|
||||
|
||||
47
DroidFish/src/org/petero/droidfish/SVGPictureDrawable.java
Normal file
47
DroidFish/src/org/petero/droidfish/SVGPictureDrawable.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package org.petero.droidfish;
|
||||
|
||||
import com.larvalabs.svgandroid.SVG;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.PictureDrawable;
|
||||
|
||||
/**
|
||||
* Like PictureDrawable but scales the picture according to current drawing bounds.
|
||||
*/
|
||||
public class SVGPictureDrawable extends PictureDrawable {
|
||||
|
||||
private final int iWidth;
|
||||
private final int iHeight;
|
||||
|
||||
public SVGPictureDrawable(SVG svg) {
|
||||
super(svg.getPicture());
|
||||
RectF bounds = svg.getBounds();
|
||||
RectF limits = svg.getLimits();
|
||||
if (bounds != null) {
|
||||
iWidth = (int)bounds.width();
|
||||
iHeight = (int)bounds.height();
|
||||
} else if (limits != null) {
|
||||
iWidth = (int)limits.width();
|
||||
iHeight = (int)limits.height();
|
||||
} else {
|
||||
iWidth = -1;
|
||||
iHeight = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicWidth() {
|
||||
return iWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntrinsicHeight() {
|
||||
return iHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
canvas.drawPicture(getPicture(), getBounds());
|
||||
}
|
||||
}
|
||||
@@ -26,8 +26,8 @@ public interface UIAction extends Runnable {
|
||||
/** Get name resource for the action. */
|
||||
public int getName();
|
||||
|
||||
/** Get icon resource or -1 for no icon. */
|
||||
public int getIcon(boolean large);
|
||||
/** Get icon SVG resource or -1 for no icon. */
|
||||
public int getIcon();
|
||||
|
||||
/** Return true if the action is currently enabled. */
|
||||
public boolean enabled();
|
||||
|
||||
Reference in New Issue
Block a user