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.
Page Index Toggle Pages: 1
ImageButtons in P3D (Read 1620 times)
ImageButtons in P3D
Jun 17th, 2008, 9:59am
 
Hello Ppeople! Proceessing is the best for me today, and I
think forever.

 I would like to create ImageButons(http://processing.org/learning/examples/imagebutton.html) in P3D, please help.

1st: I tried ImageButon in 3d sketch - it flies around with
the other objects!

2nd was SpringGUI - there is no "ImageButton" in the lib! Or
I don't know howto?

3rd: aftter the topic "Multiple Windows"
(http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1211220206)

I found that in   PFrame f; and secondApplet s;
(in my case in P3D only) - all classes (for me -ImageButton class) can be shown only in main window(P3D).
Second window I tried to use like Button panel but it
says: " w = b.width NullPointerExeption and other bad words.

PFrame f;
secondApplet s;

void setup() {
 size(320, 240);
 PFrame f = new PFrame();
}

void draw() {
  background(255,0,0);
   fill(255);
   rect(10,10,frameCount%100,10);
   s.background(0, 0, 255);
   s.fill(100);
   s.rect(10,20,frameCount%120,10);
   s.redraw();
}

public class PFrame extends Frame {
    public PFrame() {
   setBounds(100,100,400,300);
   s = new secondApplet();
   add(s);
   s.init();
   show();
    }
}
 
public class secondApplet extends PApplet {


   ImageButtons button;


    public void setup()
{
   size(400, 300);
   // Define and create image button
 PImage b = loadImage("base.gif");
 PImage r = loadImage("roll.gif");
 PImage d = loadImage("down.gif");
 int x = width/2 - b.width/2;
 int y = height/2 - b.height/2;
 int w = b.width;
 int h = b.height;
 button = new ImageButtons(x, y, w, h, b, r, d);
   noLoop();
    }

    public void draw() {
    button.update();
    button.display();
    }
}

class Button
{
 int x, y;
 int w, h;
 color basecolor, highlightcolor;
 color currentcolor;
 boolean over = false;
 boolean pressed = false;  
 
 void pressed() {
   if(over && mousePressed) {
     pressed = true;
   } else {
     pressed = false;
   }    
 }
 
 boolean overRect(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 ImageButtons extends Button
{
 PImage base;
 PImage roll;
 PImage down;
 PImage currentimage;

 ImageButtons(int ix, int iy, int iw, int ih, PImage ibase, PImage iroll, PImage idown)
 {
   x = ix;
   y = iy;
   w = iw;
   h = ih;
   base = ibase;
   roll = iroll;
   down = idown;
   currentimage = base;
 }
 
 void update()
 {
   over();
   pressed();
   if(pressed) {
     currentimage = down;
   } else if (over){
     currentimage = roll;
   } else {
     currentimage = base;
   }
 }
 
 void over()
 {
   if( overRect(x, y, w, h) ) {
     over = true;
   } else {
     over = false;
   }
 }
 
 void display()
 {
   image(currentimage, x, y);
 }
}

Wich way i'm going?
Will be grateful to any assumptions.
Re: ImageButtons in P3D
Reply #1 - Jun 17th, 2008, 11:35am
 
If you want to draw your image buttons on top of the 3D scene, you've got to proceed this way :

Quote:
void draw() {
 // save the translation/rotation matrix state
 pushMatrix();
   // draw your 3D scene
   draw3Dscene();
 // reload the saved matrix
 popMatrix();
 // clear the zBuffer
 hint(DISABLE_DEPTH_TEST);
 // draw your 2D image buttons
 draw2Dbuttons();
}
Re: ImageButtons in P3D
Reply #2 - Jun 17th, 2008, 3:59pm
 
 Thank you very much!
I'll try.
Re: ImageButtons in P3D
Reply #3 - Jun 18th, 2008, 7:35am
 
One thing I forgot  I use cameramove() and buttons rotate
again.
Doesn't it work because of cameramove()?
Re: ImageButtons in P3D
Reply #4 - Jun 18th, 2008, 10:54am
 
Do the pushMatrix() before your cameramove and all 3D stuff, then do popMatrix() then draw your buttons.
Re: ImageButtons in P3D
Reply #5 - Jun 18th, 2008, 11:50am
 
Thank you very much!
I tried again and it works. But in 1 second button gets
away somewhere if I don't use noLoop(). I check it again.
Re: ImageButtons in P3D
Reply #6 - Jun 19th, 2008, 8:29am
 
      antiplastic and JohnG thank you. Everything works.
I called matrix 3 times inside each other.
Page Index Toggle Pages: 1