/*  This file is part of the source code for 3D-XplorMath-J, Version 1.0 (January 2008).
 *  Copyright (c) 2008 The 3D-XplorMath Consortium (http://3d-xplormath.org).
 *  This source code is released under a BSD License, which allows redistribution   
 *  in source and binary form, with or without modification, provided copyright
 *  and license information are included, and with no warranty or guarantee of
 *  any kind.  For details, see http://3d-xplormath.org/j/source/BSDLicense.txt
 */
 
 package vmm.core.render;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;

import vmm.core.Transform;

public class CrosshairElement2D extends GeometryElement2D {
	
	private double x,y;
	private int armlength;
	private int strokeWidth;
	private Color color;  // can be null
	private Color backgroundColor;  // can be null
	

	public CrosshairElement2D(double x, double y, int armlength, int strokeWidth, Color color, Color background) {
		this.x = x;
		this.y = y;
		this.armlength = armlength;
		this.strokeWidth = strokeWidth;
		this.color = color;
		this.backgroundColor = background;
	}


	protected void draw(Transform transform, Graphics2D g) {
		Point2D pt = new Point2D.Double(x,y);
		transform.windowToViewport(pt);
		int cx = (int)(pt.getX()+0.499);
		int cy = (int)(pt.getY()+0.499);
		Graphics2D g1 = transform.getUntransformedGraphics();
		Color saveColor = g1.getColor();
		int size = 2*armlength + strokeWidth;
		int offset = (size+1)/2;
		int offset2 = (strokeWidth+1)/2;
		if (backgroundColor != null) {
			g1.setColor(backgroundColor);
			g1.fillRect(cx-offset-1, cy-offset2-1, size+2, strokeWidth+2);
			g1.fillRect(cx-offset2-1, cy-offset-1, strokeWidth+2, size+2);
		}
		if (color != null)
			g1.setColor(color);
		g1.fillRect(cx-offset, cy-offset2, size, strokeWidth);
		g1.fillRect(cx-offset2, cy-offset, strokeWidth, size);
		g1.setColor(saveColor);
	}

}
