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
This commit is contained in:
jason@long.name 2013-09-09 14:11:55 +00:00
parent 6b899d096d
commit 7b68e1299d
7 changed files with 70 additions and 20 deletions

View file

@ -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++) {

View file

@ -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+"]";
}
}

View file

@ -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);

View file

@ -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(),

View file

@ -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) {