home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / Livebrush / Install-LivebrushLite.air / livebrush.swf / scripts / com / livebrush / graphics / SmoothLine.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  8.0 KB  |  243 lines

  1. package com.livebrush.graphics
  2. {
  3.    import com.livebrush.data.Storable;
  4.    import com.livebrush.graphics.canvas.Canvas;
  5.    import com.livebrush.graphics.canvas.Layer;
  6.    import flash.display.Sprite;
  7.    import flash.geom.Point;
  8.    
  9.    public class SmoothLine extends Line implements Storable
  10.    {
  11.       public function SmoothLine(type:String, lines:int, weight:Number)
  12.       {
  13.          super(type,lines,weight);
  14.       }
  15.       
  16.       override public function addEdgeAt(index:int, pt:Point = null) : void
  17.       {
  18.          var aStrokes:Array = null;
  19.          var newEdge:Edge = null;
  20.          var newStroke:Stroke = null;
  21.          if(index != lastEdgeIndex && length > 1)
  22.          {
  23.             aStrokes = invalidateEdgeStrokes(index);
  24.             newEdge = Edge.interpolate(edges[index],edges[index + 1],0.5);
  25.             if(pt != null)
  26.             {
  27.                newEdge.modify(pt,newEdge.angleRads,newEdge.width);
  28.                newEdge.applyProps();
  29.             }
  30.             edges.splice(index + 1,0,newEdge);
  31.             if(length > 3)
  32.             {
  33.                if(index < 2 || index == lastEdgeIndex - 2)
  34.                {
  35.                   if(index == 0)
  36.                   {
  37.                      newStroke = new SmoothStroke(edges[index + 2],edges[index + 1],edges[index],type,weight);
  38.                      strokes[aStrokes[0]].edge3 = newEdge;
  39.                      strokes.splice(aStrokes[0],0,newStroke);
  40.                   }
  41.                   else if(index == 1)
  42.                   {
  43.                      newStroke = new SmoothStroke(edges[index + 2],edges[index + 1],edges[index],type,weight);
  44.                      strokes[aStrokes[0]].edge1 = newEdge;
  45.                      try
  46.                      {
  47.                         strokes[aStrokes[1]].edge3 = newEdge;
  48.                      }
  49.                      catch(e:Error)
  50.                      {
  51.                      }
  52.                      strokes.splice(aStrokes[0] + 1,0,newStroke);
  53.                   }
  54.                   else if(index == lastEdgeIndex - 2)
  55.                   {
  56.                      newStroke = new SmoothStroke(edges[lastEdgeIndex],newEdge,edges[index],type,weight);
  57.                      strokes[aStrokes[1]].edge1 = newEdge;
  58.                      strokes.splice(aStrokes[0] + 2,0,newStroke);
  59.                   }
  60.                }
  61.                else if(index < lastEdgeIndex - 1)
  62.                {
  63.                   newStroke = new SmoothStroke(edges[index + 2],edges[index + 1],edges[index],type,weight);
  64.                   strokes[aStrokes[1]].edge1 = newEdge;
  65.                   strokes[aStrokes[2]].edge3 = newEdge;
  66.                   strokes.splice(aStrokes[0] + 2,0,newStroke);
  67.                }
  68.             }
  69.             else if(length == 3)
  70.             {
  71.                newStroke = new SmoothStroke(edges[2],edges[1],edges[0],type,weight);
  72.                strokes[0].die();
  73.                strokes[0] = newStroke;
  74.             }
  75.             lastStrokeLength = strokes.length;
  76.             applyProps();
  77.          }
  78.       }
  79.       
  80.       override public function draw(layer:Layer) : void
  81.       {
  82.          var s:int = 0;
  83.          if(length > 1)
  84.          {
  85.             for(s = 0; s < strokes.length; s++)
  86.             {
  87.                if(edges.length == 3)
  88.                {
  89.                   strokes[s].draw(layer,Stroke.BOTH);
  90.                }
  91.                else if(s == 0)
  92.                {
  93.                   strokes[s].draw(layer,Stroke.START);
  94.                }
  95.                else if(s == strokes.length - 1)
  96.                {
  97.                   strokes[s].draw(layer,Stroke.END);
  98.                }
  99.                else
  100.                {
  101.                   strokes[s].draw(layer,Stroke.MIDDLE);
  102.                }
  103.             }
  104.             newStrokeCount = 0;
  105.          }
  106.          changed = false;
  107.       }
  108.       
  109.       override public function copy(includeDecos:Boolean = true, basic:Boolean = false) : Line
  110.       {
  111.          var newLine:SmoothLine = null;
  112.          if(basic)
  113.          {
  114.             newLine = new SmoothLine(type,2,1);
  115.          }
  116.          else
  117.          {
  118.             newLine = new SmoothLine(type,lines,weight);
  119.          }
  120.          for(var i:int = 0; i < edges.length; i++)
  121.          {
  122.             newLine.addEdge(edges[i].copy(includeDecos,basic));
  123.          }
  124.          return newLine;
  125.       }
  126.       
  127.       override public function deleteEdge(edge:Edge = null, i:int = -5) : void
  128.       {
  129.          var stroke:Stroke = null;
  130.          var index:int = edge == null ? i : getEdgeIndex(edge);
  131.          var aStrokes:Array = invalidateEdgeStrokes(index);
  132.          if(length > 3)
  133.          {
  134.             if(index > 1 && index < lastEdgeIndex - 1)
  135.             {
  136.                strokes[aStrokes[2]].edge3 = strokes[aStrokes[0]].edge2;
  137.                strokes[aStrokes[0]].edge1 = strokes[aStrokes[2]].edge2;
  138.                strokes.splice(aStrokes[1],1)[0].die();
  139.             }
  140.             else if(index == 0)
  141.             {
  142.                strokes.splice(aStrokes[0],1)[0].die();
  143.             }
  144.             else if(index == lastEdgeIndex)
  145.             {
  146.                strokes.splice(aStrokes[0],1)[0].die();
  147.             }
  148.             else if(index == 1)
  149.             {
  150.                strokes[aStrokes[1]].edge3 = edges[0];
  151.                strokes.splice(aStrokes[0],1)[0].die();
  152.             }
  153.             else if(index == lastEdgeIndex - 1)
  154.             {
  155.                strokes[aStrokes[0]].edge1 = edges[lastEdgeIndex];
  156.                strokes.splice(aStrokes[1],1)[0].die();
  157.             }
  158.             edges.splice(index,1)[0].die();
  159.             lastStrokeLength = strokes.length;
  160.             applyProps();
  161.          }
  162.          else if(length == 3)
  163.          {
  164.             edges.splice(index,1)[0].die();
  165.             stroke = new Stroke(edges[1],edges[0],null,type,weight);
  166.             strokes[0].die();
  167.             strokes[0] = stroke;
  168.          }
  169.          else if(length == 2)
  170.          {
  171.             super.deleteEdge(edge);
  172.          }
  173.       }
  174.       
  175.       override public function drawWireframe() : void
  176.       {
  177.          var vectors:Sprite = null;
  178.          var s:int = 0;
  179.          if(length > 1)
  180.          {
  181.             vectors = Canvas.GLOBAL_CANVAS.wireframe;
  182.             for(s = 0; s < strokes.length; s++)
  183.             {
  184.                if(edges.length == 3)
  185.                {
  186.                   strokes[s].drawWireframe(Stroke.BOTH);
  187.                }
  188.                else if(s == 0)
  189.                {
  190.                   strokes[s].drawWireframe(Stroke.START);
  191.                }
  192.                else if(s == strokes.length - 1)
  193.                {
  194.                   strokes[s].drawWireframe(Stroke.END);
  195.                }
  196.                else
  197.                {
  198.                   strokes[s].drawWireframe(Stroke.MIDDLE);
  199.                }
  200.             }
  201.             if(length > 2)
  202.             {
  203.                vectors.graphics.moveTo(firstStroke.edge3.a.x,firstStroke.edge3.a.y);
  204.                vectors.graphics.lineTo(firstStroke.edge3.b.x,firstStroke.edge3.b.y);
  205.             }
  206.             if(length == 2)
  207.             {
  208.                vectors.graphics.moveTo(firstStroke.edge2.a.x,firstStroke.edge2.a.y);
  209.                vectors.graphics.lineTo(firstStroke.edge2.b.x,firstStroke.edge2.b.y);
  210.             }
  211.             vectors.graphics.moveTo(lastStroke.edge1.a.x,lastStroke.edge1.a.y);
  212.             vectors.graphics.lineTo(lastStroke.edge1.b.x,lastStroke.edge1.b.y);
  213.          }
  214.       }
  215.       
  216.       override public function drawNew(layer:Layer) : void
  217.       {
  218.          var s:int = 0;
  219.          if(length > 2)
  220.          {
  221.             for(s = lastStrokeLength - 1; s < strokes.length; s++)
  222.             {
  223.                if(s == 0)
  224.                {
  225.                   strokes[s].draw(layer,Stroke.START);
  226.                }
  227.                else
  228.                {
  229.                   strokes[s].draw(layer);
  230.                }
  231.             }
  232.          }
  233.          newStrokeCount = 0;
  234.       }
  235.       
  236.       override public function getSVG() : XML
  237.       {
  238.          return new XML(<g/>);
  239.       }
  240.    }
  241. }
  242.  
  243.