示例#1
0
        public override List <ConnectionPoint> GetConnectionPoints()
        {
            List <ConnectionPoint> connectionPoints = new List <ConnectionPoint>();

            connectionPoints.Add(new ConnectionPoint(GripType.TopMiddle, ZoomRectangle.TopMiddle()));
            connectionPoints.Add(new ConnectionPoint(GripType.BottomMiddle, ZoomRectangle.BottomMiddle()));
            connectionPoints.Add(new ConnectionPoint(GripType.BottomLeft, ZoomRectangle.BottomLeftCorner()));
            connectionPoints.Add(new ConnectionPoint(GripType.BottomRight, ZoomRectangle.BottomRightCorner()));

            return(connectionPoints);
        }
示例#2
0
        public override void Draw(Graphics gr, bool showSelection = true)
        {
            Pen pen = (Pen)BorderPen.Clone();

            if (ShowConnectorAsSelected && showSelection)
            {
                pen.Color = pen.Color.ToArgb() == Color.Red.ToArgb() ? Color.Blue : Color.Red;
            }

            gr.DrawLine(pen, ZoomRectangle.TopMiddle(), ZoomRectangle.BottomMiddle());
            pen.Dispose();

            base.Draw(gr, showSelection);
        }
示例#3
0
        public virtual List <ShapeAnchor> GetAnchors()
        {
            List <ShapeAnchor> anchors = new List <ShapeAnchor>();
            Rectangle          r;
            Size anchorSize = new Size(anchorWidthHeight, anchorWidthHeight);

            if (HasCornerAnchors)
            {
                r = new Rectangle(ZoomRectangle.TopLeftCorner(), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.TopLeft, r, Cursors.SizeNWSE));
                r = new Rectangle(ZoomRectangle.TopRightCorner().Move(-anchorWidthHeight, 0), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.TopRight, r, Cursors.SizeNESW));
                r = new Rectangle(ZoomRectangle.BottomLeftCorner().Move(0, -anchorWidthHeight), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.BottomLeft, r, Cursors.SizeNESW));
                r = new Rectangle(ZoomRectangle.BottomRightCorner().Move(-anchorWidthHeight, -anchorWidthHeight), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.BottomRight, r, Cursors.SizeNWSE));
            }

            if (HasCenterAnchors || HasLeftRightAnchors)
            {
                r = new Rectangle(ZoomRectangle.LeftMiddle().Move(0, -anchorWidthHeight / 2), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.LeftMiddle, r, Cursors.SizeWE));
                r = new Rectangle(ZoomRectangle.RightMiddle().Move(-anchorWidthHeight, -anchorWidthHeight / 2), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.RightMiddle, r, Cursors.SizeWE));
            }

            if (HasCenterAnchors || HasTopBottomAnchors)
            {
                r = new Rectangle(ZoomRectangle.TopMiddle().Move(-anchorWidthHeight / 2, 0), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.TopMiddle, r, Cursors.SizeNS));
                r = new Rectangle(ZoomRectangle.BottomMiddle().Move(-anchorWidthHeight / 2, -anchorWidthHeight), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.BottomMiddle, r, Cursors.SizeNS));
            }

            if (HasCenterAnchor)
            {
                r = new Rectangle(ZoomRectangle.Center().Move(-anchorWidthHeight / 2, -anchorWidthHeight / 2), anchorSize);
                anchors.Add(new ShapeAnchor(GripType.Center, r, Cursors.Cross));
            }

            return(anchors);
        }
