; $Id: aboutdave.pro,v 1.15 2005/02/08 18:35:04 azuah Exp $
; aboutDave.pro
;
; Modal widget that displays the graphic for the DAVE development
; team and support.
;
; Modification history
; --------------------
; 01/31/02:	(RMD)	Used the map keyword and a bulletin board base to
;					allow the dismiss button to be drawn on top of the
;					ABOUTDAVE PNG graphic.
;
;###############################################################################
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used or if the code in this file is
;  included in another product.
;
;###############################################################################
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro aboutDaveCleanup,tlb
widget_control,tlb,get_uvalue = pState
; Restore the colors that were present when entering aboutDave.pro
tvlct,(*pState).oldr,(*pState).oldg,(*pState).oldb
wdelete,(*pState).winPix
ptr_free,pState
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro aboutDaveQuit,event
widget_control,event.top,/destroy
return
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro aboutDaveWinDraw,event
widget_control,event.top,get_uvalue = pState,/no_copy
image = (*pState).dispImage
case event.type of
2:	begin	; motion event
	  wset,(*pState).winVis
	  device,copy = [0,0,!d.x_size,!d.y_size,0,0,(*pState).winPix]
	  w = (*pState).w & h = (*pState).h
	  ; size of magnified box
	  xsize = (*pState).mag*w & ysize = (*pState).mag*h
      xpos = (event.x > fix(0.5*xsize)) < ((!d.x_size - fix(0.5*xsize)) - 1)
      ypos = (event.y > fix(0.5*ysize)) < ((!d.y_size - fix(0.5*ysize)) - 1)

	  ; coordinates for small box
	  xplo = (xpos-fix(w/2.)) & xphi = xplo+w;(xpos+fix(w/2.))
	  yplo = (ypos-fix(h/2.)) & yphi = yplo+h;(ypos+fix(h/2.))

	  xoff = 0 & yoff = 0
	  newxlo = (xpos-fix(0.5*xsize))+xoff
	  newxhi = (xpos+fix(0.5*xsize))+xoff
	  newylo = (ypos-fix(0.5*ysize))+yoff
	  newyhi = (ypos+fix(0.5*ysize))+yoff

	  xc = [xplo,xphi,xphi,xplo,xplo]	; small box coordinates
	  yc = [yplo,yplo,yphi,yphi,yplo]	; small box coordinates

	  xcb = [newxlo,newxhi,newxhi,newxlo,newxlo];+xoff	; big box coordinates
	  ycb = [newylo,newylo,newyhi,newyhi,newylo];+yoff	; big box coordinates

	  wset,(*pState).winPix
	  loCoords = convert_coord(xplo,yplo,/device,/to_normal)
	  hiCoords = convert_coord(xphi,yphi,/device,/to_normal)
	  devOffSet = convert_coord(xoff,yoff,/device,/to_normal)
	  xo = loCoords[0] & yo = loCoords[1]
	  xf = hiCoords[0] & yf = hiCoords[1]
	  newimage = image
	  newimage[newxlo:newxlo+xsize-1,newylo:newylo+ysize-1] = $
	          rebin(image[xplo:xphi-1,yplo:yphi-1],xsize,ysize,/sample)
	  tvimage,newimage

	  plots,xcb,ycb,/device,color = 0,thick = 1.5
	  wset,(*pState).winVis
	  device,copy = [0,0,!d.x_size,!d.y_size,0,0,(*pState).winPix]
	end
else:
endcase
widget_control,event.top,set_uvalue = pState,/no_copy
return
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro aboutDave_event,event
return
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pro aboutDave,group_leader = group_leader
; widget definition module
; default cursor
tvlct,oldr,oldg,oldb,/get
image = read_png(!DAVE_AUXILIARY_DIR+'aboutdave.png',r,g,b)
s = size(image)
sx = s[1] & sy = s[2]
aspect = 1.0*sy/sx		; find the aspect ratio of the image...
; ...and set the display window's dimensions based on this
; aspect ratio.
winxsize = 700 & winysize = fix(aspect*winxsize)
if n_elements(group_leader) ne 0 then begin
  tlb = widget_base(/modal,group_leader = group_leader,title = 'About DAVE')
endif else begin
  tlb = widget_base(title = 'About DAVE')
endelse
imageBase = widget_base(tlb,xsize = winxsize,ysize = winysize)
butBase = widget_base(imageBase,map = 0,xoffset = 20,yoffset = 20,units = 0)
butSize = 75
;tlb = widget_base(/col,/modal,tlb_frame_attr = 1,group_leader = group_leader,$
;                           title = 'About DAVE')
plotWin = widget_draw(imageBase,xsize = winxsize,ysize = winysize)

quit = widget_button(butBase,value = 'Dismiss',event_pro = 'aboutDaveQuit',xsize = butSize)
geom = widget_info(quit,/geometry)
ysize = geom.ysize
xoff = winxsize-geom.xsize - 10
yoff = winysize - geom.ysize - 10
widget_control,butBase,xoffset = xoff,yoffset = yoff

centertlb,tlb
widget_control,tlb,/realize
widget_control,plotWin,get_value = winVis

widget_control,butBase,map = quit

window,/free,/pixmap,xsize = winxsize,ysize = winysize
winPix = !d.window
tvlct,r,g,b	; load the proper color tables as found in
; read_png above.
dispImage = congrid(image,winxsize,winysize)
wset,winPix
tvimage,dispImage
; Insert version & build date info ;;;;;;;;;;;;;;;;;;;;;;
verDateInfo = ''
lun1 = 37
filename = !DAVE_AUXILIARY_DIR+'version.txt'
if (strtrim(filename,2) ne '') then begin ; get version info 
    openr, lun1, filename
    versionstr = ''
    readf, lun1, versionstr
    verDateInfo = verdateInfo + strtrim(versionstr,2) +'; '
    free_lun, lun1
endif
filename = !DAVE_AUXILIARY_DIR+'builddate.txt'
if (strtrim(filename,2) ne '') then begin             ; get build date info
    openr, lun1, filename
    datestr = ''
    readf, lun1, datestr
    free_lun, lun1
    verDateInfo = verDateInfo + 'Build Date: '+strtrim(datestr,2)
endif
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
wset,winVis
w = 40 & h = 30
mag = 2.0
device,copy = [0,0,!d.x_size,!d.y_size,0,0,winPix]
if (strtrim(verDateInfo,2) ne '') then $
  xyouts, .3, .37, charsize=1.25, color=[0,0,0], verDateInfo, /normal
state = {winPix:winPix,$
         winVis:winVis, $
         dispImage:dispImage,$
		 w:w,$
         h:h,$
         mag:mag,$
         oldr:oldr,$
         oldg:oldg,$
         oldb:oldb}

pState = ptr_new(state)
widget_control,tlb,set_uvalue = pState
xmanager,'aboutDave',tlb,cleanup = 'aboutDaveCleanup'

return
end
