1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Drawing.Drawing2D;
|
---|
4 |
|
---|
5 | namespace Netron.Diagramming.Core
|
---|
6 | {
|
---|
7 | /// <summary>
|
---|
8 | /// Like a <see cref="TextLabel"/> but without shadows and colors.
|
---|
9 | /// </summary>
|
---|
10 | public partial class TextOnly : SimpleShapeBase
|
---|
11 | {
|
---|
12 | #region Fields
|
---|
13 |
|
---|
14 | // ------------------------------------------------------------------
|
---|
15 | /// <summary>
|
---|
16 | /// Implementation of IVersion - the current version of
|
---|
17 | /// TextLabel.
|
---|
18 | /// </summary>
|
---|
19 | // ------------------------------------------------------------------
|
---|
20 | protected const double textOnlyVersion = 1.0;
|
---|
21 |
|
---|
22 | #endregion
|
---|
23 |
|
---|
24 | #region Properties
|
---|
25 |
|
---|
26 | // ------------------------------------------------------------------
|
---|
27 | /// <summary>
|
---|
28 | /// Gets the current version.
|
---|
29 | /// </summary>
|
---|
30 | // ------------------------------------------------------------------
|
---|
31 | public override double Version
|
---|
32 | {
|
---|
33 | get
|
---|
34 | {
|
---|
35 | return textOnlyVersion;
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | /// <summary>
|
---|
40 | /// Gets the friendly name of the entity to be displayed in the UI
|
---|
41 | /// </summary>
|
---|
42 | /// <value></value>
|
---|
43 | public override string EntityName
|
---|
44 | {
|
---|
45 | get { return "TextOnly Shape"; }
|
---|
46 | }
|
---|
47 | #endregion
|
---|
48 |
|
---|
49 | #region Constructor
|
---|
50 | /// <summary>
|
---|
51 | /// Default ctor
|
---|
52 | /// </summary>
|
---|
53 | /// <param name="s"></param>
|
---|
54 | public TextOnly(IModel s)
|
---|
55 | : base(s)
|
---|
56 | {
|
---|
57 | }
|
---|
58 |
|
---|
59 | /// <summary>
|
---|
60 | /// Initializes a new instance of the <see cref="T:TextOnly"/> class.
|
---|
61 | /// </summary>
|
---|
62 | public TextOnly()
|
---|
63 | : base()
|
---|
64 | { }
|
---|
65 |
|
---|
66 | #endregion
|
---|
67 |
|
---|
68 | #region Methods
|
---|
69 |
|
---|
70 | // -----------------------------------------------------------------
|
---|
71 | /// <summary>
|
---|
72 | /// Initializes this instance.
|
---|
73 | /// </summary>
|
---|
74 | // -----------------------------------------------------------------
|
---|
75 | protected override void Initialize()
|
---|
76 | {
|
---|
77 | base.Initialize();
|
---|
78 | this.PaintStyle = ArtPalette.GetTransparentPaintStyle();
|
---|
79 | }
|
---|
80 |
|
---|
81 | /// <summary>
|
---|
82 | /// Tests whether the mouse hits this shape.
|
---|
83 | /// </summary>
|
---|
84 | /// <param name="p"></param>
|
---|
85 | /// <returns></returns>
|
---|
86 | public override bool Hit(System.Drawing.Point p)
|
---|
87 | {
|
---|
88 | Rectangle r = new Rectangle(p, new Size(5, 5));
|
---|
89 | return Rectangle.Contains(r);
|
---|
90 | }
|
---|
91 |
|
---|
92 | /// <summary>
|
---|
93 | /// Paints the bundle on the canvas
|
---|
94 | /// </summary>
|
---|
95 | /// <param name="g">a Graphics object onto which to paint</param>
|
---|
96 | public override void Paint(Graphics g)
|
---|
97 | {
|
---|
98 | if (g == null)
|
---|
99 | throw new ArgumentNullException("The Graphics object is 'null'.");
|
---|
100 |
|
---|
101 | g.SmoothingMode = SmoothingMode.HighQuality;
|
---|
102 |
|
---|
103 | //the edge
|
---|
104 | if (Hovered)
|
---|
105 | g.DrawRectangle(new Pen(Color.Red, 2F), Rectangle);
|
---|
106 | //the text
|
---|
107 | if (!string.IsNullOrEmpty(Text))
|
---|
108 | {
|
---|
109 | //StringFormat format = new StringFormat();
|
---|
110 | //format.Alignment = this.VerticalAlignment;
|
---|
111 | //format.LineAlignment = this.HorizontalAlignment;
|
---|
112 |
|
---|
113 | //g.DrawString(
|
---|
114 | // Text,
|
---|
115 | // ArtPalette.DefaultFont,
|
---|
116 | // Brushes.Black,
|
---|
117 | // Rectangle,
|
---|
118 | // format);
|
---|
119 | g.DrawString(
|
---|
120 | mTextStyle.GetFormattedText(Text),
|
---|
121 | mTextStyle.Font,
|
---|
122 | mTextStyle.GetBrush(),
|
---|
123 | TextArea,
|
---|
124 | mTextStyle.StringFormat);
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | #endregion
|
---|
135 |
|
---|
136 | }
|
---|
137 | }
|
---|