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.
IndexDiscussionExhibition › shaped buttons easy and fast
Page Index Toggle Pages: 1
shaped buttons easy and fast (Read 2969 times)
shaped buttons easy and fast
Feb 13th, 2010, 11:56am
I try to make an kiosk system with a touchscreen. The Buttons on the screen should not be just rectangular, they should be shaped.

If you ever tried to make shaped buttons with any programming language, you know it is hard. I found an unusual and very easy way to make buttons in any shape you like.

I made the buttons with a graphic program and save them as an image. And I made a second image where every button is represented by a different color.

The first image is visible on the screen, but the second is just loaded not shown. You can find out which button is clicked with the second image. If you have an click event, look on the invisible image which color is there.

So, every button has an different color in the invisible image. I look in the array for the corresponding color, and I know which button it clicked.

easy and fast

Here is a demo on openprocessing:

and on instructables:

hope it is useful for you

// an unusual way to create shaped buttons with Processing

PImage button;        //image of the buttons (visible)
PImage buttoncolmap;  //colormap of the buttons (hidden)

String[] buttonstring={"quadrat","thumb up","smile","envelope",
                        "circle","four star","banner","boom",
                        "textfield",""}; //the names of the buttons
color[] buttoncolor={0xFF0000FF,0xFF00FFFF,0xFF00FF00,0xFFFFFF00,
                        0xFFFFFF66,0xFFFFFFFF}; //the colors of the buttons

String textfield="";

PFont font;

void setup ()
void draw()
void mouseReleased()
    color testcolor=0;
    testcolor=buttoncolmap.get(mouseX,mouseY); //get the color in the hidden image
    for(int i=0;i<buttonstring.length;++i) //check the color and copy the name of the button

Re: shaped buttons easy and fast
Reply #1 - Feb 13th, 2010, 12:22pm
This is a great use of 2d-picking! As soon as you need to click on complicated shapes, picking is a must.

We should add that to the hacks section maybe - where there is an existing hack on 3d-picking already :
Re: shaped buttons easy and fast
Reply #2 - Feb 13th, 2010, 3:05pm
Really neat, simple solution to a potentially complex problem!
Re: shaped buttons easy and fast
Reply #3 - Feb 13th, 2010, 6:05pm
Thank you for sharing...I had been looking for something just like this on one of my new projects.  I'm excited to try it out...good work!
Re: shaped buttons easy and fast
Reply #4 - Mar 14th, 2010, 6:04am
Thanks a lot for sharing this awesome technique.

It has so many applications

Here is a basic sketch for a paddle idea using your technique

Re: shaped buttons easy and fast
Reply #5 - Mar 30th, 2010, 4:25am
Thx for this
Re: shaped buttons easy and fast
Reply #6 - Mar 30th, 2010, 7:10am
Very simple and clever! Nice one
Re: shaped buttons easy and fast
Reply #7 - Apr 12th, 2010, 2:55am
Just wanted to report that I've used the "buffer-check" idea successfully for collision-checks of complex shapes.

Page Index Toggle Pages: 1