Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Diagram elements/Materials/IconMaterial.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 3.4 KB
Line 
1using System.Drawing;
2using System.Drawing.Drawing2D;
3namespace 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}
Note: See TracBrowser for help on using the repository browser.