Fixed axis slope calculation to be based on tile width/height as it
should be. Made tile coordinate painting be centered within tile and spaced based on actual font dimensions. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@146 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneView.java,v 1.20 2001/08/02 00:42:02 shaper Exp $
|
// $Id: IsoSceneView.java,v 1.21 2001/08/02 05:08:23 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
@@ -20,10 +20,11 @@ import java.util.ArrayList;
|
|||||||
public class IsoSceneView implements EditableSceneView
|
public class IsoSceneView implements EditableSceneView
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Construct an IsoSceneView object and initialize it with the
|
* Construct an IsoSceneView object.
|
||||||
* given tile manager.
|
|
||||||
*
|
*
|
||||||
* @param tilemgr the tile manager.
|
* @param tilemgr the tile manager.
|
||||||
|
* @param spritemgr the sprite manager.
|
||||||
|
* @param model the data model.
|
||||||
*/
|
*/
|
||||||
public IsoSceneView (TileManager tilemgr, SpriteManager spritemgr,
|
public IsoSceneView (TileManager tilemgr, SpriteManager spritemgr,
|
||||||
IsoSceneModel model)
|
IsoSceneModel model)
|
||||||
@@ -207,12 +208,21 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
*/
|
*/
|
||||||
protected void paintCoords (Graphics2D gfx, int x, int y, int sx, int sy)
|
protected void paintCoords (Graphics2D gfx, int x, int y, int sx, int sy)
|
||||||
{
|
{
|
||||||
|
FontMetrics fm = gfx.getFontMetrics(_font);
|
||||||
|
|
||||||
gfx.setFont(_font);
|
gfx.setFont(_font);
|
||||||
gfx.setColor(Color.white);
|
gfx.setColor(Color.white);
|
||||||
gfx.drawString("" + x, sx + _model.tilehwid - 2,
|
|
||||||
sy + _model.tilehhei - 2);
|
int cx = _model.tilehwid, cy = _model.tilehhei;
|
||||||
gfx.drawString("" + y, sx + _model.tilehwid - 2,
|
int fhei = fm.getAscent();
|
||||||
sy + _model.tilehei - 2);
|
|
||||||
|
// draw x-coordinate
|
||||||
|
String str = "" + x;
|
||||||
|
gfx.drawString(str, sx + cx - fm.stringWidth(str), sy + cy);
|
||||||
|
|
||||||
|
// draw y-coordinate
|
||||||
|
str = "" + y;
|
||||||
|
gfx.drawString(str, sx + cx - fm.stringWidth(str), sy + cy + fhei);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,12 +320,12 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
|
|
||||||
// calculate line parallel to the y-axis (from mouse pos to x-axis)
|
// calculate line parallel to the y-axis (from mouse pos to x-axis)
|
||||||
ly[0].setLocation(sx, sy);
|
ly[0].setLocation(sx, sy);
|
||||||
int bY = (int)(sy - (_model.SLOPE_Y * sx));
|
int bY = (int)(sy - (_model.slopeY * sx));
|
||||||
|
|
||||||
// determine intersection of x- and y-axis lines
|
// determine intersection of x- and y-axis lines
|
||||||
ly[1].x = (int)((bY - (_model.bX + _model.origin.y)) /
|
ly[1].x = (int)((bY - (_model.bX + _model.origin.y)) /
|
||||||
(_model.SLOPE_X - _model.SLOPE_Y));
|
(_model.slopeX - _model.slopeY));
|
||||||
ly[1].y = (int)((_model.SLOPE_Y * ly[1].x) + bY);
|
ly[1].y = (int)((_model.slopeY * ly[1].x) + bY);
|
||||||
|
|
||||||
// determine distance of mouse pos along the x axis
|
// determine distance of mouse pos along the x axis
|
||||||
int xdist = (int) MathUtil.distance(
|
int xdist = (int) MathUtil.distance(
|
||||||
@@ -339,8 +349,8 @@ public class IsoSceneView implements EditableSceneView
|
|||||||
*/
|
*/
|
||||||
protected void tileToScreen (int x, int y, Point spos)
|
protected void tileToScreen (int x, int y, Point spos)
|
||||||
{
|
{
|
||||||
spos.x = _model.lineX[0].x + ((x - y - 1) * _model.tilehwid);
|
spos.x = _model.origin.x + ((x - y - 1) * _model.tilehwid);
|
||||||
spos.y = _model.lineX[0].y + ((x + y) * _model.tilehhei);
|
spos.y = _model.origin.y + ((x + y) * _model.tilehhei);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScene (Scene scene)
|
public void setScene (Scene scene)
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
//
|
//
|
||||||
// $Id: IsoSceneViewModel.java,v 1.1 2001/08/02 00:42:02 shaper Exp $
|
// $Id: IsoSceneViewModel.java,v 1.2 2001/08/02 05:08:23 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.miso.scene;
|
package com.threerings.miso.scene;
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
|
|
||||||
|
import com.threerings.miso.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The IsoSceneModel provides a holding place for the myriad
|
* The IsoSceneModel provides a holding place for the myriad
|
||||||
* parameters and bits of data that describe the details of an
|
* parameters and bits of data that describe the details of an
|
||||||
@@ -36,6 +38,9 @@ public class IsoSceneModel
|
|||||||
/** The y-intercept of the x-axis line. */
|
/** The y-intercept of the x-axis line. */
|
||||||
public int bX;
|
public int bX;
|
||||||
|
|
||||||
|
/** The slope of the x- and y-axis lines. */
|
||||||
|
public float slopeX, slopeY;
|
||||||
|
|
||||||
/** The last calculated x- and y-axis mouse position tracking lines. */
|
/** The last calculated x- and y-axis mouse position tracking lines. */
|
||||||
public Point lineX[], lineY[];
|
public Point lineX[], lineY[];
|
||||||
|
|
||||||
@@ -77,6 +82,10 @@ public class IsoSceneModel
|
|||||||
|
|
||||||
// calculate the number of tile rows to render
|
// calculate the number of tile rows to render
|
||||||
tilerows = (Scene.TILE_WIDTH * Scene.TILE_HEIGHT) - 1;
|
tilerows = (Scene.TILE_WIDTH * Scene.TILE_HEIGHT) - 1;
|
||||||
|
|
||||||
|
// calculate the slope of the x- and y-axis lines
|
||||||
|
slopeX = (float)tilehei / (float)tilewid;
|
||||||
|
slopeY = -slopeX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,16 +140,10 @@ public class IsoSceneModel
|
|||||||
|
|
||||||
// determine the starting point
|
// determine the starting point
|
||||||
lineX[0].setLocation(origin.x, origin.y);
|
lineX[0].setLocation(origin.x, origin.y);
|
||||||
bX = (int)-(SLOPE_X * origin.x);
|
bX = (int)-(slopeX * origin.x);
|
||||||
|
|
||||||
// determine the ending point
|
// determine the ending point
|
||||||
lineX[1].x = lineX[0].x + (tilehwid * Scene.TILE_WIDTH);
|
lineX[1].x = lineX[0].x + (tilehwid * Scene.TILE_WIDTH);
|
||||||
lineX[1].y = lineX[0].y + (int)((SLOPE_X * lineX[1].x) + bX);
|
lineX[1].y = lineX[0].y + (int)((slopeX * lineX[1].x) + bX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The slope of the x-axis line. */
|
|
||||||
protected final float SLOPE_X = 0.5f;
|
|
||||||
|
|
||||||
/** The slope of the y-axis line. */
|
|
||||||
protected final float SLOPE_Y = -0.5f;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user