You are on page 1of 2

class Botao { int x,y; // posio na tela int w,h; // largura e altura boolean enable = true; // habilita o boto

boolean over = false; // se o ponteiro do mouse esta em cima do boto boolean pressed = false; // se oboto foi clicado void click() { if ((over && mousePressed) && enable) {pressed = true;} else { pressed = false;} } void overRect(int ix, int iy, int iw, int ih) { if (mouseX >= ix && mouseX <= ix+iw && mouseY >= iy && mouseY <= iy+ih) {ov er = true;} else {over = false;} } } class Imagem_Botao extends Botao { PImage base; PImage baseover; PImage clicado; PImage imagem_corrente; Imagem_Botao (int ix, int iy, int iw, int ih, PImage ibase, PImage ibaseover, PImage iclicado, boolean ienable) { x = ix; y = iy; w = iw; h = ih; base = ibase; baseover = ibaseover; clicado = iclicado; enable = ienable; } Imagem_Botao (int ix, int iy, int iw, int ih) { x = ix; y = iy; w = iw; h = ih; enable = this.enable; } Imagem_Botao (int ix, int iy, int iw, int ih, PImage peca) { x = ix; y = iy; w = iw; h = ih; base = peca; baseover = peca; clicado = peca; enable = this.enable;

} void update() { overRect(x,y,w,h); click(); if (pressed) {imagem_corrente = clicado;} else if (over) {imagem_corrente = baseover;} else imagem_corrente = base; } void display() { image(imagem_corrente,x,y); } } Imagem_Botao[] btn = new Imagem_Botao[100]; void setup() { size(800,600); frameRate(60); PImage b = loadImage("1A.gif"); PImage r = loadImage("1B.gif"); PImage d = loadImage("1C.gif"); int tw = b.width; int th = b.height; int contador = 0; for (int x= 1; x < 11; x++) for (int y= 1; y < 11; y++) { //btn[0] = new Imagem_Botao(width/2,height/2,tw,th,b,r,d,true); btn[contador] = new Imagem_Botao(x*(tw+15),y*(th+15),tw,th,b,r,d,true); contador++; } } void draw() { for (int x = 0; x < 100; x++) { btn[x].update(); btn[x].display(); } }

You might also like