import display.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class BresenhamMain extends Applet implements MouseInput {

    Grid view;
    int mode = 0;
    public static Color red = new Color(255, 0, 0);
    int xorig=0, yorig=0;

    public BresenhamMain() {}

    public void init() {
	view = new Grid(400,400, 41,41);
	view.addMouseInput(this);
	view.drawGrid = true;
	view.drawAxes = true;

	setLayout(new GridLayout(1,1));
	add(view);

	view.init();
	setVisible(true);
    }

    static Color darkGreen = new Color(0, 200, 0);
    
    public void mouseUp(int x, int y) {
	//do nothing
	//if in mode 1 draw the line
	if (mode==1) {
	    view.clear();
	    //view.line(xorig, yorig, x, y, red);
	    //make call to student's implementation
	    Bresenham.BresenhamAlgorithm(xorig, yorig, x, y, view);
	    view.gbuf.setXORMode(darkGreen);
	    view.line(xorig, yorig, x, y);
	    view.gbuf.setPaintMode();
	    view.updateDisplay();
	}
	mode = 0;
    }

    public void mouseDown(int x, int y, int bnum) {
	mode = bnum;
	view.clear();
	xorig = x;
	yorig = y;
    }

    public void mouseDrag(int x, int y) {
	if (mode!=1) {
	    //stretch a line from (xorig, yorig) to (x, y)
	    view.clear();
	    Bresenham.BresenhamAlgorithm(xorig, yorig, x, y, view);
	    if (mode==2) {
		view.gbuf.setXORMode(darkGreen);
		view.line(xorig, yorig, x, y);
		view.gbuf.setPaintMode();
	    }
	    view.updateDisplay();
	}
	else {
	    //draw a simple line
	    view.clear();
	    view.drawThinLine();
	    view.updateDisplay();
	}
    }

    public final static void main(String[] s) {
	BresenhamMain bmain = new BresenhamMain();
    }
}






