Thanks phi.lho i understood what my problem was and corrected it. I altered the program slightly and it seems to be working correctly.
My program uses two rect's(created using 2 classes with inheritance) to zoom in/out. While the rect's themselves stay the same 2 ellipse grow larger/smaller.
Here is the code if anyone is also having this problem
- color currentcolor;
RectButton zoomIN, zoomOUT;
float zoom = 1;
boolean locked = false;
- void setup()
{
size(700, 400);
smooth();
color baseColor;
color buttoncolor;
color highlight;
buttoncolor = color(125, 125, 125);
highlight = color(0, 125, 0);
zoomIN = new RectButton(90, 20, 50, buttoncolor, highlight);
buttoncolor = color(255, 0, 0);
highlight = color(0, 255, 0);
zoomOUT = new RectButton(150, 20, 50, buttoncolor, highlight);
}
- void draw()
{
background(255, 255, 255);
stroke(255);
zoomIN.display();
zoomOUT.display();
scale(zoom);
fill(0,0,0);
ellipse(200, 100, 100, 40);
fill(0,255,0);
ellipse(100, 100, 50, 50);
update(mouseX, mouseY);
}
- void update(int x, int y)
{
if(locked == false)
{
zoomIN.update();
zoomOUT.update();
}
else
{
locked = false;
}
- if(mousePressed)
{
if(zoomIN.pressed())
{
//trans = trans - 0.4;
zoom = zoom + 0.1;
}
else if(zoomOUT.pressed())
{
//trans = trans + 0.4;
zoom = zoom - 0.1;
}
}
}
class Button
{
int x, y;
int size;
color basecolor, highlightcolor;
color currentcolor;
boolean over = false;
boolean pressed = false;
- void update()
{
if(over())
{
currentcolor = highlightcolor;
}
else
{
currentcolor = basecolor;
}
}
- boolean pressed()
{
if(over)
{
locked = true;
return true;
}
else
{
locked = false;
return false;
}
}
- boolean over()
{
return true;
}
- boolean overZoom(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + height)
{
return true;
}
else
{
return false;
}
}
}
- class RectButton extends Button
{
RectButton(int ix, int iy, int isize, color icolor, color ihighlight)
{
x = ix;
y = iy;
size = isize;
basecolor = icolor;
highlightcolor = ihighlight;
}
- boolean over()
{
if( overZoom(x, y, size, size) )
{
over = true;
return true;
}
else
{
over = false;
return false;
}
}
- void display()
{
stroke(255);
fill(currentcolor);
rect(x, y, size, size);
}
}