1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Drawing;
|
---|
5 | namespace Netron.Diagramming.Core
|
---|
6 | {
|
---|
7 | /// <summary>
|
---|
8 | /// Simple label material
|
---|
9 | /// </summary>
|
---|
10 | public partial class LabelMaterial : ShapeMaterialBase
|
---|
11 | {
|
---|
12 | #region Fields
|
---|
13 |
|
---|
14 | // ------------------------------------------------------------------
|
---|
15 | /// <summary>
|
---|
16 | /// Implementation of IVersion - the current version of
|
---|
17 | /// LabelMaterial.
|
---|
18 | /// </summary>
|
---|
19 | // ------------------------------------------------------------------
|
---|
20 | protected double labelMaterialVersion = 1.0;
|
---|
21 |
|
---|
22 | // ------------------------------------------------------------------
|
---|
23 | /// <summary>
|
---|
24 | /// the Text field
|
---|
25 | /// </summary>
|
---|
26 | // ------------------------------------------------------------------
|
---|
27 | private string mText;
|
---|
28 | #endregion
|
---|
29 |
|
---|
30 | #region Properties
|
---|
31 |
|
---|
32 | // ------------------------------------------------------------------
|
---|
33 | /// <summary>
|
---|
34 | /// Gets the current version.
|
---|
35 | /// </summary>
|
---|
36 | // ------------------------------------------------------------------
|
---|
37 | public virtual double Version
|
---|
38 | {
|
---|
39 | get
|
---|
40 | {
|
---|
41 | return labelMaterialVersion;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | // ------------------------------------------------------------------
|
---|
46 | /// <summary>
|
---|
47 | /// Gets or sets the font for this label.
|
---|
48 | /// </summary>
|
---|
49 | // ------------------------------------------------------------------
|
---|
50 | public Font Font
|
---|
51 | {
|
---|
52 | get
|
---|
53 | {
|
---|
54 | return this.myTextStyle.Font;
|
---|
55 | }
|
---|
56 | set
|
---|
57 | {
|
---|
58 | this.myTextStyle.Font = value;
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | // ------------------------------------------------------------------
|
---|
63 | /// <summary>
|
---|
64 | /// Gets or sets the Text
|
---|
65 | /// </summary>
|
---|
66 | // ------------------------------------------------------------------
|
---|
67 | public string Text
|
---|
68 | {
|
---|
69 | get
|
---|
70 | {
|
---|
71 | return mText;
|
---|
72 | }
|
---|
73 | set
|
---|
74 | {
|
---|
75 | mText = value;
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | #endregion
|
---|
80 |
|
---|
81 | #region Constructor
|
---|
82 | ///<summary>
|
---|
83 | ///Default constructor
|
---|
84 | ///</summary>
|
---|
85 | public LabelMaterial()
|
---|
86 | : base()
|
---|
87 | {
|
---|
88 |
|
---|
89 | }
|
---|
90 | public LabelMaterial(string text)
|
---|
91 | : this()
|
---|
92 | {
|
---|
93 | this.mText = text;
|
---|
94 | }
|
---|
95 | #endregion
|
---|
96 |
|
---|
97 | #region Methods
|
---|
98 |
|
---|
99 | // ------------------------------------------------------------------
|
---|
100 | /// <summary>
|
---|
101 | /// Calculates the min size needed to fit the text in. If there is
|
---|
102 | /// no text assigned, then 'Size.Empty' is returned.
|
---|
103 | /// </summary>
|
---|
104 | /// <param name="g">Graphics</param>
|
---|
105 | /// <returns>Size</returns>
|
---|
106 | // ------------------------------------------------------------------
|
---|
107 | public override Size CalculateMinSize(Graphics g)
|
---|
108 | {
|
---|
109 | Size minSizeNeeded = Size.Empty;
|
---|
110 |
|
---|
111 | if (mText != String.Empty)
|
---|
112 | {
|
---|
113 | minSizeNeeded = Size.Round(
|
---|
114 | g.MeasureString(mText, this.myTextStyle.Font));
|
---|
115 | }
|
---|
116 | return minSizeNeeded;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /// <summary>
|
---|
120 | /// Paints the material using the given graphics object.
|
---|
121 | /// </summary>
|
---|
122 | /// <param name="g"></param>
|
---|
123 | public override void Paint(System.Drawing.Graphics g)
|
---|
124 | {
|
---|
125 | if (!Visible) return;
|
---|
126 | //the text
|
---|
127 | if (!string.IsNullOrEmpty(Text))
|
---|
128 | {
|
---|
129 | //g.DrawRectangle(Pens.Orange, Rectangle);
|
---|
130 | StringFormat stringFormat = myTextStyle.StringFormat;
|
---|
131 | stringFormat.Trimming = StringTrimming.EllipsisWord;
|
---|
132 | stringFormat.FormatFlags = StringFormatFlags.LineLimit;
|
---|
133 |
|
---|
134 | g.DrawString(
|
---|
135 | this.myTextStyle.GetFormattedText(Text),
|
---|
136 | this.myTextStyle.Font,
|
---|
137 | myTextStyle.GetBrush(),
|
---|
138 | Rectangle,
|
---|
139 | stringFormat);
|
---|
140 | }
|
---|
141 | }
|
---|
142 | #endregion
|
---|
143 |
|
---|
144 | }
|
---|
145 | }
|
---|