Fix some off-by-one painting problems

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@15 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-04-29 01:16:25 +02:00
parent 5a7118587f
commit 5a0be3261a
5 changed files with 18 additions and 9 deletions

View file

@ -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

View file

@ -65,7 +65,7 @@ public class PlayerPanel extends JPanel implements IPlayerPanel {
layout.setConstraints(currentPlayerNameLabel, c);
panel.add(currentPlayerNameLabel);
sortByNumberButton = new JButton("<html>Sort by<br>number");
sortByNumberButton = new JButton("<html><center>Sort by<br>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("<html>Sort by<br>color");
sortByColorButton = new JButton("<html><center>Sort by<br>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();

View file

@ -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);

View file

@ -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);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 18 KiB