Added highlighting to StonePainter

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@36 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-04-30 21:50:28 +02:00
parent e45610ece6
commit 9ea9b11501
3 changed files with 20 additions and 19 deletions

View file

@ -66,7 +66,7 @@ public class Board extends JPanel implements IBoard {
RenderingHints.VALUE_ANTIALIAS_ON);
for (Map.Entry<Stone, Position> stone : stones.entrySet()) {
stonePainter.paintStone(g, stone.getKey(), stone.getValue());
stonePainter.paintStone(g, stone.getKey(), stone.getValue(), false);
}
}

View file

@ -12,7 +12,6 @@ import java.awt.geom.Rectangle2D;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.model.StoneSet;
class StonePainter {
private static final float ASPECT_RATIO = 0.75f;
@ -24,6 +23,7 @@ class StonePainter {
private static final Color BACKGROUND_COLOR = new Color(0.9f, 0.9f, 0.6f);
private static final Color HIGHLIGHTED_COLOR = BACKGROUND_COLOR.darker();
public static final float BOARD_SCALE = 75.0f*ASPECT_RATIO/DEFAULT_WIDTH;
@ -75,30 +75,30 @@ class StonePainter {
}
private void paintStoneBackground(Graphics2D g, int x, int y,
int width, int height) {
int width, int height, Color background) {
// Paint background
g.setColor(BACKGROUND_COLOR);
g.setColor(background);
g.fillRect(x, y, width, height);
// Paint bevel border
g.setColor(BACKGROUND_COLOR.brighter().brighter());
g.setColor(background.brighter().brighter());
g.fillRect(x, y, 1, height);
g.setColor(BACKGROUND_COLOR.brighter());
g.setColor(background.brighter());
g.fillRect(x+1, y+1, 1, height-2);
g.setColor(BACKGROUND_COLOR.brighter().brighter());
g.setColor(background.brighter().brighter());
g.fillRect(x, y, width, 1);
g.setColor(BACKGROUND_COLOR.brighter());
g.setColor(background.brighter());
g.fillRect(x+1, y+1, width-2, 1);
g.setColor(BACKGROUND_COLOR.darker().darker());
g.setColor(background.darker().darker());
g.fillRect(x+width-1, y, 1, height);
g.setColor(BACKGROUND_COLOR.darker());
g.setColor(background.darker());
g.fillRect(x+width-2, y+1, 1, height-2);
g.setColor(BACKGROUND_COLOR.darker().darker());
g.setColor(background.darker().darker());
g.fillRect(x, y+height-1, width, 1);
g.setColor(BACKGROUND_COLOR.darker());
g.setColor(background.darker());
g.fillRect(x+1, y+height-2, width-2, 1);
}
@ -176,26 +176,27 @@ class StonePainter {
g.drawString(value, (int)(x+width/2-stringRect.getWidth()/2), pos+(fm.getAscent()-fm.getDescent())/2);
}
private void paintCircle(Graphics2D g, int x, int y, int width, int height) {
private void paintCircle(Graphics2D g, int x, int y, int width, int height, Color background) {
int size = even(width*CIRCLE_WIDTH);
int pos = y + (int)(CIRCLE_POS*height);
// Paint circle
g.setColor(BACKGROUND_COLOR.darker());
g.setColor(background.darker());
g.drawArc(x+width/2-size/2, pos-size/2, size, size, 50, 170);
g.setColor(BACKGROUND_COLOR.brighter());
g.setColor(background.brighter());
g.drawArc((int)(x+width/2-size/2), pos-size/2, size, size, -130, 170);
}
public void paintStone(Graphics2D g, Stone stone, Position p) {
public void paintStone(Graphics2D g, Stone stone, Position p, boolean highlighted) {
Color background = highlighted ? HIGHLIGHTED_COLOR : BACKGROUND_COLOR;
int width = even(DEFAULT_WIDTH*scale);
int height = (int)(DEFAULT_WIDTH*scale/ASPECT_RATIO);
int x = (int)(p.getX()*width);
int y = (int)(p.getY()*height);
paintStoneBackground(g, x, y, width, height);
paintStoneBackground(g, x, y, width, height, background);
if (stone.isJoker()) {
paintJoker(g, x, y, width, height, stone);
@ -203,6 +204,6 @@ class StonePainter {
paintStoneNumber(g, x, y, width, height, stone);
}
paintCircle(g, x, y, width, height);
paintCircle(g, x, y, width, height, background);
}
}

View file

@ -99,7 +99,7 @@ public class Table extends JPanel implements ITable {
float x = pos.getX();
for(Stone stone : stoneSet){
stonePainter.paintStone(g, stone, new Position(x, pos.getY()));
stonePainter.paintStone(g, stone, new Position(x, pos.getY()), false);
x++;
}
}