drag zoom window

I made a script that draws a drag window allows holding down a button at the bottom right to zoom the window in real time with mouse. It works, but when I move the mouse too quickly falls behind the window and not longer able to resize it, because mouse go out of window and the button is no longer pressed. Anyone suggest me a solution? Thanks!

var ix = 5;
var iy = 5;
var bx = 25;
var by = 25;
var dbx = 5;
var dby = 5;
var hix = 200;
var hiy = 200;
private var windowRect : Rect;

private var hx : int;
private var hy : int;
private var hx2 : int;
private var hy2 : int;
private var hx3 : int;
private var hy3 : int;

private var mpx : int;
private var mpy : int;
private var mix : int;
private var miy : int;

function Start () {
hx = hix;
hy = hiy;
windowRect = Rect (ix, iy, hx, hy);
}

function Update () {

if (Input.GetMouseButtonDown(0)){
mix = mpx ;
miy = mpy ;
hx3 = hx;
hy3 = hy;}

ix = windowRect.x;
iy = windowRect.y; 
hx2 = hx3 + mpx - mix ;
hy2 = hy3 + mpy - miy ;

windowRect = Rect (ix, iy, hx, hy);
}

function OnGUI () {
    windowRect = GUI.Window (0, windowRect, DoMyWindow, "");
	var  mp : Event = Event.current;
    mpx = mp.mousePosition.x;
    mpy = mp.mousePosition.y; 
	}

function DoMyWindow (windowID : int){ 
    if ((GUI.RepeatButton (Rect (hx-bx-dbx,hy-by-dby,bx,by), "x")) && (hx2>hix) && (hy2>hiy)){
	hx = hx2;
	hy = hy2;
	}
	
    GUI.DragWindow ();
}

Here you go.

private var pressed:boolean = false;
private var pressed2:boolean = false;
private var recordMouseX:boolean = false;
var ix = 5;
var iy = 5;
var bx = 25;
var by = 25;
var dbx =5;
var dby =5;
var hix = 200;
var hiy = 200;
private var windowRect : Rect;


private var hx : int;
private var hy : int;
private var hx2 : int;
private var hy2 : int;
private var hx3 : int;
private var hy3 : int;

private var mpx : int;
private var mpy : int;
private var mix : int;
private var miy : int;

function Start () {
hx = hix;
hy = hiy;
windowRect = Rect (ix, iy, hx, hy);
}

function Update () {
	
   if (Input.GetMouseButtonDown(0)){

	pressed = true;
mix = mpx ;
miy = mpy ;
hx3 = hx;
hy3 = hy;
}else if(Input.GetMouseButtonUp(0)){
	pressed = false;
	pressed2 = false;

	}


ix = windowRect.x;
iy = windowRect.y; 
hx2 = hx3 + mpx - mix ;
hy2 = hy3 + mpy - miy ;

windowRect = Rect (ix, iy, hx, hy);
}

function OnGUI () {
	
    windowRect = GUI.Window (0, windowRect, DoMyWindow, "TRT");
    var  mp : Event = Event.current;
   
	 print( windowRect.x+ "   mouseX "+ mpx);

	
	 mpx = mp.mousePosition.x;
	 mpy = mp.mousePosition.y; 
	
}


function DoMyWindow (windowID : int){ 
	GUI.DragWindow (Rect (0,0, windowRect.width - bx -dbx, windowRect.height));
	GUI.DragWindow (Rect (0,0, windowRect.width, windowRect.height - by-dby));
   
	var rect = Rect (windowRect.width - bx - dbx, windowRect.height-by -dby,bx,by);

	if(windowRect.width<=bx +(dbx *2)  ){
		windowRect.width = bx+(dbx *2);
		
	}
			if( windowRect.height<=by+(dby*2) + 15 ){
		windowRect.height=by+(dby*2) +15;
				

	}
	
	if (pressed && (GUI.RepeatButton (rect, "x")) ){
   recordMouse = true;
		pressed2 = true;
	hx = hx2;
    hy = hy2;
	
    }else if(pressed && pressed2 &&  !rect.Contains(Input.mousePosition) ){
		hx = hx2;
		hy = hy2;
		} else if(!pressed ){
			GUI.RepeatButton (rect, "x");
		}else{
				GUI.RepeatButton (rect, "x");
		}
}

Improved script (Applicable to an object):

var btnTexture:Texture;
var levels : int = 0;
var op :float = 1;
var myCustomSkin : GUISkin;
var vzoom : float = 10;
var ix =5;
var iy = 5;
var bx = 25;
var by = 25;
var dbx =5;
var dby =5;

private var txw : float;
private var txh : float;
private var rtxt : float;
private var txtiw : float;
private var pressed:boolean = false;
private var pressed2:boolean = false;
private var pressed3:boolean = false;
private var starting : boolean = false;
private var ddx : float;
private var ddy : float;
private var windowOpen : boolean;
private var showbutton : boolean = false;
private var mpv : Vector2;
private var dangl : float;
private var iangl : float;
private var rotAngle : float ;
private var rotAngleF : float ;
private var oldrotAngle : float ;
private var anglrotg : float ;
private var pivotPoint : Vector2;
private var ixin : float;
private var iyin : float;
private var windowRect : Rect ;
private var rect : Rect;
private var ix3 : float;
private var iy3 : float;
private var ix2 : float;
private var iy2 : float;
private var hx : float;
private var hy : float;
private var hx2 : float;
private var hy2 : float;
private var hx3 : float;
private var hy3 : float;
private var mpx : float;
private var mpy : float;
private var mix : float;
private var miy : float;

