Double ist das neue float
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@377 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
41786cb842
commit
682357b584
7 changed files with 170 additions and 148 deletions
|
@ -110,12 +110,13 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
}
|
||||
}));
|
||||
|
||||
connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn(true);
|
||||
}
|
||||
}));
|
||||
connections.add(view.getPlayerPanel().getRedealEvent()
|
||||
.add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn(true);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void addHandPanelHandlers() {
|
||||
|
@ -233,9 +234,10 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
|
||||
int i = 0;
|
||||
for (Stone s : handStones) {
|
||||
float x = Math.max(0,
|
||||
double x = Math.max(0,
|
||||
Math.min(13, pos.getX() - handStones.size() / 2.0f + i));
|
||||
player.getHand().drop(s, new Position(x, (float) Math.floor(pos.getY())));
|
||||
player.getHand().drop(s,
|
||||
new Position(x, (float) Math.floor(pos.getY())));
|
||||
selectedStones.remove(s);
|
||||
i++;
|
||||
}
|
||||
|
@ -432,13 +434,15 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
table.drop(joinedSet, newPos);
|
||||
} else {
|
||||
StoneSet joinedSet = new StoneSet(selectedStones).join(newSet);
|
||||
table.drop(joinedSet,
|
||||
new Position(newPos.getX() - selectedStones.size(), newPos.getY()));
|
||||
table.drop(joinedSet, new Position(newPos.getX()
|
||||
- selectedStones.size(), newPos.getY()));
|
||||
}
|
||||
} else {
|
||||
table.drop(new StoneSet(selectedStones),
|
||||
new Position(pos.getX() + (set.getSize() - selectedStones.size())
|
||||
* 0.5f, pos.getY()));
|
||||
table.drop(
|
||||
new StoneSet(selectedStones),
|
||||
new Position(pos.getX()
|
||||
+ (set.getSize() - selectedStones.size()) * 0.5f,
|
||||
pos.getY()));
|
||||
}
|
||||
|
||||
selectedStones.clear();
|
||||
|
@ -533,7 +537,8 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
static class HandStonePositionComparator implements
|
||||
Comparator<Pair<Stone, Position>> {
|
||||
@Override
|
||||
public int compare(Pair<Stone, Position> pair1, Pair<Stone, Position> pair2) {
|
||||
public int compare(Pair<Stone, Position> pair1,
|
||||
Pair<Stone, Position> pair2) {
|
||||
Position pos1 = pair1.getSecond(), pos2 = pair2.getSecond();
|
||||
if (pos1.getY() < pos2.getY()) {
|
||||
return -1;
|
||||
|
|
|
@ -43,10 +43,10 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Pair<Position, Direction> fixInvalidDrop(Stone stone, Position pos,
|
||||
Direction dir) {
|
||||
float x = pos.getX();
|
||||
float y = pos.getY();
|
||||
protected Pair<Position, Direction> fixInvalidDrop(Stone stone,
|
||||
Position pos, Direction dir) {
|
||||
double x = pos.getX();
|
||||
double y = pos.getY();
|
||||
|
||||
if (x >= 0 && x <= WIDTH - 1) {
|
||||
return null;
|
||||
|
@ -55,9 +55,11 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
return new Pair<Position, Direction>(new Position(0, y), RIGHT);
|
||||
} else {
|
||||
if (getFreeRowSpace((int) y) == 0) {
|
||||
return new Pair<Position, Direction>(new Position(0, y + 1), RIGHT);
|
||||
return new Pair<Position, Direction>(new Position(0, y + 1),
|
||||
RIGHT);
|
||||
} else {
|
||||
return new Pair<Position, Direction>(new Position(WIDTH - 1, y), LEFT);
|
||||
return new Pair<Position, Direction>(
|
||||
new Position(WIDTH - 1, y), LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +85,8 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
|
||||
List<Stone> stones = new ArrayList<Stone>();
|
||||
|
||||
for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter.hasNext();) {
|
||||
for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter
|
||||
.hasNext();) {
|
||||
stones.add(iter.next().getFirst());
|
||||
}
|
||||
|
||||
|
@ -101,7 +104,8 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
public int getIdenticalStoneCount() {
|
||||
List<Stone> stones = new ArrayList<Stone>();
|
||||
|
||||
for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter.hasNext();) {
|
||||
for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter
|
||||
.hasNext();) {
|
||||
stones.add(iter.next().getFirst());
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ package jrummikub.model;
|
|||
|
||||
public class Position {
|
||||
|
||||
private float x;
|
||||
private float y;
|
||||
private double x;
|
||||
private double y;
|
||||
|
||||
/**
|
||||
* Create a new position by specifying the coordinates
|
||||
|
@ -18,7 +18,7 @@ public class Position {
|
|||
* @param y
|
||||
* y coordinate
|
||||
*/
|
||||
public Position(float x, float y) {
|
||||
public Position(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ public class Position {
|
|||
*
|
||||
* @return x coordinate
|
||||
*/
|
||||
public float getX() {
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ public class Position {
|
|||
*
|
||||
* @return y coordinate
|
||||
*/
|
||||
public float getY() {
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
|
@ -55,9 +55,9 @@ public class Position {
|
|||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Position other = (Position) obj;
|
||||
if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x))
|
||||
if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x))
|
||||
return false;
|
||||
if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y))
|
||||
if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
@ -66,8 +66,8 @@ public class Position {
|
|||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Float.floatToIntBits(x);
|
||||
result = prime * result + Float.floatToIntBits(y);
|
||||
result = (int) (prime * result + Double.doubleToLongBits(x));
|
||||
result = (int) (prime * result + Double.doubleToLongBits(y));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,17 +100,17 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static boolean lessOrEqual(float x, float y) {
|
||||
if (-0.000001f < y && y < 0.000001f) {
|
||||
return (x < y + 0.000001f);
|
||||
private static boolean lessOrEqual(double d, double e) {
|
||||
if (-0.000001 < e && e < 0.000001) {
|
||||
return (d < e + 0.000001);
|
||||
}
|
||||
|
||||
float q = x / y;
|
||||
if (0.999999f < q && q < 1.000001f) {
|
||||
double q = d / e;
|
||||
if (0.999999 < q && q < 1.000001) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return x < y;
|
||||
return d < e;
|
||||
}
|
||||
|
||||
/** Tests whether two objects overlap **/
|
||||
|
@ -137,11 +137,11 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
private Direction getMoveDirection(E object, Position position,
|
||||
Pair<E, Position> blocking) {
|
||||
boolean isVertical = getMoveOrientation(object, position, blocking);
|
||||
float objectMidpointX = position.getX() + object.getWidth() / 2;
|
||||
float objectMidpointY = position.getY() + object.getHeight() / 2;
|
||||
float blockingMidpointX = blocking.getSecond().getX()
|
||||
double objectMidpointX = position.getX() + object.getWidth() / 2;
|
||||
double objectMidpointY = position.getY() + object.getHeight() / 2;
|
||||
double blockingMidpointX = blocking.getSecond().getX()
|
||||
+ blocking.getFirst().getWidth() / 2;
|
||||
float blockingMidpointY = blocking.getSecond().getY()
|
||||
double blockingMidpointY = blocking.getSecond().getY()
|
||||
+ blocking.getFirst().getHeight() / 2;
|
||||
if (isVertical) {
|
||||
if (objectMidpointY < blockingMidpointY) {
|
||||
|
@ -165,20 +165,20 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
*/
|
||||
private boolean getMoveOrientation(E object, Position position,
|
||||
Pair<E, Position> blocking) {
|
||||
float objectRight = position.getX() + object.getWidth();
|
||||
float blockingRight = blocking.getSecond().getX()
|
||||
double objectRight = position.getX() + object.getWidth();
|
||||
double blockingRight = blocking.getSecond().getX()
|
||||
+ blocking.getFirst().getWidth();
|
||||
float overlapRight = Math.min(objectRight, blockingRight);
|
||||
float overlapLeft = Math.max(position.getX(), blocking.getSecond()
|
||||
double overlapRight = Math.min(objectRight, blockingRight);
|
||||
double overlapLeft = Math.max(position.getX(), blocking.getSecond()
|
||||
.getX());
|
||||
float overlapX = overlapRight - overlapLeft;
|
||||
float objectBottom = position.getY() + object.getHeight();
|
||||
float blockingBottom = blocking.getSecond().getY()
|
||||
double overlapX = overlapRight - overlapLeft;
|
||||
double objectBottom = position.getY() + object.getHeight();
|
||||
double blockingBottom = blocking.getSecond().getY()
|
||||
+ blocking.getFirst().getHeight();
|
||||
float overlapBottom = Math.min(objectBottom, blockingBottom);
|
||||
float overlapTop = Math.max(position.getY(), blocking.getSecond()
|
||||
double overlapBottom = Math.min(objectBottom, blockingBottom);
|
||||
double overlapTop = Math.max(position.getY(), blocking.getSecond()
|
||||
.getY());
|
||||
float overlapY = overlapBottom - overlapTop;
|
||||
double overlapY = overlapBottom - overlapTop;
|
||||
// vertical or horizontal Shift
|
||||
// TODO magic factor
|
||||
return overlapX > overlapY;
|
||||
|
|
|
@ -174,7 +174,7 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
|||
for (Pair<Stone, Position> entry : stones) {
|
||||
Stone stone = entry.getFirst();
|
||||
Position p = entry.getSecond();
|
||||
Rectangle2D rect = new Rectangle2D.Float(p.getX(), p.getY(), 1, 1);
|
||||
Rectangle2D rect = new Rectangle2D.Double(p.getX(), p.getY(), 1, 1);
|
||||
|
||||
if (rect.contains(pos.getX(), pos.getY()))
|
||||
return stone;
|
||||
|
|
|
@ -23,17 +23,17 @@ import jrummikub.model.StoneColor;
|
|||
* coordinates
|
||||
*/
|
||||
class StonePainter {
|
||||
private static final float ASPECT_RATIO = 0.75f;
|
||||
private static final float DEFAULT_WIDTH = 40;
|
||||
private static final float TEXT_POS = 0.275f;
|
||||
private static final float FACE_WIDTH = 0.475f;
|
||||
private static final float CIRCLE_POS = 0.725f;
|
||||
private static final float CIRCLE_WIDTH = 0.45f;
|
||||
private static final double ASPECT_RATIO = 0.75f;
|
||||
private static final double DEFAULT_WIDTH = 40;
|
||||
private static final double TEXT_POS = 0.275f;
|
||||
private static final double FACE_WIDTH = 0.475f;
|
||||
private static final double CIRCLE_POS = 0.725f;
|
||||
private static final double CIRCLE_WIDTH = 0.45f;
|
||||
|
||||
private static final Color BACKGROUND_COLOR = new Color(0.9f, 0.9f, 0.6f);
|
||||
|
||||
private static final float BRIGHTER_SCALE = 1.15f;
|
||||
private static final float HOVER_RATIO = 0.7f;
|
||||
private static final double BRIGHTER_SCALE = 1.15f;
|
||||
private static final double HOVER_RATIO = 0.7f;
|
||||
|
||||
private Map<StoneColor, Map<Integer, BufferedImage>> defaultStones;
|
||||
private Map<StoneColor, Map<Integer, BufferedImage>> selectedStones;
|
||||
|
@ -43,15 +43,15 @@ class StonePainter {
|
|||
/**
|
||||
* The width of one pixel in the scale of 1.0
|
||||
*/
|
||||
public static final float WIDTH_SCALE = 1 / DEFAULT_WIDTH;
|
||||
public static final double WIDTH_SCALE = 1 / DEFAULT_WIDTH;
|
||||
/**
|
||||
* The height of one pixel in the scale of 1.0
|
||||
*/
|
||||
public static final float HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH;
|
||||
public static final double HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH;
|
||||
|
||||
private float scale;
|
||||
private double scale;
|
||||
|
||||
private static int even(float f) {
|
||||
private static int even(double f) {
|
||||
return 2 * (int) (f / 2);
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,8 @@ class StonePainter {
|
|||
int g = (int) (color.getGreen() * BRIGHTER_SCALE);
|
||||
int b = (int) (color.getBlue() * BRIGHTER_SCALE);
|
||||
|
||||
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
|
||||
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
|
||||
: b);
|
||||
}
|
||||
|
||||
private static Color hover(Color color) {
|
||||
|
@ -68,27 +69,28 @@ class StonePainter {
|
|||
int g = (int) (color.getGreen() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
|
||||
int b = (int) (color.getBlue() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
|
||||
|
||||
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
|
||||
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
|
||||
: b);
|
||||
}
|
||||
|
||||
public static Color getColor(StoneColor color) {
|
||||
switch (color) {
|
||||
case BLACK:
|
||||
return new Color(0.0f, 0.0f, 0.0f);
|
||||
case BLUE:
|
||||
return new Color(0.0f, 0.0f, 1.0f);
|
||||
case ORANGE:
|
||||
return new Color(1.0f, 0.4f, 0.0f);
|
||||
case RED:
|
||||
return new Color(0.9f, 0.0f, 0.25f);
|
||||
case AQUA:
|
||||
return new Color(0.0f, 0.85f, 0.75f);
|
||||
case GREEN:
|
||||
return new Color(0.0f, 0.65f, 0.0f);
|
||||
case VIOLET:
|
||||
return new Color(0.75f, 0.325f, 0.75f);
|
||||
case GRAY:
|
||||
return new Color(0.5f, 0.5f, 0.5f);
|
||||
case BLACK:
|
||||
return new Color(0.0f, 0.0f, 0.0f);
|
||||
case BLUE:
|
||||
return new Color(0.0f, 0.0f, 1.0f);
|
||||
case ORANGE:
|
||||
return new Color(1.0f, 0.4f, 0.0f);
|
||||
case RED:
|
||||
return new Color(0.9f, 0.0f, 0.25f);
|
||||
case AQUA:
|
||||
return new Color(0.0f, 0.85f, 0.75f);
|
||||
case GREEN:
|
||||
return new Color(0.0f, 0.65f, 0.0f);
|
||||
case VIOLET:
|
||||
return new Color(0.75f, 0.325f, 0.75f);
|
||||
case GRAY:
|
||||
return new Color(0.5f, 0.5f, 0.5f);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -98,9 +100,9 @@ class StonePainter {
|
|||
* Sets the new grid scale
|
||||
*
|
||||
* @param scale
|
||||
* the new scale
|
||||
* the new scale
|
||||
*/
|
||||
public void setScale(float scale) {
|
||||
public void setScale(double scale) {
|
||||
this.scale = scale;
|
||||
|
||||
if (this.scale == 0) {
|
||||
|
@ -112,14 +114,14 @@ class StonePainter {
|
|||
|
||||
/**
|
||||
* @param x
|
||||
* x position in screen coordinates
|
||||
* x position in screen coordinates
|
||||
* @param y
|
||||
* y position in screen coordinates
|
||||
* y position in screen coordinates
|
||||
* @return position in grid coordinates
|
||||
*/
|
||||
public Position calculatePosition(int x, int y) {
|
||||
float width = getStoneWidth();
|
||||
float height = getStoneHeight();
|
||||
double width = getStoneWidth();
|
||||
double height = getStoneHeight();
|
||||
|
||||
return new Position(x / width, y / height);
|
||||
}
|
||||
|
@ -209,19 +211,21 @@ class StonePainter {
|
|||
defaultStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||
selectedStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||
hoveredStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||
hoveredSelectedStones.put(color, new HashMap<Integer, BufferedImage>());
|
||||
hoveredSelectedStones.put(color,
|
||||
new HashMap<Integer, BufferedImage>());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scale
|
||||
* the scaling factor for the grid coordinates
|
||||
* the scaling factor for the grid coordinates
|
||||
*/
|
||||
StonePainter(float scale) {
|
||||
StonePainter(double scale) {
|
||||
setScale(scale);
|
||||
}
|
||||
|
||||
private void paintStoneBackground(Graphics2D g, Rectangle r, Color background) {
|
||||
private void paintStoneBackground(Graphics2D g, Rectangle r,
|
||||
Color background) {
|
||||
// Paint background
|
||||
g.setColor(background);
|
||||
g.fillRect(r.x, r.y, r.width, r.height);
|
||||
|
@ -322,8 +326,9 @@ class StonePainter {
|
|||
pos + (fm.getAscent() - fm.getDescent()) / 2 + 1);
|
||||
}
|
||||
g.setColor(color);
|
||||
g.drawString(value, (int) (r.x + r.width / 2 - stringRect.getWidth() / 2),
|
||||
pos + (fm.getAscent() - fm.getDescent()) / 2);
|
||||
g.drawString(value,
|
||||
(int) (r.x + r.width / 2 - stringRect.getWidth() / 2), pos
|
||||
+ (fm.getAscent() - fm.getDescent()) / 2);
|
||||
}
|
||||
|
||||
private void paintCircle(Graphics2D g, Rectangle r, Color background) {
|
||||
|
@ -332,40 +337,42 @@ class StonePainter {
|
|||
|
||||
// Paint circle
|
||||
g.setColor(background.darker());
|
||||
g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50, 170);
|
||||
g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50,
|
||||
170);
|
||||
|
||||
g.setColor(brighter(background));
|
||||
g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size, size,
|
||||
-130, 170);
|
||||
g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size,
|
||||
size, -130, 170);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paints a stone
|
||||
*
|
||||
* @param g
|
||||
* the graphics context to paint the stone on
|
||||
* the graphics context to paint the stone on
|
||||
* @param stone
|
||||
* the stone to paint
|
||||
* the stone to paint
|
||||
* @param p
|
||||
* the position of the stone
|
||||
* the position of the stone
|
||||
* @param selected
|
||||
* if selected is true the stone will be painted darker
|
||||
* if selected is true the stone will be painted darker
|
||||
* @param hovered
|
||||
* if hovered is true the stone will be painted brighter
|
||||
* if hovered is true the stone will be painted brighter
|
||||
*/
|
||||
public void paintStone(Graphics2D g, Stone stone, Position p,
|
||||
boolean selected, boolean hovered) {
|
||||
int width = getStoneWidth();
|
||||
int height = getStoneHeight();
|
||||
int x = Math.round(p.getX() * width), y = Math.round(p.getY() * height);
|
||||
int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p
|
||||
.getY() * height);
|
||||
|
||||
if (stone.isJoker()) {
|
||||
g.drawImage(getStoneImage(stone.getColor(), 0, selected, hovered), x, y,
|
||||
null);
|
||||
g.drawImage(getStoneImage(stone.getColor(), 0, selected, hovered),
|
||||
x, y, null);
|
||||
} else {
|
||||
g.drawImage(
|
||||
getStoneImage(stone.getColor(), stone.getValue(), selected, hovered),
|
||||
x, y, null);
|
||||
getStoneImage(stone.getColor(), stone.getValue(), selected,
|
||||
hovered), x, y, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,17 +39,18 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
private final static ImageIcon BRIGHT_BACKGROUND = new ImageIcon(
|
||||
HandPanel.class.getResource("/jrummikub/resource/bright_felt.png"));
|
||||
|
||||
private final static float MIN_VISIBLE_WIDTH = 15;
|
||||
private final static float MIN_VISIBLE_HEIGHT = 7.5f;
|
||||
private final static float HORIZONTAL_MARGIN = 1;
|
||||
private final static float VERTICAL_MARGIN = 0.7f;
|
||||
private final static float CONNECTOR_WIDTH = 0.25f;
|
||||
private final float COLLECTION_RATIO = 0.12f;
|
||||
private final static double MIN_VISIBLE_WIDTH = 15;
|
||||
private final static double MIN_VISIBLE_HEIGHT = 7.5f;
|
||||
private final static double HORIZONTAL_MARGIN = 1;
|
||||
private final static double VERTICAL_MARGIN = 0.7f;
|
||||
private final static double CONNECTOR_WIDTH = 0.25f;
|
||||
private final double COLLECTION_RATIO = 0.12f;
|
||||
private final int COLLECTION_GAP = 5;
|
||||
|
||||
private StoneCollectionPanel stoneCollection;
|
||||
|
||||
private Iterable<Pair<StoneSet, Position>> stoneSets = Collections.emptySet();
|
||||
private Iterable<Pair<StoneSet, Position>> stoneSets = Collections
|
||||
.emptySet();
|
||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||
|
||||
private Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
|
||||
|
@ -73,7 +74,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>();
|
||||
|
||||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||
float x = entry.getSecond().getX(), y = entry.getSecond().getY();
|
||||
double x = entry.getSecond().getX(), y = entry.getSecond().getY();
|
||||
|
||||
for (Stone stone : entry.getFirst()) {
|
||||
stones.add(new Pair<Stone, Position>(stone, new Position(x, y)));
|
||||
|
@ -98,7 +99,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
* Sets the currently selected stones
|
||||
*
|
||||
* @param stones
|
||||
* the selected stones
|
||||
* the selected stones
|
||||
*/
|
||||
void setSelectedStones(Collection<Stone> stones) {
|
||||
selectedStones = stones;
|
||||
|
@ -134,8 +135,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
}
|
||||
|
||||
private Rectangle2D calculateTableExtent() {
|
||||
float minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
|
||||
float miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
|
||||
double minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
|
||||
double miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
|
||||
|
||||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||
Position p = entry.getSecond();
|
||||
|
@ -154,20 +155,20 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
maxy = p.getY() + 1;
|
||||
}
|
||||
|
||||
return new Rectangle2D.Float(minx - HORIZONTAL_MARGIN, miny
|
||||
- VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy - miny + 2
|
||||
* VERTICAL_MARGIN);
|
||||
return new Rectangle2D.Double(minx - HORIZONTAL_MARGIN, miny
|
||||
- VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy
|
||||
- miny + 2 * VERTICAL_MARGIN);
|
||||
}
|
||||
|
||||
private void rescale() {
|
||||
Insets insets = getInsets();
|
||||
int x = insets.left, y = insets.top, width = getWidth() - insets.left
|
||||
- insets.right, height = getHeight() - insets.top - insets.bottom;
|
||||
- insets.right, height = getHeight() - insets.top
|
||||
- insets.bottom;
|
||||
|
||||
int collectionHeight = (int) (height * COLLECTION_RATIO);
|
||||
stoneCollection
|
||||
.setBounds(x, y + height - collectionHeight - COLLECTION_GAP, width,
|
||||
collectionHeight);
|
||||
stoneCollection.setBounds(x, y + height - collectionHeight
|
||||
- COLLECTION_GAP, width, collectionHeight);
|
||||
|
||||
setScale();
|
||||
|
||||
|
@ -180,10 +181,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
- insets.top - insets.bottom;
|
||||
Rectangle2D extent = calculateTableExtent();
|
||||
|
||||
float widthScale = width / (float) extent.getWidth()
|
||||
double widthScale = width / (double) extent.getWidth()
|
||||
* StonePainter.WIDTH_SCALE;
|
||||
float heightScale = height * (1 - COLLECTION_RATIO)
|
||||
/ (float) extent.getHeight() * StonePainter.HEIGHT_SCALE;
|
||||
double heightScale = height * (1 - COLLECTION_RATIO)
|
||||
/ (double) extent.getHeight() * StonePainter.HEIGHT_SCALE;
|
||||
|
||||
getStonePainter().setScale(Math.min(widthScale, heightScale));
|
||||
}
|
||||
|
@ -193,10 +194,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||
Position p = entry.getSecond();
|
||||
StoneSet stoneSet = entry.getFirst();
|
||||
float x = p.getX(), y = p.getY();
|
||||
double x = p.getX(), y = p.getY();
|
||||
|
||||
// left connector
|
||||
Rectangle2D rect = new Rectangle2D.Float(x - CONNECTOR_WIDTH, y,
|
||||
Rectangle2D rect = new Rectangle2D.Double(x - CONNECTOR_WIDTH, y,
|
||||
CONNECTOR_WIDTH, 1);
|
||||
if (rect.contains(pos.getX(), pos.getY())) {
|
||||
leftConnectorClickEvent.emit(stoneSet);
|
||||
|
@ -204,7 +205,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
}
|
||||
|
||||
// right connector
|
||||
rect = new Rectangle2D.Float(x + stoneSet.getSize(), y, CONNECTOR_WIDTH, 1);
|
||||
rect = new Rectangle2D.Double(x + stoneSet.getSize(), y,
|
||||
CONNECTOR_WIDTH, 1);
|
||||
if (rect.contains(pos.getX(), pos.getY())) {
|
||||
rightConnectorClickEvent.emit(stoneSet);
|
||||
return true;
|
||||
|
@ -224,10 +226,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||
Position p = entry.getSecond();
|
||||
StoneSet stoneSet = entry.getFirst();
|
||||
float x = p.getX(), y = p.getY();
|
||||
double x = p.getX(), y = p.getY();
|
||||
|
||||
// left connector
|
||||
Rectangle2D rect = new Rectangle2D.Float(x - CONNECTOR_WIDTH, y,
|
||||
Rectangle2D rect = new Rectangle2D.Double(x - CONNECTOR_WIDTH, y,
|
||||
CONNECTOR_WIDTH, 1);
|
||||
if (rect.contains(pos.getX(), pos.getY())) {
|
||||
leftHoveredConnector = stoneSet;
|
||||
|
@ -235,7 +237,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
}
|
||||
|
||||
// right connector
|
||||
rect = new Rectangle2D.Float(x + stoneSet.getSize(), y, CONNECTOR_WIDTH, 1);
|
||||
rect = new Rectangle2D.Double(x + stoneSet.getSize(), y,
|
||||
CONNECTOR_WIDTH, 1);
|
||||
if (rect.contains(pos.getX(), pos.getY())) {
|
||||
rightHoveredConnector = stoneSet;
|
||||
break;
|
||||
|
@ -257,15 +260,15 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
.getStoneHeight();
|
||||
Rectangle2D extent = calculateTableExtent();
|
||||
|
||||
return new Pair<Integer, Integer>((int) (width / 2 - extent.getCenterX()
|
||||
* stoneWidth),
|
||||
(int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent.getCenterY()
|
||||
* stoneHeight));
|
||||
return new Pair<Integer, Integer>(
|
||||
(int) (width / 2 - extent.getCenterX() * stoneWidth),
|
||||
(int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent
|
||||
.getCenterY() * stoneHeight));
|
||||
}
|
||||
|
||||
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos,
|
||||
Area connectorArea, Area hoveredConnectorArea) {
|
||||
float x = pos.getX();
|
||||
double x = pos.getX();
|
||||
int width = getStonePainter().getStoneWidth(), height = getStonePainter()
|
||||
.getStoneHeight();
|
||||
Area leftConnectorArea = (stoneSet == leftHoveredConnector ? hoveredConnectorArea
|
||||
|
@ -275,9 +278,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
|
||||
// Left connector
|
||||
|
||||
leftConnectorArea.add(new Area(new Rectangle2D.Float(Math.round(x * width)
|
||||
- (int) width * CONNECTOR_WIDTH + 1, Math.round(pos.getY() * height),
|
||||
(int) (width * CONNECTOR_WIDTH), height)));
|
||||
leftConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x
|
||||
* width)
|
||||
- (int) width * CONNECTOR_WIDTH + 1, Math.round(pos.getY()
|
||||
* height), (int) (width * CONNECTOR_WIDTH), height)));
|
||||
|
||||
for (Stone stone : stoneSet) {
|
||||
getStonePainter().paintStone(g, stone, new Position(x, pos.getY()),
|
||||
|
@ -286,8 +290,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
}
|
||||
|
||||
// Right connector
|
||||
rightConnectorArea.add(new Area(new Rectangle2D.Float(
|
||||
Math.round(x * width), Math.round(pos.getY() * height),
|
||||
rightConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x
|
||||
* width), Math.round(pos.getY() * height),
|
||||
(int) (width * CONNECTOR_WIDTH), height)));
|
||||
}
|
||||
|
||||
|
@ -311,15 +315,16 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
Area hoveredConnectorArea = new Area();
|
||||
|
||||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||
paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea,
|
||||
hoveredConnectorArea);
|
||||
paintStoneSet(g, entry.getFirst(), entry.getSecond(),
|
||||
connectorArea, hoveredConnectorArea);
|
||||
}
|
||||
|
||||
g.setClip(connectorArea);
|
||||
g.setTransform(oldTransform);
|
||||
|
||||
for (int x = 0; x < getWidth(); x += DARK_BACKGROUND.getIconWidth()) {
|
||||
for (int y = 0; y < getHeight(); y += DARK_BACKGROUND.getIconHeight()) {
|
||||
for (int y = 0; y < getHeight(); y += DARK_BACKGROUND
|
||||
.getIconHeight()) {
|
||||
DARK_BACKGROUND.paintIcon(this, g, x, y);
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +340,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
|||
g.setTransform(oldTransform);
|
||||
|
||||
for (int x = 0; x < getWidth(); x += BRIGHT_BACKGROUND.getIconWidth()) {
|
||||
for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND.getIconHeight()) {
|
||||
for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND
|
||||
.getIconHeight()) {
|
||||
BRIGHT_BACKGROUND.paintIcon(this, g, x, y);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue