} else if (mouseButton == MouseEvent.BUTTON3) {
if (layer instanceof TileLayer) {
if (!bMouseIsDragging) {
// Click event is sent before the drag event
// so this one always happens
Tile newTile = ((TileLayer) layer).getTileAt(tile.x, tile.y);
setCurrentTile(newTile);
} else if (currentPointerState == PS_PAINT) {
// In case we are dragging to create a custom brush, let
// the user know where we are creating it from
if (marqueeSelection == null) {
marqueeSelection = new SelectionLayer(currentMap.getWidth(), currentMap.getHeight());
currentMap.addLayerSpecial(marqueeSelection);
}
Point limp = mouseInitialPressLocation;
Rectangle oldArea = marqueeSelection.getSelectedAreaBounds();
int minx = Math.min(limp.x, tile.x);
int miny = Math.min(limp.y, tile.y);
Rectangle selRect = new Rectangle(minx, miny, Math.max(limp.x, tile.x) - minx + 1, Math.max(limp.y, tile.y) - miny + 1);
marqueeSelection.selectRegion(selRect);
if (oldArea != null) {
oldArea.add(marqueeSelection.getSelectedAreaBounds());
mapView.repaintRegion(oldArea);
}
}
} else if (layer instanceof ObjectGroup && !bMouseIsDragging) {
// Get the object on this location and display the relative
// options dialog
ObjectGroup group = (ObjectGroup) layer;
Point pos = mapView.screenToPixelCoords(event.getX(), event.getY());
MapObject obj = group.getObjectNear(pos.x, pos.y, mapView.getZoom());
if (obj != null) {
ObjectDialog od = new ObjectDialog(YaFrame.get(), obj, undoSupport);
od.getProps();
}
}
} else if (mouseButton == MouseEvent.BUTTON2 || mouseButton == MouseEvent.BUTTON1
&& (event.getModifiersEx() & InputEvent.ALT_DOWN_MASK) != 0) {
// Scroll with middle mouse button
int dx = event.getX() - mouseInitialScreenLocation.x;
int dy = event.getY() - mouseInitialScreenLocation.y;
JViewport mapViewPort = mapScrollPane.getViewport();
Point currentPosition = mapViewPort.getViewPosition();
mouseInitialScreenLocation = new Point(event.getX() - dx, event.getY() - dy);
Point newPosition = new Point(currentPosition.x - dx, currentPosition.y - dy);
// Take into account map boundaries in order to prevent
// scrolling past them
int maxX = mapView.getWidth() - mapViewPort.getWidth();
int maxY = mapView.getHeight() - mapViewPort.getHeight();
newPosition.x = Math.min(maxX, Math.max(0, newPosition.x));
newPosition.y = Math.min(maxY, Math.max(0, newPosition.y));
mapViewPort.setViewPosition(newPosition);
} else if (mouseButton == MouseEvent.BUTTON1) {
switch (currentPointerState) {
case PS_PAINT:
paintEdit.setPresentationName(TOOL_PAINT);
if (layer instanceof TileLayer) {
try {
mapView.repaintRegion(currentBrush.doPaint(tile.x, tile.y));
} catch (Exception e) {
e.printStackTrace();
}
}
break;
case PS_ERASE:
paintEdit.setPresentationName(TOOL_ERASE);
if (layer instanceof TileLayer) {
((TileLayer) layer).setTileAt(tile.x, tile.y, null);
mapView.repaintRegion(new Rectangle(tile.x, tile.y, 1, 1));
}
break;
case PS_POUR:
paintEdit = null;
if (layer instanceof TileLayer) {
TileLayer tileLayer = (TileLayer) layer;
Tile oldTile = tileLayer.getTileAt(tile.x, tile.y);
pour(tileLayer, tile.x, tile.y, currentTile, oldTile);
mapView.repaint();
}
break;
case PS_EYED:
if (layer instanceof TileLayer) {
TileLayer tileLayer = (TileLayer) layer;
Tile newTile = tileLayer.getTileAt(tile.x, tile.y);
setCurrentTile(newTile);
}
break;
case PS_MOVE: {
Point translation = new Point(tile.x - mousePressLocation.x, tile.y - mousePressLocation.y);