; Define a rectangle or line with 2 mouse clicks.  Get size in pixels.

pro uvspcursor,struc=struc,left=left,right=right,topper=topper,bottom=bottom, $
		hsiz=hsiz,vsiz=vsiz,type=type

common order1, diskexp, control, generic, comment

   ; Read cursor position and put values in required order.
   if type eq 0 then widget_control, comment, set_value=' '+$
		'CLICK ON OPPOSITE CORNERS, TO MAKE A BOX.', /append $
     else if type eq 1 then widget_control, comment, set_value= $
	  'CLICK AT TWO POINTS, TO MAKE A LINE.',/append $
        else begin
	        widget_control, comment, set_value='ERROR: ' + $
		           'Invalid type of call to UVSPCURSOR.', /append
	        return
	     end

   cursor,xa,ya,/down,/normal  &  cursor,xb,yb,/down,/normal
                                                       
   x00 = xa<xb  &  xb = xa>xb  &  xa = x00
   y00 = ya<yb  &  yb = ya>yb  &  ya = y00

   if type eq 1 then begin
      ;  This will be a line (for slice), not a retangle
      ; 	Make line vertical or horzinotal, no diagonals allowed.
      if (yb-ya) lt (xb-xa) then yb = ya else xb = xa
   endif

   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ; Find the edges of defined area.
   ; Truncate to the image area if user clicks outside the image.
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                                    
   left   = 0 > fix( ( (xa-struc.st2.xpos)/struc.st2.xfact ) $
				*struc.st7.nx)   < (struc.st7.nx-1)
   right  = 0 > fix( ( (xb-struc.st2.xpos)/struc.st2.xfact ) $
				*struc.st7.nx)  < (struc.st7.nx-1)
   bottom = 0 > fix( ( (ya-struc.st2.ypos)/struc.st2.yfact ) $
                                *struc.st7.ny) < (struc.st7.ny-1)
   topper = 0 > fix( ( (yb-struc.st2.ypos)/struc.st2.yfact ) $
                                *struc.st7.ny) < (struc.st7.ny-1)
                                        

   hsiz = right - left + 1  &  vsiz = topper - bottom + 1

   ; Draw user's lines
   plots,[xa,xa,xb,xb,xa],[ya,yb,yb,ya,ya],/normal

return
end
