Check Click area?
in
Programming Questions
•
1 year ago
I need a help.
I need to check when the mouse click is done in an area of the screen and send the word that is in the area click to another area.
For example if you clicked on the area of the word "o mundo" it is sent to the gray area.
This is my code:
I need to check when the mouse click is done in an area of the screen and send the word that is in the area click to another area.
For example if you clicked on the area of the word "o mundo" it is sent to the gray area.
This is my code:
- color strokeColor = #FFE836;
String[] palavras = {
"a vida", "o mundo", "as coisas", "o céu", "bonito", "ruim", "menos alegre", "feliz"
}; // variavel contem o conteudo;
String[] frase; // variavel que ira receber o conteudo
void setup() {
b1 = new Botoes(65, 100, #C9C7C7);
b2 = new Botoes(185, 100, #C9C7C7);
size(640, 480);
background(0);
// configuracao do tipo de font para texto e posicao do texto na tela
PFont font;
font = loadFont("Serif-48.vlw");
textFont(font);
textSize(20);
fill(#74FC6B);
textLeading (15);
for (int i=0, x = 20, y = 20; i < 8 ; i++) {
if (i < 4) {
text(palavras[i], 370, x);
x+=20;
}
if ( i > 3) {
text(palavras[i], 490, y );
y+=20;
}
} // fim configuracao
strokeJoin(ROUND);
strokeWeight(1);
stroke(#74FC6B);
fill(#C9C7C7);
rect(20, 20, 300, 30);
//rect(95, 100, 60, 20);
//rect(185, 100, 95, 20);
}
void draw() {
b1.render();
b2.render();
fill(#096A03);
text("OK", 100, 118);
text("LIMPAR", 195, 118);
}
class Botoes {
int x, y;
int bWidth = 95;
int bHeight = 20;
color clr;
boolean selected = false;
Botoes(int _x, int _y, color _clr)
{
x = _x;
y = _y;
clr = _clr;
}
void checkClick() {
if (mouseX >= x && mouseX < x+bWidth &&
mouseY >= y && mouseY < y+bHeight) {
strokeColor = clr;
selected = true;
}
else {
selected = false;
}
}
void render() {
fill(clr);
if (selected) {
stroke(#FFE836);
}
else {
stroke(clr);
}
rect(x, y, bWidth, bHeight);
}
}
Botoes b1, b2;
void mouseDragged()
{
stroke(strokeColor);
line(pmouseX, pmouseY, mouseX, mouseY);
}
void mousePressed()
{
b1.checkClick();
b2.checkClick();
}
1