1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 using System
.Collections
.Generic
;
7 using System
.Windows
.Forms
;
8 using Aga
.Controls
.Properties
;
9 using System
.ComponentModel
;
11 namespace Aga
.Controls
.Tree
.NodeControls
13 public class NodeIcon
: BindableControl
20 public override Size
MeasureSize(TreeNodeAdv node
, DrawContext context
)
22 Image image
= GetIcon(node
);
30 public override void Draw(TreeNodeAdv node
, DrawContext context
)
32 Image image
= GetIcon(node
);
35 Rectangle r
= GetBounds(node
, context
);
36 if ( image
.Width
> 0 && image
.Height
> 0 )
40 case ImageScaleMode
.Fit
:
41 context
.Graphics
.DrawImage(image
, r
);
43 case ImageScaleMode
.ScaleDown
:
45 float factor
= Math
.Min((float)r
.Width
/ (float)image
.Width
, (float)r
.Height
/ (float)image
.Height
);
47 context
.Graphics
.DrawImage(image
, r
.X
, r
.Y
, image
.Width
* factor
, image
.Height
* factor
);
49 context
.Graphics
.DrawImage(image
, r
.X
, r
.Y
, image
.Width
, image
.Height
);
51 case ImageScaleMode
.ScaleUp
:
53 float factor
= Math
.Max((float)r
.Width
/ (float)image
.Width
, (float)r
.Height
/ (float)image
.Height
);
55 context
.Graphics
.DrawImage(image
, r
.X
, r
.Y
, image
.Width
* factor
, image
.Height
* factor
);
57 context
.Graphics
.DrawImage(image
, r
.X
, r
.Y
, image
.Width
, image
.Height
);
59 case ImageScaleMode
.AlwaysScale
:
61 float fx
= (float)r
.Width
/ (float)image
.Width
;
62 float fy
= (float)r
.Height
/ (float)image
.Height
;
63 if (Math
.Min(fx
, fy
) < 1)
65 float factor
= Math
.Min(fx
, fy
);
66 context
.Graphics
.DrawImage(image
, r
.X
, r
.Y
, image
.Width
* factor
, image
.Height
* factor
);
68 else if (Math
.Max(fx
, fy
) > 1)
70 float factor
= Math
.Max(fx
, fy
);
71 context
.Graphics
.DrawImage(image
, r
.X
, r
.Y
, image
.Width
* factor
, image
.Height
* factor
);
74 context
.Graphics
.DrawImage(image
, r
.X
, r
.Y
, image
.Width
, image
.Height
);
76 case ImageScaleMode
.Clip
:
78 context
.Graphics
.DrawImage(image
, r
.X
, r
.Y
, image
.Width
, image
.Height
);
86 protected virtual Image
GetIcon(TreeNodeAdv node
)
88 return GetValue(node
) as Image
;
91 private ImageScaleMode _scaleMode
= ImageScaleMode
.Clip
;
92 [DefaultValue("Clip"), Category("Appearance")]
93 public ImageScaleMode ScaleMode
95 get { return _scaleMode; }
96 set { _scaleMode = value; }