Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/PointMarkers/CenteredTextMarker.cs @ 13777

Last change on this file since 13777 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.4 KB
Line 
1using System.Threading;
2using System.Windows;
3using System.Windows.Media;
4
5namespace Microsoft.Research.DynamicDataDisplay.PointMarkers
6{
7  /// <summary>Renders specified text near the point</summary>
8  public class CenteredTextMarker : PointMarker
9  {
10    public string Text
11    {
12      get { return (string)GetValue(TextProperty); }
13      set { SetValue(TextProperty, value); }
14    }
15
16    public static readonly DependencyProperty TextProperty =
17      DependencyProperty.Register(
18        "Text",
19        typeof(string),
20        typeof(CenteredTextMarker),
21        new FrameworkPropertyMetadata(""));
22
23    public override void Render(DrawingContext dc, Point screenPoint)
24    {
25      FormattedText textToDraw = new FormattedText(Text, Thread.CurrentThread.CurrentCulture,
26         FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black);
27
28      double width = textToDraw.Width;
29      double height = textToDraw.Height;
30
31      const double verticalShift = -20; // px
32
33      Rect bounds = RectExtensions.FromCenterSize(new Point(screenPoint.X, screenPoint.Y + verticalShift - height / 2),
34        new Size(width, height));
35
36      Point loc = bounds.Location;
37      bounds = CoordinateUtilities.RectZoom(bounds, 1.05, 1.15);
38
39      dc.DrawLine(new Pen(Brushes.Black, 1), Point.Add(screenPoint, new Vector(0, verticalShift)), screenPoint);
40      dc.DrawRectangle(Brushes.White, new Pen(Brushes.Black, 1), bounds);
41      dc.DrawText(textToDraw, loc);
42    }
43  }
44}
Note: See TracBrowser for help on using the repository browser.