} 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.x, event.y);
MapObject obj = group.getObjectNear(pos.x, pos.y,
mapView.getZoom());
if (obj != null) {
int tileWidth = mapView.getMap().getTileWidth();
int tileHeight = mapView.getMap().getTileHeight();
ObjectPropertyDialog dialog = new ObjectPropertyDialog(
getSite().getShell(), obj, this, tileWidth, tileHeight);
dialog.open();
mapView.redraw();
}
}
} else if (mouseButton == 2
|| (mouseButton == 1 && (event.stateMask & SWT.ALT) != 0)) {
// Scroll with middle mouse button
int dx = event.x - mouseInitialScreenLocation.x;
int dy = event.y - mouseInitialScreenLocation.y;
Point currentPosition = mapScrollView.getOrigin();
// JViewport mapViewPort = mapScrollPane.getViewport();
// Point currentPosition = mapViewPort.getViewPosition();
mouseInitialScreenLocation = new Point(event.x - dx, event.y - dy);
Point newPosition = new Point(currentPosition.x - dx,
currentPosition.y - dy);
// Take into account map boundaries in order to prevent
// scrolling past them
Point viewSize = mapView.getSize();
Point viewportSize = mapScrollView.getSize();
int maxX = viewSize.x - viewportSize.x;
int maxY = viewSize.y - viewportSize.y;
newPosition.x = Math.min(maxX, Math.max(0, newPosition.x));
newPosition.y = Math.min(maxY, Math.max(0, newPosition.y));
mapScrollView.setOrigin(newPosition);
// mapViewPort.setViewPosition(newPosition);
} else if (mouseButton == 1) {
switch (currentPointerState) {
case PS_PAINT:
paintEdit.setPresentationName(TOOL_PAINT);
if (layer instanceof TileLayer && canPaint(currentBrush)) {
try {
mapView.repaintRegion(currentBrush.doPaint(tile.x,
tile.y));
currentMap.fireMapChanged();
} 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.redraw();
}
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);
layer.translate(translation.x, translation.y);
mousePressLocation = tile;
moveDist.x += translation.x;
moveDist.y += translation.y;
mapView.redraw();
break;
}
case PS_MARQUEE:
if (!(layer instanceof TileLayer)) {
break;
}
if (marqueeSelection != null) {
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);
if ((event.stateMask & SWT.SHIFT) > 0) {
marqueeSelection.add(new Area(Converter
.SWTRectToAWT(selRect)));
} else if ((event.stateMask & SWT.CONTROL) > 0) {
marqueeSelection.subtract(new Area(Converter
.SWTRectToAWT(selRect)));
} else {
marqueeSelection.selectRegion(Converter
.SWTRectToAWT(selRect));
}
if (oldArea != null) {
oldArea.add(marqueeSelection.getSelectedAreaBounds());
mapView.repaintRegion(oldArea);
}
}
break;
case PS_ADDOBJ:
if (layer instanceof ObjectGroup) {
if (marqueeSelection == null) {
setMarqueeSelection(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(Converter
.SWTRectToAWT(selRect));
if (oldArea != null) {
oldArea.add(marqueeSelection.getSelectedAreaBounds());
mapView.repaintRegion(oldArea);
}
}
break;
case PS_REMOVEOBJ:
if (layer instanceof ObjectGroup) {
ObjectGroup group = (ObjectGroup) layer;
Point pos = mapView.screenToPixelCoords(event.x, event.y);
MapObject obj = group.getObjectNear(pos.x, pos.y,
mapView.getZoom());
if (obj != null) {
// addEdit(new RemoveObjectEdit(group,
// obj));
group.removeObject(obj);