Added bling-bling
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@219 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
3940612608
commit
d542d142c8
2 changed files with 83 additions and 8 deletions
|
@ -81,6 +81,8 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
||||||
- trans.getFirst(), e.getY() - insets.top - trans.getSecond());
|
- trans.getFirst(), e.getY() - insets.top - trans.getSecond());
|
||||||
|
|
||||||
setHoveredStone(getStoneAt(pos));
|
setHoveredStone(getStoneAt(pos));
|
||||||
|
|
||||||
|
handleOtherMoveEvent(pos);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -148,7 +150,7 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* *Overwrite this method* to signal if special zone was clicked
|
* Overwrite this method to signal if special zone was clicked
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param pos
|
||||||
* the clicked position
|
* the clicked position
|
||||||
|
@ -159,6 +161,15 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrite this method to signal if special zone was hovered
|
||||||
|
*
|
||||||
|
* @param pos
|
||||||
|
* the hovered position
|
||||||
|
*/
|
||||||
|
protected void handleOtherMoveEvent(Position pos) {
|
||||||
|
}
|
||||||
|
|
||||||
private Stone getStoneAt(Position pos) {
|
private Stone getStoneAt(Position pos) {
|
||||||
for (Pair<Stone, Position> entry : stones) {
|
for (Pair<Stone, Position> entry : stones) {
|
||||||
Stone stone = entry.getFirst();
|
Stone stone = entry.getFirst();
|
||||||
|
|
|
@ -38,6 +38,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
HandPanel.class.getResource("/jrummikub/resource/felt.png"));
|
HandPanel.class.getResource("/jrummikub/resource/felt.png"));
|
||||||
private final static ImageIcon DARK_BACKGROUND = new ImageIcon(
|
private final static ImageIcon DARK_BACKGROUND = new ImageIcon(
|
||||||
HandPanel.class.getResource("/jrummikub/resource/dark_felt.png"));
|
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_WIDTH = 15;
|
||||||
private final static float MIN_VISIBLE_HEIGHT = 7.5f;
|
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> leftConnectorClickEvent = new Event1<StoneSet>();
|
||||||
private Event1<StoneSet> rightConnectorClickEvent = new Event1<StoneSet>();
|
private Event1<StoneSet> rightConnectorClickEvent = new Event1<StoneSet>();
|
||||||
|
|
||||||
|
private StoneSet leftHoveredConnector;
|
||||||
|
private StoneSet rightHoveredConnector;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLeftPlayerName(String playerName) {
|
public void setLeftPlayerName(String playerName) {
|
||||||
leftPlayerLabel.setText(playerName);
|
leftPlayerLabel.setText(playerName);
|
||||||
|
@ -229,6 +234,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
getStonePainter().setScale(Math.min(widthScale, heightScale));
|
getStonePainter().setScale(Math.min(widthScale, heightScale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected boolean handleOtherClickEvent(Position pos) {
|
protected boolean handleOtherClickEvent(Position pos) {
|
||||||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||||
Position p = entry.getSecond();
|
Position p = entry.getSecond();
|
||||||
|
@ -253,6 +259,41 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
protected Pair<Integer, Integer> getTranslation() {
|
protected Pair<Integer, Integer> getTranslation() {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
|
@ -269,14 +310,19 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos,
|
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos,
|
||||||
Area connectorArea) {
|
Area connectorArea, Area hoveredConnectorArea) {
|
||||||
float x = pos.getX();
|
float x = pos.getX();
|
||||||
int width = getStonePainter().getStoneWidth(), height = getStonePainter()
|
int width = getStonePainter().getStoneWidth(), height = getStonePainter()
|
||||||
.getStoneHeight();
|
.getStoneHeight();
|
||||||
|
Area leftConnectorArea = (stoneSet == leftHoveredConnector ? hoveredConnectorArea
|
||||||
|
: connectorArea);
|
||||||
|
Area rightConnectorArea = (stoneSet == rightHoveredConnector ? hoveredConnectorArea
|
||||||
|
: connectorArea);
|
||||||
|
|
||||||
// Left connector
|
// 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)));
|
(int) (width * CONNECTOR_WIDTH), height)));
|
||||||
|
|
||||||
for (Stone stone : stoneSet) {
|
for (Stone stone : stoneSet) {
|
||||||
|
@ -286,9 +332,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right connector
|
// Right connector
|
||||||
connectorArea.add(new Area(new Rectangle2D.Float(Math.round(x * width),
|
rightConnectorArea.add(new Area(new Rectangle2D.Float(
|
||||||
Math.round(pos.getY() * height), (int) (width * CONNECTOR_WIDTH),
|
Math.round(x * width), Math.round(pos.getY() * height),
|
||||||
height)));
|
(int) (width * CONNECTOR_WIDTH), height)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -308,9 +354,11 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
g.translate(translation.getFirst(), translation.getSecond());
|
g.translate(translation.getFirst(), translation.getSecond());
|
||||||
|
|
||||||
Area connectorArea = new Area();
|
Area connectorArea = new Area();
|
||||||
|
Area hoveredConnectorArea = new Area();
|
||||||
|
|
||||||
for (Pair<StoneSet, Position> entry : stoneSets) {
|
for (Pair<StoneSet, Position> entry : stoneSets) {
|
||||||
paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea);
|
paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea,
|
||||||
|
hoveredConnectorArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
g.setClip(connectorArea);
|
g.setClip(connectorArea);
|
||||||
|
@ -323,5 +371,21 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
g.setClip(oldClip);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue