package eco;

import org.lwjgl.opengl.GL11;
import java.awt.Rectangle;

public class ToggleButton extends Button{

  public boolean toggle = false;

	public ToggleButton(float x, float y, float size, int tex, int tey, int texselected, int teyselected, boolean on){
		super(x, y, size, tex, tey, texselected, teyselected);
    toggle = on;
	}

	public void click(float mousex, float mousey){
		Rectangle rect = new Rectangle((int) x, (int)y, (int)size, (int)size);
		if (rect.contains(mousex, mousey)){
			clickFlag = true;
      toggle ^= true;
		}
	}

	public void render(float mousex, float mousey){
		TextureAtlas atlas = Render.atlas;
		if (toggle){
			GL11.glBegin(GL11.GL_QUADS);
			GL11.glTexCoord2f(atlas.getCoord(texselected, false), atlas.getCoord(teyselected, false));
			GL11.glVertex2f(x, y);
			GL11.glTexCoord2f(atlas.getCoord(texselected, true), atlas.getCoord(teyselected, false));
			GL11.glVertex2f(x + size, y);
			GL11.glTexCoord2f(atlas.getCoord(texselected, true), atlas.getCoord(teyselected, true));
			GL11.glVertex2f(x + size, y + size);
			GL11.glTexCoord2f(atlas.getCoord(texselected, false), atlas.getCoord(teyselected, true));
			GL11.glVertex2f(x, y + size);
			GL11.glEnd();
		}
		else{
			GL11.glBegin(GL11.GL_QUADS);
			GL11.glTexCoord2f(atlas.getCoord(tex, false), atlas.getCoord(tey, false));
			GL11.glVertex2f(x, y);
			GL11.glTexCoord2f(atlas.getCoord(tex, true), atlas.getCoord(tey, false));
			GL11.glVertex2f(x + size, y);
			GL11.glTexCoord2f(atlas.getCoord(tex, true), atlas.getCoord(tey, true));
			GL11.glVertex2f(x + size, y + size);
			GL11.glTexCoord2f(atlas.getCoord(tex, false), atlas.getCoord(tey, true));
			GL11.glVertex2f(x, y + size);
			GL11.glEnd();
	}

	}

}

@@ -65,16 +65,203 @@
 angle;%0A%0A
+/**%0A * A %3Ci%3EToggleButton%3C/i%3E behaves just like%0A * a normal %3Ci%3EButton%3C/i%3E, but will toggle to%0A * it's second texture when pressed, not just when%0A * moused over%0A * %0A * @author phil%0A *%0A */%0A%0A
 public c
@@ -299,16 +299,16 @@
 n%7B%0A%0A
-  public
+%09private
  boo
@@ -502,20 +502,18 @@
 ected);%0A
-    
+%09%09
 toggle =
@@ -612,39 +612,61 @@
 nt) 
-x
+getX()
 , (int)
-y
+getY()
 , (int)
-s
+ getS
 ize
+()
 , (int)
-s
+ getS
 ize
+()
 );%0A%09
@@ -709,17 +709,20 @@
 %0A%09%09%09
-c
+setC
 lickFlag
  = t
@@ -721,23 +721,19 @@
 Flag
- = 
+(
 true
+)
 ;%0A
-      
+%09%09%09
 togg
@@ -838,16 +838,203 @@
 .atlas;%0A
+%09%09float x = getX();%0A%09%09float y = getY();%0A%09%09float size = getSize();%0A%09%09int texselected = getTexselected();%0A%09%09int teyselected = getTeyselected();%0A%09%09int tex = getTex();%0A%09%09int tey = getTey();%0A%0A
 %09%09if (to
@@ -2094,16 +2094,17 @@
 lEnd();%0A
+%09
 %09%7D%0A%0A%09%7D%0A%0A

Update ToggleButton.java