Improved the gadget formatting and added an option to remove the hardware names in the gadget.
authormoel.mich
Tue, 07 Sep 2010 22:15:02 +0000
changeset 1819901dbb25f18
parent 180 d40f49d45614
child 182 4801e9eaf979
Improved the gadget formatting and added an option to remove the hardware names in the gadget.
GUI/Gadget.cs
GUI/SensorGadget.cs
Properties/AssemblyVersion.cs
     1.1 --- a/GUI/Gadget.cs	Tue Sep 07 18:51:42 2010 +0000
     1.2 +++ b/GUI/Gadget.cs	Tue Sep 07 22:15:02 2010 +0000
     1.3 @@ -54,9 +54,8 @@
     1.4        CreateBuffer();
     1.5      }
     1.6  
     1.7 -    public void Dispose() {
     1.8 -      this.graphics.Dispose();
     1.9 -      this.buffer.Dispose();
    1.10 +    public virtual void Dispose() {
    1.11 +      DisposeBuffer();
    1.12      }
    1.13  
    1.14      public Point Location {
     2.1 --- a/GUI/SensorGadget.cs	Tue Sep 07 18:51:42 2010 +0000
     2.2 +++ b/GUI/SensorGadget.cs	Tue Sep 07 22:15:02 2010 +0000
     2.3 @@ -54,19 +54,22 @@
     2.4      private const int leftBorder = 6;
     2.5      private const int rightBorder = 6;
     2.6      private const int iconSize = 11;
     2.7 -    private const int hardwareLineHeight = 13;
     2.8 -    private const int sensorLineHeight = 11;
     2.9 +    private const int hardwareLineHeight = 12;
    2.10 +    private const int sensorLineHeight = 10;
    2.11  
    2.12      private IDictionary<IHardware, IList<ISensor>> sensors =
    2.13        new SortedDictionary<IHardware, IList<ISensor>>(new HardwareComparer());
    2.14  
    2.15      private PersistentSettings settings;
    2.16 +    private UserOption hardwareNames;
    2.17      private UserOption alwaysOnTop;
    2.18      private UserOption lockPosition;
    2.19  
    2.20      private Font largeFont;
    2.21      private Font smallFont;
    2.22 -    private Brush darkWhite = new SolidBrush(Color.FromArgb(0xF0, 0xF0, 0xF0));
    2.23 +    private Brush darkWhite;
    2.24 +    private StringFormat trimStringFormat;
    2.25 +    private StringFormat alignRightStringFormat;
    2.26  
    2.27      public SensorGadget(IComputer computer, PersistentSettings settings, 
    2.28        UnitManager unitManager) 
    2.29 @@ -78,7 +81,14 @@
    2.30  
    2.31        this.largeFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 7.5f, 
    2.32          FontStyle.Bold); 
    2.33 -      this.smallFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 6.5f);      
    2.34 +      this.smallFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 7.5f);
    2.35 +      this.darkWhite = new SolidBrush(Color.FromArgb(0xF0, 0xF0, 0xF0));
    2.36 +
    2.37 +      this.trimStringFormat = new StringFormat();
    2.38 +      this.trimStringFormat.Trimming = StringTrimming.EllipsisCharacter;
    2.39 +
    2.40 +      this.alignRightStringFormat = new StringFormat();
    2.41 +      this.alignRightStringFormat.Alignment = StringAlignment.Far;
    2.42  
    2.43        this.Location = new Point(
    2.44          settings.GetValue("sensorGadget.Location.X", 100),
    2.45 @@ -89,6 +99,9 @@
    2.46        };
    2.47        
    2.48        ContextMenu contextMenu = new ContextMenu();
    2.49 +      MenuItem hardwareNamesItem = new MenuItem("Hardware Names");
    2.50 +      contextMenu.MenuItems.Add(hardwareNamesItem);
    2.51 +      contextMenu.MenuItems.Add(new MenuItem("-"));
    2.52        MenuItem lockItem = new MenuItem("Lock Position");
    2.53        contextMenu.MenuItems.Add(lockItem);
    2.54        contextMenu.MenuItems.Add(new MenuItem("-"));
    2.55 @@ -111,6 +124,13 @@
    2.56        }
    2.57        this.ContextMenu = contextMenu;
    2.58  
    2.59 +      hardwareNames = new UserOption("sensorGadget.Hardwarenames", true,
    2.60 +        hardwareNamesItem, settings);
    2.61 +      hardwareNames.Changed += delegate(object sender, EventArgs e) {
    2.62 +        Resize();
    2.63 +        Redraw();
    2.64 +      };
    2.65 +
    2.66        alwaysOnTop = new UserOption("sensorGadget.AlwaysOnTop", false, 
    2.67          alwaysOnTopItem, settings);
    2.68        alwaysOnTop.Changed += delegate(object sender, EventArgs e) {
    2.69 @@ -125,6 +145,26 @@
    2.70        Resize();
    2.71      }
    2.72  
    2.73 +    public override void Dispose() {
    2.74 +
    2.75 +      largeFont.Dispose();
    2.76 +      largeFont = null;
    2.77 +
    2.78 +      smallFont.Dispose();
    2.79 +      smallFont = null;
    2.80 +
    2.81 +      darkWhite.Dispose();
    2.82 +      darkWhite = null;
    2.83 +
    2.84 +      trimStringFormat.Dispose();
    2.85 +      trimStringFormat = null;
    2.86 +
    2.87 +      alignRightStringFormat.Dispose();
    2.88 +      alignRightStringFormat = null;      
    2.89 +
    2.90 +      base.Dispose();
    2.91 +    }
    2.92 +
    2.93      private void HardwareRemoved(IHardware hardware) {
    2.94        hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
    2.95        hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
    2.96 @@ -213,12 +253,16 @@
    2.97      }
    2.98  
    2.99      private void Resize() {
   2.100 -      int y = topBorder + 1;
   2.101 +      int y = topBorder + 1;      
   2.102        foreach (KeyValuePair<IHardware, IList<ISensor>> pair in sensors) {
   2.103 -        y += hardwareLineHeight;
   2.104 +        if (hardwareNames.Value) {
   2.105 +          if (y > topBorder + 1)
   2.106 +            y += 2;
   2.107 +          y += hardwareLineHeight;
   2.108 +        }
   2.109          y += pair.Value.Count * sensorLineHeight;
   2.110        }
   2.111 -      y += bottomBorder + 2;
   2.112 +      y += bottomBorder + 3;
   2.113        y = Math.Max(y, topBorder + bottomBorder + 10);
   2.114        this.Size = new Size(130, y);
   2.115      }
   2.116 @@ -277,25 +321,24 @@
   2.117  
   2.118        DrawBackground(g);
   2.119  
   2.120 -      StringFormat stringFormat = new StringFormat();
   2.121 -      stringFormat.Alignment = StringAlignment.Far;
   2.122 -
   2.123        int x;
   2.124        int y = topBorder + 1;
   2.125        foreach (KeyValuePair<IHardware, IList<ISensor>> pair in sensors) {
   2.126 -        x = leftBorder + 1;
   2.127 -        g.DrawImage(HardwareTypeImage.Instance.GetImage(pair.Key.HardwareType),
   2.128 -          new Rectangle(x, y + 2, iconSize, iconSize));
   2.129 -        x += iconSize + 1;
   2.130 -        g.DrawString(pair.Key.Name, largeFont, Brushes.White,
   2.131 -          new Rectangle(x, y, w - rightBorder - x, 15));
   2.132 -        y += hardwareLineHeight;
   2.133 +        if (hardwareNames.Value) {
   2.134 +          if (y > topBorder + 1)
   2.135 +            y += 2;
   2.136 +          x = leftBorder + 1;
   2.137 +          g.DrawImage(HardwareTypeImage.Instance.GetImage(pair.Key.HardwareType),
   2.138 +            new Rectangle(x, y + 1, iconSize, iconSize));
   2.139 +          x += iconSize + 1;
   2.140 +          g.DrawString(pair.Key.Name, largeFont, Brushes.White,
   2.141 +            new Rectangle(x, y - 1, w - rightBorder - x, 15));
   2.142 +          y += hardwareLineHeight;
   2.143 +        }
   2.144  
   2.145          foreach (ISensor sensor in pair.Value) {
   2.146 +          int restWidth;
   2.147  
   2.148 -          g.DrawString(sensor.Name + ":", smallFont, darkWhite,
   2.149 -            new Rectangle(9, y, 64, 15));
   2.150 -          
   2.151            if (sensor.SensorType != SensorType.Load && 
   2.152              sensor.SensorType != SensorType.Control) 
   2.153            {
   2.154 @@ -327,14 +370,25 @@
   2.155                formattedValue = string.Format(format, sensor.Value);
   2.156              }
   2.157  
   2.158 -            x = 75;
   2.159 +            int rightMargin = 8;
   2.160              g.DrawString(formattedValue, smallFont, darkWhite,
   2.161 -              new RectangleF(x, y, w - x - 9, 15), stringFormat);            
   2.162 +              new RectangleF(-1, y - 1, w - rightMargin + 2, 15), 
   2.163 +              alignRightStringFormat);
   2.164 +
   2.165 +            restWidth = w - (int)Math.Floor(g.MeasureString(formattedValue,
   2.166 +              smallFont, w, StringFormat.GenericTypographic).Width) - 
   2.167 +              rightMargin;
   2.168            } else {
   2.169 -            x = 80;
   2.170 -            DrawProgress(g, x, y + 4, w - x - 9, 6, 0.01f * sensor.Value.Value);
   2.171 +            restWidth = 80;
   2.172 +            DrawProgress(g, restWidth, y + 4, w - restWidth - 9, 6, 
   2.173 +              0.01f * sensor.Value.Value);
   2.174            }
   2.175  
   2.176 +          int leftMargin = 8;
   2.177 +          g.DrawString(sensor.Name, smallFont, darkWhite,
   2.178 +            new RectangleF(leftMargin - 1, y - 1, restWidth - leftMargin + 2, 
   2.179 +            15), trimStringFormat);
   2.180 +
   2.181            y += sensorLineHeight;
   2.182          }
   2.183        }
     3.1 --- a/Properties/AssemblyVersion.cs	Tue Sep 07 18:51:42 2010 +0000
     3.2 +++ b/Properties/AssemblyVersion.cs	Tue Sep 07 22:15:02 2010 +0000
     3.3 @@ -38,5 +38,5 @@
     3.4  using System;
     3.5  using System.Reflection;
     3.6  
     3.7 -[assembly: AssemblyVersion("0.1.37.11")]
     3.8 -[assembly: AssemblyFileVersion("0.1.37.11")]
     3.9 +[assembly: AssemblyVersion("0.1.37.12")]
    3.10 +[assembly: AssemblyFileVersion("0.1.37.12")]