	pro wbc_ex_event,ev

widget_control,ev.top,get_uval=a

wset,a.Win

	IF ev.id eq a.View THEN BEGIN

	tmp=a.a
w_box_cursor,ev,xy,init=a.init,cur=tmp
	a.a=tmp
a.init=0
a.xy=xy

widget_control,ev.top,set_uval=a

return
	ENDIF

	WIDGET_CONTROL,ev.id,GET_UVALUE = uv

	CASE uv OF

"DONE": begin
	print,a.xy
	WIDGET_CONTROL,ev.top,/DESTROY
	end

"Nest":	wbc_ex

"Invert":	begin
	a.image(a.xy(0,0):a.xy(1,0),a.xy(0,1):a.xy(1,1))=	$
not 	a.image(a.xy(0,0):a.xy(1,0),a.xy(0,1):a.xy(1,1))
		tmp=a.a
w_box_cursor,cur=tmp
		a.a=tmp

widget_control,ev.top,set_uval=a
tv,a.image

		end

ENDCASE

	end


	pro wbc_ex,xx

init_structure={w_b_state,	$
	x:0, y:0, press:0, first:1, Xc:[0.,0.], Yc:[0.,0.],	$
	Output:intarr(2,2), stretch:0., move:0.}

a={init:1,	$
	View:0L,	$
	Win:0L,		$
		xy:intarr(2,2),	$
			image: bytscl(dist(200),top=!d.n_colors-1), $
	a:init_structure}

base=widget_base(/column,uval=a)

button=widget_button(base,val='DONE',uval='DONE')
button=widget_button(base,val='Invert',uval='Invert')
button=widget_button(base,val='Nest',uval='Nest')

a.View=WIDGET_DRAW(base, xsize=200,ysize=200,$
	/motion_events, /button_events, retain=2)

WIDGET_CONTROL,base,/REALIZE,/HOURGLASS

WIDGET_CONTROL,a.View,get_val=tmp
a.Win=tmp
wset,a.Win

tv,a.image	&	empty

widget_control,base,set_uval=a

xmanager,'wbc_ex',base

end