home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.graphics
- {
- import com.livebrush.data.Storable;
- import com.livebrush.graphics.canvas.Canvas;
- import com.livebrush.graphics.canvas.Layer;
- import flash.display.Sprite;
- import flash.geom.Point;
-
- public class SmoothLine extends Line implements Storable
- {
- public function SmoothLine(type:String, lines:int, weight:Number)
- {
- super(type,lines,weight);
- }
-
- override public function addEdgeAt(index:int, pt:Point = null) : void
- {
- var aStrokes:Array = null;
- var newEdge:Edge = null;
- var newStroke:Stroke = null;
- if(index != lastEdgeIndex && length > 1)
- {
- aStrokes = invalidateEdgeStrokes(index);
- newEdge = Edge.interpolate(edges[index],edges[index + 1],0.5);
- if(pt != null)
- {
- newEdge.modify(pt,newEdge.angleRads,newEdge.width);
- newEdge.applyProps();
- }
- edges.splice(index + 1,0,newEdge);
- if(length > 3)
- {
- if(index < 2 || index == lastEdgeIndex - 2)
- {
- if(index == 0)
- {
- newStroke = new SmoothStroke(edges[index + 2],edges[index + 1],edges[index],type,weight);
- strokes[aStrokes[0]].edge3 = newEdge;
- strokes.splice(aStrokes[0],0,newStroke);
- }
- else if(index == 1)
- {
- newStroke = new SmoothStroke(edges[index + 2],edges[index + 1],edges[index],type,weight);
- strokes[aStrokes[0]].edge1 = newEdge;
- try
- {
- strokes[aStrokes[1]].edge3 = newEdge;
- }
- catch(e:Error)
- {
- }
- strokes.splice(aStrokes[0] + 1,0,newStroke);
- }
- else if(index == lastEdgeIndex - 2)
- {
- newStroke = new SmoothStroke(edges[lastEdgeIndex],newEdge,edges[index],type,weight);
- strokes[aStrokes[1]].edge1 = newEdge;
- strokes.splice(aStrokes[0] + 2,0,newStroke);
- }
- }
- else if(index < lastEdgeIndex - 1)
- {
- newStroke = new SmoothStroke(edges[index + 2],edges[index + 1],edges[index],type,weight);
- strokes[aStrokes[1]].edge1 = newEdge;
- strokes[aStrokes[2]].edge3 = newEdge;
- strokes.splice(aStrokes[0] + 2,0,newStroke);
- }
- }
- else if(length == 3)
- {
- newStroke = new SmoothStroke(edges[2],edges[1],edges[0],type,weight);
- strokes[0].die();
- strokes[0] = newStroke;
- }
- lastStrokeLength = strokes.length;
- applyProps();
- }
- }
-
- override public function draw(layer:Layer) : void
- {
- var s:int = 0;
- if(length > 1)
- {
- for(s = 0; s < strokes.length; s++)
- {
- if(edges.length == 3)
- {
- strokes[s].draw(layer,Stroke.BOTH);
- }
- else if(s == 0)
- {
- strokes[s].draw(layer,Stroke.START);
- }
- else if(s == strokes.length - 1)
- {
- strokes[s].draw(layer,Stroke.END);
- }
- else
- {
- strokes[s].draw(layer,Stroke.MIDDLE);
- }
- }
- newStrokeCount = 0;
- }
- changed = false;
- }
-
- override public function copy(includeDecos:Boolean = true, basic:Boolean = false) : Line
- {
- var newLine:SmoothLine = null;
- if(basic)
- {
- newLine = new SmoothLine(type,2,1);
- }
- else
- {
- newLine = new SmoothLine(type,lines,weight);
- }
- for(var i:int = 0; i < edges.length; i++)
- {
- newLine.addEdge(edges[i].copy(includeDecos,basic));
- }
- return newLine;
- }
-
- override public function deleteEdge(edge:Edge = null, i:int = -5) : void
- {
- var stroke:Stroke = null;
- var index:int = edge == null ? i : getEdgeIndex(edge);
- var aStrokes:Array = invalidateEdgeStrokes(index);
- if(length > 3)
- {
- if(index > 1 && index < lastEdgeIndex - 1)
- {
- strokes[aStrokes[2]].edge3 = strokes[aStrokes[0]].edge2;
- strokes[aStrokes[0]].edge1 = strokes[aStrokes[2]].edge2;
- strokes.splice(aStrokes[1],1)[0].die();
- }
- else if(index == 0)
- {
- strokes.splice(aStrokes[0],1)[0].die();
- }
- else if(index == lastEdgeIndex)
- {
- strokes.splice(aStrokes[0],1)[0].die();
- }
- else if(index == 1)
- {
- strokes[aStrokes[1]].edge3 = edges[0];
- strokes.splice(aStrokes[0],1)[0].die();
- }
- else if(index == lastEdgeIndex - 1)
- {
- strokes[aStrokes[0]].edge1 = edges[lastEdgeIndex];
- strokes.splice(aStrokes[1],1)[0].die();
- }
- edges.splice(index,1)[0].die();
- lastStrokeLength = strokes.length;
- applyProps();
- }
- else if(length == 3)
- {
- edges.splice(index,1)[0].die();
- stroke = new Stroke(edges[1],edges[0],null,type,weight);
- strokes[0].die();
- strokes[0] = stroke;
- }
- else if(length == 2)
- {
- super.deleteEdge(edge);
- }
- }
-
- override public function drawWireframe() : void
- {
- var vectors:Sprite = null;
- var s:int = 0;
- if(length > 1)
- {
- vectors = Canvas.GLOBAL_CANVAS.wireframe;
- for(s = 0; s < strokes.length; s++)
- {
- if(edges.length == 3)
- {
- strokes[s].drawWireframe(Stroke.BOTH);
- }
- else if(s == 0)
- {
- strokes[s].drawWireframe(Stroke.START);
- }
- else if(s == strokes.length - 1)
- {
- strokes[s].drawWireframe(Stroke.END);
- }
- else
- {
- strokes[s].drawWireframe(Stroke.MIDDLE);
- }
- }
- if(length > 2)
- {
- vectors.graphics.moveTo(firstStroke.edge3.a.x,firstStroke.edge3.a.y);
- vectors.graphics.lineTo(firstStroke.edge3.b.x,firstStroke.edge3.b.y);
- }
- if(length == 2)
- {
- vectors.graphics.moveTo(firstStroke.edge2.a.x,firstStroke.edge2.a.y);
- vectors.graphics.lineTo(firstStroke.edge2.b.x,firstStroke.edge2.b.y);
- }
- vectors.graphics.moveTo(lastStroke.edge1.a.x,lastStroke.edge1.a.y);
- vectors.graphics.lineTo(lastStroke.edge1.b.x,lastStroke.edge1.b.y);
- }
- }
-
- override public function drawNew(layer:Layer) : void
- {
- var s:int = 0;
- if(length > 2)
- {
- for(s = lastStrokeLength - 1; s < strokes.length; s++)
- {
- if(s == 0)
- {
- strokes[s].draw(layer,Stroke.START);
- }
- else
- {
- strokes[s].draw(layer);
- }
- }
- }
- newStrokeCount = 0;
- }
-
- override public function getSVG() : XML
- {
- return new XML(<g/>);
- }
- }
- }
-
-