X
4669

IDL 8.2: Example of the Erase method for IDL 8 Function Graphics windows

One new addition to IDL 8.2 is the ERASE method that is now included with the Function Graphics windows. The ERASE method can be used with windows created using the WINDOW or WIDGET_WINDOW property. The erase method will clear out the contents of a window without closing it. 

An example  program that demonstrates how this method can be used is shown below. This example is a widget program that is composed of three routines. "ds_erase_example" sets up the widget. "ds_make_random_image" creates 5 images of a rose and  draws them to random locations in the window. "ds_erase_example_event" is the event handler that controls the widget, and the ERASE method is used in this routine.


;The event handler for the example widget
pro ds_erase_example_event, event
  compile_opt idl2
 
  widget_control, event.top, get_uvalue=state
  widget_control, event.id, get_value=uval

  WIDGET_CONTROL, state.win, GET_VALUE=owin ;get the window reference from the state

  case (uval) of
       'Restart': begin
          owin.select ;select the window as the current window
          owin.erase ;erase the current contents of the window
           ds_make_random_image ;draw the new images
         end
         else: begin
         end
  endcase
 
end

;Routine that will draw the different color rose pictures in different colors

pro ds_make_random_image
  compile_opt idl2
 
 
  random_picks = RANDOMU(seed,6);create random distribution
  sorted_random = sort(random_picks) ;return indexes of random_picks in order
  sorted_random += 1 ;add 1 to work with LAYOUT keyword
 
  ;create images of different colors
  rose=READ_IMAGE(FILE_WHICH('rose.jpg'))
  red_rose=rose
 
  yellow_rose=rose
  yellow_rose[2,*,*]=0
 
  red_rose=yellow_rose
  red_rose[1,*,*]=0
 
  green_rose=yellow_rose
  green_rose[0,*,*]=0
 
   
  purple_rose=rose
  purple_rose[1,*,*]=0  
 
  ;Draw the rose of different colors in random order using the result of the
  ;SORT funtion
  !NULL = image(rose, LAYOUT=[3,3, sorted_random[0]], /CURRENT, MARGIN=0)
  !NULL = image(red_rose, LAYOUT=[3,3, sorted_random[1]], /CURRENT, MARGIN=0)
  !NULL = image(yellow_rose, LAYOUT=[3,3, sorted_random[2]], /CURRENT, MARGIN=0)
  !NULL = image(green_rose, LAYOUT=[3,3, sorted_random[3]], /CURRENT, MARGIN=0)
  !NULL = image(purple_rose, LAYOUT=[3,3, sorted_random[4]], /CURRENT, MARGIN=0)
 
end


;sets up the widget

pro ds_erase_example
 
  compile_opt idl2
  on_error, 2
 

  ;create the widget base and window
  base = WIDGET_BASE(/COLUMN)
  win = WIDGET_WINDOW(base, XSIZE=600, YSIZE=400 )
  wcontrolbase=widget_base(base, /row) ;make button base
  restart_button = WIDGET_BUTTON(base, VALUE="Restart", UVALUE="restart_button")
 
 ; create the state variable
  state={win:win, restart_button:restart_button}
 
  widget_control, base, SET_UVALUE=state
  WIDGET_CONTROL, base, /REALIZE
 
  ;Draw the images of the rose in random order
  ds_make_random_image
 

  xmanager, 'ds_erase_example', base, /no_block ;starts xmanager
 
 
end