你也可以使用JSL函数isShiftKey,isAltKey,isControlKey来管理红/白决策。 可以在按钮释放上运行用于收集选择的循环。 我认为这是“发布”,打印出按钮变量来检查...远离桌面......
感谢您为我设定正确的道路。
我对代码进行了一些更改,以便用户可以选择选择或取消选择,而不是自动取消选择所有内容。
所以我想下一个问题是跟踪选择。 看到下面的代码,它似乎可以工作,但是对我来说却很尴尬。
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>
在获取此代码之前,您可能需要关闭页面顶部的页面翻译功能。 魔术在最后几行;其他一切都已设置。 最后,在循环中使用<< getChildBox(location)来查找由鼠标向下选择到当前鼠标位置的范围内的像素网格(每10个像素X和Y)。 在本示例中,getChildBox返回1、2或3个框,具体取决于像素是在位图(第3个框)还是仅在边框(第2个框)中,还是在鼠标框的子代(第1个框)中。 如果找到第二个框,请使其具有红色背景。 还要注意,在将所有框清除为白色之前的循环。 此代码在鼠标移动和计时器刻度上都运行; “ button”参数说明了为什么调用该函数。 按下是鼠标向下的位置。 lb [borderbox(1)] << getbackgroundcolor将在发布事件发生时告诉您方框是红色还是白色。 您也可以添加文本标签。 请注意,左边框...底部值是根据图片尺寸设置的,以使图片居中。 如果添加了文本,则需要进行一些调整。
如果您需要更多控制,则可以选择带有图片段和捕鼠器的图形框。
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" )
);
)
);
)
)
);
我想使用鼠标框选择多个图像。
以下是我编写脚本的示例,显示了如何一次选择一张图像。 但是由于可能有数百张图片,我希望我的用户能够通过拖动功能选择多张图片,而不必单击每张图片。 有小费吗?
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>