public override void Draw(Graphics gr, bool showSelection = true) { SizeF size = gr.MeasureString(TOOLBOX_TEXT, TextFont); Point textpos = DisplayRectangle.Center().Move((int)(-size.Width / 2), (int)(-size.Height / 2)); gr.DrawString(TOOLBOX_TEXT, TextFont, brush, textpos); base.Draw(gr, showSelection); }
protected void UpdateDisplayRectangle(Graphics gr) { SizeF size = gr.MeasureString(Text, TextFont); Point center = DisplayRectangle.Center(); // Grow so selection is not right on top of text, and so that anti-aliasing has some room. DisplayRectangle = new Rectangle(center.X - (int)(size.Width / 2), center.Y - (int)(size.Height) / 2, (int)size.Width, (int)size.Height).Grow(3); }
public virtual void DrawText(Graphics gr) { SizeF size = gr.MeasureString(Text, TextFont); Point textpos = DisplayRectangle.Center().Move((int)(-size.Width / 2), (int)(-size.Height / 2)); Brush brush = new SolidBrush(TextColor); gr.DrawString(Text, TextFont, brush, textpos); brush.Dispose(); }
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())); } if (HasCenterConnection) { connectionPoints.Add(new ConnectionPoint(GripType.Center, DisplayRectangle.Center())); } return(connectionPoints); }
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(); }