示例#4
0
        protected virtual void DrawText(Graphics gr, string text, Font textFont, Color textColor, ContentAlignment textAlign)
        {
            SizeF size  = gr.MeasureString(text, textFont);
            Brush brush = new SolidBrush(textColor);
            Point textpos;
            Font  font        = textFont;
            bool  disposeFont = false;

            // TODO: Should we just create the font and dispose it every time we draw?
            if (canvas.Controller.Zoom != 100)
            {
                font        = new Font(textFont.FontFamily, textFont.Size * canvas.Controller.Zoom / 100, textFont.Style);
                disposeFont = true;
            }

            // TextRenderer is terrible when font is bolded.  Not sure why.
            // Would be great to use this, but the rendering is so bad, I won't.

            // Some info here:
            // http://stackoverflow.com/questions/9038125/asp-net-textrenderer-drawtext-awful-text-images
            //gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //gr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // <-- important!
            //gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            //gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            //gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            //gr.TextContrast = 0;
            //TextFormatFlags flags = TextFormatFlags.Right | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak;
            //TextRenderer.DrawText(gr, Text, TextFont, DisplayRectangle, TextColor, flags);

            switch (textAlign)
            {
            case ContentAlignment.TopLeft:
                textpos = ZoomRectangle.TopLeftCorner().Move(5, 5);
                break;

            case ContentAlignment.TopCenter:
                textpos = ZoomRectangle.TopMiddle().Move((int)(-size.Width / 2), 5);
                break;

            case ContentAlignment.TopRight:
                textpos = ZoomRectangle.TopRightCorner().Move((int)(-(size.Width + 5)), 5);
                break;

            case ContentAlignment.MiddleLeft:
                textpos = ZoomRectangle.LeftMiddle().Move(5, (int)(-size.Height / 2));
                break;

            case ContentAlignment.MiddleCenter:
                textpos = ZoomRectangle.Center().Move((int)(-size.Width / 2), (int)(-size.Height / 2));
                break;

            case ContentAlignment.MiddleRight:
                textpos = ZoomRectangle.RightMiddle().Move((int)(-(size.Width + 5)), (int)(-size.Height / 2));
                break;

            case ContentAlignment.BottomLeft:
                textpos = ZoomRectangle.BottomLeftCorner().Move(5, (int)-(size.Height + 5));
                break;

            case ContentAlignment.BottomCenter:
                textpos = ZoomRectangle.BottomMiddle().Move((int)(-size.Width / 2), (int)-(size.Height + 5));
                break;

            case ContentAlignment.BottomRight:
                textpos = ZoomRectangle.BottomRightCorner().Move((int)(-(size.Width + 5)), (int)-(size.Height + 5));
                break;

            default:            // middle center
                textpos = ZoomRectangle.Center().Move((int)(-size.Width / 2), (int)(-size.Height / 2));
                break;
            }

            TextFormatFlags tff = TextFormatFlags.Default;

            switch (textAlign)
            {
            case ContentAlignment.TopLeft:
                tff |= TextFormatFlags.Left;
                break;

            case ContentAlignment.TopCenter:
                tff |= TextFormatFlags.Top | TextFormatFlags.HorizontalCenter;
                break;

            case ContentAlignment.TopRight:
                tff |= TextFormatFlags.Top | TextFormatFlags.Right;
                break;

            case ContentAlignment.MiddleLeft:
                tff |= TextFormatFlags.VerticalCenter | TextFormatFlags.Left;
                break;

            case ContentAlignment.MiddleCenter:
                tff |= TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
                break;

            case ContentAlignment.MiddleRight:
                tff |= TextFormatFlags.VerticalCenter | TextFormatFlags.Right;
                break;

            case ContentAlignment.BottomLeft:
                tff |= TextFormatFlags.Bottom | TextFormatFlags.Left;
                break;

            case ContentAlignment.BottomCenter:
                tff |= TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter;
                break;

            case ContentAlignment.BottomRight:
                tff |= TextFormatFlags.Bottom | TextFormatFlags.Right;
                break;

            default:            // middle center
                tff |= TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
                break;
            }

            TextRenderer.DrawText(gr, text, font, ZoomRectangle.Grow(-3), textColor, FillColor, tff);
            // gr.DrawString(text, textFont, brush, textpos);
            brush.Dispose();

            if (disposeFont)
            {
                font.Dispose();
            }
        }