summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/StonePainter.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-05-06 03:39:34 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-05-06 03:39:34 +0200
commitb8206243a7e6b0ecea7ec9cf568e9d686017c3f9 (patch)
treebd76cea810c38ae6589e7b54ffecd586c6448ec6 /src/jrummikub/view/impl/StonePainter.java
parent093e1560188f5c84416c4d8e46bbc0259ece362e (diff)
downloadJRummikub-b8206243a7e6b0ecea7ec9cf568e9d686017c3f9.tar
JRummikub-b8206243a7e6b0ecea7ec9cf568e9d686017c3f9.zip
Added hover effects
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@166 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl/StonePainter.java')
-rw-r--r--src/jrummikub/view/impl/StonePainter.java57
1 files changed, 46 insertions, 11 deletions
diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java
index 68ab72c..bfa61ea 100644
--- a/src/jrummikub/view/impl/StonePainter.java
+++ b/src/jrummikub/view/impl/StonePainter.java
@@ -31,12 +31,14 @@ class StonePainter {
private static final float CIRCLE_WIDTH = 0.45f;
private static final Color BACKGROUND_COLOR = new Color(0.9f, 0.9f, 0.6f);
- private static final Color SELECTED_COLOR = BACKGROUND_COLOR.darker();
private static final float BRIGHTER_SCALE = 1.15f;
+ private static final float HOVER_RATIO = 0.7f;
private Map<StoneColor, Map<Integer, BufferedImage>> defaultStones;
private Map<StoneColor, Map<Integer, BufferedImage>> selectedStones;
+ private Map<StoneColor, Map<Integer, BufferedImage>> hoveredStones;
+ private Map<StoneColor, Map<Integer, BufferedImage>> hoveredSelectedStones;
/**
* The width of one pixel in the scale of 1.0
@@ -55,8 +57,16 @@ class StonePainter {
private static Color brighter(Color color) {
int r = (int) (color.getRed() * BRIGHTER_SCALE);
- int g = (int) (color.getRed() * BRIGHTER_SCALE);
- int b = (int) (color.getRed() * BRIGHTER_SCALE);
+ 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);
+ }
+
+ private static Color hover(Color color) {
+ int r = (int) (color.getRed() * HOVER_RATIO + 255 * (1-HOVER_RATIO));
+ 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);
}
@@ -156,16 +166,25 @@ class StonePainter {
private void prepaint() {
defaultStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
selectedStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
+ hoveredStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
+ hoveredSelectedStones = new HashMap<StoneColor, Map<Integer, BufferedImage>>();
Color defaultBackground = BACKGROUND_COLOR;
- Color selectedBackground = SELECTED_COLOR;
+ Color selectedBackground = BACKGROUND_COLOR.darker();
+ Color hoveredBackground = hover(defaultBackground);
+ Color hoveredSelectedBackground = hover(selectedBackground);
for (StoneColor color : StoneColor.values()) {
Color defaultFg = getColor(color);
Color selectedFg = defaultFg.darker();
+ Color hoveredFg = hover(defaultFg);
+ Color hoveredSelectedFg = hover(selectedFg);
defaultStones.put(color, prepaintColor(defaultFg, defaultBackground));
selectedStones.put(color, prepaintColor(selectedFg, selectedBackground));
+ hoveredStones.put(color, prepaintColor(hoveredFg, hoveredBackground));
+ hoveredSelectedStones.put(color,
+ prepaintColor(hoveredSelectedFg, hoveredSelectedBackground));
}
}
@@ -303,21 +322,37 @@ class StonePainter {
* the position of the stone
* @param selected
* if selected is true the stone will be painted darker
+ * @param hovered
+ * if hovered is true the stone will be painted brighter
*/
- public void paintStone(Graphics2D g, Stone stone, Position p, boolean selected) {
+ public void paintStone(Graphics2D g, Stone stone, Position p,
+ boolean selected, boolean hovered) {
// Color background = selected ? SELECTED_COLOR : BACKGROUND_COLOR;
int width = getStoneWidth();
int height = getStoneHeight();
int x = (int) (p.getX() * width), y = (int) (p.getY() * height);
+ Map<StoneColor, Map<Integer, BufferedImage>> stoneMap;
+
+ if (selected) {
+ if (hovered) {
+ stoneMap = hoveredSelectedStones;
+ } else {
+ stoneMap = selectedStones;
+ }
+ } else {
+ if (hovered) {
+ stoneMap = hoveredStones;
+ } else {
+ stoneMap = defaultStones;
+ }
+ }
+
if (stone.isJoker()) {
- g.drawImage(
- (selected ? selectedStones : defaultStones).get(stone.getColor())
- .get(0), x, y, null);
+ g.drawImage(stoneMap.get(stone.getColor()).get(0), x, y, null);
} else {
- g.drawImage(
- (selected ? selectedStones : defaultStones).get(stone.getColor())
- .get(stone.getValue()), x, y, null);
+ g.drawImage(stoneMap.get(stone.getColor()).get(stone.getValue()), x, y,
+ null);
}
}
}