summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/StonePainter.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl/StonePainter.java')
-rw-r--r--src/jrummikub/view/impl/StonePainter.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java
index ab523a7..47c0e9b 100644
--- a/src/jrummikub/view/impl/StonePainter.java
+++ b/src/jrummikub/view/impl/StonePainter.java
@@ -14,6 +14,10 @@ import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
+/**
+ * The StonePainter paints stones and converts between pixel and grid
+ * coordinates
+ */
class StonePainter {
private static final float ASPECT_RATIO = 0.75f;
private static final float DEFAULT_WIDTH = 40;
@@ -27,7 +31,13 @@ class StonePainter {
private static final float BRIGHTER_SCALE = 1.15f;
+ /**
+ * The width of one pixel in the scale of 1.0
+ */
public static final float 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;
private float scale;
@@ -59,10 +69,19 @@ class StonePainter {
return null;
}
+ /**
+ * Sets the new grid scale
+ *
+ * @param scale
+ * the new scale
+ */
public void setScale(float scale) {
this.scale = scale;
}
+ /**
+ * @return the current grid scale
+ */
public float getScale() {
return scale;
}
@@ -81,14 +100,24 @@ class StonePainter {
return new Position(x / width, y / height);
}
+ /**
+ * @return the width of a stone in the current scale in pixels
+ */
public int getStoneWidth() {
return even(DEFAULT_WIDTH * scale);
}
+ /**
+ * @return the height of a stone in the current scale in pixels
+ */
public int getStoneHeight() {
return (int) (DEFAULT_WIDTH * scale / ASPECT_RATIO);
}
+ /**
+ * @param scale
+ * the scaling factor for the grid coordinates
+ */
StonePainter(float scale) {
this.scale = scale;
}
@@ -208,6 +237,18 @@ class StonePainter {
-130, 170);
}
+ /**
+ * Paints a stone
+ *
+ * @param g
+ * the graphics context to paint the stone on
+ * @param stone
+ * the stone to paint
+ * @param p
+ * the position of the stone
+ * @param selected
+ * if selected is true the stone will be painted darker
+ */
public void paintStone(Graphics2D g, Stone stone, Position p, boolean selected) {
Color background = selected ? SELECTED_COLOR : BACKGROUND_COLOR;
int width = getStoneWidth();