示例#1
0
        public override void Draw(Graphics gr, bool showSelection = true)
        {
            base.Draw(gr, showSelection);
            Rectangle r = ZoomRectangle.Grow(-4);

            if (control.Location != r.Location)
            {
                control.Location = r.Location;
            }

            if (control.Size != r.Size)
            {
                control.Size = r.Size;
            }

            if (control.Enabled != Enabled)
            {
                control.Enabled = Enabled;
            }

            if (control.Visible != Visible)
            {
                control.Visible = Visible;
            }
        }
示例#2
0
        public override void Draw(Graphics gr, bool showSelection = true)
        {
            base.Draw(gr, showSelection);
            int min = ZoomRectangle.Width.Min(ZoomRectangle.Height);

            min = min / 2;
            Point topleft = ZoomRectangle.Center();

            topleft.X -= min / 2;
            topleft.Y -= 3;
            target     = new Rectangle(topleft, new Size(min, min));
            Point innerTopLeft = target.Center();

            innerTopLeft.Offset(-min / 4, -min / 4);
            Rectangle targetInner  = new Rectangle(innerTopLeft, new Size(min / 2, min / 2));
            Brush     fillBrush    = new SolidBrush(Color.White);
            Brush     middleTarget = new SolidBrush(Color.Red);
            Pen       borderPen    = new Pen(Color.Red);

            gr.FillEllipse(fillBrush, target);
            gr.FillEllipse(middleTarget, targetInner);
            gr.DrawEllipse(borderPen, target);
            fillBrush.Dispose();
            borderPen.Dispose();
            middleTarget.Dispose();
        }
示例#3
0
        public override void Draw(Graphics gr, bool showSelection = true)
        {
            base.Draw(gr, showSelection);
            Rectangle r = ZoomRectangle.Grow(-4);

            if (control.Location != r.Location)
            {
                control.Location = r.Location;
            }

            if (control.Size != r.Size)
            {
                // Use the control's height so we don't get continuous redraws.
                control.Size = new Size(r.Width, control.Height);
            }

            if (control.Enabled != Enabled)
            {
                control.Enabled = Enabled;
            }

            if (control.Visible != Visible)
            {
                control.Visible = Visible;
            }
        }
示例#4
0
        public override void Draw(Graphics gr, bool showSelection = true)
        {
            // While this clips the region, the lines are no longer antialiased.

            /*
             * GraphicsPath gp = new GraphicsPath();
             * gp.AddPolygon(path);
             * Region region = new Region(gp);
             * gr.SetClip(region, CombineMode.Replace);
             * gr.IntersectClip(ZoomRectangle);
             * ...
             * gr.ResetClip();
             */

            // Drawing onto a bitmap that constrains the drawing area fixes the trail problem
            // but still has issues with larger pen widths (try 10) as triangle points are clipped.
            Rectangle r      = ZoomRectangle.Grow(2);
            Bitmap    bitmap = new Bitmap(r.Width, r.Height);
            Graphics  g2     = Graphics.FromImage(bitmap);

            g2.SmoothingMode = SmoothingMode.AntiAlias;
            Point[] path = ZPath();
            g2.FillPolygon(FillBrush, path);
            g2.DrawPolygon(BorderPen, path);
            gr.DrawImage(bitmap, ZoomRectangle.X, ZoomRectangle.Y);
            bitmap.Dispose();
            g2.Dispose();
            base.Draw(gr, showSelection);
        }
示例#5
0
        public virtual ShapeAnchor GetBottomRightAnchor()
        {
            Size        anchorSize = new Size(anchorWidthHeight, anchorWidthHeight);
            Rectangle   r          = new Rectangle(ZoomRectangle.BottomRightCorner().Move(-anchorWidthHeight, -anchorWidthHeight), anchorSize);
            ShapeAnchor anchor     = new ShapeAnchor(GripType.BottomRight, r, Cursors.SizeNWSE);

            return(anchor);
        }
示例#6
0
        public override List <ConnectionPoint> GetConnectionPoints()
        {
            List <ConnectionPoint> connectionPoints = new List <ConnectionPoint>();

            connectionPoints.Add(new ConnectionPoint(GripType.LeftMiddle, ZoomRectangle.LeftMiddle()));
            connectionPoints.Add(new ConnectionPoint(GripType.RightMiddle, ZoomRectangle.RightMiddle()));
            connectionPoints.Add(new ConnectionPoint(GripType.TopRight, ZoomRectangle.TopRightCorner()));
            connectionPoints.Add(new ConnectionPoint(GripType.BottomRight, ZoomRectangle.BottomRightCorner()));

            return(connectionPoints);
        }
示例#7
0
        public override void Draw(Graphics gr, bool showSelection = true)
        {
            base.Draw(gr, showSelection);
            Rectangle r = ZoomRectangle.Grow(-4);

            control.Location = r.Location;
            control.Size     = r.Size;
            control.Text     = Text;
            control.Enabled  = Enabled;
            control.Visible  = Visible;
        }
示例#8
0
        public override void Draw(Graphics gr, bool showSelection = true)
        {
            base.Draw(gr, showSelection);
            Rectangle r = ZoomRectangle.Grow(-4);

            control.Location = r.Location;
            // Use the control's height so we don't get continuous redraws, unless the textbox is a multiline textbox.
            control.Size = new Size(r.Width, Multiline ? r.Height : control.Height);
            control.Text = Text;
            control.Font = TextFont;
            ((TextBox)control).Multiline = Multiline;
            ((TextBox)control).ReadOnly  = ReadOnly;
        }
示例#9
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.LeftMiddle(), ZoomRectangle.RightMiddle());
            pen.Dispose();

            base.Draw(gr, showSelection);
        }
示例#10
0
 public override void Draw(Graphics gr, bool showSelection = true)
 {
     Rectangle r = ZoomRectangle.Grow(2);
     Bitmap bitmap = new Bitmap(r.Width, r.Height);
     Graphics g2 = Graphics.FromImage(bitmap);
     g2.SmoothingMode = SmoothingMode.AntiAlias;
     Point[] path = ZPath();
     g2.FillPolygon(FillBrush, path);
     g2.DrawPolygon(BorderPen, path);
     gr.DrawImage(bitmap, ZoomRectangle.X, ZoomRectangle.Y);
     bitmap.Dispose();
     g2.Dispose();
     base.Draw(gr, showSelection);
 }
示例#11
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);
        }
示例#12
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();
            }
        }