package gizmoball.ui.r2;

import gizmoball.game.AbstractGizmo;
import gizmoball.game.AbstractGizmoWithPolygonalGeometry;

import java.awt.Color;
import java.awt.Graphics2D;

import physics.Vect;

/**
 * A drawer for AbstractGizmosWithPolygonalGeometry.  This drawer
 * can handle SquareGizmos, TriangleGizmos, Absorbers, OuterWalls,
 * and all other imaginable polygonal gizmos. <p>
 * 
 * @see R2DrawerFactory
 * @see AbstractGizmoWithPolygonalGeometry
 * @author Albert Leung
 * @version $Id: R2PolygonDrawer.java,v 1.7 2004/04/28 01:47:32 aleung Exp $
 *  
 */
public class R2PolygonDrawer implements R2GizmoDrawer {

	/**
	 * The singleton R2PolygonDrawer returned by the R2DrawerFactory.
	 * 
	 */
	public static final R2PolygonDrawer DRAWER = new R2PolygonDrawer();

	/**
	 * Draws an AbstractGizmoWithPolygonalGeometry.
	 * 
	 * @param g the Graphics context on which to draw
	 * @param gizmo the gizmo from which to extract properties for
	 * representation
	 * @modifies g
	 * 
	 */
	public void drawGizmo(Graphics2D g, AbstractGizmo gizmo) {
		AbstractGizmoWithPolygonalGeometry agwpg =(AbstractGizmoWithPolygonalGeometry)gizmo;
		Vect[] points = agwpg.getGeometry();
		int n = points.length;
		int[] xPoints = new int[n];
		int[] yPoints = new int[n];
		for (int i = 0; i < n; i++) {
			xPoints[i] =(int)(Math.round((points[i].x()*L_IN_PIXELS)));
			yPoints[i] =(int)(Math.round((points[i].y()*L_IN_PIXELS)));
		}
		g.setColor(Color.GREEN);
		//g.fillPolygon(xPoints, yPoints, n);
                g.drawPolygon(xPoints, yPoints, n);
	}

	/**
	 * Returns the singleton instance.
	 * 
	 * @return the only instance of an R2PolygonDrawer
	 * 
	 */
	public static R2GizmoDrawer getInstance() {
		return DRAWER;
	}

}