function Start () {
txw = btnTexture.width;
txh = btnTexture.height;
rtxt = (txw/txh);
txtiw = Screen.width/4;
hx = bx;
hy = hx/rtxt;
ix = Screen.width/2 - hx/2;
iy = Screen.height/2 - hy/2;
rotAngle = 0;
Hide();
}

function Update () {
//Zoom animation start
//---------------------------------------------------------------
if ( (starting)  && (hx<txtiw)) {
	hx = hx + vzoom;
	hy = hx/rtxt;
	ixin = ix- hx/2 - windowRect.x - 5;
	iyin = iy - hy/2- windowRect.y -5;
	ix = ixin + Screen.width/2;
	iy = iyin + Screen.height/2;
}else if (starting){
	hx =txtiw;
	hy = hx/rtxt;
	starting= false;
	}
//-------------------------------------------------------------
//Variables
//---------------------------------------------------------------
if (!pressed && Input.GetMouseButtonDown(0) ){
    mix = mpx ;
    miy = mpy ;
    hx3 = hx;
    hy3 = hx/rtxt;
    ix3 = windowRect.x;
    iy3 = windowRect.y;
    iangl = anglrotg;
    pressed = true;

}else if(Input.GetMouseButtonUp(0) ){
    pressed = false;
    pressed2 = false;
    pressed3= false;
    }

ix2 = ix3 - (mpx-mix) ;
iy2 = iy3 - ((mpx-mix)/rtxt) ;
hx2 = hx3 + 2*(mpx - mix) ;
hy2 = hx2/rtxt;
windowRect = Rect (ix, iy, hx, hy);
}
//---------------------------------------------------------------
//Open window
//---------------------------------------------------------------
function OnMouseDown() {
	windowOpen = true;
	starting = true;
	}
//---------------------------------------------------------------

function OnGUI () {

  GUI.skin = myCustomSkin;

//Rotation GUI
//---------------------------------------------------------------
    GUIUtility.RotateAroundPivot (rotAngle, pivotPoint);
//---------------------------------------------------------------

  if(windowOpen) {
         windowRect = GUI.Window (levels, windowRect, DoMyWindow, "");
         windowRect = GUI.Window (levels+1, windowRect, DoMyWindowT, "");
         }
       if (windowRect.Contains(Event.current.mousePosition)) {
      showbutton = true;
      }
       else {
       showbutton = false;
       }
	   
    var  mp : Event = Event.current;
    mpx = mp.mousePosition.x;
    mpy = mp.mousePosition.y;
//Rotation angle
//---------------------------------------------------------------
	anglrot = Mathf.Atan2(mpx-(windowRect.x+windowRect.width/2),mpy-(windowRect.y+windowRect.height/2));
	anglrotg = anglrot*Mathf.Rad2Deg + 360;
	rotAngleF = iangl - anglrotg;
//---------------------------------------------------------------
}

function DoMyWindow (windowID : int){

if(!starting && windowRect.width<= txtiw/2 ){
       windowRect.width = txtiw/2;
       ix2 =  windowRect.x;
       iy2 = windowRect.y;
   }
if( !starting && windowRect.height<=txtiw/rtxt/2){
       windowRect.height=txtiw/rtxt/2;
       ix2 =  windowRect.x;
       iy2 = windowRect.y;
   }

ix =  windowRect.x ;
iy = windowRect.y ;
rect = Rect (windowRect.width - bx - dbx, windowRect.height-by -dby,bx,by);

if (showbutton || pressed2 || pressed3  ){

//Opacity slider
//---------------------------------------------------------------
op = GUI.HorizontalSlider (Rect (2*dbx, windowRect.height - dby - by/2  , windowRect.width - 2*bx -6*dbx , by ), op, 1, 0.1);
//---------------------------------------------------------------
//Zoom button
//---------------------------------------------------------------
    if (GUI.RepeatButton (rect, "+")){
    pressed2 = true;
    ix=ix2;
    iy=iy2;
    hx = hx2;
    hy = hy2;
    }else if(pressed2){
       ix=ix2;
       iy=iy2;
       hx = hx2;
       hy = hy2;
       }else{
          GUI.RepeatButton (rect, "+");
       }
//---------------------------------------------------------------
// Rotation button
//---------------------------------------------------------------
  if (GUI.RepeatButton (Rect(windowRect.width - 2*bx - 2*dbx, windowRect.height-by -dby,bx,by), "o")){
	pressed3 = true;
    rotAngle =  rotAngle + rotAngleF;
    pivotPoint = Vector2(  windowRect.x + windowRect.width/2   ,  windowRect.y+ windowRect.height/2  );
    }else if(pressed3 ){
       rotAngle =  rotAngle + rotAngleF;
       pivotPoint = Vector2(  windowRect.x + windowRect.width/2   ,  windowRect.y+ windowRect.height/2  );
       }else{
          GUI.RepeatButton (Rect(windowRect.width - 2*bx - 2*dbx, windowRect.height-by -dby,bx,by), "o");
       }
//---------------------------------------------------------------
//Close button
//---------------------------------------------------------------
if(GUI.Button(Rect(windowRect.width-bx-dbx, dby, bx, by),"X")){

     Hide();
     hx=0;
     hy=0;
     rotAngle = 0;
     }
//---------------------------------------------------------------
GUI.DragWindow (Rect (0,0, windowRect.width , windowRect.height ));
}
}

//Texture window
//---------------------------------------------------------------
function DoMyWindowT (windowID : int){
	GUI.color.a = op;
	GUI.DrawTexture(Rect(0,0,windowRect.width,windowRect.height), btnTexture, ScaleMode.ScaleToFit, true, 0f);
}
//---------------------------------------------------------------
function Hide() {
	windowOpen = false;
     }