import com.cult3d.*;
import com.cult3d.world.*;

import java.awt.*;
import java.awt.image.*;

// The TextBox Example
public class WoodText implements Cult3DScript
{
	Texture texture;

	TextureImage image;
	TextureImage copy;
	Graphics gr;

	int width;
	int height;
	int textascent;
	int textheight;

	FontMetrics fm;

	public WoodText()
	{
		texture = new Texture("WOODtext");

		width = texture.getWidth();
		height = texture.getHeight();

		image = (TextureImage) Cult.createImage(width, height);
		copy = (TextureImage) Cult.createImage(width, height);
		texture.getTexture(copy);
		gr = image.getGraphics();

		gr.setFont(new Font("Arial", Font.PLAIN, 100));
		fm = gr.getFontMetrics();
		textascent = fm.getMaxAscent();
		textheight = fm.getHeight();
	}

	public void cultEvent(String event)
	{
		System.out.println("Event: " + event);
		gr.drawImage(copy, 0, 0, null);
		gr.setColor(Color.red);
		int textwidth = fm.stringWidth(event);
		gr.drawString(event, (width - textwidth) / 2,
		  (height - textheight) / 2 + textascent);
		texture.setTexture(image);
	}

	public void cult3dDestroy()
	{
	      image = null;
	      copy = null;
	      Graphics gr = null;
	}
}
