public virtual List <ConnectionPoint> GetConnectionPoints() { List <ConnectionPoint> connectionPoints = new List <ConnectionPoint>(); if (HasCornerConnections) { connectionPoints.Add(new ConnectionPoint(GripType.TopLeft, DisplayRectangle.TopLeftCorner())); connectionPoints.Add(new ConnectionPoint(GripType.TopRight, DisplayRectangle.TopRightCorner())); connectionPoints.Add(new ConnectionPoint(GripType.BottomLeft, DisplayRectangle.BottomLeftCorner())); connectionPoints.Add(new ConnectionPoint(GripType.BottomRight, DisplayRectangle.BottomRightCorner())); } if (HasCenterConnections) { connectionPoints.Add(new ConnectionPoint(GripType.LeftMiddle, DisplayRectangle.LeftMiddle())); connectionPoints.Add(new ConnectionPoint(GripType.RightMiddle, DisplayRectangle.RightMiddle())); connectionPoints.Add(new ConnectionPoint(GripType.TopMiddle, DisplayRectangle.TopMiddle())); connectionPoints.Add(new ConnectionPoint(GripType.BottomMiddle, DisplayRectangle.BottomMiddle())); } if (HasLeftRightConnections) { connectionPoints.Add(new ConnectionPoint(GripType.Start, DisplayRectangle.LeftMiddle())); connectionPoints.Add(new ConnectionPoint(GripType.End, DisplayRectangle.RightMiddle())); } if (HasTopBottomConnections) { connectionPoints.Add(new ConnectionPoint(GripType.Start, DisplayRectangle.TopMiddle())); connectionPoints.Add(new ConnectionPoint(GripType.End, DisplayRectangle.BottomMiddle())); } return(connectionPoints); }
public override TextBox CreateTextBox(Point mousePosition) { TextBox tb; // Get cell where mouse cursor is currently over. Point localMousePos = Canvas.PointToClient(mousePosition); editCol = -1; editRow = -1; int cellWidth = DisplayRectangle.Width / Columns; int cellHeight = DisplayRectangle.Height / Rows; if (DisplayRectangle.Contains(localMousePos)) { editCol = (localMousePos.X - DisplayRectangle.Left) / cellWidth; editRow = (localMousePos.Y - DisplayRectangle.Top) / cellHeight; tb = new TextBox(); tb.Location = DisplayRectangle.TopLeftCorner().Move(editCol * cellWidth, editRow * cellHeight + cellHeight / 2 - 10); tb.Size = new Size(cellWidth, 20); string text; cellText.TryGetValue(new Cell() { Column = editCol, Row = editRow }, out text); tb.Text = text; } else { tb = base.CreateTextBox(mousePosition); } return(tb); }
public override List <ConnectionPoint> GetConnectionPoints() { List <ConnectionPoint> connectionPoints = new List <ConnectionPoint>(); connectionPoints.Add(new ConnectionPoint(GripType.LeftMiddle, DisplayRectangle.LeftMiddle())); connectionPoints.Add(new ConnectionPoint(GripType.RightMiddle, DisplayRectangle.RightMiddle())); connectionPoints.Add(new ConnectionPoint(GripType.TopLeft, DisplayRectangle.TopLeftCorner())); connectionPoints.Add(new ConnectionPoint(GripType.BottomLeft, DisplayRectangle.BottomLeftCorner())); return(connectionPoints); }
public virtual List <ShapeAnchor> GetAnchors() { List <ShapeAnchor> anchors = new List <ShapeAnchor>(); Rectangle r; Size anchorSize = new Size(anchorWidthHeight, anchorWidthHeight); if (HasCornerAnchors) { r = new Rectangle(DisplayRectangle.TopLeftCorner(), anchorSize); anchors.Add(new ShapeAnchor(GripType.TopLeft, r, Cursors.SizeNWSE)); r = new Rectangle(DisplayRectangle.TopRightCorner().Move(-anchorWidthHeight, 0), anchorSize); anchors.Add(new ShapeAnchor(GripType.TopRight, r, Cursors.SizeNESW)); r = new Rectangle(DisplayRectangle.BottomLeftCorner().Move(0, -anchorWidthHeight), anchorSize); anchors.Add(new ShapeAnchor(GripType.BottomLeft, r, Cursors.SizeNESW)); r = new Rectangle(DisplayRectangle.BottomRightCorner().Move(-anchorWidthHeight, -anchorWidthHeight), anchorSize); anchors.Add(new ShapeAnchor(GripType.BottomRight, r, Cursors.SizeNWSE)); } if (HasCenterAnchors || HasLeftRightAnchors) { r = new Rectangle(DisplayRectangle.LeftMiddle().Move(0, -anchorWidthHeight / 2), anchorSize); anchors.Add(new ShapeAnchor(GripType.LeftMiddle, r, Cursors.SizeWE)); r = new Rectangle(DisplayRectangle.RightMiddle().Move(-anchorWidthHeight, -anchorWidthHeight / 2), anchorSize); anchors.Add(new ShapeAnchor(GripType.RightMiddle, r, Cursors.SizeWE)); } if (HasCenterAnchors || HasTopBottomAnchors) { r = new Rectangle(DisplayRectangle.TopMiddle().Move(-anchorWidthHeight / 2, 0), anchorSize); anchors.Add(new ShapeAnchor(GripType.TopMiddle, r, Cursors.SizeNS)); r = new Rectangle(DisplayRectangle.BottomMiddle().Move(-anchorWidthHeight / 2, -anchorWidthHeight), anchorSize); anchors.Add(new ShapeAnchor(GripType.BottomMiddle, r, Cursors.SizeNS)); } return(anchors); }
public virtual void DrawText(Graphics gr) { SizeF size = gr.MeasureString(Text, TextFont); Brush brush = new SolidBrush(TextColor); Point textpos; // 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 = DisplayRectangle.TopLeftCorner().Move(5, 5); break; case ContentAlignment.TopCenter: textpos = DisplayRectangle.TopMiddle().Move((int)(-size.Width / 2), 5); break; case ContentAlignment.TopRight: textpos = DisplayRectangle.TopRightCorner().Move((int)(-(size.Width + 5)), 5); break; case ContentAlignment.MiddleLeft: textpos = DisplayRectangle.LeftMiddle().Move(5, (int)(-size.Height / 2)); break; case ContentAlignment.MiddleCenter: textpos = DisplayRectangle.Center().Move((int)(-size.Width / 2), (int)(-size.Height / 2)); break; case ContentAlignment.MiddleRight: textpos = DisplayRectangle.RightMiddle().Move((int)(-(size.Width + 5)), (int)(-size.Height / 2)); break; case ContentAlignment.BottomLeft: textpos = DisplayRectangle.BottomLeftCorner().Move(5, (int)-(size.Height + 5)); break; case ContentAlignment.BottomCenter: textpos = DisplayRectangle.BottomMiddle().Move((int)(-size.Width / 2), (int)-(size.Height + 5)); break; case ContentAlignment.BottomRight: textpos = DisplayRectangle.BottomRightCorner().Move((int)(-(size.Width + 5)), (int)-(size.Height + 5)); break; default: // middle center textpos = DisplayRectangle.Center().Move((int)(-size.Width / 2), (int)(-size.Height / 2)); break; } gr.DrawString(Text, TextFont, brush, textpos); brush.Dispose(); }