Best practices for selection sets, click-and-drag?
in
Programming Questions
•
2 years ago
I'm looking for guidance on best practice for creating click-and-drag selection sets in Processing.
I describe below my specific application, but I am interested in generic guidance on what seems a pretty standard function.
I have an array of 480 (Sector) objects stored in an array sectors[]. Each Sector includes, among others, the following variables:
x x-position [set up as an Integrator to allow smooth transitions]
y y-position [ditto]
active whether or not the sector is active (highlighted on screen) [boolean]
Currently, multiple sectors can be activated by shift-clicking their location on screen. And I can click-and-drag an individual sector using the following code:
void mouseDragged() {
for (int i = 0; i < finalStart; i++) {
if (sectors[i].rollover(mouseX,mouseY) && sectors[i].active) {
sectors[i].locate(mouseX,mouseY);
sectors[i].target(mouseX,mouseY);
}
}
}
I'd like to be able to do the following:
1. Click-and-drag all selected sectors as long as the mouse is over one of the selected sectors
2. Select multiple sectors using a bounding box
These seem like pretty standard GUI functions, and I'm wondering if there are some best-practice code examples (or even a library?) out there for the most efficient way to achieve these effects?
I am also open to advice on whether my click-and-drag is the most efficient way to achieve the desired effect.
(Note that the second part of the if condition is required in order to avoid sectors getting "picked up" along the way if another sector is dragged over their location. I assume that creating a selection set would be the other way to deal with this, but I'd prefer to create it with the benefit of others' knowledge of the best ways to do this...)
I describe below my specific application, but I am interested in generic guidance on what seems a pretty standard function.
I have an array of 480 (Sector) objects stored in an array sectors[]. Each Sector includes, among others, the following variables:
x x-position [set up as an Integrator to allow smooth transitions]
y y-position [ditto]
active whether or not the sector is active (highlighted on screen) [boolean]
Currently, multiple sectors can be activated by shift-clicking their location on screen. And I can click-and-drag an individual sector using the following code:
void mouseDragged() {
for (int i = 0; i < finalStart; i++) {
if (sectors[i].rollover(mouseX,mouseY) && sectors[i].active) {
sectors[i].locate(mouseX,mouseY);
sectors[i].target(mouseX,mouseY);
}
}
}
I'd like to be able to do the following:
1. Click-and-drag all selected sectors as long as the mouse is over one of the selected sectors
2. Select multiple sectors using a bounding box
These seem like pretty standard GUI functions, and I'm wondering if there are some best-practice code examples (or even a library?) out there for the most efficient way to achieve these effects?
I am also open to advice on whether my click-and-drag is the most efficient way to achieve the desired effect.
(Note that the second part of the if condition is required in order to avoid sectors getting "picked up" along the way if another sector is dragged over their location. I assume that creating a selection set would be the other way to deal with this, but I'd prefer to create it with the benefit of others' knowledge of the best ways to do this...)
1