float bx;
float by;
int bs = 20;
boolean bover = false;
boolean locked = false;
float bdifx = 0.0; //These hold the offset of the cursor at selection time from the center of the circle;
float bdify = 0.0; //essentially they allow you to drag it from and edge etc., otherwise everytime you selected sth,
PImage b; //it's center would immediately move to the cursor's pos.
void setup()
{
size(1280, 750); // border size
bx = width/2.0;
by = height/2.0;
rectMode(RADIUS);
}
void draw()
{
background(255);//background in white colour
//noStroke();
//b = loadImage("Nike.jpg");// Loading image by putting into sketch
//image(b, 0, 0);
// Test if the cursor is over the box
if (mouseX > bx-bs && mouseX < bx+bs &&
mouseY > by-bs && mouseY < by+bs) {
bover = true;
if(!locked) {
// Bright red
fill(255,0,0);
// ellipse(20,20,16,16);
}
} else {
stroke(153);
fill(153);
bover = false;
}
// Draw the box
rect(bx, by, bs, bs);
}
void mousePressed() {
if(bover) {
locked = true;
// Bright red
fill(255,0,0);
//ellipse(20,20,16,16);
} else {
locked = false;
}
bdifx = mouseX-bx;
bdify = mouseY-by;
}
void mouseDragged() {
if(locked) {
bx = mouseX-bdifx;
by = mouseY-bdify;
}
}
void mouseReleased() {
locked = false;
}
From this program how do i change the small box to a picture that i can drag around like those in the google map.
1