Exemple #1
0
        private void DrawGroupPinNodeFakeEdge(ICircuitGroupPin <TElement> grpPin, PointF grpPinPos, bool inputSide, DiagramDrawingStyle style, D2dGraphics g)
        {
            ElementTypeInfo info = GetElementTypeInfo(grpPin.InternalElement, g);
            D2dBrush        pen  = (style == DiagramDrawingStyle.Normal) ? SubGraphPinBrush : Theme.GetOutLineBrush(style);

            if (inputSide)
            {
                PointF op = grpPinPos;
                float  x1 = op.X + CircuitGroupPinInfo.FloatingPinBoxWidth;
                float  y1 = op.Y + CircuitGroupPinInfo.FloatingPinBoxHeight / 2;

                Point ip = grpPin.InternalElement.Bounds.Location;
                float x2 = ip.X;
                float y2 = ip.Y + GetPinOffset(grpPin.InternalElement, grpPin.InternalPinIndex, true);

                DrawWire(g, m_fakeInputLinkPen, x1, y1, x2, y2, 1.0f, m_VirtualLinkStrokeStyle);
            }
            else
            {
                Point op = grpPin.InternalElement.Bounds.Location;
                float x1 = op.X + info.Size.Width;
                float y1 = op.Y + GetPinOffset(grpPin.InternalElement, grpPin.InternalPinIndex, false);

                PointF ip = grpPinPos;
                float  x2 = ip.X;
                float  y2 = ip.Y + CircuitGroupPinInfo.FloatingPinBoxHeight / 2;
                DrawWire(g, m_fakeOutputLinkPen, x1, y1, x2, y2, 1.0f, m_VirtualLinkStrokeStyle);
            }
        }
        private void DrawArrow(D2dGraphics g, D2dBrush brush, PointF p, float dx, float dy)
        {
            const float cos  = 0.866f;
            const float sin  = 0.500f;
            PointF      end1 = new PointF(
                (float)(p.X + (dx * cos + dy * -sin)),
                (float)(p.Y + (dx * sin + dy * cos)));
            PointF end2 = new PointF(
                (float)(p.X + (dx * cos + dy * sin)),
                (float)(p.Y + (dx * -sin + dy * cos)));

            g.DrawLine(p, end1, brush, m_theme.StrokeWidth);
            g.DrawLine(p, end2, brush, m_theme.StrokeWidth);
        }
Exemple #3
0
        /// <summary>
        /// Registers a brush (pen) with a unique key</summary>
        /// <param name="key">Key to access brush</param>
        /// <param name="brush">Custom brush</param>
        public void RegisterCustomBrush(object key, D2dBrush brush)
        {
            D2dBrush oldBrush;

            m_brushes.TryGetValue(key, out oldBrush);
            if (brush != oldBrush)
            {
                if (oldBrush != null)
                {
                    oldBrush.Dispose();
                }

                m_brushes[key] = brush;
                OnRedraw();
            }
        }
Exemple #4
0
        private void DrawArrow(Vec2F p, Vec2F d, D2dBrush brush, D2dGraphics g)
        {
            d.Normalize();
            // draw arrowhead
            const double cos  = -0.866;
            const double sin  = -0.500;
            PointF       head = new PointF(p.X, p.Y);
            PointF       end1 = new PointF(
                (float)(p.X + (d.X * cos + d.Y * -sin) * m_arrowSize),
                (float)(p.Y + (d.X * sin + d.Y * cos) * m_arrowSize));
            PointF end2 = new PointF(
                (float)(p.X + (d.X * cos + d.Y * sin) * m_arrowSize),
                (float)(p.Y + (d.X * -sin + d.Y * cos) * m_arrowSize));


            g.DrawLine(head, end1, brush, m_theme.StrokeWidth);
            g.DrawLine(head, end2, brush, m_theme.StrokeWidth);
        }
        private void Draw(TEdge edge, D2dBrush brush, D2dGraphics g)
        {
            PointF p1, p2, p3, p4;
            float  d = GetTransitionPoints(edge, out p1, out p2, out p3, out p4);

            DrawEdgeSpline(p1, p2, p3, p4, d, brush, g);
            GdiUtil.MakeRectangle(p1, p2);

            BezierCurve2F curve    = new BezierCurve2F(p1, p2, p3, p4);
            Vec2F         midpoint = curve.Evaluate(0.5f);

            midpoint.X += 2;
            string label = edge.Label;

            if (!string.IsNullOrEmpty(label))
            {
                g.DrawText(edge.Label, m_theme.TextFormat, new PointF(midpoint.X, midpoint.Y), m_theme.TextBrush);
            }
        }
