summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/TablePanel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl/TablePanel.java')
-rw-r--r--src/jrummikub/view/impl/TablePanel.java78
1 files changed, 71 insertions, 7 deletions
diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java
index 4b385d3..74a2b1f 100644
--- a/src/jrummikub/view/impl/TablePanel.java
+++ b/src/jrummikub/view/impl/TablePanel.java
@@ -38,6 +38,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
HandPanel.class.getResource("/jrummikub/resource/felt.png"));
private final static ImageIcon DARK_BACKGROUND = new ImageIcon(
HandPanel.class.getResource("/jrummikub/resource/dark_felt.png"));
+ 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;
@@ -56,6 +58,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
private Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
private Event1<StoneSet> rightConnectorClickEvent = new Event1<StoneSet>();
+ private StoneSet leftHoveredConnector;
+ private StoneSet rightHoveredConnector;
+
@Override
public void setLeftPlayerName(String playerName) {
leftPlayerLabel.setText(playerName);
@@ -229,6 +234,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
getStonePainter().setScale(Math.min(widthScale, heightScale));
}
+ @Override
protected boolean handleOtherClickEvent(Position pos) {
for (Pair<StoneSet, Position> entry : stoneSets) {
Position p = entry.getSecond();
@@ -254,6 +260,41 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
@Override
+ protected void handleOtherMoveEvent(Position pos) {
+ StoneSet oldLeftHoveredConnector = leftHoveredConnector;
+ StoneSet oldRightHoveredConnector = rightHoveredConnector;
+
+ leftHoveredConnector = null;
+ rightHoveredConnector = null;
+
+ for (Pair<StoneSet, Position> entry : stoneSets) {
+ Position p = entry.getSecond();
+ StoneSet stoneSet = entry.getFirst();
+ float x = p.getX(), y = p.getY();
+
+ // left connector
+ Rectangle2D rect = new Rectangle2D.Float(x - CONNECTOR_WIDTH, y,
+ CONNECTOR_WIDTH, 1);
+ if (rect.contains(pos.getX(), pos.getY())) {
+ leftHoveredConnector = stoneSet;
+ break;
+ }
+
+ // right connector
+ rect = new Rectangle2D.Float(x + stoneSet.size(), y, CONNECTOR_WIDTH, 1);
+ if (rect.contains(pos.getX(), pos.getY())) {
+ rightHoveredConnector = stoneSet;
+ break;
+ }
+ }
+
+ if (leftHoveredConnector != oldLeftHoveredConnector
+ || rightHoveredConnector != oldRightHoveredConnector) {
+ repaint();
+ }
+ }
+
+ @Override
protected Pair<Integer, Integer> getTranslation() {
Insets insets = getInsets();
int width = getWidth() - insets.left - insets.right, height = getHeight()
@@ -269,14 +310,19 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos,
- Area connectorArea) {
+ Area connectorArea, Area hoveredConnectorArea) {
float x = pos.getX();
int width = getStonePainter().getStoneWidth(), height = getStonePainter()
.getStoneHeight();
+ Area leftConnectorArea = (stoneSet == leftHoveredConnector ? hoveredConnectorArea
+ : connectorArea);
+ Area rightConnectorArea = (stoneSet == rightHoveredConnector ? hoveredConnectorArea
+ : connectorArea);
// Left connector
- connectorArea.add(new Area(new Rectangle2D.Float(Math.round(x * width)
- - (int) width * CONNECTOR_WIDTH, Math.round(pos.getY() * height),
+
+ 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)));
for (Stone stone : stoneSet) {
@@ -286,9 +332,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
// Right connector
- connectorArea.add(new Area(new Rectangle2D.Float(Math.round(x * width),
- Math.round(pos.getY() * height), (int) (width * CONNECTOR_WIDTH),
- height)));
+ rightConnectorArea.add(new Area(new Rectangle2D.Float(
+ Math.round(x * width), Math.round(pos.getY() * height),
+ (int) (width * CONNECTOR_WIDTH), height)));
}
@Override
@@ -308,9 +354,11 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
g.translate(translation.getFirst(), translation.getSecond());
Area connectorArea = new Area();
+ Area hoveredConnectorArea = new Area();
for (Pair<StoneSet, Position> entry : stoneSets) {
- paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea);
+ paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea,
+ hoveredConnectorArea);
}
g.setClip(connectorArea);
@@ -323,5 +371,21 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
g.setClip(oldClip);
+
+ if (leftHoveredConnector == null && rightHoveredConnector == null) {
+ return; // We're done here...
+ }
+
+ g.translate(translation.getFirst(), translation.getSecond());
+ g.setClip(hoveredConnectorArea);
+ g.setTransform(oldTransform);
+
+ for (int x = 0; x < getWidth(); x += BRIGHT_BACKGROUND.getIconWidth()) {
+ for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND.getIconHeight()) {
+ BRIGHT_BACKGROUND.paintIcon(this, g, x, y);
+ }
+ }
+
+ g.setClip(oldClip);
}
}