mouse move selection retention
in
Programming Questions
•
9 months ago
I have a simple mouse drag setup in my program, that can move objects from an array of a slightly complicated class...
Setup+++++++++++++++++++++++
int sel=0;
Draw++++++++++++++++++++++++
Rect dragR = (Rect) rects.get(i);
if (mouseX <= (dragR.pos.x + (sWidth/2)) && mouseX >= (dragR.pos.x - (sWidth/2)) && mouseY <= (dragR.pos.y + (dragR.tHeight/2)) && mouseY >= (dragR.pos.y - (dragR.tHeight/2))){
sel=1;
if (dragging){
dragR.pos.x=mouseX;
dragR.pos.y=mouseY;
}
else {
sel=0;
}
++++++++++++++++++++++++++++
void mouseDragged(){
dragging=true;
}
void mouseReleased(){
dragging=false;
}
Obviously, this does not work when the mouse strays away from the object.
Is there a simple way to 'lock down' the selection to keep the move active when the mouse strays?
I've looked at other code, and it is specific to their setup. What would be ideal I think is some sort of boolean that keeps the object selected if the mouse is not released after initial good selection.
If anyone can give me hint, I'd be happy!
1