Exemple #6
0
        private void DrawEyeIcon(RectangleF rect, D2dBrush pen, float strokeWidth, D2dGraphics g)
        {
            //g.DrawRectangle(rect, pen);
            float delta = rect.Width / 3;
            var   p1    = new PointF(rect.X, rect.Y + rect.Height / 2);
            var   p2    = new PointF(p1.X + delta, rect.Y);
            var   p3    = new PointF(p1.X + 2 * delta, rect.Y);
            var   p4    = new PointF(rect.X + rect.Width, rect.Y + rect.Height / 2);

            g.DrawBezier(p1, p2, p3, p4, pen, strokeWidth);// top lid
            p2 = new PointF(p2.X, rect.Y + rect.Height);
            p3 = new PointF(p3.X, rect.Y + rect.Height);
            g.DrawBezier(p1, p2, p3, p4, pen, strokeWidth); //bottom lid

            PointF     irisCenter = new PointF(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
            float      irisRadius = 0.2f * Math.Min(rect.Width, rect.Height);
            RectangleF irisRect   = new RectangleF(irisCenter.X - irisRadius, irisCenter.Y - irisRadius, 2 * irisRadius, 2 * irisRadius);

            g.DrawEllipse(irisRect, pen, strokeWidth * 1.8f);
        }
        private void DrawOutline(TNode state, D2dBrush brush, D2dGraphics g)
        {
            RectangleF bounds = state.Bounds;

            if (state.Type != StateType.Normal)
            {
                g.DrawEllipse((D2dEllipse)bounds, brush, m_theme.StrokeWidth);
            }
            else
            {
                float scaleX     = g.Transform.M11; // assume no rotation.
                float radInPixel = scaleX * CornerRadius;
                if (radInPixel > MinRadiusInPixel)
                {
                    m_stateRect.Rect = bounds;
                    g.DrawRoundedRectangle(m_stateRect, brush, m_theme.StrokeWidth);
                }
                else
                {
                    g.DrawRectangle(bounds, brush, m_theme.StrokeWidth);
                }
            }
        }
Exemple #8
0
        private void Draw(TEdge edge, D2dBrush brush, D2dGraphics g)
        {
            Vec2F   startPoint  = new Vec2F();
            Vec2F   endPoint    = new Vec2F();
            CircleF c           = new CircleF();
            bool    moreThan180 = false;
            Vec2F   endTangent;
            Vec2F   textPoint;
            int     route = edge.FromRoute.Index;

            if (GetEdgeGeometry(edge, route, ref startPoint, ref endPoint, ref c, ref moreThan180))
            {
                g.DrawLine(new PointF(startPoint.X, startPoint.Y),
                           new PointF(endPoint.X, endPoint.Y),
                           brush,
                           m_theme.StrokeWidth);

                endTangent = endPoint - startPoint;
                textPoint  = (endPoint + startPoint) * 0.5f;
            }
            else
            {
                // prepare to draw arc
                RectangleF rect = new RectangleF(c.Center.X - c.Radius, c.Center.Y - c.Radius, 2 * c.Radius, 2 * c.Radius);

                double       angle1 = Math.Atan2(startPoint.Y - c.Center.Y, startPoint.X - c.Center.X);
                double       angle2 = Math.Atan2(endPoint.Y - c.Center.Y, endPoint.X - c.Center.X);
                const double twoPi  = 2 * Math.PI;

                // swap so we always go clockwise
                if (angle1 > angle2)
                {
                    double temp = angle1;
                    angle1 = angle2;
                    angle2 = temp;
                }

                double startAngle = angle1;
                double sweepAngle = angle2 - angle1;

                if (moreThan180)
                {
                    if (sweepAngle < Math.PI)
                    {
                        sweepAngle = -(twoPi - sweepAngle);
                    }
                }
                else
                {
                    if (sweepAngle > Math.PI)
                    {
                        sweepAngle = -(twoPi - sweepAngle);
                    }
                }

                const double RadiansToDegrees = 360 / twoPi;
                startAngle *= RadiansToDegrees;
                sweepAngle *= RadiansToDegrees;

                g.DrawArc((D2dEllipse)rect,
                          brush,
                          (float)startAngle,
                          (float)sweepAngle,
                          m_theme.StrokeWidth);

                endTangent = endPoint - c.Center; endTangent = endTangent.Perp;
                textPoint  = (endPoint + startPoint) * 0.5f;
                CircleF.Project(textPoint, c, ref textPoint);
                if (moreThan180)
                {
                    textPoint -= 2 * (textPoint - c.Center);
                }
            }

            DrawArrow(endPoint, endTangent, brush, g);

            string label = edge.Label;

            if (!string.IsNullOrEmpty(label))
            {
                RectangleF textBox = new RectangleF(textPoint.X - 512, textPoint.Y, 1024, m_theme.TextFormat.FontHeight);
                g.DrawText(label, m_theme.TextFormat, textBox, m_theme.TextBrush);
            }
        }
Exemple #9
0
 private void DrawOutline(TNode node, D2dBrush brush, D2dGraphics g)
 {
     g.DrawEllipse((D2dEllipse)node.Bounds, brush, m_theme.StrokeWidth);
 }
        private void DrawEdgeSpline(PointF p1, PointF p2, PointF p3, PointF p4, float d, D2dBrush brush, D2dGraphics g)
        {
            g.DrawBezier(p1, p2, p3, p4, brush, m_theme.StrokeWidth);
            float arrowScale = (float)ArrowSize / d;
            float dx         = (p3.X - p4.X) * arrowScale;
            float dy         = (p3.Y - p4.Y) * arrowScale;

            DrawArrow(g, brush, p4, dx, dy);
        }