From 3a7f7f6bdb7785699b2ee606fd8e61733067f4c1 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 18 Apr 2003 18:33:07 +0000 Subject: [PATCH] Allow an object to be relocated (which requires recalculation of our cached screen bounds, etc.). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2417 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/miso/client/SceneObject.java | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/java/com/threerings/miso/client/SceneObject.java b/src/java/com/threerings/miso/client/SceneObject.java index c18781bd5..c961cdf39 100644 --- a/src/java/com/threerings/miso/client/SceneObject.java +++ b/src/java/com/threerings/miso/client/SceneObject.java @@ -1,5 +1,5 @@ // -// $Id: SceneObject.java,v 1.1 2003/04/17 19:21:16 mdb Exp $ +// $Id: SceneObject.java,v 1.2 2003/04/18 18:33:07 mdb Exp $ package com.threerings.miso.client; @@ -53,7 +53,7 @@ public class SceneObject try { tile = (ObjectTile)panel.getTileManager().getTile( tsid, tidx, panel.getColorizer(info)); - init(panel); + relocateObject(panel.getSceneMetrics(), info.x, info.y); } catch (NoSuchTileException nste) { Log.warning("Scene contains non-existent object tile " + @@ -71,48 +71,7 @@ public class SceneObject { this.info = info; this.tile = tile; - init(panel); - } - - /** - * Finishes the initialization of this scene object. - */ - protected void init (MisoScenePanel panel) - { - // compute our object's screen bounds - MisoSceneMetrics metrics = panel.getSceneMetrics(); - - // start with the screen coordinates of our origin tile - Point tpos = MisoUtil.tileToScreen( - metrics, info.x, info.y, new Point()); - - // if the tile has an origin coordinate, use that, otherwise - // compute it from the tile footprint - int tox = tile.getOriginX(), toy = tile.getOriginY(); - if (tox == Integer.MIN_VALUE) { - tox = tile.getBaseWidth() * metrics.tilehwid; - } - if (toy == Integer.MIN_VALUE) { - toy = tile.getHeight(); - } - - bounds = new Rectangle(tpos.x + metrics.tilehwid - tox, - tpos.y + metrics.tilehei - toy, - tile.getWidth(), tile.getHeight()); - - // compute our object footprint as well - _footprint = MisoUtil.getFootprintPolygon( - metrics, info.x-tile.getWidth()+1, info.y-tile.getHeight()+1, - tile.getWidth(), tile.getHeight()); - - // compute our object spot if we've got one - if (tile.hasSpot()) { - _fspot = MisoUtil.tilePlusFineToFull( - metrics, info.x, info.y, tile.getSpotX(), tile.getSpotY(), - new Point()); - _sspot = MisoUtil.fullToScreen( - metrics, _fspot.x, _fspot.y, new Point()); - } + relocateObject(panel.getSceneMetrics(), info.x, info.y); } /** @@ -219,6 +178,47 @@ public class SceneObject return false; } + /** + * Updates this object's origin tile coordinate. It's bounds and other + * cached screen coordinate information are updated. + */ + public void relocateObject (MisoSceneMetrics metrics, int tx, int ty) + { + info.x = tx; info.y = ty; + + // start with the screen coordinates of our origin tile + Point tpos = MisoUtil.tileToScreen( + metrics, info.x, info.y, new Point()); + + // if the tile has an origin coordinate, use that, otherwise + // compute it from the tile footprint + int tox = tile.getOriginX(), toy = tile.getOriginY(); + if (tox == Integer.MIN_VALUE) { + tox = tile.getBaseWidth() * metrics.tilehwid; + } + if (toy == Integer.MIN_VALUE) { + toy = tile.getHeight(); + } + + bounds = new Rectangle(tpos.x + metrics.tilehwid - tox, + tpos.y + metrics.tilehei - toy, + tile.getWidth(), tile.getHeight()); + + // compute our object footprint as well + _footprint = MisoUtil.getFootprintPolygon( + metrics, info.x-tile.getWidth()+1, info.y-tile.getHeight()+1, + tile.getWidth(), tile.getHeight()); + + // compute our object spot if we've got one + if (tile.hasSpot()) { + _fspot = MisoUtil.tilePlusFineToFull( + metrics, info.x, info.y, tile.getSpotX(), tile.getSpotY(), + new Point()); + _sspot = MisoUtil.fullToScreen( + metrics, _fspot.x, _fspot.y, new Point()); + } + } + /** * Returns a string representation of this instance. */