Started tooling about with Java2D BufferedImages. Retrieve tileset

config information from miso.properties for now.  Don't pass around
ImageObservers since we're hoping to be able to address that
differently.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@49 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-07-14 00:21:24 +00:00
parent 007ce996f7
commit edc687fcb4
5 changed files with 74 additions and 67 deletions
@@ -1,5 +1,5 @@
//
// $Id: DisplayMisoSceneImpl.java,v 1.1 2001/07/12 22:38:03 shaper Exp $
// $Id: DisplayMisoSceneImpl.java,v 1.2 2001/07/14 00:21:23 shaper Exp $
package com.threerings.cocktail.miso.scene;
@@ -31,7 +31,7 @@ public class Scene
tiles = new Tile[TILE_WIDTH][TILE_HEIGHT][NUM_LAYERS];
Tile tile = _tmgr.getTile(DEF_TILESET_NAME, DEF_TILE_NAME);
Tile tile = _tmgr.getTile(DEF_TSID, DEF_TID);
for (int xx = 0; xx < TILE_WIDTH; xx++) {
for (int yy = 0; yy < TILE_HEIGHT; yy++) {
for (int ii = 0; ii < NUM_LAYERS; ii++) {
@@ -214,8 +214,8 @@ public class Scene
protected static final String DEF_SCENE_NAME = "Untitled Scene";
protected static final String DEF_TILESET_NAME = "ground";
protected static final String DEF_TILE_NAME = "dirt";
protected static final short DEF_TSID = 0;
protected static final short DEF_TID = 1;
protected String _name; // the scene name
protected short _sid; // the unique scene id
@@ -1,12 +1,15 @@
//
// $Id: IsoSceneView.java,v 1.1 2001/07/12 22:38:03 shaper Exp $
// $Id: IsoSceneView.java,v 1.2 2001/07/14 00:21:23 shaper Exp $
package com.threerings.cocktail.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 java.awt.*;
import java.awt.image.*;
/**
* The IsoSceneView provides an isometric graphics view of a
@@ -26,16 +29,23 @@ public class IsoSceneView implements SceneView
public void paint (Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
_offGraphics.setColor(Color.white);
// Image img = ImageManager.getImage("/home/shaper/workspace/cocktail/rsrc/media/miso/tiles-base.png");
// _scene.tiles[10][10][0].img =
// ImageManager.getImageCropped(img, 32, 0, 32, 16);
_offGraphics.setColor(Color.red);
_offGraphics.fillRect(0, 0, _bounds.width, _bounds.height);
// draw the full scene into the offscreen image buffer
renderScene(_offGraphics, _viewX, _viewY);
g.drawImage(_offImage, 0, 0, null);
// copy offscreen buffer to the given graphics context
g2.drawImage(_offImg, null, 0, 0);
}
protected void renderScene (Graphics g, int x, int y)
protected void renderScene (Graphics2D g2, int x, int y)
{
int mapX = x / Tile.HALF_WIDTH;
int xOff = x & (Tile.HALF_WIDTH - 1);
@@ -67,8 +77,11 @@ public class IsoSceneView implements SceneView
// TODO: draw layers L1+.
Tile tile = _scene.tiles[tx][ty][Scene.LAYER_BASE];
g.drawImage(tile.img, screenX, screenY, null);
g2.drawImage(tile.img, screenX, screenY, null);
//Log.info("Drawing tile [tx=" + tx + ", ty=" + ty +
// ", sx=" + screenX + ", sy=" + screenY +
// ", img=" + tile.img + "].");
screenX += Tile.WIDTH;
if ((tx += 1) > Scene.TILE_WIDTH - 1) tx = 0;
@@ -89,11 +102,17 @@ public class IsoSceneView implements SceneView
{
_scene = scene;
}
public void setTarget (Component target)
{
_offImage = target.createImage(_bounds.width, _bounds.height);
_offGraphics = _offImage.getGraphics();
_target = target;
int width = _bounds.width, height = _bounds.height;
_offImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
_offGraphics = _offImg.createGraphics();
Log.info("Creating offscreen [width=" + width + ", height=" +
height + "].");
}
protected static final int OFF_X = -Tile.WIDTH;
@@ -102,14 +121,12 @@ public class IsoSceneView implements SceneView
protected static final int DEF_BOUNDS_WIDTH = 600;
protected static final int DEF_BOUNDS_HEIGHT = 600;
protected BufferedImage _offImg;
protected Graphics2D _offGraphics;
protected Rectangle _bounds;
protected int _viewX, _viewY;
protected Graphics _offGraphics;
protected Image _offImage;
protected int _viewX, _viewY;
protected Scene _scene;
protected Component _target;
protected TileManager _tmgr;
}