gui: scroll with middle-button
Hold-down middle button and drag to scroll map without using scroll bars. Contributed by askywhale (email, 2013-09-01) git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@850 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
dc412a71b6
commit
436789c12e
1 changed files with 63 additions and 0 deletions
|
@ -40,6 +40,8 @@ public class MicropolisDrawingArea extends JComponent
|
||||||
TileImages tileImages;
|
TileImages tileImages;
|
||||||
int TILE_WIDTH;
|
int TILE_WIDTH;
|
||||||
int TILE_HEIGHT;
|
int TILE_HEIGHT;
|
||||||
|
int dragX, dragY;
|
||||||
|
boolean dragging;
|
||||||
|
|
||||||
public MicropolisDrawingArea(Micropolis engine)
|
public MicropolisDrawingArea(Micropolis engine)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +58,46 @@ public class MicropolisDrawingArea extends JComponent
|
||||||
}
|
}
|
||||||
public void ancestorMoved(AncestorEvent evt) {}
|
public void ancestorMoved(AncestorEvent evt) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addMouseListener(new MouseListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
if(e.getButton()==MouseEvent.BUTTON2)
|
||||||
|
startDrag(e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
if(e.getButton()==MouseEvent.BUTTON2)
|
||||||
|
endDrag(e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addMouseMotionListener(new MouseMotionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved(MouseEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseDragged(MouseEvent e) {
|
||||||
|
if(dragging)
|
||||||
|
continueDrag(e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectTileSize(int newTileSize)
|
public void selectTileSize(int newTileSize)
|
||||||
|
@ -350,6 +392,27 @@ public class MicropolisDrawingArea extends JComponent
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void startDrag(int x, int y)
|
||||||
|
{
|
||||||
|
dragging = true;
|
||||||
|
dragX = x;
|
||||||
|
dragY = y;
|
||||||
|
}
|
||||||
|
protected void endDrag(int x, int y)
|
||||||
|
{
|
||||||
|
dragging = false;
|
||||||
|
}
|
||||||
|
protected void continueDrag(int x, int y)
|
||||||
|
{
|
||||||
|
int dx = x - dragX;
|
||||||
|
int dy = y - dragY;
|
||||||
|
JScrollPane js = (JScrollPane)getParent().getParent();
|
||||||
|
js.getHorizontalScrollBar().setValue(
|
||||||
|
js.getHorizontalScrollBar().getValue()-dx);
|
||||||
|
js.getVerticalScrollBar().setValue(
|
||||||
|
js.getVerticalScrollBar().getValue()-dy);
|
||||||
|
}
|
||||||
|
|
||||||
void doBlink()
|
void doBlink()
|
||||||
{
|
{
|
||||||
if (!unpoweredZones.isEmpty())
|
if (!unpoweredZones.isEmpty())
|
||||||
|
|
Reference in a new issue