Browse Source

Now you can toggle the state, and it isn't spazzy!

master
Josh Hofing 12 years ago
parent
commit
e800be6f33
1 changed files with 33 additions and 3 deletions
  1. +33
    -3
      src/Render.java

+ 33
- 3
src/Render.java View File

@@ -31,6 +31,7 @@ public class Render extends Canvas implements Runnable, MouseListener,
private JFrame _frame;
private JButton pauseButton;
private Random random = new Random();
private int _lastX, _lastY;
public Render(int width, int height, Grid g, String[] rules) {
addMouseListener(this);
@@ -47,6 +48,7 @@ public class Render extends Canvas implements Runnable, MouseListener,
_pixels = ((DataBufferInt) _image.getRaster().getDataBuffer()).getData();
_lastTick = 0;
_rules = rules;
_lastX = _lastY = -1;
fps_now = 15;
setFrame();
}
@@ -215,14 +217,32 @@ public class Render extends Canvas implements Runnable, MouseListener,
int states = Goldfish.getMaxStates(rule) - 1;
if (e.getX() < 0 || e.getY() < 0 || e.getX() / scale > width || e.getY() / scale > height)
return;
_grid.getPatch(e.getX() / scale, e.getY() / scale).setState(states);
if (e.getX()/scale != _lastX && e.getY()/scale != _lastY) {
_lastX = e.getX()/scale;
_lastY = e.getY()/scale;
Patch p = _grid.getPatch(_lastX, _lastY);
if (p.getState() == states) {
p.setState(0);
} else {
_grid.getPatch(e.getX() / scale, e.getY() / scale).setState(states);
}
}
e.consume();
}
@Override
public void mouseClicked(MouseEvent e) {
int states = Goldfish.getMaxStates(rule) - 1;
_grid.getPatch(e.getX() / scale, e.getY() / scale).setState(states);
if (e.getX()/scale != _lastX && e.getY()/scale != _lastY) {
_lastX = e.getX()/scale;
_lastY = e.getY()/scale;
Patch p = _grid.getPatch(_lastX, _lastY);
if (p.getState() == states) {
p.setState(0);
} else {
_grid.getPatch(e.getX() / scale, e.getY() / scale).setState(states);
}
}
e.consume();
}
@@ -237,12 +257,22 @@ public class Render extends Canvas implements Runnable, MouseListener,
@Override
public void mousePressed(MouseEvent e) {
int states = Goldfish.getMaxStates(rule) - 1;
_grid.getPatch(e.getX() / scale, e.getY() / scale).setState(states);
if (e.getX()/scale != _lastX && e.getY()/scale != _lastY) {
_lastX = e.getX()/scale;
_lastY = e.getY()/scale;
Patch p = _grid.getPatch(_lastX, _lastY);
if (p.getState() == states) {
p.setState(0);
} else {
_grid.getPatch(e.getX() / scale, e.getY() / scale).setState(states);
}
}
e.consume();
}
@Override
public void mouseReleased(MouseEvent e) {
_lastX = _lastY = -1;
}
@Override


Loading…
Cancel
Save