1 | using System.Drawing;
|
---|
2 | using System.Drawing.Drawing2D;
|
---|
3 | namespace Netron.Diagramming.Core {
|
---|
4 | /// <summary>
|
---|
5 | /// Icon shape material without <see cref="IMouseListener"/> service.
|
---|
6 | /// <seealso cref="ClickableIconMaterial"/>
|
---|
7 | /// </summary>
|
---|
8 | public partial class IconMaterial : ShapeMaterialBase {
|
---|
9 | #region Fields
|
---|
10 |
|
---|
11 | // ------------------------------------------------------------------
|
---|
12 | /// <summary>
|
---|
13 | /// Implementation of IVersion - the current version of
|
---|
14 | /// IconMaterial.
|
---|
15 | /// </summary>
|
---|
16 | // ------------------------------------------------------------------
|
---|
17 | protected double iconMaterialVersion = 1.0;
|
---|
18 |
|
---|
19 | // ------------------------------------------------------------------
|
---|
20 | /// <summary>
|
---|
21 | /// the Text field
|
---|
22 | /// </summary>
|
---|
23 | // ------------------------------------------------------------------
|
---|
24 | private Bitmap mIcon;
|
---|
25 |
|
---|
26 | #endregion
|
---|
27 |
|
---|
28 | #region Properties
|
---|
29 |
|
---|
30 | // ------------------------------------------------------------------
|
---|
31 | /// <summary>
|
---|
32 | /// Gets the current version.
|
---|
33 | /// </summary>
|
---|
34 | // ------------------------------------------------------------------
|
---|
35 | public override double Version {
|
---|
36 | get {
|
---|
37 | return iconMaterialVersion;
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | // ------------------------------------------------------------------
|
---|
42 | /// <summary>
|
---|
43 | /// Gets or sets the Text
|
---|
44 | /// </summary>
|
---|
45 | // ------------------------------------------------------------------
|
---|
46 | public Bitmap Icon {
|
---|
47 | get {
|
---|
48 | return mIcon;
|
---|
49 | }
|
---|
50 | set {
|
---|
51 | mIcon = value;
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | #endregion
|
---|
56 |
|
---|
57 | #region Constructor
|
---|
58 | /// <summary>
|
---|
59 | /// Initializes a new instance of the <see cref="IconMaterial"/> class.
|
---|
60 | /// </summary>
|
---|
61 | /// <param name="resourceLocation">The resource location.</param>
|
---|
62 | public IconMaterial(string resourceLocation)
|
---|
63 | : base() {
|
---|
64 |
|
---|
65 | mIcon = GetBitmap(resourceLocation);
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected Bitmap GetBitmap(string resourceLocation) {
|
---|
69 | if (resourceLocation.Length == 0)
|
---|
70 | throw new InconsistencyException("Invalid icon specification.");
|
---|
71 | try {
|
---|
72 | return new Bitmap(this.GetType(), resourceLocation);
|
---|
73 | }
|
---|
74 | catch {
|
---|
75 |
|
---|
76 | throw;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | public IconMaterial()
|
---|
80 | : base() {
|
---|
81 | }
|
---|
82 |
|
---|
83 | #endregion
|
---|
84 |
|
---|
85 | #region Methods
|
---|
86 |
|
---|
87 | // ------------------------------------------------------------------
|
---|
88 | /// <summary>
|
---|
89 | /// Calculates the min size needed to fit this material in. The
|
---|
90 | /// min size is determined by the size of the icon used. If there
|
---|
91 | /// isn't an icon specified, then 'Size.Empty' is returned.
|
---|
92 | /// </summary>
|
---|
93 | /// <param name="g">Graphics</param>
|
---|
94 | /// <returns>Size</returns>
|
---|
95 | // ------------------------------------------------------------------
|
---|
96 | public override Size CalculateMinSize(Graphics g) {
|
---|
97 | Size minSizeNeeded = Size.Empty;
|
---|
98 |
|
---|
99 | if (mIcon != null) {
|
---|
100 | minSizeNeeded = new Size(mIcon.Width, mIcon.Height);
|
---|
101 | }
|
---|
102 | return minSizeNeeded;
|
---|
103 | }
|
---|
104 |
|
---|
105 | /// <summary>
|
---|
106 | /// Paints the entity using the given graphics object
|
---|
107 | /// </summary>
|
---|
108 | /// <param name="g"></param>
|
---|
109 | public override void Paint(Graphics g) {
|
---|
110 | if (!Visible)
|
---|
111 | return;
|
---|
112 |
|
---|
113 | if (mIcon != null) {
|
---|
114 | GraphicsContainer cto = g.BeginContainer();
|
---|
115 | g.SetClip(Shape.Rectangle);
|
---|
116 | g.DrawImage(mIcon, Rectangle);
|
---|
117 | g.EndContainer(cto);
|
---|
118 | }
|
---|
119 | }
|
---|
120 | #endregion
|
---|
121 |
|
---|
122 | }
|
---|
123 | }
|
---|