WwGetPosition Function
Obtains the coordinates of a selected point inside a widget. The selected point coordinates are passed in an event structure by a PV‑WAVE Widgets event handler.
Usage
point = WwGetPosition(event)
Input Parameters
event — The event handle received by the event handler.
Returned Value
point — A two-element array containing the position obtained from the event parameter. If WwGetPosition fails, [-1,-1] is returned.
Keywords
None.
Example
This example demonstrates the use of a number of PV‑WAVE Widgets in a simple application. The PV‑WAVE Widgets used in this example include: WwHandler, WwGetPosition, WwGetKey, WwSetCursor, and WwGetButton.
Two event handler procedures, DrawHandler and DrawKeyHandler, are registered with a drawing area widget:
*The DrawHandler procedure is called when a mouse button is pressed while the pointer is in the drawing area. DrawHandler prints the position of the pointer when the mouse button is pressed, which button was pressed, and the state of the modifier keys using the WwGetPosition and WwGetButton functions. Finally, DrawHandler removes itself from the drawing area widget.
*The DrawKeyHandler procedure is called when a key is pressed while the pointer is in the drawing area. DrawKeyHandler prints the ASCII character of the key, the state of the modifier keys, and the ASCII value of the key using the WwGetKey function.
*If the key pressed is <w>, the drawing area cursor changes to the “wait cursor” (WwSetCursor). If the key pressed is <n> the drawing area cursor changes to the “default” cursor (WwSetCursor).
To run this example, enter the callback procedures into a file, and compile the procedure with the .RUN command. Then, enter the widget commands at the WAVE> prompt. To dismiss the drawing area widget, select the appropriate function (such as Close) from the window manager menu.
Callback Procedures
This procedure performs an action when a button is pressed.
PRO DrawHandler, wid, shell, event
   COMMON draw, top, img
   ; Print the position of the button press.
   PRINT, 'Position: ', WwGetPosition(event)
   ; Print the button and modifier keys.
   PRINT, WwGetButton(event, State = state)
   PRINT, 'State: ', state
   ; Remove the handler.
   h=WwHandler(wid, 'DrawHandler', /Remove)
END
 
; This event handler performs an action when a key is pressed.
PRO DrawKeyHandler, wid, shell, event
   COMMON draw, top, img
   key = WwGetKey(event, State = state, Keysym = keysym)
   ; Print the ASCII value of the key, state of the modifier keys,
   ; and key symbol.
   PRINT, 'Key: ', key, 'State: ', state, 'Keysym: ', keysym
   ; If the key is 'w', set the wait cursor; if the key is 'n' set
   ; the default cursor.
   IF key EQ 'w' THEN status = WwSetCursor(wid, /Wait)
   IF key EQ 'n' THEN status = WwSetCursor(wid, /Default)
END
 
PRO DrawCB, wid, data
   ; A callback procedure to display an image.
   COMMON draw, top, img
   TV, img
END
Widget Commands
COMMON draw, top, img
top=WwInit('ww_ex100', 'Examples', layout)
LOADCT, 5, /SILENT
img=BYTARR(512,512)
OPENR,1, !Data_Dir + 'head.img'
READU,1,img
CLOSE, 1
draw=WwDrawing(layout, 1,'DrawCB', [256,256], [512,512], $
   Area = darea)
status = WwHandler(darea, 'DrawHandler', 'ButtonPressMask')
status = WwHandler(darea, 'DrawKeyHandler', 'KeyPressMask')
status=WwSetValue(top, /Display)
WwLoop
See Also