toolstroke: show the tool's effect as a preview when mouse is down
git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@645 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
d0a6bb2303
commit
52794b9c25
7 changed files with 108 additions and 32 deletions
|
@ -934,6 +934,7 @@ public class MainWindow extends JFrame
|
|||
}
|
||||
else {
|
||||
this.toolStroke = currentTool.beginStroke(engine, x, y);
|
||||
previewTool();
|
||||
}
|
||||
|
||||
this.lastX = x;
|
||||
|
@ -943,6 +944,8 @@ public class MainWindow extends JFrame
|
|||
private void onToolUp(MouseEvent ev)
|
||||
{
|
||||
if (toolStroke != null) {
|
||||
drawingArea.setToolPreview(null);
|
||||
|
||||
CityLocation loc = toolStroke.getLocation();
|
||||
ToolResult tr = toolStroke.apply();
|
||||
showToolResult(loc, tr);
|
||||
|
@ -952,6 +955,20 @@ public class MainWindow extends JFrame
|
|||
onToolHover(ev);
|
||||
}
|
||||
|
||||
void previewTool()
|
||||
{
|
||||
assert this.toolStroke != null;
|
||||
assert this.currentTool != null;
|
||||
|
||||
drawingArea.setToolCursor(
|
||||
toolStroke.getBounds(),
|
||||
currentTool
|
||||
);
|
||||
drawingArea.setToolPreview(
|
||||
toolStroke.getPreview()
|
||||
);
|
||||
}
|
||||
|
||||
private void onToolDrag(MouseEvent ev)
|
||||
{
|
||||
if (currentTool == null)
|
||||
|
@ -966,10 +983,7 @@ public class MainWindow extends JFrame
|
|||
|
||||
if (toolStroke != null) {
|
||||
toolStroke.dragTo(x, y);
|
||||
drawingArea.setToolCursor(
|
||||
toolStroke.getBounds(),
|
||||
currentTool
|
||||
);
|
||||
previewTool();
|
||||
}
|
||||
else if (currentTool == MicropolisTool.QUERY) {
|
||||
doQueryTool(x, y);
|
||||
|
|
|
@ -163,16 +163,23 @@ public class MicropolisDrawingArea extends JComponent
|
|||
for (int x = minX; x < maxX; x++)
|
||||
{
|
||||
int cell = m.getTile(x,y);
|
||||
int tile = (cell & LOMASK) % tileImages.length;
|
||||
if (blinkUnpoweredZones &&
|
||||
(cell & ZONEBIT) != 0 &&
|
||||
(cell & PWRBIT) == 0)
|
||||
{
|
||||
unpoweredZones.add(new Point(x,y));
|
||||
if (blink)
|
||||
tile = LIGHTNINGBOLT;
|
||||
cell = LIGHTNINGBOLT;
|
||||
}
|
||||
|
||||
if (toolPreview != null) {
|
||||
int c = toolPreview.getTile(x, y);
|
||||
if (c != CLEAR) {
|
||||
cell = c;
|
||||
}
|
||||
}
|
||||
|
||||
int tile = (cell & LOMASK) % tileImages.length;
|
||||
gr.drawImage(tileImages[tile],
|
||||
x*TILE_WIDTH + (shakeStep != 0 ? getShakeModifier(y) : 0),
|
||||
y*TILE_HEIGHT,
|
||||
|
@ -266,6 +273,33 @@ public class MicropolisDrawingArea extends JComponent
|
|||
}
|
||||
}
|
||||
|
||||
public void setToolPreview(ToolPreview newPreview)
|
||||
{
|
||||
if (toolPreview != null) {
|
||||
Rectangle b = toolPreview.getBounds();
|
||||
Rectangle r = new Rectangle(
|
||||
b.x*TILE_WIDTH,
|
||||
b.y*TILE_HEIGHT,
|
||||
b.width*TILE_WIDTH,
|
||||
b.height*TILE_HEIGHT
|
||||
);
|
||||
repaint(r);
|
||||
}
|
||||
|
||||
toolPreview = newPreview;
|
||||
if (toolPreview != null) {
|
||||
|
||||
Rectangle b = toolPreview.getBounds();
|
||||
Rectangle r = new Rectangle(
|
||||
b.x*TILE_WIDTH,
|
||||
b.y*TILE_HEIGHT,
|
||||
b.width*TILE_WIDTH,
|
||||
b.height*TILE_HEIGHT
|
||||
);
|
||||
repaint(r);
|
||||
}
|
||||
}
|
||||
|
||||
//implements Scrollable
|
||||
public Dimension getPreferredScrollableViewportSize()
|
||||
{
|
||||
|
|
Reference in a new issue