From 5a0be3261a52f6a0849941283487d08212a35983 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 29 Apr 2011 01:16:25 +0200 Subject: Fix some off-by-one painting problems git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@15 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/Board.java | 12 ++++++++++-- src/jrummikub/view/PlayerPanel.java | 6 ++---- src/jrummikub/view/StonePainter.java | 5 +++-- src/jrummikub/view/View.java | 4 +++- src/jrummikub/view/resource/wood.png | Bin 35308 -> 17920 bytes 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/jrummikub/view/Board.java b/src/jrummikub/view/Board.java index d0a3173..5fc0390 100644 --- a/src/jrummikub/view/Board.java +++ b/src/jrummikub/view/Board.java @@ -2,6 +2,7 @@ package jrummikub.view; import java.awt.Color; import java.awt.Graphics; +import java.awt.Insets; import javax.swing.ImageIcon; import javax.swing.JPanel; @@ -21,8 +22,15 @@ public class Board extends JPanel implements IBoard { @Override protected void paintComponent(Graphics g) { - for(int x = 0; x < getWidth(); x += background.getIconWidth()) { - background.paintIcon(this, g, x, 0); + Insets insets = getInsets(); + int x = insets.left, y = insets.top, width = getWidth()-insets.left-insets.right, height = getHeight()-insets.top-insets.bottom; + g = g.create(x, y, width, height); + + for(int xpos = 0; xpos < width; xpos += background.getIconWidth()) { + background.paintIcon(this, g, xpos, 0); + } + for(int xpos = -32; xpos < width; xpos += background.getIconWidth()) { + background.paintIcon(this, g, xpos, 75); } // TODO Rest of painting code diff --git a/src/jrummikub/view/PlayerPanel.java b/src/jrummikub/view/PlayerPanel.java index 1688d7c..e9ffff3 100644 --- a/src/jrummikub/view/PlayerPanel.java +++ b/src/jrummikub/view/PlayerPanel.java @@ -65,7 +65,7 @@ public class PlayerPanel extends JPanel implements IPlayerPanel { layout.setConstraints(currentPlayerNameLabel, c); panel.add(currentPlayerNameLabel); - sortByNumberButton = new JButton("Sort by
number"); + sortByNumberButton = new JButton("
Sort by
number"); sortByNumberButton.setPreferredSize(new Dimension(85, 50)); c.gridwidth = GridBagConstraints.RELATIVE; c.gridheight = GridBagConstraints.REMAINDER; @@ -73,14 +73,13 @@ public class PlayerPanel extends JPanel implements IPlayerPanel { layout.setConstraints(sortByNumberButton, c); panel.add(sortByNumberButton); - sortByColorButton = new JButton("Sort by
color"); + sortByColorButton = new JButton("
Sort by
color"); sortByColorButton.setPreferredSize(new Dimension(85, 50)); c.gridwidth = GridBagConstraints.REMAINDER; c.insets = new Insets(15, 5, 20, 0); layout.setConstraints(sortByColorButton, c); panel.add(sortByColorButton); - return panel; } @@ -118,7 +117,6 @@ public class PlayerPanel extends JPanel implements IPlayerPanel { GridBagConstraints c = new GridBagConstraints(); setLayout(layout); - setBorder(new CustomBorder(Color.BLACK, 1, 0, 0, 0)); setBackground(Color.LIGHT_GRAY); JPanel leftPanel = createLeftPanel(); diff --git a/src/jrummikub/view/StonePainter.java b/src/jrummikub/view/StonePainter.java index dbdf3c8..8b104df 100644 --- a/src/jrummikub/view/StonePainter.java +++ b/src/jrummikub/view/StonePainter.java @@ -18,7 +18,7 @@ class StonePainter { private static final Color BACKGROUND_COLOR = new Color(0.9f, 0.9f, 0.6f); - public static final float BOARD_SCALE = 75.0f/DEFAULT_WIDTH*ASPECT_RATIO; + public static final float BOARD_SCALE = 75.0f*ASPECT_RATIO/DEFAULT_WIDTH; private static Color getColor(StoneColor color) { @@ -43,7 +43,7 @@ class StonePainter { } int width = (int)(DEFAULT_WIDTH*scale); - int height = (int)(width/ASPECT_RATIO); + int height = (int)(DEFAULT_WIDTH*scale/ASPECT_RATIO); int xpos = (int)(x*width); int ypos = (int)(y*height); @@ -84,6 +84,7 @@ class StonePainter { g.setColor(getColor(stone.getColor())); g.drawString(value, (int)(xpos+width/2-stringRect.getWidth()/2), ypos+height/4+(fm.getAscent()-fm.getDescent())/2); + // Paint circle g.setColor(BACKGROUND_COLOR.darker()); g.drawArc((int)(xpos+width/2-width*CIRCLE_WIDTH/2), (int)(ypos+height*0.65f-width*CIRCLE_WIDTH/2), (int)(width*CIRCLE_WIDTH), (int)(width*CIRCLE_WIDTH), 50, 170); diff --git a/src/jrummikub/view/View.java b/src/jrummikub/view/View.java index e2fd037..65e26b5 100644 --- a/src/jrummikub/view/View.java +++ b/src/jrummikub/view/View.java @@ -1,6 +1,7 @@ package jrummikub.view; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Dimension; import javax.swing.JFrame; @@ -35,7 +36,8 @@ public class View extends JFrame implements IView { add(table, BorderLayout.CENTER); playerPanel = new PlayerPanel(); - playerPanel.setPreferredSize(new Dimension(0, PLAYER_PANEL_HEIGHT)); + playerPanel.setBorder(new CustomBorder(Color.BLACK, 1, 0, 0, 0)); + playerPanel.setPreferredSize(new Dimension(0, PLAYER_PANEL_HEIGHT+1)); add(playerPanel, BorderLayout.SOUTH); } diff --git a/src/jrummikub/view/resource/wood.png b/src/jrummikub/view/resource/wood.png index 424ec6d..ed9cf14 100644 Binary files a/src/jrummikub/view/resource/wood.png and b/src/jrummikub/view/resource/wood.png differ -- cgit v1.2.3