!B (Sandbox) (CE-21795) Importing models with multisubmaterials via fbx switches...
[CRYENGINE.git] / Code / Tools / LuaRemoteDebugger / Aga.Controls / Tree / NodeControls / NodeIcon.cs
blob4b578733f5dfcafa05de379885ce8cb4b21cd51e
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 using System;
4 using System.Collections.Generic;
5 using System.Text;
6 using System.Drawing;
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
15 public NodeIcon()
17 LeftMargin = 1;
20 public override Size MeasureSize(TreeNodeAdv node, DrawContext context)
22 Image image = GetIcon(node);
23 if (image != null)
24 return image.Size;
25 else
26 return Size.Empty;
30 public override void Draw(TreeNodeAdv node, DrawContext context)
32 Image image = GetIcon(node);
33 if (image != null)
35 Rectangle r = GetBounds(node, context);
36 if ( image.Width > 0 && image.Height > 0 )
38 switch (_scaleMode)
40 case ImageScaleMode.Fit:
41 context.Graphics.DrawImage(image, r);
42 break;
43 case ImageScaleMode.ScaleDown:
45 float factor = Math.Min((float)r.Width / (float)image.Width, (float)r.Height / (float)image.Height);
46 if (factor < 1)
47 context.Graphics.DrawImage(image, r.X, r.Y, image.Width * factor, image.Height * factor);
48 else
49 context.Graphics.DrawImage(image, r.X, r.Y, image.Width, image.Height);
50 } break;
51 case ImageScaleMode.ScaleUp:
53 float factor = Math.Max((float)r.Width / (float)image.Width, (float)r.Height / (float)image.Height);
54 if (factor > 1)
55 context.Graphics.DrawImage(image, r.X, r.Y, image.Width * factor, image.Height * factor);
56 else
57 context.Graphics.DrawImage(image, r.X, r.Y, image.Width, image.Height);
58 } break;
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)
64 { //scale down
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);
73 else
74 context.Graphics.DrawImage(image, r.X, r.Y, image.Width, image.Height);
75 } break;
76 case ImageScaleMode.Clip:
77 default:
78 context.Graphics.DrawImage(image, r.X, r.Y, image.Width, image.Height);
79 break;
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; }