home *** CD-ROM | disk | FTP | other *** search
/ GameStar Special 2002 April / GSSH42002.iso / EDITOREN / DS / gmax / gmaxinst_1-1.exe / gmaxsetup11.cab / gMaterialEDtabs.swf / scripts / frame_2 / DoAction.as
Text File  |  2002-02-13  |  4KB  |  146 lines

  1. function hitTab()
  2. {
  3.    var dx = drag.x + this._xmouse - drag.icon._x;
  4.    var dy = drag.y + this._ymouse - drag.icon._y;
  5.    if(distanceDrop < dx * dx + dy * dy)
  6.    {
  7.       return null;
  8.    }
  9.    vDrop[0].x = drag.icon._x + Math.floor((drag.icon._width - widthDrop) / 2);
  10.    vDrop[0].y = drag.icon._y + Math.floor((drag.icon._height - heightDrop) / 2);
  11.    vDrop[1].x = vDrop[0].x;
  12.    vDrop[1].y = drag.icon._y + Math.ceil((drag.icon._height + heightDrop) / 2);
  13.    vDrop[2].x = drag.icon._x + Math.ceil((drag.icon._width + widthDrop) / 2);
  14.    vDrop[2].y = vDrop[1].y;
  15.    vDrop[3].x = vDrop[2].x;
  16.    vDrop[3].y = vDrop[0].y;
  17.    var tab;
  18.    var i;
  19.    var j;
  20.    i = 0;
  21.    while(i < tabs.list.length)
  22.    {
  23.       tab = tabs.list[i];
  24.       if(!tab.targetNull)
  25.       {
  26.          j = 0;
  27.          while(j < 4 and tab.hitTest(vDrop[j].x,vDrop[j].y,true))
  28.          {
  29.             j++;
  30.          }
  31.          if(j == 4)
  32.          {
  33.             if(tab == drag.tab)
  34.             {
  35.                return null;
  36.             }
  37.             if(drag.icon.type == "color" and !tab.targetColor)
  38.             {
  39.                return null;
  40.             }
  41.             if(tab == tabs.ambient and tabs.lockAmbient._visible)
  42.             {
  43.                return null;
  44.             }
  45.             if(tab == tabs.specularColor and tabs.lockSpecular._visible)
  46.             {
  47.                return null;
  48.             }
  49.             return tab;
  50.          }
  51.       }
  52.       i++;
  53.    }
  54.    return null;
  55. }
  56. function dragIcon(icon)
  57. {
  58.    var tab = icon._parent;
  59.    if(!drag.enabled or drag.tab != null or tab == this)
  60.    {
  61.       return undefined;
  62.    }
  63.    if(icon.type == "color")
  64.    {
  65.       tab = tab._parent;
  66.    }
  67.    if(tabs.current != tab)
  68.    {
  69.       tabs.select(tab);
  70.    }
  71.    drag.tab = tab;
  72.    var src;
  73.    if(icon.type == "color")
  74.    {
  75.       drag.icon = dragColor;
  76.       src = tab.value;
  77.       new Color(dragColor.value).setRGB(new Color(src.color.value).getRGB());
  78.    }
  79.    else
  80.    {
  81.       if(icon.type != "map")
  82.       {
  83.          return undefined;
  84.       }
  85.       drag.icon = dragMap;
  86.       src = tab.map;
  87.    }
  88.    drag.x = tab._x + src._x - this._xmouse;
  89.    drag.y = tab._y + src._y - this._ymouse;
  90.    drag.icon._x = drag.x + this._xmouse;
  91.    drag.icon._y = drag.y + this._ymouse;
  92.    drag.icon._visible = true;
  93.    getURL("FSCommand:copy",icon.type + "," + target.label.text);
  94. }
  95. function moveIcon()
  96. {
  97.    if(!drag.enabled or drag.tab == null)
  98.    {
  99.       return undefined;
  100.    }
  101.    var x = drag.x + this._xmouse;
  102.    var y = drag.y + this._ymouse;
  103.    x = Math.max(x,0);
  104.    y = Math.max(y,0);
  105.    x = Math.min(x,this._width - drag.icon._width - 1);
  106.    y = Math.min(y,tabs._height - drag.icon._height - 1);
  107.    drag.icon._x = x;
  108.    drag.icon._y = y;
  109.    var target = hitTab();
  110.    if(target == null or target == drag.tab)
  111.    {
  112.       dragTarget._visible = false;
  113.    }
  114.    else
  115.    {
  116.       var icon;
  117.       if(drag.icon.type == "map")
  118.       {
  119.          icon = target.map;
  120.       }
  121.       else
  122.       {
  123.          icon = target.value;
  124.       }
  125.       dragTarget._x = target._x + icon._x + 0.5;
  126.       dragTarget._y = target._y + icon._y + 0.2;
  127.       dragTarget._visible = true;
  128.    }
  129. }
  130. function dropIcon(icon)
  131. {
  132.    var source = drag.tab;
  133.    drag.tab = null;
  134.    drag.icon._visible = false;
  135.    dragTarget._visible = false;
  136.    if(!drag.enabled)
  137.    {
  138.       return undefined;
  139.    }
  140.    var target = hitTab();
  141.    if(target != null and target != source)
  142.    {
  143.       getURL("FSCommand:" add icon.type,source.label.text + "," + target.label.text);
  144.    }
  145. }
  146.