你也可以使用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>