From 7b68e1299d9794f46f5d3ebb037919e0948c7332 Mon Sep 17 00:00:00 2001 From: "jason@long.name" Date: Mon, 9 Sep 2013 14:11:55 +0000 Subject: [PATCH] android port: convert use of java.awt.Rectangle to own CityRect class java.awt.Rectangle does not exist in the android SDK, so this patch replaces its use within the Micropolis engine code with a custom class with equivalent functionality. This way all the classes in micropolisj.engine can be compiled with the subset of the Java SDK that also exists in the Android SDK. git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@853 d9718cc8-9f43-0410-858b-315f434eb58c --- src/micropolisj/engine/Bulldozer.java | 3 +- src/micropolisj/engine/CityRect.java | 54 +++++++++++++++++++ src/micropolisj/engine/RoadLikeTool.java | 11 ++-- src/micropolisj/engine/ToolPreview.java | 5 +- src/micropolisj/engine/ToolStroke.java | 7 ++- src/micropolisj/gui/MainWindow.java | 2 +- .../gui/MicropolisDrawingArea.java | 8 +-- 7 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 src/micropolisj/engine/CityRect.java diff --git a/src/micropolisj/engine/Bulldozer.java b/src/micropolisj/engine/Bulldozer.java index b8ea990..dda8b4d 100644 --- a/src/micropolisj/engine/Bulldozer.java +++ b/src/micropolisj/engine/Bulldozer.java @@ -1,6 +1,5 @@ package micropolisj.engine; -import java.awt.Rectangle; import static micropolisj.engine.TileConstants.*; class Bulldozer extends ToolStroke @@ -13,7 +12,7 @@ class Bulldozer extends ToolStroke @Override protected void applyArea(ToolEffectIfc eff) { - Rectangle b = getBounds(); + CityRect b = getBounds(); // scan selection area for rubble, forest, etc... for (int y = 0; y < b.height; y++) { diff --git a/src/micropolisj/engine/CityRect.java b/src/micropolisj/engine/CityRect.java new file mode 100644 index 0000000..8eb9c94 --- /dev/null +++ b/src/micropolisj/engine/CityRect.java @@ -0,0 +1,54 @@ +// This file is part of MicropolisJ. +// Copyright (C) 2013 Jason Long +// Portions Copyright (C) 1989-2007 Electronic Arts Inc. +// +// MicropolisJ is free software; you can redistribute it and/or modify +// it under the terms of the GNU GPLv3, with additional terms. +// See the README file, included in this distribution, for details. + +package micropolisj.engine; + +public class CityRect +{ + /** The X coordinate of the upper-left corner of the rectangle. */ + public int x; + + /** The Y coordinate of the upper-left corner of the rectangle. */ + public int y; + + public int width; + public int height; + + public CityRect() + { + } + + public CityRect(int x, int y, int width, int height) + { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + @Override + public boolean equals(Object obj) + { + if (obj instanceof CityRect) { + CityRect rhs = (CityRect)obj; + return this.x == rhs.x && + this.y == rhs.y && + this.width == rhs.width && + this.height == rhs.height; + } + else { + return false; + } + } + + @Override + public String toString() + { + return "["+x+","+y+","+width+"x"+height+"]"; + } +} diff --git a/src/micropolisj/engine/RoadLikeTool.java b/src/micropolisj/engine/RoadLikeTool.java index 036bb3d..2f37de5 100644 --- a/src/micropolisj/engine/RoadLikeTool.java +++ b/src/micropolisj/engine/RoadLikeTool.java @@ -1,6 +1,5 @@ package micropolisj.engine; -import java.awt.Rectangle; import static micropolisj.engine.TileConstants.*; class RoadLikeTool extends ToolStroke @@ -27,7 +26,7 @@ class RoadLikeTool extends ToolStroke { boolean anyChange = false; - Rectangle b = getBounds(); + CityRect b = getBounds(); for (int i = b.height - 1; i >= 0; i--) { for (int j = b.width - 1; j >= 0; j--) { TranslatedToolEffect tte = new TranslatedToolEffect(eff, b.x+j, b.y+i); @@ -41,7 +40,7 @@ class RoadLikeTool extends ToolStroke { boolean anyChange = false; - Rectangle b = getBounds(); + CityRect b = getBounds(); for (int i = 0; i < b.height; i++) { for (int j = 0; j < b.width; j++) { TranslatedToolEffect tte = new TranslatedToolEffect(eff, b.x+j, b.y+i); @@ -52,7 +51,7 @@ class RoadLikeTool extends ToolStroke } @Override - public Rectangle getBounds() + public CityRect getBounds() { // constrain bounds to be a rectangle with // either width or height equal to one. @@ -62,7 +61,7 @@ class RoadLikeTool extends ToolStroke if (Math.abs(xdest-xpos) >= Math.abs(ydest-ypos)) { // horizontal line - Rectangle r = new Rectangle(); + CityRect r = new CityRect(); r.x = Math.min(xpos, xdest); r.width = Math.abs(xdest-xpos) + 1; r.y = ypos; @@ -71,7 +70,7 @@ class RoadLikeTool extends ToolStroke } else { // vertical line - Rectangle r = new Rectangle(); + CityRect r = new CityRect(); r.x = xpos; r.width = 1; r.y = Math.min(ypos, ydest); diff --git a/src/micropolisj/engine/ToolPreview.java b/src/micropolisj/engine/ToolPreview.java index 497b0ac..c0158f2 100644 --- a/src/micropolisj/engine/ToolPreview.java +++ b/src/micropolisj/engine/ToolPreview.java @@ -1,6 +1,5 @@ package micropolisj.engine; -import java.awt.Rectangle; import java.util.*; import static micropolisj.engine.TileConstants.*; @@ -45,9 +44,9 @@ public class ToolPreview implements ToolEffectIfc } } - public Rectangle getBounds() + public CityRect getBounds() { - return new Rectangle( + return new CityRect( -offsetX, -offsetY, getWidth(), diff --git a/src/micropolisj/engine/ToolStroke.java b/src/micropolisj/engine/ToolStroke.java index 79b06fa..fdd8a28 100644 --- a/src/micropolisj/engine/ToolStroke.java +++ b/src/micropolisj/engine/ToolStroke.java @@ -8,7 +8,6 @@ package micropolisj.engine; -import java.awt.Rectangle; import static micropolisj.engine.TileConstants.*; public class ToolStroke @@ -53,7 +52,7 @@ public class ToolStroke protected void applyArea(ToolEffectIfc eff) { - Rectangle r = getBounds(); + CityRect r = getBounds(); for (int i = 0; i < r.height; i += tool.getHeight()) { for (int j = 0; j < r.width; j += tool.getWidth()) { @@ -111,9 +110,9 @@ public class ToolStroke this.ydest = ydest; } - public Rectangle getBounds() + public CityRect getBounds() { - Rectangle r = new Rectangle(); + CityRect r = new CityRect(); r.x = xpos; if (tool.getWidth() >= 3) { diff --git a/src/micropolisj/gui/MainWindow.java b/src/micropolisj/gui/MainWindow.java index 848ca8f..c77dcc3 100644 --- a/src/micropolisj/gui/MainWindow.java +++ b/src/micropolisj/gui/MainWindow.java @@ -1265,7 +1265,7 @@ public class MainWindow extends JFrame if (h >= 3) y--; - drawingArea.setToolCursor(new Rectangle(x,y,w,h), currentTool); + drawingArea.setToolCursor(new CityRect(x,y,w,h), currentTool); } private void onToolExited(MouseEvent ev) diff --git a/src/micropolisj/gui/MicropolisDrawingArea.java b/src/micropolisj/gui/MicropolisDrawingArea.java index 9e4e464..14547ce 100644 --- a/src/micropolisj/gui/MicropolisDrawingArea.java +++ b/src/micropolisj/gui/MicropolisDrawingArea.java @@ -243,12 +243,12 @@ public class MicropolisDrawingArea extends JComponent static class ToolCursor { - Rectangle rect; + CityRect rect; Color borderColor; Color fillColor; } - public void setToolCursor(Rectangle newRect, MicropolisTool tool) + public void setToolCursor(CityRect newRect, MicropolisTool tool) { ToolCursor tp = new ToolCursor(); tp.rect = newRect; @@ -292,7 +292,7 @@ public class MicropolisDrawingArea extends JComponent public void setToolPreview(ToolPreview newPreview) { if (toolPreview != null) { - Rectangle b = toolPreview.getBounds(); + CityRect b = toolPreview.getBounds(); Rectangle r = new Rectangle( b.x*TILE_WIDTH, b.y*TILE_HEIGHT, @@ -305,7 +305,7 @@ public class MicropolisDrawingArea extends JComponent toolPreview = newPreview; if (toolPreview != null) { - Rectangle b = toolPreview.getBounds(); + CityRect b = toolPreview.getBounds(); Rectangle r = new Rectangle( b.x*TILE_WIDTH, b.y*TILE_HEIGHT,