Browse Source

Drawing patches should make more sense now.

master
Ben Kurtovic 12 years ago
parent
commit
4ab26e5a48
1 changed files with 14 additions and 13 deletions
  1. +14
    -13
      src/Render.java

+ 14
- 13
src/Render.java View File

@@ -35,7 +35,7 @@ public class Render extends Canvas implements Runnable, MouseListener,
private JFrame _frame; private JFrame _frame;
private JButton pauseButton; private JButton pauseButton;
private Random random = new Random(); private Random random = new Random();
private Patch _lastPatch;
private int _drawState;
public Render(int width, int height, Grid g, String[] rules) { public Render(int width, int height, Grid g, String[] rules) {
addMouseListener(this); addMouseListener(this);
@@ -47,16 +47,18 @@ public class Render extends Canvas implements Runnable, MouseListener,
paused = false; paused = false;
reset = false; reset = false;
rule = rules[0]; rule = rules[0];
_flags = new AtomicBoolean[2]; _flags = new AtomicBoolean[2];
for (int i = 0; i < _flags.length; i++) for (int i = 0; i < _flags.length; i++)
_flags[i] = new AtomicBoolean(); _flags[i] = new AtomicBoolean();
_turn = new AtomicInteger(); _turn = new AtomicInteger();
_grid = g; _grid = g;
_image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); _image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
_pixels = ((DataBufferInt) _image.getRaster().getDataBuffer()).getData(); _pixels = ((DataBufferInt) _image.getRaster().getDataBuffer()).getData();
_lastTick = 0; _lastTick = 0;
_rules = rules; _rules = rules;
_lastPatch = null;
_drawState = -1;
fps_now = 15; fps_now = 15;
setFrame(); setFrame();
} }
@@ -252,19 +254,18 @@ public class Render extends Canvas implements Runnable, MouseListener,
int states = Goldfish.getMaxStates(rule); int states = Goldfish.getMaxStates(rule);
if (e.getX() < 0 || e.getY() < 0 || e.getX() / scale >= width || e.getY() / scale >= height) if (e.getX() < 0 || e.getY() < 0 || e.getX() / scale >= width || e.getY() / scale >= height)
return; return;
Patch p = _grid.getPatch(e.getX()/scale, e.getY()/scale);
if (_lastPatch != p) {
if (p.getState() != 0) {
p.setState(0);
Patch p = _grid.getPatch(e.getX() / scale, e.getY() / scale);
if (_drawState == -1) {
if (p.getState() == 0) {
if (SwingUtilities.isLeftMouseButton(e))
_drawState = states - 1;
else if (SwingUtilities.isRightMouseButton(e))
_drawState = 1;
} else { } else {
if (SwingUtilities.isLeftMouseButton(e)) {
p.setState(states - 1);
} else if (SwingUtilities.isRightMouseButton(e)) {
p.setState(1);
}
_drawState = 0;
} }
_lastPatch = p;
} }
p.setState(_drawState);
e.consume(); e.consume();
} }
@@ -292,7 +293,7 @@ public class Render extends Canvas implements Runnable, MouseListener,
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
_lastPatch = null;
_drawState = -1;
} }
@Override @Override


Loading…
Cancel
Save