1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/External/Aga.Controls/Tree/NodeControls/NodeIcon.cs Sun May 27 15:16:19 2012 +0000
1.3 @@ -0,0 +1,99 @@
1.4 +using System;
1.5 +using System.Collections.Generic;
1.6 +using System.Text;
1.7 +using System.Drawing;
1.8 +using System.Windows.Forms;
1.9 +using Aga.Controls.Properties;
1.10 +using System.ComponentModel;
1.11 +
1.12 +namespace Aga.Controls.Tree.NodeControls
1.13 +{
1.14 + public class NodeIcon : BindableControl
1.15 + {
1.16 + public NodeIcon()
1.17 + {
1.18 + LeftMargin = 1;
1.19 + }
1.20 +
1.21 + public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
1.22 + {
1.23 + Image image = GetIcon(node);
1.24 + if (image != null)
1.25 + return image.Size;
1.26 + else
1.27 + return Size.Empty;
1.28 + }
1.29 +
1.30 +
1.31 + public override void Draw(TreeNodeAdv node, DrawContext context)
1.32 + {
1.33 + Image image = GetIcon(node);
1.34 + if (image != null)
1.35 + {
1.36 + Rectangle r = GetBounds(node, context);
1.37 + if ( image.Width > 0 && image.Height > 0 )
1.38 + {
1.39 + switch (_scaleMode)
1.40 + {
1.41 + case ImageScaleMode.Fit:
1.42 + context.Graphics.DrawImage(image, r);
1.43 + break;
1.44 + case ImageScaleMode.ScaleDown:
1.45 + {
1.46 + float factor = Math.Min((float)r.Width / (float)image.Width, (float)r.Height / (float)image.Height);
1.47 + if (factor < 1)
1.48 + context.Graphics.DrawImage(image, r.X, r.Y, image.Width * factor, image.Height * factor);
1.49 + else
1.50 + context.Graphics.DrawImage(image, r.X, r.Y, image.Width, image.Height);
1.51 + } break;
1.52 + case ImageScaleMode.ScaleUp:
1.53 + {
1.54 + float factor = Math.Max((float)r.Width / (float)image.Width, (float)r.Height / (float)image.Height);
1.55 + if (factor > 1)
1.56 + context.Graphics.DrawImage(image, r.X, r.Y, image.Width * factor, image.Height * factor);
1.57 + else
1.58 + context.Graphics.DrawImage(image, r.X, r.Y, image.Width, image.Height);
1.59 + } break;
1.60 + case ImageScaleMode.AlwaysScale:
1.61 + {
1.62 + float fx = (float)r.Width / (float)image.Width;
1.63 + float fy = (float)r.Height / (float)image.Height;
1.64 + if (Math.Min(fx, fy) < 1)
1.65 + { //scale down
1.66 + float factor = Math.Min(fx, fy);
1.67 + context.Graphics.DrawImage(image, r.X, r.Y, image.Width * factor, image.Height * factor);
1.68 + }
1.69 + else if (Math.Max(fx, fy) > 1)
1.70 + {
1.71 + float factor = Math.Max(fx, fy);
1.72 + context.Graphics.DrawImage(image, r.X, r.Y, image.Width * factor, image.Height * factor);
1.73 + }
1.74 + else
1.75 + context.Graphics.DrawImage(image, r.X, r.Y, image.Width, image.Height);
1.76 + } break;
1.77 + case ImageScaleMode.Clip:
1.78 + default:
1.79 + context.Graphics.DrawImage(image, r.X, r.Y, image.Width, image.Height);
1.80 + break;
1.81 + }
1.82 + }
1.83 +
1.84 + }
1.85 + }
1.86 +
1.87 + protected virtual Image GetIcon(TreeNodeAdv node)
1.88 + {
1.89 + return GetValue(node) as Image;
1.90 + }
1.91 +
1.92 + private ImageScaleMode _scaleMode = ImageScaleMode.Clip;
1.93 + [DefaultValue("Clip"), Category("Appearance")]
1.94 + public ImageScaleMode ScaleMode
1.95 + {
1.96 + get { return _scaleMode; }
1.97 + set { _scaleMode = value; }
1.98 + }
1.99 +
1.100 +
1.101 + }
1.102 +}