Author Topic: Problem with sliding window extent  (Read 536 times)

Code: [Select]
function GuiWindowCtrl::extentSlide(%this,%ext,%tick)
{
cancel(%this.extentSlide);
if(%this.extent $= %ext)
return;
if(strLen(%this.currDir) < 1)
%this.currDir = 0;
%dirExt = getWord(%this.extent,%this.currDir);
%dirFin = getWord(%ext,%this.currDir);
if(%dirFin $= %dirExt && %currDir = 0)
%this.currDir = 1;
else if(%dirFin $= %dirExt && %currDir = 1)
{
%this.currDir = "";
return;
}
else if(%dirExt < %dirFin)
%this.extent = (%this.currDir ? getWord(%this.extent,0) SPC %dirExt+1 : %dirExt+1 SPC getWord(%this.extent,1));
else if(%dirExt > %dirFin)
%this.extent = (%this.currDir ? getWord(%this.extent,0) SPC %dirExt-1 : %dirExt-1 SPC getWord(%this.extent,1));
else
{
%this.currDir = "";
return;
}
%this.extentSlide = %this.schedule(%tick,extentSlide,%ext,%tick);
}

Simply does not work. No syntax errors. When I try the following, nothing happens:
SomeWindowCtrl.extentSlide(500 SPC 500,75);

Obviously, I don't use "SomeWindowCtrl", but I use a valid one.


In some areas, you use %this.currDir, elsewhere, you use %currDir. Where you use %currDirm, you are using a single = rather than a ==, so it is setting %currDir to 1 rather checking if the direction is already the y axis.

Try this (almost completely rewritten) version:

Code: [Select]
function GuiWindowCtrl::extentSlide(%this, %ext, %rate, %tick)
{
    cancel(%this.extentSlide);
    if(%this.extent $= %ext || %rate == 0)
      return;
    if(getWord(%ext, 0) != getWord(%this.extent, 0))
    {
        %dif = getWord(%ext, 0) - getWord(%this.extent, 0);
        if(mAbs(%dif) < %rate)
          %this.extent = getWord(%ext, 0) SPC getWord(%this.extent, 0);
        else if(%dif > 0)
          %this.extent = vectorAdd(%this.extent, %rate SPC 0);
        else
          %this.extent = vectorAdd(%this.extent, -%rate SPC 0);
    }
    else if(getWord(%ext, 1) != getWord(%this.extent, 1))
    {
        %dif = getWord(%ext, 1) - getWord(%this.extent, 1);
        if(mAbs(%dif) < %rate)
          %this.extent = %ext;
        else if(%dif > 0)
          %this.extent = vectorAdd(%this.extent, 0 SPC %rate);
        else
          %this.extent = vectorAdd(%this.extent, 0 SPC -%rate);
    }
    else
      return;
    %this.resize(getWord(%this.position, 0), getWord(%this.position, 1), getWord(%this.extent, 0), getWord(%this.extent, 1));
    %this.extentSlide = %this.schedule(%tick, extentSlide, %ext, %rate, %tick);
}

Using %this.resize() is required for the window controls and probably any contained GUI components to properly update.