summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/StoneCollectionPanel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl/StoneCollectionPanel.java')
-rw-r--r--src/jrummikub/view/impl/StoneCollectionPanel.java35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/jrummikub/view/impl/StoneCollectionPanel.java b/src/jrummikub/view/impl/StoneCollectionPanel.java
index 5064b56..3bd57ea 100644
--- a/src/jrummikub/view/impl/StoneCollectionPanel.java
+++ b/src/jrummikub/view/impl/StoneCollectionPanel.java
@@ -2,6 +2,8 @@ package jrummikub.view.impl;
import java.awt.Graphics;
import java.awt.Graphics2D;
+import java.awt.Insets;
+import java.awt.Point;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.geom.RoundRectangle2D;
@@ -14,6 +16,8 @@ import javax.swing.ImageIcon;
import jrummikub.model.Position;
import jrummikub.model.Stone;
+import jrummikub.util.Event1;
+import jrummikub.util.IEvent1;
import jrummikub.util.Pair;
import jrummikub.view.IStoneCollectionPanel;
@@ -31,6 +35,8 @@ class StoneCollectionPanel extends AbstractStonePanel implements
private Collection<Stone> selectedStones = Collections.emptyList();
+ private Event1<Point> otherClickEvent = new Event1<Point>();
+
/**
* Creates a new StoneCollection instance
*/
@@ -81,6 +87,32 @@ class StoneCollectionPanel extends AbstractStonePanel implements
return new Pair<Integer, Integer>(x + inset, inset);
}
+ /**
+ * The other click event is emitted by the stone collection when the player
+ * has clicked on it, but hasn't hit a stone. This is rather probable as the
+ * stone collection panel is filling the whole table width while being mostly
+ * invisible.
+ *
+ * @return the event
+ */
+ IEvent1<Point> getOtherClickEvent() {
+ return otherClickEvent;
+ }
+
+ @Override
+ protected boolean handleOtherClickEvent(Position pos) {
+ Insets insets = getInsets();
+ Pair<Integer, Integer> trans = getTranslation();
+ int x = (int) (pos.getX() * getStonePainter().getStoneWidth())
+ + insets.left + trans.getFirst();
+ int y = (int) (pos.getY() * getStonePainter().getStoneHeight())
+ + insets.top + trans.getSecond();
+
+ otherClickEvent.emit(new Point(x, y));
+
+ return true;
+ }
+
@Override
public void paintComponent(Graphics g1) {
for (int xpos = 0; xpos < getWidth(); xpos += BACKGROUND.getIconWidth()) {
@@ -110,7 +142,8 @@ class StoneCollectionPanel extends AbstractStonePanel implements
float xpos = 0;
for (Stone stone : selectedStones) {
- getStonePainter().paintStone(g, stone, new Position(xpos, 0), false, stone == getHoveredStone());
+ getStonePainter().paintStone(g, stone, new Position(xpos, 0), false,
+ stone == getHoveredStone());
xpos++;
}
}