Changeset 10518 for branches/HeuristicLab.Visualization
- Timestamp:
- 02/26/14 10:46:57 (11 years ago)
- Location:
- branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives
- Files:
-
- 2 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/RectangularPrimitiveBase.cs
r7780 r10518 40 40 get { return new SizeD(UpperRight.X - LowerLeft.X, UpperRight.Y - LowerLeft.Y); } 41 41 } 42 43 public string Text { get; set; } 44 public Font Font { get; set; } 42 45 43 46 protected RectangularPrimitiveBase(IChart chart, PointD lowerLeft, PointD upperRight) … … 133 136 } 134 137 } 138 139 protected virtual void DrawText(Graphics graphics) { // draw the text in the center of the bounding rectangle4 140 var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y)); 141 var s = Chart.TransformWorldToPixel(Size); 142 var stringSize = graphics.MeasureString(Text, Font); 143 var fontSize = Font.Size * s.Width / stringSize.Width; 144 if (fontSize > 12) fontSize = 12; // limit maximum font size so that nodes look nicer 145 Font = new Font(Font.FontFamily, fontSize, GraphicsUnit.Pixel); 146 stringSize = graphics.MeasureString(Text, Font); 147 graphics.DrawString(Text, Font, new SolidBrush(Pen.Color), p.X + (s.Width - stringSize.Width) / 2f, p.Y - (s.Height + stringSize.Height) / 2f); 148 } 149 150 public override void Draw(Graphics graphics) { 151 if (!string.IsNullOrEmpty(Text)) 152 DrawText(graphics); 153 base.Draw(graphics); 154 } 135 155 } 136 156 }
Note: See TracChangeset
for help on using the changeset viewer.