Beispiel #1
0
        public void UpdateNoodlePath(NoodleStyle style, object helper)
        {
            if (path != null)
            {
                path.Dispose();
            }

            path = new GraphicsPath();

            //recalculate the two points relative to the parent container
            //and adjust for scrollbar positions
            if (_outputPin.ParentNode != null)
            {
                if (_outputPin.ParentUIGraph != null)
                {
                    _outputPoint    = (_outputPin.ParentUIGraph as DaggerUIGraph).PointToClient((_outputPin.ParentNode.UINode as DaggerUINode).PointToScreen((_outputPin.PinUIElements as PinUI).PinLocation));
                    _outputPoint.X += (_outputPin.ParentNode.UINode.PinSize / 2) - (_outputPin.ParentUIGraph as DaggerUIGraph).AutoScrollPosition.X;
                    _outputPoint.Y += (_outputPin.ParentNode.UINode.PinSize / 2) - (_outputPin.ParentUIGraph as DaggerUIGraph).AutoScrollPosition.Y;
                }
            }
            else
            {
                //it's an imported pin
                _outputPoint = (_outputPin.PinUIElements as PinUI).PinLocation;
                if (_outputPin.ParentUIGraph != null)
                {
                    _outputPoint.X += (_outputPin.ParentUIGraph.PinSize / 2);
                    _outputPoint.Y += (_outputPin.ParentUIGraph.PinSize / 2);
                }
            }

            if (_inputPin.ParentNode != null)
            {
                if (_inputPin.ParentUIGraph != null)
                {
                    _inputPoint    = (_inputPin.ParentUIGraph as DaggerUIGraph).PointToClient((_inputPin.ParentNode.UINode as DaggerUINode).PointToScreen((_inputPin.PinUIElements as PinUI).PinLocation));
                    _inputPoint.X += (_inputPin.ParentNode.UINode.PinSize / 2) - (_inputPin.ParentUIGraph as DaggerUIGraph).AutoScrollPosition.X;
                    _inputPoint.Y += (_inputPin.ParentNode.UINode.PinSize / 2) - (_inputPin.ParentUIGraph as DaggerUIGraph).AutoScrollPosition.Y;
                }
            }
            else
            {
                //it's an exported pin
                _inputPoint = (_inputPin.PinUIElements as PinUI).PinLocation;
                if (_inputPin.ParentUIGraph != null)
                {
                    _inputPoint.X += (_inputPin.ParentUIGraph.PinSize / 2);
                    _inputPoint.Y += (_inputPin.ParentUIGraph.PinSize / 2);
                }
            }

            switch (style)
            {
            case NoodleStyle.Bezier:
                _bezierStyle();
                break;

            case NoodleStyle.Lines:
                _lineStyle();
                break;

            case NoodleStyle.CircuitBoardFine:
            case NoodleStyle.CircuitBoardCoarse:
            {
                AstarHelper bshelper = (AstarHelper)helper;
                path.AddLines(_pathFinder(bshelper.grid, bshelper.pathCost, bshelper.grain).ToArray());
            }
            break;

            case NoodleStyle.Ramen:
            {
                AstarHelper bshelper = (AstarHelper)helper;
                path.AddCurve(_pathFinder(bshelper.grid, bshelper.pathCost, bshelper.grain).ToArray(), 0.75f);
                path.Flatten();
            }
            break;

            case NoodleStyle.BendyStraws:
            {
                AstarHelper bshelper = (AstarHelper)helper;
                // traverse the points of the pathfinder and create 90 degree ellipses
                List <Point> points    = _pathFinder(bshelper.grid, bshelper.pathCost, bshelper.grain);
                int          pcount    = 0;
                Point        lastpoint = points[0];
                while (pcount < points.Count - 2)
                {
                    float yi = 0, xi = 0;
                    float m1 = _slope(lastpoint, points[pcount + 1], ref yi, ref xi);
                    float m2 = _slope(points[pcount + 1], points[pcount + 2], ref yi, ref xi);
                    if (m1 != m2)
                    {
                        // an angle

                        // get the mid point of seg2 and create bezier curve
                        Point mpoint = (m2 == 0) ? _hmidPoint(points[pcount + 1], points[pcount + 2]) : _vmidPoint(points[pcount + 1], points[pcount + 2]);
                        path.AddBezier(lastpoint, points[pcount + 1], points[pcount + 1], mpoint);
                        lastpoint = mpoint;
                        pcount++;
                    }
                    else
                    {
                        // strait line
                        pcount++;
                    }
                }

                // add the last line
                path.AddLine(lastpoint, points[points.Count - 1]);
                path.Flatten();
            }
            break;

            default:
                break;
            }
        }
Beispiel #2
0
 public DaggerNoodleContainer(DaggerUIGraph uigraph, NoodleStyle style)
 {
     _uigraph = uigraph;
     _noodles = new List <DaggerNoodle>();
 }