subr get_box_image, w1, ix1, ix2, iy1, iy2, button_widget
 ;where w1 is the X window, interactively allows user to adjust
 ;a box on the window and returns the coords of the box in x1, x2, y1, y2
 ;this does not allow the box to rotate
 narg = !narg
 if check_selects(w1) ne 1 then return
 if narg gt 5 then {
 change_button_label, button_widget, 'waiting for'+#nl+'mouse down', 'red' }
 ;;xflush
 xwindow,w1
 $view_cb_case(w1) = 5
 xtloop, 1
 !motif = 1
 if narg gt 5 then {
   change_button_label, button_widget, 'tracking'+#nl+'mouse' }
 ;;xtloop, 2
 !kb=0
 ix1=(!ix<!ixhigh)>0		iy1=(!iy<!iyhigh)>0
 iy2 = iy1+1	ix2 = ix1+1
 ;we use (ix1,iy1) and (ix2, iy2) as coords for opposite
 ;corners
 draw_box_inverted, ix1, ix2, iy1, iy2, w1
 wait,.2
 xlast1=ix1	ylast1=iy1
 xlast2=ix2	ylast2=iy2
 ;;ty,'starting box definition'
 while (1) {
   xquery,w1
   ;2 cases for mouse condition, just holding button moves the
   ;second corner, add a shift and both corners move
   ;in all cases, the mouse drags ix2,iy2
   ;note that we keep within the plot limit area
   ix2=(!ix<!ixhigh)>0   iy2=(!iy<!iyhigh)>0
   if ix2 ne xlast2 or iy2 ne ylast2 then {

     if (!kb and 1) eq 1 then {
     ;shift key down, move everything with fixed orientation
     dx = ix2 - xlast2	dy = iy2 - ylast2
     ix1 += dx
     iy1 += dy
     ix1=(ix1<!ixhigh)>0   iy1=(iy1<!iyhigh)>0
     }

     ;first undraw the old box
     draw_box_inverted, xlast1, xlast2, ylast1, ylast2, w1
     ;now draw the new box
     draw_box_inverted, ix1, ix2, iy1, iy2, w1
     xlast2 = ix2	ylast2 = iy2	;save the current points
     xlast1 = ix1	ylast1 = iy1
   }
   if (!kb and 0xf01) eq 0 then break
 }
 ;now draw the box for real
 draw_box, ix1, ix2, iy1, iy2, w1
 ty,'end of box definition'
 if narg gt 5 then {
 change_button_label, button_widget, 'select'+#nl+'rectangle', 'gray' }
 $select_in_progress = 0
 endsubr
 ;===============================================================================
