Al_11
Junior Member
Offline
Posts: 75
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.