mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-26 22:33:53 +01:00
DroidFish: Better layout for edit board in landscape mode.
This commit is contained in:
parent
0456c02cf9
commit
87e38eca80
|
@ -34,14 +34,20 @@
|
|||
<Button
|
||||
android:text="@android:string/ok"
|
||||
android:id="@+id/eb_ok"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
</Button>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/LinearLayout03"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Button
|
||||
android:text="@string/cancel"
|
||||
android:id="@+id/eb_cancel"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
</Button>
|
||||
|
|
|
@ -354,6 +354,7 @@ public abstract class ChessBoard extends View {
|
|||
protected abstract int getSqSizeW(int width);
|
||||
protected abstract int getSqSizeH(int height);
|
||||
protected abstract int getMaxHeightPercentage();
|
||||
protected abstract int getMaxWidthPercentage();
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
|
@ -369,7 +370,8 @@ public abstract class ChessBoard extends View {
|
|||
int p = getMaxHeightPercentage();
|
||||
height = Math.min(getHeight(sqSize), height * p / 100);
|
||||
} else {
|
||||
width = Math.min(getWidth(sqSize), width * 65 / 100);
|
||||
int p = getMaxWidthPercentage();
|
||||
width = Math.min(getWidth(sqSize), width * p / 100);
|
||||
}
|
||||
setMeasuredDimension(width, height);
|
||||
}
|
||||
|
@ -490,8 +492,7 @@ public abstract class ChessBoard extends View {
|
|||
}
|
||||
}
|
||||
|
||||
protected void drawExtraSquares(Canvas canvas) {
|
||||
}
|
||||
abstract protected void drawExtraSquares(Canvas canvas);
|
||||
|
||||
protected final void drawPiece(Canvas canvas, int xCrd, int yCrd, int p) {
|
||||
String psb, psw;
|
||||
|
@ -601,6 +602,7 @@ public abstract class ChessBoard extends View {
|
|||
}
|
||||
|
||||
protected abstract int minValidY();
|
||||
protected abstract int maxValidX();
|
||||
protected abstract int getSquare(int x, int y);
|
||||
|
||||
public final Move handleTrackballEvent(MotionEvent event) {
|
||||
|
@ -622,7 +624,7 @@ public abstract class ChessBoard extends View {
|
|||
cursorX += c * event.getX();
|
||||
cursorY -= c * event.getY();
|
||||
if (cursorX < 0) cursorX = 0;
|
||||
if (cursorX > 7) cursorX = 7;
|
||||
if (cursorX > maxValidX()) cursorX = maxValidX();
|
||||
if (cursorY < minValidY()) cursorY = minValidY();
|
||||
if (cursorY > 7) cursorY = 7;
|
||||
invalidate();
|
||||
|
|
|
@ -29,13 +29,11 @@ import org.petero.droidfish.gamelogic.TextIO;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Canvas;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* Chess board widget suitable for play mode.
|
||||
* @author petero
|
||||
*/
|
||||
/** Chess board widget suitable for play mode. */
|
||||
public class ChessBoardPlay extends ChessBoard {
|
||||
private PGNOptions pgnOptions = null;
|
||||
boolean oneTouchMoves;
|
||||
|
@ -68,6 +66,8 @@ public class ChessBoardPlay extends ChessBoard {
|
|||
protected int getSqSizeH(int height) { return (height) / 8; }
|
||||
@Override
|
||||
protected int getMaxHeightPercentage() { return 75; }
|
||||
@Override
|
||||
protected int getMaxWidthPercentage() { return 65; }
|
||||
|
||||
@Override
|
||||
protected void computeOrigin(int width, int height) {
|
||||
|
@ -84,8 +84,13 @@ public class ChessBoardPlay extends ChessBoard {
|
|||
@Override
|
||||
protected int minValidY() { return 0; }
|
||||
@Override
|
||||
protected int maxValidX() { return 7; }
|
||||
@Override
|
||||
protected int getSquare(int x, int y) { return Position.getSquare(x, y); }
|
||||
|
||||
@Override
|
||||
protected void drawExtraSquares(Canvas canvas) {
|
||||
}
|
||||
|
||||
private final boolean myColor(int piece) {
|
||||
return (piece != Piece.EMPTY) && (Piece.isWhite(piece) == pos.whiteMove);
|
||||
|
|
|
@ -30,55 +30,86 @@ import android.graphics.Paint;
|
|||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
/**
|
||||
* Chess board widget suitable for edit mode.
|
||||
* @author petero
|
||||
*/
|
||||
/** Chess board widget suitable for edit mode. */
|
||||
public class ChessBoardEdit extends ChessBoard {
|
||||
private final boolean landScape;
|
||||
|
||||
public ChessBoardEdit(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
drawSquareLabels = true;
|
||||
Configuration config = getResources().getConfiguration();
|
||||
landScape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
|
||||
private final static int gap = 4;
|
||||
|
||||
@Override
|
||||
protected int getWidth(int sqSize) { return sqSize * 8; }
|
||||
protected int getWidth(int sqSize) {
|
||||
return landScape ? sqSize * 10 + gap : sqSize * 8;
|
||||
}
|
||||
@Override
|
||||
protected int getHeight(int sqSize) { return sqSize * 10 + gap; }
|
||||
protected int getHeight(int sqSize) {
|
||||
return landScape ? sqSize * 8 : sqSize * 10 + gap;
|
||||
}
|
||||
@Override
|
||||
protected int getSqSizeW(int width) { return (width) / 8; }
|
||||
protected int getSqSizeW(int width) {
|
||||
return landScape ? (width - gap) / 10 : width / 8;
|
||||
}
|
||||
@Override
|
||||
protected int getSqSizeH(int height) { return (height - gap) / 10; }
|
||||
protected int getSqSizeH(int height) {
|
||||
return landScape ? height / 8 : (height - gap) / 10;
|
||||
}
|
||||
@Override
|
||||
protected int getMaxHeightPercentage() { return 85; }
|
||||
@Override
|
||||
protected int getMaxWidthPercentage() { return 75; }
|
||||
|
||||
@Override
|
||||
protected void computeOrigin(int width, int height) {
|
||||
x0 = (width - sqSize * 8) / 2;
|
||||
Configuration config = getResources().getConfiguration();
|
||||
boolean landScape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE);
|
||||
y0 = landScape ? 0 : (height - (sqSize * 10 + gap)) / 2;
|
||||
x0 = (width - getWidth(sqSize)) / 2;
|
||||
y0 = landScape ? 0 : (height - getHeight(sqSize)) / 2;
|
||||
}
|
||||
|
||||
private final int extraPieces(int x, int y) {
|
||||
if (y == -1) { // White pieces
|
||||
switch (x) {
|
||||
case 0: return Piece.WKING;
|
||||
case 1: return Piece.WQUEEN;
|
||||
case 2: return Piece.WROOK;
|
||||
case 3: return Piece.WBISHOP;
|
||||
case 4: return Piece.WKNIGHT;
|
||||
case 5: return Piece.WPAWN;
|
||||
if (landScape) {
|
||||
if (x == 8) {
|
||||
switch (y) {
|
||||
case 0: return Piece.WKING;
|
||||
case 1: return Piece.WQUEEN;
|
||||
case 2: return Piece.WROOK;
|
||||
case 3: return Piece.WBISHOP;
|
||||
case 4: return Piece.WKNIGHT;
|
||||
case 5: return Piece.WPAWN;
|
||||
}
|
||||
} else if (x == 9) {
|
||||
switch (y) {
|
||||
case 0: return Piece.BKING;
|
||||
case 1: return Piece.BQUEEN;
|
||||
case 2: return Piece.BROOK;
|
||||
case 3: return Piece.BBISHOP;
|
||||
case 4: return Piece.BKNIGHT;
|
||||
case 5: return Piece.BPAWN;
|
||||
}
|
||||
}
|
||||
} else if (y == -2) {
|
||||
switch (x) {
|
||||
case 0: return Piece.BKING;
|
||||
case 1: return Piece.BQUEEN;
|
||||
case 2: return Piece.BROOK;
|
||||
case 3: return Piece.BBISHOP;
|
||||
case 4: return Piece.BKNIGHT;
|
||||
case 5: return Piece.BPAWN;
|
||||
} else {
|
||||
if (y == -1) {
|
||||
switch (x) {
|
||||
case 0: return Piece.WKING;
|
||||
case 1: return Piece.WQUEEN;
|
||||
case 2: return Piece.WROOK;
|
||||
case 3: return Piece.WBISHOP;
|
||||
case 4: return Piece.WKNIGHT;
|
||||
case 5: return Piece.WPAWN;
|
||||
}
|
||||
} else if (y == -2) {
|
||||
switch (x) {
|
||||
case 0: return Piece.BKING;
|
||||
case 1: return Piece.BQUEEN;
|
||||
case 2: return Piece.BROOK;
|
||||
case 3: return Piece.BBISHOP;
|
||||
case 4: return Piece.BKNIGHT;
|
||||
case 5: return Piece.BPAWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Piece.EMPTY;
|
||||
|
@ -90,14 +121,18 @@ public class ChessBoardEdit extends ChessBoard {
|
|||
return Position.getX(sq);
|
||||
} else {
|
||||
int p = -2 - sq;
|
||||
switch (p) {
|
||||
case Piece.WKING: case Piece.BKING: return 0;
|
||||
case Piece.WQUEEN: case Piece.BQUEEN: return 1;
|
||||
case Piece.WROOK: case Piece.BROOK: return 2;
|
||||
case Piece.WBISHOP: case Piece.BBISHOP: return 3;
|
||||
case Piece.WKNIGHT: case Piece.BKNIGHT: return 4;
|
||||
case Piece.WPAWN: case Piece.BPAWN: return 5;
|
||||
default: return 6;
|
||||
if (landScape) {
|
||||
return Piece.isWhite(p) ? 8 : 9;
|
||||
} else {
|
||||
switch (p) {
|
||||
case Piece.WKING: case Piece.BKING: return 0;
|
||||
case Piece.WQUEEN: case Piece.BQUEEN: return 1;
|
||||
case Piece.WROOK: case Piece.BROOK: return 2;
|
||||
case Piece.WBISHOP: case Piece.BBISHOP: return 3;
|
||||
case Piece.WKNIGHT: case Piece.BKNIGHT: return 4;
|
||||
case Piece.WPAWN: case Piece.BPAWN: return 5;
|
||||
default: return 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,13 +143,25 @@ public class ChessBoardEdit extends ChessBoard {
|
|||
return Position.getY(sq);
|
||||
} else {
|
||||
int p = -2 - sq;
|
||||
return Piece.isWhite(p) ? -1 : -2;
|
||||
if (landScape) {
|
||||
switch (p) {
|
||||
case Piece.WKING: case Piece.BKING: return 0;
|
||||
case Piece.WQUEEN: case Piece.BQUEEN: return 1;
|
||||
case Piece.WROOK: case Piece.BROOK: return 2;
|
||||
case Piece.WBISHOP: case Piece.BBISHOP: return 3;
|
||||
case Piece.WKNIGHT: case Piece.BKNIGHT: return 4;
|
||||
case Piece.WPAWN: case Piece.BPAWN: return 5;
|
||||
default: return 6;
|
||||
}
|
||||
} else {
|
||||
return Piece.isWhite(p) ? -1 : -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSquare(int x, int y) {
|
||||
if (y >= 0) {
|
||||
if ((y >= 0) && (x < 8)) {
|
||||
return Position.getSquare(x, y);
|
||||
} else {
|
||||
int p = extraPieces(x, y);
|
||||
|
@ -124,8 +171,12 @@ public class ChessBoardEdit extends ChessBoard {
|
|||
|
||||
@Override
|
||||
protected void drawExtraSquares(Canvas canvas) {
|
||||
for (int x = 0; x < 8; x++) {
|
||||
for (int y = -2; y < 0; y++) {
|
||||
int xMin = landScape ? 8 : 0;
|
||||
int xMax = landScape ? 10 : 8;
|
||||
int yMin = landScape ? 0 : -2;
|
||||
int yMax = landScape ? 8 : 0;
|
||||
for (int x = xMin; x < xMax; x++) {
|
||||
for (int y = yMin; y < yMax; y++) {
|
||||
final int xCrd = getXCrd(x);
|
||||
final int yCrd = getYCrd(y);
|
||||
Paint paint = Position.darkSquare(x, y) ? darkPaint : brightPaint;
|
||||
|
@ -156,33 +207,37 @@ public class ChessBoardEdit extends ChessBoard {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int minValidY() { return -2; }
|
||||
protected int minValidY() {
|
||||
return landScape ? 0 : -2;
|
||||
}
|
||||
@Override
|
||||
protected int maxValidX() {
|
||||
return landScape ? 9 : 7;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getXCrd(int x) {
|
||||
return x0 + sqSize * (flipped ? 7 - x : x);
|
||||
return x0 + sqSize * x + ((x >= 8) ? gap : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getYCrd(int y) {
|
||||
if (y >= 0) {
|
||||
return y0 + sqSize * (flipped ? y : 7 - y);
|
||||
} else {
|
||||
return y0 + gap + sqSize * (7 - y);
|
||||
}
|
||||
return y0 + sqSize * (7 - y) + ((y < 0) ? gap : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getXSq(int xCrd) {
|
||||
int t = (xCrd - x0) / sqSize; return flipped ? 7 - t : t;
|
||||
int x = (xCrd - x0) / sqSize;
|
||||
if (x < 8)
|
||||
return x;
|
||||
return (xCrd - x0 - gap) / sqSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getYSq(int yCrd) {
|
||||
int t = (yCrd - y0) / sqSize;
|
||||
t = flipped ? t : 7 - t;
|
||||
if ((t >= 0) && (t < 8))
|
||||
return t;
|
||||
int y = 7 - (yCrd - y0) / sqSize;
|
||||
if (y >= 0)
|
||||
return y;
|
||||
return 7 - (yCrd - y0 - gap) / sqSize;
|
||||
}
|
||||
|
||||
|
@ -203,7 +258,8 @@ public class ChessBoardEdit extends ChessBoard {
|
|||
if (sqSize > 0) {
|
||||
int x = getXSq(xCrd);
|
||||
int y = getYSq(yCrd);
|
||||
if ((x >= 0) && (x < 8) && (y >= -2) && (y < 0)) {
|
||||
if ( landScape && (x >= 0) && (x < 10) && (y >= 0) && (y < 8) ||
|
||||
!landScape && (x >= 0) && (x < 8) && (y >= -2) && (y < 0)) {
|
||||
int p = extraPieces(x, y);
|
||||
sq = -p - 2;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user