;+ ; ; FILE DRAWBUTTON.PRO -- includes DRAWBUTTON_EV, DRAWBUTTON ; ; ; ; NAME: ; DRAWBUTTON_EV ; ; PURPOSE: ; The event handler for DRAWBUTTON.PRO ; ; CATEGORY: ; Widgets ; ; CALLING SEQUENCE: ; DRAWBUTTON_EV, EVENT ; ; CALLED BY: ; DRAWBUTTON ; ; CALLS TO: ; none ; ; INPUTS: ; none explicit, only through commons; ; ; OPTIONAL INPUTS: ; none ; ; OUTPUTS: ; none explicit, only through commons; ; ; OPTIONAL OUTPUTS: ; none ; ; COMMON BLOCKS: ; DRAWBUTBASE for passing widget ID's to event handler ; DRAWBUTVARI for passing program variables ; ; SIDE EFFECTS: ; Creates widgets and possibly files. ; ; RESTRICTIONS: ; Widgets must be available ; ; PROCEDURE: ; Handle events as generated by the user of DRAWBUTTON. ; The user is to draw a picture that will be a widget button. ; Display the button picture after each modification. ; If the save option is chosen, create widget to prompt for filename ; and save to a file. A single assignment of a variable called ; BUTTON_8_23_61 is made. The file is to be called in batch mode in ; any desired widget creation programs. ; ; Example: ; ; select desired button file ; @MYBUTTON.WIDGET ; ; ; define base for button ; mybase=widget_base() ; ; ; define your button ; var = widget_base(mybase, value=button_8_23_61) ; ; ; realize the widget ; widget_control, mybase, /realize ; end ; ; ; MODIFICATION HISTORY: ; APR 93 - Elaine Einfalt (HSTX) ;- pro drawbutton_ev, event common drawbutbase, d_base, pressrelease, $ xslide, yslide, mslide, nslide, $ xtext, ytext, mtext, ntext, ftext common drawbutvari, backg, drawarray, xsize, ysize, amag, continue, $ tv_x_size, tv_y_size, xcur, ycur, drawcond, filename widget_control, event.id, get_uvalue=input if n_elements(input) eq 0 then input=' ' type=strmid(tag_names(event, /structure_name),7,4) case type of "BUTT" : case input of "B_DRAW" : if event.select ne 0 then drawcond=0 "W_DRAW" : if event.select ne 0 then drawcond=1 "O_DRAW" : if event.select ne 0 then drawcond=2 "C_DRAW" : if event.select ne 0 then drawcond=3 "BLACK" : begin widget_control, pressrelease, set_value='Erasing...',$ /append backg = 0 drawarray = intarr(tv_x_size, tv_y_size) + backg tv, drawarray widget_control, pressrelease, set_value='Reset ' + $ 'complete.',/append end "WHITE" : begin widget_control, pressrelease, set_value='Erasing...',$ /append backg = !p.color drawarray = intarr(tv_x_size, tv_y_size) + backg tv, drawarray widget_control, pressrelease, set_value='Erase ' + $ 'complete.',/append end "READY" : begin widget_control, event.top, /destroy continue = 1 end "QUIT" : begin widget_control, event.top, /destroy continue = 0 end "WRITE" : begin ; ; Get array back to original size ; and with values of "on" or "off" ; reduce = 1- (congrid(drawarray, xsize, ysize)/!p.color) mybutton = bytarr(xsize/8, ysize) ; ; Convert each row of "on/off" values to 8 bit bytes, ; reversing order. Also, TV images are flipped. ; for y = ysize-1, 0, -1 do begin for x = 0, xsize-1, 8 do begin bits = 0 for s = 0, 7 do $ bits = ishft(reduce(x+s ,y), s) + bits mybutton(x/8,(ysize-1)-y) = bits endfor endfor ; ; Create yet another, to show user the actual button ; and to ask user for a filename ; filebase = widget_base(title='Button''s filename', $ xpad=25, ypad=25, space=20, /column) picbutton = widget_base(filebase, /row) myshow = widget_base(picbutton) show = widget_button(myshow, value=mybutton) inter = widget_base(picbutton, /row, /frame) fname = widget_base(inter, /column) lab = widget_label(fname, $ value='Current filename: ') lab = widget_label(fname, $ value='Enter filename : ') utext = widget_base(inter, /column) ftext = widget_label(utext, value=filename) usertext = widget_text(utext, /editable, xsize=30) done = widget_button(filebase, $ value='SAVE TO FILE', uvalue='READY') quit = widget_button(filebase, $ value='QUIT', uvalue='QUIT') widget_control, filebase, /realize xmanager, 'filebase', filebase, /modal, $ event_handler='drawbutton_ev', $ group_leader=group if not(continue) then return ; ; Write array to file ; widget_control, pressrelease, set_value='Saving...', $ /append openw, lun, filename, /get_lun printf, lun, ';+' printf, lun, ';' printf, lun, '; NAME : ' + filename printf, lun, '; PURPOSE : Assigns array ' + $ 'that represents a widget button ' printf, lun, '; picture' printf, lun, '; CALLING SEQUENCE : @' + filename printf, lun, '; PROCEDURE : Include as batch '+ $ 'mode file, prior to defining' printf, lun, '; the widget '+ $ 'button. Array name is BUTTON_8_23_61' printf, lun, ';' printf, lun, '; Example: ' printf, lun, '; ; select desired button'+$ ' file' printf, lun, '; @widget_button.pro' printf, lun, '; ; define base for button' printf, lun, '; base=widget_base()' printf, lun, '; ; define your button' printf, lun, '; var = widget_button(' + $ 'base, value=' + $ 'button_8_23_61)' printf, lun, '; ; realize the widget' printf, lun, '; widget_control, base, ' +$ '/realize' printf, lun, '; end' printf, lun, ';' printf, lun, ';-' printf, lun, ' ' printf, lun, 'button_8_23_61 = [ $' for i = 0, ysize-1 do begin line = '['+ string(mybutton(0,i),'(i3.3)') +'B ' for k = 1, (xsize/8)-1 do begin line = line + ',' + $ string(mybutton(k,i),'(i3.3)') +'B ' if strlen(line) ge 67 then begin printf, lun, line + '$' line = '' endif endfor if (i ne ysize-1) then printf, lun, line + '], $' $ else printf, lun, line + '] $' endfor printf, lun, ']' printf, lun, ' ' free_lun, lun ; close file widget_control, pressrelease, set_value= $ 'Saved file '+filename, /append end else : widget_control, pressrelease, set_value='Great button !', $ /append endcase "SLID" : case input of "XDIR" : begin widget_control, xslide, get_value=xsize & xsize = xsize*8 widget_control, xtext, set_value=strtrim(xsize,2) end "YDIR" : begin widget_control, yslide, get_value=ysize & ysize = ysize*8 widget_control, ytext, set_value=strtrim(ysize,2) end "MAGI" : begin widget_control, mslide, get_value=amag widget_control, mtext, set_value=strtrim(amag,2) end else : endcase "TEXT" : begin widget_control, event.id, get_value=filename, set_value=' ' filename = filename(0) if strtrim(filename) eq '' then filename='mybutton.widget' widget_control, ftext, set_value=filename end "DRAW" : begin ; ; Turn pixels on and off by clicking the cursor in the window ; if event.press ne 0b then begin ; ; Find the leader pixel of this pixel set ; xcur = 0 > (fix(event.x/amag) * amag) < (tv_x_size-1) ycur = 0 > (fix(event.y/amag) * amag) < (tv_y_size-1) widget_control, pressrelease, set_value='First position ' + $ '@ (' + strtrim(fix(xcur),2) + ',' + $ strtrim(fix(ycur),2) + ').',/append return endif ; ; Find the leader pixel of this pixel set ; xcur2 = 0 > (fix(event.x/amag) * amag) < (tv_x_size-1) ycur2 = 0 > (fix(event.y/amag) * amag) < (tv_y_size-1) widget_control, pressrelease, set_value='Second position ' + $ '@ (' + strtrim(fix(xcur2),2) + ',' + $ strtrim(fix(ycur2),2) + ').',/append widget_control, pressrelease, set_value='Working...', /append ymin = ycur < ycur2 & ymax = ycur > ycur2 xmin = xcur < xcur2 & xmax = xcur > xcur2 yext = indgen(amag) ; do them in pixel sets for y = ymin, ymax, amag do begin ymod = (y/amag) mod 2 for x = xmin, xmax, amag do begin xmod = (x/amag) mod 2 case drawcond of 0 : for j = x, x+(amag-1) do $ drawarray(intarr(amag)+j, yext+y) = 0 1 : for j = x, x+(amag-1) do $ drawarray(intarr(amag)+j, yext+y) = !p.color 2 : if drawarray(x,y) eq 0 $ then for j = x, x+(amag-1) do $ drawarray(intarr(amag)+j, yext+y) = !p.color $ else for j = x, x+(amag-1) do $ drawarray(intarr(amag)+j, yext+y) = 0 3 : for j = x, x+(amag-1) do $ drawarray(intarr(amag)+j, yext+y) = $ abs(ymod - xmod) * !p.color else : endcase endfor endfor tv, drawarray ; the button as it looks now widget_control, pressrelease, set_value='Ready.', /append end endcase return end ;------------------------------------------------------------------------------ ;+ ; ; NAME: ; DRAWBUTTON ; ; PURPOSE: ; Create widgets to get parameters of the button to be created. ; And create drawing board widget. ; ; CATEGORY: ; Widget ; ; CALLING SEQUENCE: ; DRAWBUTTON, [GROUP_LEADER=GROUP] ; ; CALLED BY: ; none ; ; CALLS TO: ; none ; ; INPUTS: ; none ; ; OPTIONAL INPUTS: ; none ; ; OUTPUTS: ; none ; ; OPTIONAL OUTPUTS: ; none ; ; COMMON BLOCKS: ; DRAWBUTBASE for passing widget ID's to event handler ; DRAWBUTVARI for passing initial program variables ; ; SIDE EFFECTS: ; Create widgets ; ; RESTRICTIONS: ; Widgets must be available ; ; PROCEDURE: ; Create widget to prompt user for button size (pixels) and ; magnification to make it easier to draw. Next the drawing ; board is created and control is passed to the event handler. ; ; MODIFICATION HISTORY: ; APR 93 - Elaine Einfalt (HSTX) ; ;- PRO drawbutton, GROUP = GROUP common drawbutbase, d_base, pressrelease, $ xslide, yslide, mslide, nslide, $ xtext, ytext, mtext, ntext, ftext common drawbutvari, backg, drawarray, xsize, ysize, amag, continue, $ tv_x_size, tv_y_size, xcur, ycur, drawcond, filename xsize = 40 & ysize = 40 & amag = 10 backg = !p.color & drawcond = 2 filename = 'MYBUTTON.WIDGET' ; ; Create a widget to get the actual button size and the drawing board size. ; questbase = widget_base(title='Create a widget button', xpad=25, ypad=25, $ space=20, /column) lab = widget_label(questbase, value='Answer the following questions to ' + $ 'create the drawing board.') xit = widget_base(questbase, /column, /frame) xdirc = widget_base(xit, /row) lab = widget_label(xdirc, value='Current X direction: ') ; xtext = widget_text(xdirc, value='40', xsize=3) xtext = widget_label(xdirc, value='40') xslide = widget_slider(xit, value=5, min=1, max=100, uvalue='XDIR', $ /drag, /suppress_value, $ title='Enter the X direction size of the ' + $ 'resulting button (pixels).') yit = widget_base(questbase, /column, /frame) ydirc = widget_base(yit, /row) lab = widget_label(ydirc, value='Current Y direction: ') ; ytext = widget_label(ydirc, value='40'), xsize=3) ytext = widget_label(ydirc, value='40') yslide = widget_slider(yit, value=5, min=1, max=100, uvalue='YDIR', $ /drag, /suppress_value, $ title='Enter the Y direction size of the ' + $ 'resulting button (pixels).') mit = widget_base(questbase, /column, /frame) magif = widget_base(mit, /row) lab = widget_label(magif, value='Current magnification: ') ; mtext = widget_text(magif, value='10', xsize=3) mtext = widget_label(magif, value='10') mslide = widget_slider(mit, value=10, min=1, max=100, /drag, $ uvalue='MAGI', title='Enter a magnification,'+$ ' for easy drawing.') ready = widget_button(questbase, value='READY TO DRAW', uvalue='READY') quit = widget_button(questbase, value='CANCEL', uvalue='QUIT') widget_control, questbase, /realize xmanager, 'DRAWINGBOARD', questbase, event_handler='drawbutton_ev', $ group_leader=group if not(continue) then return tv_x_size = xsize * amag & tv_y_size = ysize * amag ; ; Create the drawing board so the user can create their buttons. ; d_base = widget_base(title='Button Drawing Board', /row, $ xpad=25, ypad=25) butts = widget_base(d_base, /column, space=10) instruct = widget_base(butts, /column) lab = widget_label(instruct, value='Use mouse to select area:') lab = widget_label(instruct, value='Press down left button.') lab = widget_label(instruct, value='Drag to desired location.') lab = widget_label(instruct, value='Release to define area.') condition = widget_base(butts, /column, /exclusive, /frame) draw_b = widget_button(condition, $ value='Draw with black brush', $ uvalue='B_DRAW') draw_w = widget_button(condition, $ value='Draw with white brush', $ uvalue='W_DRAW') draw_o = widget_button(condition, $ value='Draw with opposite brush', $ uvalue='O_DRAW') draw_c = widget_button(condition, $ value='Draw with checkered brush', $ uvalue='C_DRAW') back = widget_base(butts, /column, /exclusive, /frame) black = widget_button(back, $ value='ERASE and use BLACK background', $ uvalue='BLACK') white = widget_button(back, $ value='ERASE and use WHITE background', $ uvalue='WHITE') pressrelease = widget_text(butts, /scroll, ysize=3) done = widget_button(butts, value='READY TO SAVE', uvalue='WRITE') quit = widget_button(butts, value='QUIT', uvalue='QUIT') drawing = widget_base(d_base) draw = widget_draw(drawing, xsize=tv_x_size, ysize=tv_y_size, $ retain=2,/button_events) widget_control, d_base, /realize widget_control, draw_o, /set_button widget_control, pressrelease, set_value='Setting up...',/append widget_control, get_value=index, draw wset, index xyouts, 0.5, 0.5, 'WAIT....', alignment=0.5, /normal, charsize=2 drawarray = intarr(tv_x_size, tv_y_size) + backg tv, drawarray widget_control, pressrelease, set_value='Ready.',/append xmanager, 'drawbutton', d_base, event_handler='drawbutton_ev', $ group_leader=group return end