Well, looks like I should pay closer attention to the docs since I'm using awt and that's not allowed. Anyhow, I built the following class in eclipse(first attempt) and I would like a quick way of feeding coordinates from an SVG file to a PolygonButton object. I'm guessing one way to do this is parsing the SVG file, translating the coordinates, stuffing those in arrays and using that data to instantiate a PolyButton object. My java parsing xml knowledge is non-existent so I'm looking for some leads or other approaches.
Thanks.
The PolyButton Class
Code:
import processing.core.*;
import java.awt.*;
public class PolyButton {
int x,y;
Polygon pg;
private int[] xpoints;
private int[] ypoints;
private int pointsNum;
PApplet parent;
PImage baseImage;
PImage overImage;
PImage pressImage;
boolean over = false;
boolean pressed = false;
PolyButton(PApplet p,int xpos,int ypos,int[] xpts,int[] ypts, int pts, PImage base, PImage over, PImage press){
parent = p;
x = xpos;
y = ypos;
xpoints = xpts;
ypoints = ypts;
pointsNum = pts;
baseImage = base;
overImage = over;
pressImage = press;
for(int i=0;i<xpoints.length;i++){
xpoints[i] = xpoints[i] + x;
}
for(int i=0;i<ypoints.length;i++){
ypoints[i] = ypoints[i] + y;
}
pg = new Polygon(xpoints,ypoints,pointsNum);
}
public void update(){
if(pg.contains(parent.mouseX,parent.mouseY)){
over = true;
}else{
over = false;
}
}
public boolean press(){
if(over == true){
pressed = true;
return true;
}else{
return false;
}
}
public void release(){
pressed = false;
}
public void display(){
if(pressed == true){
parent.image(pressImage,x,y);
}else if(over == true){
parent.image(overImage,x,y);
}else{
parent.image(baseImage,x,y);
}
}
}