;+
;hide widget
;+
PRO sesMagnifier::HideWidget
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	self.magModel->SetProperty,Hide = 1
	oSystem.oWindow -> Draw,oSystem.oScene
END
;+
;show magnifier image
;+
PRO sesMagnifier::ShowImage , eventX , eventY
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	imageClass = (oSystem.CurrentPro)
	oView = (oSystem.CurrentPro).oView
	oView->GetProperty, Location = viewLoc , dimensions = dim
	self.magModel->GetProperty, UValue = image
	imageSize = Size(image,/Dimensions)
	self.magModel->SetProperty, Hide=0
	x0 = (0>(eventX-viewLoc[0]))<(dim[0]-1)
	y0 = (0>(eventY-viewLoc[1]))<(dim[1]-1)
	drawSize = [200,200]
	rate = self.zoomRate
	img_lox = x0 - drawSize[0]/2
	img_loy = y0 - drawSize[1]/2
	win_size = drawSize/rate/2.

	x_low = (x0 - win_size[0]+viewLoc[0])>0
	x_high = ((x0 + win_size[0]+viewLoc[0])>0)<(imageSize[1]-1)
	y_low = (y0 - win_size[1]+viewLoc[1])>0
	y_high = ((y0 + win_size[1]+viewLoc[1])>0)<(imageSize[2]-1)

	zoom_img = congrid(image $
					   [*,x_low:x_high, y_low:y_high], $
		               3, drawSize[0], drawSize[1])

	self.magImage->SetProperty, data=zoom_img, $
				   location=[img_lox, img_loy]

	oSystem.oWindow -> Draw,oSystem.oScene

END
;+
;handle event
;+
PRO sesMagnifier::HandleEvent, event
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	UName = Widget_Info(event.id, /UName)
	IF Tag_Names(event, /Structure_Name) EQ 'WIDGET_KILL_REQUEST' THEN BEGIN
		Widget_Control, event.top, /Destroy
        oSystem.oWindow -> Draw,oSystem.oScene
		Return
	ENDIF
	CASE UName OF
		'magnify_text':BEGIN
			Widget_Control, event.id, Get_Value=value
			value = 2 > value < 10
			self.zoomRate = value
			Widget_Control, event.id, Set_Value=value
		END
	ELSE:
	ENDCASE
END
;+
;create object
;+
PRO sesMagnifier::Create
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	Device, Get_Screen_Size = screenSize
	xOff = 4
	yOff = screenSize[1]-(oSystem.baseSize)[1]-2
	imageClass = (oSystem.CurrentPro)
	imageClass.oView->GetProperty, Dimensions = dim
	Obj_Destroy , self.mContainer
	self.mContainer = Obj_New('IDL_Container')

	cBase = Widget_Base(Group_Leader = self.mainBase		, $
		                UName      = 'zoomBase'  	        , $
		                UValue	   = self					, $
		                Title      = 'zoom out multiple'	, $
		                Space      = 2          			, $
		                XOffSet    = xOff					, $
		                YOffSet    = yOff					, $
		                Map        = 1                      , $
		                tlb_frame_attr = 2 	   		        , $
		                /ToolBar 							, $
		                /Column		               			, $
		                /Floating               			, $
		                /Tlb_Kill_Request_Events 			)
	self.cBase = cBase

	wMagnify_base = Widget_Base(cBase, $
								/row, $
								uname='zoom out multiple', $
								ypad=0, $
								map=1)

	wMagnify_text = cw_field(wMagnify_base, $
							title='zoom :', $
							value=2, $
							uname='magnify_text', $
							xsize=3, $
							ysize=1, $
							FONT='Helvetica*15' , $
							/integer, $
							/RETURN_EVENTS)

	self.magModel = Obj_New('IDLgrModel', name='MagModel')
	imageClass.oView->Add, self.magModel
	self.magImage = Obj_New('IDLgrImage', name='magImage')
	self.magPlot = Obj_New('IDLgrPlot', $
							color=[255,0,0], $
							name='magPlot', $
							Depth_Test_DisAble=1)
	self.magModel->Add,	self.magImage
	self.magModel->Add,	self.magPlot
	self.obuffer = Obj_New('IDLgrBuffer', $
	                        dimensions=[self.baseSize[0],self.baseSize[1] ])
	self.magModel->SetProperty, Hide=1
	self.obuffer->draw, imageClass.oView
	oImage = self.obuffer->Read()
	oImage->GetProperty, data=image
	self.magModel->setproperty, uvalue=Temporary(image)

	self.mContainer->Add,self.magModel
	self.mContainer->Add,self.magImage
	self.mContainer->Add,self.magPlot
	self.mContainer->Add,self.obuffer
	Obj_Destroy, self.obuffer

	widget_control, cBase, /realize

	XManager, 'SunEle'                              , $
	           cBase                                , $
	           /No_Block                            , $
	           Event_Handler = 'sesFrame_Event'   , $
  			   Cleanup = 'sesFrame_Cleanup'
END
;+
;clean up
;+
PRO sesMagnifier::CleanUp
	COMPILE_OPT IDL2
	Obj_Destroy , self.mContainer

END
;+
;initialize
;+
FUNCTION sesMagnifier::Init  , oSystem = oSystem

	COMPILE_OPT IDL2
	self.oSystem = oSystem
	self.mainBase = oSystem.mBase
	self.baseSize =  oSystem.baseSize
	self.zoomRate = 2;*(oSystem.CurrentPro).zoom
	zoom = (oSystem.CurrentPro).zoom
	self->Create

	Return,1
END
;+
;Title class name
;+
PRO sesMagnifier__Define
	COMPILE_OPT IDL2
	void = { sesMagnifier                         , $
	         ;system parameter
	         mainBase           :    0L           , $
	         cBase              :    0L           , $
	         baseSize           :    [0,0]        , $
	         zoomRate           :    0            , $
 			 ;system objct

			 mContainer         :    Obj_New()    , $
			 magModel           :    Obj_New()    , $
			 magImage           :    Obj_New()    , $
			 magPlot            :    Obj_New()    , $
			 obuffer            :    Obj_New()    , $
	         oSystem            :    Obj_New()      $

	        }
END