root/plot/Pybrary.Plot/Annotation.cs

Revision 746, 2.5 kB (checked in by mfenniak, 2 years ago)

--

Line 
1 using System;
2 using System.Collections.Generic;
3 using System.Drawing;
4
5 namespace Pybrary.Plot
6 {
7     public abstract class Annotation : EventObject
8     {
9         private BrushDescription background = new BrushDescription(Color.FromArgb(192, Color.White));
10         private FontDescription textFont = new FontDescription("Arial", 12f, FontStyle.Regular);
11         private PenDescription border = new PenDescription(Color.Black, 1f / 96);
12         private string text;
13         private Plot plot;
14
15         public Annotation(Plot plot)
16         {
17             this.plot = plot;
18             background.OnBrushDescriptionChanged += delegate() { raiseEvent(); };
19             textFont.OnBrushDescriptionChanged += delegate() { raiseEvent(); };
20             border.OnPenDescriptionChanged += delegate() { raiseEvent(); };
21         }
22
23         protected Plot Plot
24         {
25             get
26             {
27                 return plot;
28             }
29         }
30
31         public abstract void Draw(Graphics g, AdvancedRect dataArea);
32
33         protected SizeF Size(Graphics g)
34         {
35             using (Font f = TextFont.CreateFont())
36                 return g.MeasureString(text, f);
37         }
38
39         protected void DrawTextBox(Graphics g, PointF pt)
40         {
41             SizeF size = Size(g);
42
43             using (Pen p = Border.CreatePen())
44             using (Brush br = Background.CreateBrush())
45             {
46                 RectangleF rect = new RectangleF(pt, size);
47                 g.FillRectangle(br, rect);
48                 g.DrawRectangle(p, rect.X, rect.Y, rect.Width, rect.Height);
49             }
50
51             using (Font f = TextFont.CreateFont())
52             using (Brush br = TextFont.CreateBrush())
53             {
54                 g.DrawString(Text, f, br, pt);
55             }
56         }
57
58         public string Text
59         {
60             get
61             {
62                 return text;
63             }
64             set
65             {
66                 text = value;
67                 raiseEvent();
68             }
69         }
70
71         public BrushDescription Background
72         {
73             get
74             {
75                 return background;
76             }
77         }
78
79         public FontDescription TextFont
80         {
81             get
82             {
83                 return textFont;
84             }
85         }
86
87         public PenDescription Border
88         {
89             get
90             {
91                 return border;
92             }
93         }
94     }
95 }
Note: See TracBrowser for help on using the browser.