CURSOR is a very simple "one-time event handler" function that IDL created for a very limited purpose- providing on a direct graphics window the coordinates where a user presses a button. For the functionality you want, where the display of coordinates should update dynamically as a mouse "drags", IDL programmers need to learn some basic IDL Widget code. The place to learn this is in 'Online Help -> Contents tab page -> Programmer's Guides -> Building IDL Applications -> Part IV: Creating Graphical User Interfaces in IDL'
This sample code below gives you a taste of what is involved in widget programming, using your cursor coordinates example:
PRO ex_display_mouse_location_event, event
; Handle only draw widget events
if tag_names(event, /STRUCTURE_NAME) ne 'WIDGET_DRAW' then return
widget_control, event.top, GET_UVALUE=info
; Handle motion events only if button is pressed while dragging
switch event.type of
0: begin ; button press
if event.press eq 1 then *info.buttonPressed = 1
break
end
1: begin ; button release - clear the label text
widget_control, info.wLabel, SET_VALUE=info.defaultLabelText
*info.buttonPressed = 0
return
end
2: break ; motion event
else: begin ; all other events
widget_control, info.wLabel, SET_VALUE=info.defaultLabelText
*info.buttonPressed = 0
return
end
endswitch
; Process events not processed in switch statement above
if *info.buttonPressed ne 1 then return ; If mouse not pressed, don't process
; If mouse moves off draw window, then clear label text
if event.x lt 0 or event.x gt 359 or event.y lt 0 or event.y gt 359 then begin
widget_control, info.wLabel, SET_VALUE=info.defaultLabelText
return
endif
statusMsg = 'Value at [' + strtrim(event.x, 2) + ',' + strtrim(event.y, 2) + $
'] = ' + strtrim(info.data[event.x, event.y], 2)
widget_control, info.wLabel, SET_VALUE=statusMsg
END
PRO ex_display_mouse_location
tlb = widget_base(/COLUMN, TITLE='Cursor Coordinate Displayer')
wDraw = widget_draw(tlb, XSIZE=360, YSIZE=360, /BUTTON_EVENTS, /MOTION_EVENTS)
instructionMsg = 'Hold button down and drag on image ...'
wLabel = widget_label(tlb, XSIZE=360, /SUNKEN_FRAME, VALUE=instructionMsg)
widget_control, tlb, /REALIZE
; Draw some example data on the draw widget window
data = dist(360)
widget_control, wDraw, GET_VALUE=winID
wset, winID
tv, data
; Method for passing variables and handles to event handler code:
info = {wDraw:wDraw, wLabel:wLabel, data:data, buttonPressed:ptr_new(0), $
defaultLabelText:instructionMsg}
widget_control, tlb, SET_UVALUE=info
; Method for accessing event handler
xmanager, 'ex_display_mouse_location', tlb
END
|