pro mg_functiongraphics_widget_event, event
compile_opt strictarr
widget_control, event.top, get_uvalue=pstate
uname = widget_info(event.id, /uname)
case uname of
'draw': begin
status = widget_info(event.top, find_by_uname='status')
coords = (*pstate).plot->convertCoord(event.x, event.y, $
/device, /to_data)
label = string(coords[0], coords[1], format='(%"(%f, %f)")')
widget_control, status, set_value=label
end
'save': begin
filename = dialog_pickfile()
if (filename ne '') then (*pstate).plot->save, filename
end
endcase
end
pro mg_functiongraphics_widget_cleanup, tlb
compile_opt strictarr
widget_control, tlb, get_uvalue=pstate
obj_destroy, (*pstate).plot
ptr_free, pstate
end
pro mg_functiongraphics_widget, data
compile_opt strictarr
tlb = widget_base(/column)
save = widget_button(tlb, value='Save as PNG', uname='save')
draw = widget_window(tlb, xsize=500, ysize=300, $
/button_events, uname='draw')
status = widget_label(tlb, value='Ready.', $
scr_xsize=500, /sunken_frame, /align_left, $
uname='status')
widget_control, tlb, /realize
widget_control, draw, get_value=win
p = plot(n_elements(data) eq 0L ? sin(findgen(360) * !dtor) : data, $
/current)
state = { plot: p }
pstate = ptr_new(state, /no_copy)
widget_control, tlb, set_uvalue=pstate
xmanager, 'mg_functiongraphics_widget', tlb, /no_block, $
event_handler='mg_functiongraphics_widget_event', $
cleanup='mg_functiongraphics_widget_cleanup'
end