Repackage classes from com.threerings.cocktail.miso to
com.threerings.miso. Moved ImageManager to com.threerings.media. Removed unused StripImage. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@62 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: Log.java,v 1.1 2001/07/12 22:38:03 shaper Exp $
|
||||
// $Id: Log.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso;
|
||||
package com.threerings.miso;
|
||||
|
||||
/**
|
||||
* A placeholder class that contains a reference to the log object used by
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: CompiledSceneManager.java,v 1.2 2001/07/16 22:12:01 shaper Exp $
|
||||
// $Id: CompiledSceneManager.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.scene;
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
public class CompiledSceneManager extends SceneManagerImpl
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
//
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.5 2001/07/17 17:21:33 shaper Exp $
|
||||
// $Id: DisplayMisoSceneImpl.java,v 1.6 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.scene;
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.cocktail.miso.tile.Tile;
|
||||
import com.threerings.cocktail.miso.tile.TileManager;
|
||||
import com.threerings.miso.tile.Tile;
|
||||
import com.threerings.miso.tile.TileManager;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.io.*;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: EditableSceneManager.java,v 1.2 2001/07/16 22:12:01 shaper Exp $
|
||||
// $Id: EditableSceneManager.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.scene;
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
public class EditableSceneManager extends SceneManagerImpl
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: ExitPoint.java,v 1.1 2001/07/12 22:38:03 shaper Exp $
|
||||
// $Id: ExitPoint.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.scene;
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
/**
|
||||
* Represents a point in a scene that leads to a different scene.
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//
|
||||
// $Id: IsoSceneView.java,v 1.5 2001/07/18 21:19:00 shaper Exp $
|
||||
// $Id: IsoSceneView.java,v 1.6 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.scene;
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.cocktail.miso.Log;
|
||||
import com.threerings.cocktail.miso.media.ImageManager;
|
||||
import com.threerings.cocktail.miso.tile.Tile;
|
||||
import com.threerings.cocktail.miso.tile.TileManager;
|
||||
import com.threerings.cocktail.miso.util.MathUtil;
|
||||
import com.threerings.miso.Log;
|
||||
import com.threerings.miso.tile.Tile;
|
||||
import com.threerings.miso.tile.TileManager;
|
||||
import com.threerings.miso.util.MathUtil;
|
||||
import com.threerings.media.ImageManager;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: SceneManager.java,v 1.2 2001/07/16 22:12:01 shaper Exp $
|
||||
// $Id: SceneManager.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.scene;
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
/**
|
||||
* Manages the various scenes that are displayed during the game and
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: SceneManagerImpl.java,v 1.2 2001/07/17 17:21:33 shaper Exp $
|
||||
// $Id: SceneManagerImpl.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.scene;
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
public abstract class SceneManagerImpl implements SceneManager
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// $Id: SceneView.java,v 1.3 2001/07/16 22:12:01 shaper Exp $
|
||||
// $Id: SceneView.java,v 1.4 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.scene;
|
||||
package com.threerings.miso.scene;
|
||||
|
||||
import com.threerings.cocktail.miso.tile.Tile;
|
||||
import com.threerings.miso.tile.Tile;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
//
|
||||
// $Id: ImageManager.java,v 1.5 2001/07/18 21:19:00 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.media;
|
||||
|
||||
import com.threerings.cocktail.miso.Log;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* The ImageManager class provides a single point of access for image
|
||||
* retrieval and caching.
|
||||
*
|
||||
* <p> <b>Note:</b> The ImageManager must be initialized with a root
|
||||
* AWT component before images can be retrieved, in the interest of
|
||||
* allowing for proper preparation of images for optimal storage and
|
||||
* eventual display.
|
||||
*/
|
||||
public class ImageManager
|
||||
{
|
||||
public static Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
|
||||
/**
|
||||
* Initialize the ImageManager with a root component to which
|
||||
* images will later be rendered.
|
||||
*/
|
||||
public static void init (Component root)
|
||||
{
|
||||
_root = root;
|
||||
tk = root.getToolkit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the image from the specified filename and cache it for
|
||||
* faster retrieval henceforth.
|
||||
*/
|
||||
public static Image getImage (String fname)
|
||||
{
|
||||
if (_root == null) {
|
||||
Log.warning("Attempt to get image without valid root component.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: fix this to properly find the file within the
|
||||
// classpath. getResourceAsStream() returns an InputStream,
|
||||
// but java.awt.Toolkit.createImage() can only take one of a
|
||||
// byte[], String, URL, or ImageProducer.
|
||||
fname = "/home/shaper/workspace/cocktail/" + fname;
|
||||
|
||||
Image img = (Image)_imgs.get(fname);
|
||||
if (img != null) {
|
||||
Log.info("Retrieved image from cache [fname=" + fname + "].");
|
||||
return img;
|
||||
}
|
||||
|
||||
Log.info("Loading image into cache [fname=" + fname + "].");
|
||||
|
||||
img = tk.createImage(fname);
|
||||
MediaTracker tracker = new MediaTracker(_root);
|
||||
tracker.addImage(img, 0);
|
||||
|
||||
try {
|
||||
tracker.waitForID(0);
|
||||
if (tracker.isErrorAny()) {
|
||||
Log.warning("Error loading image [fname=" + fname + "].");
|
||||
return null;
|
||||
|
||||
} else {
|
||||
_imgs.put(fname, img);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new image representing the specified rectangular
|
||||
* section cropped from the specified full image object.
|
||||
*/
|
||||
public static BufferedImage getImageCropped (Image fullImg, int x, int y,
|
||||
int width, int height)
|
||||
{
|
||||
BufferedImage img =
|
||||
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
Graphics2D g2 = img.createGraphics();
|
||||
g2.drawImage(fullImg, -x, -y, null);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
protected static Component _root;
|
||||
protected static Hashtable _imgs = new Hashtable();
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// $Id: StripImage.java,v 1.1 2001/07/12 22:38:03 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.media;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.image.*;
|
||||
|
||||
/**
|
||||
* StripImage facilitates cutting an image up into individual frames.
|
||||
*/
|
||||
public class StripImage
|
||||
{
|
||||
public StripImage (Image img, int frameWidth, int frameHeight,
|
||||
int framesPerRow, int numFrames)
|
||||
{
|
||||
_img = img;
|
||||
_frameWidth = frameWidth;
|
||||
_frameHeight = frameHeight;
|
||||
_framesPerRow = framesPerRow;
|
||||
_numFrames = numFrames;
|
||||
}
|
||||
|
||||
public Image getFrame (int idx, ImageObserver obs)
|
||||
{
|
||||
int frameX = (idx % _framesPerRow) * _frameWidth;
|
||||
int frameY = (idx / _framesPerRow) * _frameHeight;
|
||||
CropImageFilter crop =
|
||||
new CropImageFilter(frameX, frameY, _frameWidth, _frameHeight);
|
||||
|
||||
FilteredImageSource prod =
|
||||
new FilteredImageSource(_img.getSource(), crop);
|
||||
|
||||
Image img = ImageManager.tk.createImage(prod);
|
||||
ImageManager.tk.prepareImage(img, -1, -1, obs);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
public Image[] getAllFrames (ImageObserver obs)
|
||||
{
|
||||
Image allImgs[] = new Image[_numFrames];
|
||||
|
||||
for (int ii = 0; ii < _numFrames; ii++) {
|
||||
allImgs[ii] = getFrame(ii, obs);
|
||||
}
|
||||
|
||||
return allImgs;
|
||||
}
|
||||
|
||||
protected Image _img;
|
||||
protected int _frameWidth, _frameHeight;
|
||||
protected int _framesPerRow, _numFrames;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: CompiledTileSetManager.java,v 1.3 2001/07/17 17:21:33 shaper Exp $
|
||||
// $Id: CompiledTileSetManager.java,v 1.4 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.tile;
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//
|
||||
// $Id: EditableTileSetManager.java,v 1.3 2001/07/17 17:21:33 shaper Exp $
|
||||
// $Id: EditableTileSetManager.java,v 1.4 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.tile;
|
||||
package com.threerings.miso.tile;
|
||||
|
||||
import com.threerings.cocktail.miso.Log;
|
||||
import com.threerings.miso.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// $Id: SwingUtil.java,v 1.1 2001/07/12 22:38:03 shaper Exp $
|
||||
// $Id: SwingUtil.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
|
||||
|
||||
package com.threerings.cocktail.miso.util;
|
||||
package com.threerings.miso.util;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user