More work on the scene map.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@313 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-08-23 23:44:12 +00:00
parent 19b05150db
commit 9f1d5c1534
4 changed files with 58 additions and 32 deletions
+21 -14
View File
@@ -1,5 +1,5 @@
//
// $Id: Node.java,v 1.2 2001/08/23 00:22:30 shaper Exp $
// $Id: Node.java,v 1.3 2001/08/23 23:44:12 shaper Exp $
package com.threerings.nodemap;
@@ -28,7 +28,6 @@ public abstract class Node
_width = width;
_height = height;
_pos = new Point();
_edges = new ArrayList();
}
@@ -61,13 +60,20 @@ public abstract class Node
}
/**
* Return the node's current position in pixels.
*
* @return point the node position.
* Returns the node's x position in screen coordinates.
*/
public Point getPosition ()
public int getX ()
{
return _pos;
return _x;
}
/**
* Returns the node's y position in screen coordinates.
*/
public int getY ()
{
return _y;
}
/**
@@ -76,9 +82,10 @@ public abstract class Node
* @param x the x-position.
* @param y the y-position.
*/
public void setPosition (int x, int y)
public void setLocation (int x, int y)
{
_pos.setLocation(x, y);
_x = x;
_y = y;
}
/**
@@ -91,8 +98,8 @@ public abstract class Node
*/
public boolean contains (int x, int y)
{
return (x >= _pos.x && x <= (_pos.x + _width) &&
y >= _pos.y && y <= (_pos.y + _height));
return (x >= _x && x <= (_x + _width) &&
y >= _y && y <= (_y + _height));
}
/**
@@ -146,8 +153,8 @@ public abstract class Node
int wid = fm.stringWidth(_name) + 10;
int hei = fm.getAscent() + 4;
int xpos = _pos.x + ((_width - wid) / 2);
int ypos = _pos.y + ((_height - hei) / 2);
int xpos = _x + ((_width - wid) / 2);
int ypos = _y + ((_height - hei) / 2);
// draw the yellow box
g.setColor(Color.yellow);
@@ -195,7 +202,7 @@ public abstract class Node
}
/** The position in pixel coordinates. */
protected Point _pos;
protected int _x, _y;
/** The dimensions in pixel coordinates. */
protected int _width, _height;
+10 -10
View File
@@ -1,5 +1,5 @@
//
// $Id: NodeMap.java,v 1.2 2001/08/23 00:22:30 shaper Exp $
// $Id: NodeMap.java,v 1.3 2001/08/23 23:44:12 shaper Exp $
package com.threerings.nodemap;
@@ -59,13 +59,13 @@ public class NodeMap
Iterator iter = _nodes.iterator();
while (iter.hasNext()) {
Node n = (Node)iter.next();
Point pos = n.getPosition();
int x = n.getX(), y = n.getY();
int wid = n.getWidth(), hei = n.getHeight();
_minx = Math.min(_minx, pos.x);
_maxx = Math.max(_maxx, pos.x + wid);
_miny = Math.min(_miny, pos.y);
_maxy = Math.max(_maxy, pos.y + hei);
_minx = Math.min(_minx, x);
_maxx = Math.max(_maxx, x + wid);
_miny = Math.min(_miny, y);
_maxy = Math.max(_maxy, y + hei);
}
}
@@ -100,9 +100,9 @@ public class NodeMap
// highlight the last node entered
if (_lastnode != null) {
g.setColor(Color.red);
Point pos = _lastnode.getPosition();
int x = _lastnode.getX(), y = _lastnode.getY();
int wid = _lastnode.getWidth(), hei = _lastnode.getHeight();
g.drawRect(pos.x, pos.y, wid, hei);
g.drawRect(x, y, wid, hei);
}
// draw the tool tip, if any
@@ -263,8 +263,8 @@ public class NodeMap
// inform the node of the mouse click, with
// coordinates translated to suit node interior
Point pos = n.getPosition();
n.handleMouseClicked(x - pos.x, y - pos.y);
int nx = n.getX(), ny = n.getY();
n.handleMouseClicked(x - nx, y - ny);
// let the tool tip manager know about the click
if (_tipmgr != null) {
@@ -1,5 +1,5 @@
//
// $Id: DirectionalEdge.java,v 1.1 2001/08/20 22:56:55 shaper Exp $
// $Id: DirectionalEdge.java,v 1.2 2001/08/23 23:44:12 shaper Exp $
package com.threerings.nodemap.direction;
@@ -7,28 +7,47 @@ import java.awt.*;
import com.threerings.nodemap.*;
/**
* A directional edge extends the {@link Edge} object to allow
* associating a direction with the edge and rendering the edge to the
* screen. The edge direction must be one of the directional
* constants detailed in the {@link Directions} object.
*/
public class DirectionalEdge extends Edge
{
/** The edge direction as a {@link Directions} constant. */
public int dir;
/**
* Construct a directional edge.
*
* @param src the source node.
* @param dst the destination node.
* @param dir the edge direction.
*/
public DirectionalEdge (Node src, Node dst, int dir)
{
super(src, dst);
this.dir = dir;
}
/**
* Render the edge to the given graphics context.
*
* @param g the graphics context.
*/
public void paint (Graphics g)
{
g.setColor(Color.black);
Point spos = src.getPosition(), dpos = dst.getPosition();
int sx = src.getX(), sy = src.getY();
int dx = dst.getX(), dy = dst.getY();
int csx = spos.x + (src.getWidth() / 2);
int csy = spos.y + (src.getHeight() / 2);
int csx = sx + (src.getWidth() / 2);
int csy = sy + (src.getHeight() / 2);
int cdx = dpos.x + (dst.getWidth() / 2);
int cdy = dpos.y + (dst.getHeight() / 2);
int cdx = dx + (dst.getWidth() / 2);
int cdy = dy + (dst.getHeight() / 2);
g.drawLine(csx, csy, cdx, cdy);
}
@@ -1,5 +1,5 @@
//
// $Id: DirectionalLayoutManager.java,v 1.1 2001/08/20 22:56:55 shaper Exp $
// $Id: DirectionalLayoutManager.java,v 1.2 2001/08/23 23:44:12 shaper Exp $
package com.threerings.nodemap.direction;
@@ -37,7 +37,7 @@ public class DirectionalLayoutManager implements LayoutManager
}
// set the node's location
n.setPosition(x, y);
n.setLocation(x, y);
// remember that we've placed this node
_closed.put(n, null);