1.1 --- a/GUI/SensorGadget.cs Tue Sep 07 18:51:42 2010 +0000
1.2 +++ b/GUI/SensorGadget.cs Tue Sep 07 22:15:02 2010 +0000
1.3 @@ -54,19 +54,22 @@
1.4 private const int leftBorder = 6;
1.5 private const int rightBorder = 6;
1.6 private const int iconSize = 11;
1.7 - private const int hardwareLineHeight = 13;
1.8 - private const int sensorLineHeight = 11;
1.9 + private const int hardwareLineHeight = 12;
1.10 + private const int sensorLineHeight = 10;
1.11
1.12 private IDictionary<IHardware, IList<ISensor>> sensors =
1.13 new SortedDictionary<IHardware, IList<ISensor>>(new HardwareComparer());
1.14
1.15 private PersistentSettings settings;
1.16 + private UserOption hardwareNames;
1.17 private UserOption alwaysOnTop;
1.18 private UserOption lockPosition;
1.19
1.20 private Font largeFont;
1.21 private Font smallFont;
1.22 - private Brush darkWhite = new SolidBrush(Color.FromArgb(0xF0, 0xF0, 0xF0));
1.23 + private Brush darkWhite;
1.24 + private StringFormat trimStringFormat;
1.25 + private StringFormat alignRightStringFormat;
1.26
1.27 public SensorGadget(IComputer computer, PersistentSettings settings,
1.28 UnitManager unitManager)
1.29 @@ -78,7 +81,14 @@
1.30
1.31 this.largeFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 7.5f,
1.32 FontStyle.Bold);
1.33 - this.smallFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 6.5f);
1.34 + this.smallFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 7.5f);
1.35 + this.darkWhite = new SolidBrush(Color.FromArgb(0xF0, 0xF0, 0xF0));
1.36 +
1.37 + this.trimStringFormat = new StringFormat();
1.38 + this.trimStringFormat.Trimming = StringTrimming.EllipsisCharacter;
1.39 +
1.40 + this.alignRightStringFormat = new StringFormat();
1.41 + this.alignRightStringFormat.Alignment = StringAlignment.Far;
1.42
1.43 this.Location = new Point(
1.44 settings.GetValue("sensorGadget.Location.X", 100),
1.45 @@ -89,6 +99,9 @@
1.46 };
1.47
1.48 ContextMenu contextMenu = new ContextMenu();
1.49 + MenuItem hardwareNamesItem = new MenuItem("Hardware Names");
1.50 + contextMenu.MenuItems.Add(hardwareNamesItem);
1.51 + contextMenu.MenuItems.Add(new MenuItem("-"));
1.52 MenuItem lockItem = new MenuItem("Lock Position");
1.53 contextMenu.MenuItems.Add(lockItem);
1.54 contextMenu.MenuItems.Add(new MenuItem("-"));
1.55 @@ -111,6 +124,13 @@
1.56 }
1.57 this.ContextMenu = contextMenu;
1.58
1.59 + hardwareNames = new UserOption("sensorGadget.Hardwarenames", true,
1.60 + hardwareNamesItem, settings);
1.61 + hardwareNames.Changed += delegate(object sender, EventArgs e) {
1.62 + Resize();
1.63 + Redraw();
1.64 + };
1.65 +
1.66 alwaysOnTop = new UserOption("sensorGadget.AlwaysOnTop", false,
1.67 alwaysOnTopItem, settings);
1.68 alwaysOnTop.Changed += delegate(object sender, EventArgs e) {
1.69 @@ -125,6 +145,26 @@
1.70 Resize();
1.71 }
1.72
1.73 + public override void Dispose() {
1.74 +
1.75 + largeFont.Dispose();
1.76 + largeFont = null;
1.77 +
1.78 + smallFont.Dispose();
1.79 + smallFont = null;
1.80 +
1.81 + darkWhite.Dispose();
1.82 + darkWhite = null;
1.83 +
1.84 + trimStringFormat.Dispose();
1.85 + trimStringFormat = null;
1.86 +
1.87 + alignRightStringFormat.Dispose();
1.88 + alignRightStringFormat = null;
1.89 +
1.90 + base.Dispose();
1.91 + }
1.92 +
1.93 private void HardwareRemoved(IHardware hardware) {
1.94 hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
1.95 hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
1.96 @@ -213,12 +253,16 @@
1.97 }
1.98
1.99 private void Resize() {
1.100 - int y = topBorder + 1;
1.101 + int y = topBorder + 1;
1.102 foreach (KeyValuePair<IHardware, IList<ISensor>> pair in sensors) {
1.103 - y += hardwareLineHeight;
1.104 + if (hardwareNames.Value) {
1.105 + if (y > topBorder + 1)
1.106 + y += 2;
1.107 + y += hardwareLineHeight;
1.108 + }
1.109 y += pair.Value.Count * sensorLineHeight;
1.110 }
1.111 - y += bottomBorder + 2;
1.112 + y += bottomBorder + 3;
1.113 y = Math.Max(y, topBorder + bottomBorder + 10);
1.114 this.Size = new Size(130, y);
1.115 }
1.116 @@ -277,25 +321,24 @@
1.117
1.118 DrawBackground(g);
1.119
1.120 - StringFormat stringFormat = new StringFormat();
1.121 - stringFormat.Alignment = StringAlignment.Far;
1.122 -
1.123 int x;
1.124 int y = topBorder + 1;
1.125 foreach (KeyValuePair<IHardware, IList<ISensor>> pair in sensors) {
1.126 - x = leftBorder + 1;
1.127 - g.DrawImage(HardwareTypeImage.Instance.GetImage(pair.Key.HardwareType),
1.128 - new Rectangle(x, y + 2, iconSize, iconSize));
1.129 - x += iconSize + 1;
1.130 - g.DrawString(pair.Key.Name, largeFont, Brushes.White,
1.131 - new Rectangle(x, y, w - rightBorder - x, 15));
1.132 - y += hardwareLineHeight;
1.133 + if (hardwareNames.Value) {
1.134 + if (y > topBorder + 1)
1.135 + y += 2;
1.136 + x = leftBorder + 1;
1.137 + g.DrawImage(HardwareTypeImage.Instance.GetImage(pair.Key.HardwareType),
1.138 + new Rectangle(x, y + 1, iconSize, iconSize));
1.139 + x += iconSize + 1;
1.140 + g.DrawString(pair.Key.Name, largeFont, Brushes.White,
1.141 + new Rectangle(x, y - 1, w - rightBorder - x, 15));
1.142 + y += hardwareLineHeight;
1.143 + }
1.144
1.145 foreach (ISensor sensor in pair.Value) {
1.146 + int restWidth;
1.147
1.148 - g.DrawString(sensor.Name + ":", smallFont, darkWhite,
1.149 - new Rectangle(9, y, 64, 15));
1.150 -
1.151 if (sensor.SensorType != SensorType.Load &&
1.152 sensor.SensorType != SensorType.Control)
1.153 {
1.154 @@ -327,14 +370,25 @@
1.155 formattedValue = string.Format(format, sensor.Value);
1.156 }
1.157
1.158 - x = 75;
1.159 + int rightMargin = 8;
1.160 g.DrawString(formattedValue, smallFont, darkWhite,
1.161 - new RectangleF(x, y, w - x - 9, 15), stringFormat);
1.162 + new RectangleF(-1, y - 1, w - rightMargin + 2, 15),
1.163 + alignRightStringFormat);
1.164 +
1.165 + restWidth = w - (int)Math.Floor(g.MeasureString(formattedValue,
1.166 + smallFont, w, StringFormat.GenericTypographic).Width) -
1.167 + rightMargin;
1.168 } else {
1.169 - x = 80;
1.170 - DrawProgress(g, x, y + 4, w - x - 9, 6, 0.01f * sensor.Value.Value);
1.171 + restWidth = 80;
1.172 + DrawProgress(g, restWidth, y + 4, w - restWidth - 9, 6,
1.173 + 0.01f * sensor.Value.Value);
1.174 }
1.175
1.176 + int leftMargin = 8;
1.177 + g.DrawString(sensor.Name, smallFont, darkWhite,
1.178 + new RectangleF(leftMargin - 1, y - 1, restWidth - leftMargin + 2,
1.179 + 15), trimStringFormat);
1.180 +
1.181 y += sensorLineHeight;
1.182 }
1.183 }