
; Robbies Tools (rt)
; Plot brown noise
; Present a "redraw" button to redraw the plot in the given window
; This code has absolutely now warranty at all and is not guarunteed
; to actually work. 
; Written by Robbie Barnett, Westmead Hospital Sydney

; Draw the graph of the brown noise in the specified window
pro rt_brownian_draw, window
; Keep the seed as a global variable between calls
common rt_brownian, seed
; Set the window to draw in
wset, window
; Create the array which contains the values of the brown noise
values = lonarr(20)
for i=1,19 do values[i] = values[i] + (randomu(seed)-0.5)*10.0
; Plot the brown noise
plot, values
end

; Process an event generated from the widget_button
pro rt_brownian_event, ev
; Get the draw_id which has been packed in the user value of the
; widget button. If this problem were more complicated I would have
; packed a pointer to a structure or object.
widget_control, ev.id, GET_UVALUE=draw_id
; Get the window id which maps to the desired the draw_widget
widget_control, draw_id, GET_VALUE=window
; Draw onto the desired window
rt_brownian_draw, window
end

; Create a widget which allows the user to redraw a plot of brown
; noise.
function rt_brownian, PARENT=parent
; Create the "top level base" widget. This lays out the widget_button
; and widget_draw in a column. Allow for the possibility that the
; parent was not specified.
if (keyword_set(parent)) then tlb = widget_base(parent,COLUMN=1) $
else tlb = widget_base(COLUMN=1)
; Create the canvas (window) for drawing on to
draw_id = widget_draw(tlb,XSIZE=300,YSIZE=300)
; Create the button 
button_id = widget_button(tlb,VALUE="redraw",UVALUE=draw_id)
; Realize the widget elements
widget_control, tlb, /realize
; Register for events
xmanager, "rt_brownian", button_id, /JUST_REG
; Return an id for referencing to this widget
return, tlb
end

; Create 3 widgets arranged in a row. Each widget is independant and
; allows the user to redraw a plot of brown noise in each
pro rt_brownians
;  Create the parent widget for holding all of them
parent = widget_base(ROW=1)
; Create the independant plots arranged in a single row
a = rt_brownian(PARENT=parent)
b = rt_brownian(PARENT=parent)
c = rt_brownian(PARENT=parent)
end

