using System.Drawing;
using System.Drawing.Drawing2D;
namespace Netron.Diagramming.Core {
///
/// Icon shape material without service.
///
///
public partial class IconMaterial : ShapeMaterialBase {
#region Fields
// ------------------------------------------------------------------
///
/// Implementation of IVersion - the current version of
/// IconMaterial.
///
// ------------------------------------------------------------------
protected double iconMaterialVersion = 1.0;
// ------------------------------------------------------------------
///
/// the Text field
///
// ------------------------------------------------------------------
private Bitmap mIcon;
#endregion
#region Properties
// ------------------------------------------------------------------
///
/// Gets the current version.
///
// ------------------------------------------------------------------
public override double Version {
get {
return iconMaterialVersion;
}
}
// ------------------------------------------------------------------
///
/// Gets or sets the Text
///
// ------------------------------------------------------------------
public Bitmap Icon {
get {
return mIcon;
}
set {
mIcon = value;
}
}
#endregion
#region Constructor
///
/// Initializes a new instance of the class.
///
/// The resource location.
public IconMaterial(string resourceLocation)
: base() {
mIcon = GetBitmap(resourceLocation);
}
protected Bitmap GetBitmap(string resourceLocation) {
if (resourceLocation.Length == 0)
throw new InconsistencyException("Invalid icon specification.");
try {
return new Bitmap(this.GetType(), resourceLocation);
}
catch {
throw;
}
}
public IconMaterial()
: base() {
}
#endregion
#region Methods
// ------------------------------------------------------------------
///
/// Calculates the min size needed to fit this material in. The
/// min size is determined by the size of the icon used. If there
/// isn't an icon specified, then 'Size.Empty' is returned.
///
/// Graphics
/// Size
// ------------------------------------------------------------------
public override Size CalculateMinSize(Graphics g) {
Size minSizeNeeded = Size.Empty;
if (mIcon != null) {
minSizeNeeded = new Size(mIcon.Width, mIcon.Height);
}
return minSizeNeeded;
}
///
/// Paints the entity using the given graphics object
///
///
public override void Paint(Graphics g) {
if (!Visible)
return;
if (mIcon != null) {
GraphicsContainer cto = g.BeginContainer();
g.SetClip(Shape.Rectangle);
g.DrawImage(mIcon, Rectangle);
g.EndContainer(cto);
}
}
#endregion
}
}