From 093e1560188f5c84416c4d8e46bbc0259ece362e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 6 May 2011 03:14:05 +0200 Subject: Got rid of alpha blending in TablePanel git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@165 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/TablePanel.java | 34 +++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java index 19489f2..c118613 100644 --- a/src/jrummikub/view/impl/TablePanel.java +++ b/src/jrummikub/view/impl/TablePanel.java @@ -4,9 +4,11 @@ import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; +import java.awt.Shape; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.geom.AffineTransform; +import java.awt.geom.Area; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.Collection; @@ -31,6 +33,8 @@ import jrummikub.view.ITablePanel; class TablePanel extends AbstractStonePanel implements ITablePanel { private final static ImageIcon BACKGROUND = new ImageIcon( 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 float MIN_VISIBLE_WIDTH = 15; private final static float MIN_VISIBLE_HEIGHT = 7.5f; @@ -238,14 +242,16 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { * stoneHeight)); } - private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) { + private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos, + Area connectorArea) { float x = pos.getX(); int width = getStonePainter().getStoneWidth(), height = getStonePainter() .getStoneHeight(); - g.setColor(new Color(0, 0, 0, 0.25f)); - g.fillRect((int) (x * width - width * CONNECTOR_WIDTH), - (int) (pos.getY() * height), (int) (width * CONNECTOR_WIDTH), height); + // Left connector + connectorArea.add(new Area(new Rectangle2D.Float((int) (x * width - width + * CONNECTOR_WIDTH), (int) (pos.getY() * height), + (int) (width * CONNECTOR_WIDTH), height))); for (Stone stone : stoneSet) { getStonePainter().paintStone(g, stone, new Position(x, pos.getY()), @@ -253,9 +259,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { x++; } - g.setColor(new Color(0, 0, 0, 0.25f)); - g.fillRect((int) (x * width), (int) (pos.getY() * height), - (int) (width * CONNECTOR_WIDTH), height); + // Right connector + connectorArea.add(new Area(new Rectangle2D.Float((int) (x * width), + (int) (pos.getY() * height), (int) (width * CONNECTOR_WIDTH), height))); } @Override @@ -269,14 +275,26 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { } AffineTransform oldTransform = g.getTransform(); + Shape oldClip = g.getClip(); Pair translation = getTranslation(); g.translate(translation.getFirst(), translation.getSecond()); + Area connectorArea = new Area(); + for (Pair entry : stoneSets) { - paintStoneSet(g, entry.getFirst(), entry.getSecond()); + paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea); } + g.setClip(connectorArea); g.setTransform(oldTransform); + + for (int x = 0; x < getWidth(); x += DARK_BACKGROUND.getIconWidth()) { + for (int y = 0; y < getHeight(); y += DARK_BACKGROUND.getIconHeight()) { + DARK_BACKGROUND.paintIcon(this, g, x, y); + } + } + + g.setClip(oldClip); } } -- cgit v1.2.3