We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Creating Polygon Buttons/ Using SVG
Page Index Toggle Pages: 1
Creating Polygon Buttons/ Using SVG? (Read 782 times)
Creating Polygon Buttons/ Using SVG?
Oct 18th, 2007, 4:01am
 
Hi List,
I'm currently working on some basic UI classes one of which is a "button" that can take any sort of 2D form. I'm using a Polygon object for this. My current method of translating complex shapes over to the Polygon object is a little time consuming so I'm looking for a more streamlined approach.

Is there a way to create an SVG shape in Illustrator and use the data from this to create the Polygon or use a SVG shape as a button?  Any other solutions welcome as well.

Thanks.
Re: Creating Polygon Buttons/ Using SVG?
Reply #1 - Oct 18th, 2007, 7:47am
 
http://processing.org/reference/libraries/candy/index.html

?
F
Re: Creating Polygon Buttons/ Using SVG?
Reply #2 - Oct 18th, 2007, 6:53pm
 
Sorry, I don't think I was explicit enough in my post. I know about the Processing SVG library. If I did use SVG to create these buttons, what approach would you use to determine if the user had clicked on them. Right now I'm using the Polygon object's contains method to determine if a mouse click is contained by that shape. Should I parse the SVG and use that information to create a Polygon object? I'm not much of a java programmer so I'm probably missing something obvious.

Thanks,
joe
Re: Creating Polygon Buttons/ Using SVG?
Reply #3 - Oct 18th, 2007, 9:26pm
 
some code example would be helpful
Re: Creating Polygon Buttons/ Using SVG?
Reply #4 - Oct 19th, 2007, 12:21am
 
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);


}


}

}

Re: Creating Polygon Buttons/ Using SVG?
Reply #5 - Oct 20th, 2007, 3:25pm
 
When it comes to UI stuff I usually build my own. It's a bit of a pain in the ass to do everything manually, but it's pretty straightforward.

Use your SVGs simply as a graphic. Then, use its bounding box (its x,y and width,height) to determine if mouse is inside.

For buttons, you need to do a few logic booleans. Useful ones might be mouseOver, mousePressing, mouseDragging, etc.

I hope that helps. It really is pretty straightforward when you simply break it down with logical operations and bounding boxes.
Page Index Toggle Pages: 1