;+
;change view size
;+
PRO sesViewSize, drawSize, Type = type   , $
                     ZoomRate = zoomRate   , $
                     viewPlane = viewPlane , $
                     viewDim = viewDim     , $
                     viewLoc = viewLoc     , $
                     windowVD = windowVD   , $
                     currentXY = currentXY , $
                     oDraw = odraw         , $
                     oView = oView         , $
                     oldLoc = oldLoc       , $
                     oldDim = oldDim       , $
                     new = new             , $
                     scrollXY = scrollXY

	CASE type OF
		'initSize' : BEGIN
			windowVD = drawSize[0:1]
			IF 1.0*drawSize[2]/drawSize[3] GE 1.0*drawSize[0]/drawSize[1] THEN BEGIN
				IF drawSize[2] GE drawSize[0] THEN BEGIN
					fitDrawY = 0.9*drawSize[3]*drawSize[0]/drawSize[2]
					viewDim = [0.9*drawSize[0],fitDrawY]
					viewPlane = [0,0,viewDim]
					viewLoc = [(drawSize[0]-viewDim[0])/2,(drawSize[1]-fitDrawY)/2]
					zoomRate = 0.9*drawSize[0]/drawSize[2]
				ENDIF ELSE BEGIN
					viewDim = drawSize[2:3]
					viewPlane = [0,0,viewDim]
					viewLoc = [(drawSize[0]-drawSize[2])/2,(drawSize[1]-drawSize[3])/2]
					zoomRate = 1.
				ENDELSE
			ENDIF ELSE BEGIN
				IF drawSize[3] GE drawSize[1] THEN BEGIN
					fitDrawX = 0.9*drawSize[2]*drawSize[1]/drawSize[3]
					viewDim = [fitDrawX,0.9*drawSize[1]]
					viewPlane = [0,0,viewDim]
					viewLoc = [(drawSize[0]-fitDrawX)/2,(drawSize[1]-viewDim[1])/2]
					zoomRate = 0.9*drawSize[1]/drawSize[3]
				ENDIF ELSE BEGIN
					viewDim = drawSize[2:3]
					viewPlane = [0,0,viewDim]
					viewLoc = [(drawSize[0]-drawSize[2])/2,(drawSize[1]-drawSize[3])/2]
					zoomRate = 1.
				ENDELSE
			ENDELSE
		END
		'fullSize' : BEGIN
			windowVD = drawSize[0:1]
			IF 1.0*drawSize[2]/drawSize[3] GE 1.0*drawSize[0]/drawSize[1] THEN BEGIN
			  	fitDrawY = Float(drawSize[3])*drawSize[0]/drawSize[2]
				viewDim = [drawSize[0],fitDrawY]
				viewPlane = [0,0,viewDim]
				viewLoc = [0,(drawSize[1]-fitDrawY)/2]
				zoomRate = Float(drawSize[0])/drawSize[2]<16.
			ENDIF ELSE BEGIN
				fitDrawX = Float(drawSize[2])*drawSize[1]/drawSize[3]
				viewDim = [fitDrawX,drawSize[1]]
				viewPlane = [0,0,viewDim]
				viewLoc = [(drawSize[0]-fitDrawX)/2,0]
				zoomRate = Float(drawSize[1])/drawSize[3]<16.
			ENDELSE
		END
		'realSize' : BEGIN
			zoomRate = 1.
			IF drawSize[2] LE drawSize[0] OR drawSize[3] LE drawSize[1] THEN BEGIN
				viewDim = [drawSize[2],drawSize[3]]
				IF drawSize[2] LE drawSize[0] AND drawSize[3] GT drawSize[1] THEN BEGIN
				  	windowVD = [drawSize[0],drawSize[3]]
				  	viewPlane = [0,(drawSize[3]-drawSize[1])/2,viewDim]
				  	viewLoc = [(drawSize[0]-drawSize[2])/2,0]
				ENDIF ELSE BEGIN
				  	IF drawSize[2] GT drawSize[0] AND drawSize[3] LE drawSize[1] THEN BEGIN
				    	windowVD = [drawSize[2],drawSize[1]]
				    	viewPlane = [(drawSize[2]-drawSize[0])/2,0,viewDim]
				    	viewLoc = [0,(drawSize[1]-drawSize[3])/2]
				  	ENDIF ELSE BEGIN
				    	windowVD = drawSize[0:1]
				    	viewPlane = [0,0,viewDim]
				    	viewLoc = [(drawSize[0]-drawSize[2])/2,(drawSize[1]-drawSize[3])/2]
				  	ENDELSE
				ENDELSE
			ENDIF ELSE BEGIN
				viewDim = [drawSize[2],drawSize[3]]
				windowVD = drawSize[2:3]
				viewPlane = [0,drawSize[3]-drawSize[1],viewDim]
				viewLoc = [0,0]
			ENDELSE

		END
		'pan' : BEGIN
		  	ViewPlane[0:1]=scrollXY
		END
		'zoom' : BEGIN
			viewDim = drawSize[2:3]*zoomRate

			IF viewDim[0] LE drawSize[0] OR viewDim[1] LE drawSize[1] THEN BEGIN
				IF viewDim[0] LE drawSize[0] AND viewDim[1] GT drawSize[1] THEN BEGIN
				  	windowVD = [drawSize[0],viewDim[1]]
				  	viewPlane = [0,(viewDim[1]-drawSize[1])/2,viewDim]
				  	viewLoc = [(drawSize[0]-viewDim[0])/2,-17]
				ENDIF ELSE BEGIN
				  	IF viewDim[0] GT drawSize[0] AND viewDim[1] LE drawSize[1] THEN BEGIN
				  		windowVD = [viewDim[0],drawSize[1]]
				    	viewPlane = [0,0,viewDim]
				    	viewLoc = [0,(drawSize[1]-viewDim[1])/2]
				  	ENDIF ELSE BEGIN
				    	windowVD = drawSize[0:1]
				    	viewPlane = [0,0,viewDim]
				    	viewLoc = [(drawSize[0]-viewDim[0])/2,(drawSize[1]-viewDim[1])/2]
				  	ENDELSE
				ENDELSE
			ENDIF ELSE BEGIN
				windowVD = viewDim
				dis = [(drawSize[0]/2-currentXY[0]),(drawSize[1]/2-currentXY[1])]
				nx = ((oldLoc[0] + dis[0])<0)>(drawSize[0]-viewDim[0])
				ny = ((oldLoc[1] + dis[1])<0)>(drawSize[1]-viewDim[1])
				viewLoc = [nx,ny]
				viewPlane = [0,0,viewDim]
			ENDELSE
		END
	ELSE:
	ENDCASE

END