;+
; Project	: SOHO - LASCO/EIT
;
; Name		: WCURSOR
;
; Purpose	: Widgets program for reading current cursor position from ;window.
;
; Category	: Widgets
;
; Explanation	: 
;
; Syntax	: wcursor,image,x,y,counts,win_id=win_id
;
; Examples      :
;
; Inputs	: image
;
; Opt. Inputs	: 
;	x variable for cursor position
;	y variable for cursor position
;	counts variable
;
; Outputs	: 
;	current x and y position if set as optional input parameter
;	counts value at x,y if set as optional input parameter.
;
; Opt. Outputs	: 
;	current x position
;	current y position
;	counts = image(x,y)
;
; Keywords	: win_id, if not set then current window will be read and set.
;
; Common	:
;
; Restrictions  : No check for not valid windows yet !
;
; Side effects	: None.
;
; History	:1-dec-1994, Borut Podlipnik, MPAe, Written
;
; Contact     : BP, borut@lasco1.mpae.gwdg.de
;-
;
 
PRO wcursor,image,x,y,counts,win_id=win_id

	IF N_ELEMENTS(image) EQ 0 THEN RETURN

	IF N_ELEMENTS(x) EQ 0 THEN x = 0
	IF N_ELEMENTS(y) EQ 0 THEN y = 0
	IF N_ELEMENTS(counts) EQ 0 THEN counts = 0
	IF NOT KEYWORD_SET(win_id) THEN win_id = !D.WINDOW 
 	IF win_id LT 0 THEN RETURN

	WCurBase = WIDGET_BASE(TITLE = "Reading Cursor Position",/ROW)
	lcol     = WIDGET_BASE(WCurBase, /FRAME, /COLUMN)
 
	drawbase = WIDGET_BASE(lcol,/ROW)
 
	resbase  = WIDGET_BASE(drawbase, /COLUMN)
	w5 = WIDGET_BASE(resbase, /ROW)
 
	cur_label = WIDGET_LABEL(w5,VALUE = 'Current Cursor position and value: ')
 
	PosHistory = ' '
	w5      = WIDGET_BASE(resbase, /ROW )
	p_curr = WIDGET_TEXT(w5,XSIZE=32, VALUE=PosHistory)

;	p_curr = WIDGET_LIST(w5 ,VALUE=PosHistory,XSIZE=100,YSIZE=3,/FRAME )
 
	WIDGET_CONTROL, WCurBase, /REALIZE

        WSET,win_id
        counts = 0
        simg = size(image)
        title='Press Right Button to Quit'

        REPEAT BEGIN
           cursor,x,y,/CHANGE,/DEVICE
           press = !err
 
           if ( x gt 0 and x lt simg(1)-1 ) and  $
              ( y gt 0 and y lt simg(1)-1 ) then counts = FLOAT(image(x,y))

	   sx = STRCOMPRESS(string(x))
	   sy = STRCOMPRESS(string(y))
	   sc = STRCOMPRESS(string(counts))

	   sxyc = sx + '  ' + sy + '  ' + sc
	;   PosHistory = [sxyc,PosHistory]

           WIDGET_CONTROL,p_curr, SET_VALUE = sxyc 
           ;WIDGET_CONTROL,p_curr, SET_VALUE = PosHistory 

	   IF press eq 1 THEN print,x,y,counts 

        ENDREP UNTIL press eq 4

 	WIDGET_CONTROL, WCurBase, /DESTROY
END
