Re: MouseBox Selecting Multiple Imagesyou could also use the JSL functions isShiftKey, isAltKey, isControlKey to manage the red/white decision. The loop to gather the selection could be run on the button release. I think it is "Release", print out the button variable to check...away from desk...
Re: MouseBox Selecting Multiple ImagesThanks a ton for setting me on the right path.
I changed the code a bit so the user can choose to select or unselect, instead of automatically unselecting everything.
So i guess the next problem, comes with tracking the selection. See the below code, it seems to work, but it just feels awkward to me.
mb << setclick(
Function( {this, coords, button},
If( button == "Pressed",
{pressedX, pressedY} = coords;
Try(
pressedBox = mb << getchildbox( {pressedX, pressedY} );
pressedBoxColor = pressedBox[2] << GetBackgroundColor;
);
,
{thisX, thisY} = coords;
xstart = Min( thisX, pressedX ) - 5;
xstop = Max( thisX, pressedX ) + 5;
xstep = 10;
ystart = Min( thisY, pressedY ) - 5;
ystop = Max( thisY, pressedY ) + 5;
ystep = 10;
// turn off all previous selections
//for( b=lb<<CHILD>= 2,
If( pressedBoxColor == "Red",
boxes[2] << setbackgroundcolor( "white" ),
boxes[2] << setbackgroundcolor( "red" )
)
);
)
);
)
)
);
selection = J( 1, 200, 0 );
counter = 0;
For( b = lb << child, !Is Empty( b ), b = b << sib,
counter++;
If( (b << getbackgroundcolor) == "Red",
selection[counter] = 1
);
);</CHILD>Re: MouseBox Selecting Multiple Images
You might need to turn off the page translate feature at the top of the page before grabbing this code. The magic is in the last few lines; everything else is setup. At the end, <
If you need more control, the graphbox with picture segments and mousetrap might be an alternative.
New Window( "selection test", mb = MouseBox( lb = Lineup Box( N Col( 10 ) ) ) );
// generate some pictures of various sizes
For( i = 1, i < 200, i++,
rows = Random Uniform( 10, 100 );
cols = Random Uniform( 10, 100 );
ls = (120 - cols) / 2;
rs = 120 - cols - ls;
ts = (120 - rows) / 2;
bs = 120 - rows - ts;
red = J( rows, cols, Random Uniform( 0, 1 ) );
green = J( rows, cols, Random Uniform( 0, 1 ) );
blue = J( rows, cols, Random Uniform( 0, 1 ) );
lb << append(
Border Box( sides( 15 ), Left( ls ), Right( rs ), top( ts ), bottom( bs ), New Image( "rgb", {red, green, blue} ) )
);
);
mb << setclickenable( 1 );
mb << setclick(
Function( {this, coords, button},
If( button == "Pressed",
{pressedX, pressedY} = coords,
{thisX, thisY} = coords;
xstart = Min( thisX, pressedX ) - 5;
xstop = Max( thisX, pressedX ) + 5;
xstep = 10;
ystart = Min( thisY, pressedY ) - 5;
ystop = Max( thisY, pressedY ) + 5;
ystep = 10;
// turn off all previous selections
For( b = lb << child, !Is Empty( b ), b = b << sib,
b << setbackgroundcolor( "white" )
);
// test points in the selection box
For( x = xstart, x <= xstop, x += xstep,
For( y = ystart, y <= ystop, y += ystep,
boxes = mb << getchildbox( {x, y} );
If( N Items( boxes ) >= 2,
boxes[2] << setbackgroundcolor( "red" )
);
)
);
)
)
);
MouseBox Selecting Multiple ImagesI want to select multiple images using a mousebox.
Below is an example that I've scripted showing how one can select an image one at a time. But since there could be potentially hundreds of pictures, I want my user to be able to select multiple images with a drag function instead of having to click each one. Any tips?
Names Default To Here( 1 );
//dtFull contains image path information
dtFull = Current Data Table();
path1 = dtFull:LocalPath[20];
path2 = dtFull:LocalPath[21];
path3 = dtFull:LocalPath[22];
path4 = dtFull:LocalPath[23];
img = New Image( path1 );
img2 = New Image( path2 );
img3 = New Image( path3 );
img4 = New Image( path4 );
selected = [0, 0, 0, 0];
New Window( "test",
H List Box(
vlb = V List Box(
mb = MouseBox(
pb = Picture Box( img ),
<<SETCLICKENABLE></SETCLICKENABLE>