mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-09-03 15:55:26 +00:00
Improved the gadget formatting and added an option to remove the hardware names in the gadget.
This commit is contained in:
@@ -54,9 +54,8 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
CreateBuffer();
|
CreateBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() {
|
public virtual void Dispose() {
|
||||||
this.graphics.Dispose();
|
DisposeBuffer();
|
||||||
this.buffer.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point Location {
|
public Point Location {
|
||||||
|
@@ -54,19 +54,22 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
private const int leftBorder = 6;
|
private const int leftBorder = 6;
|
||||||
private const int rightBorder = 6;
|
private const int rightBorder = 6;
|
||||||
private const int iconSize = 11;
|
private const int iconSize = 11;
|
||||||
private const int hardwareLineHeight = 13;
|
private const int hardwareLineHeight = 12;
|
||||||
private const int sensorLineHeight = 11;
|
private const int sensorLineHeight = 10;
|
||||||
|
|
||||||
private IDictionary<IHardware, IList<ISensor>> sensors =
|
private IDictionary<IHardware, IList<ISensor>> sensors =
|
||||||
new SortedDictionary<IHardware, IList<ISensor>>(new HardwareComparer());
|
new SortedDictionary<IHardware, IList<ISensor>>(new HardwareComparer());
|
||||||
|
|
||||||
private PersistentSettings settings;
|
private PersistentSettings settings;
|
||||||
|
private UserOption hardwareNames;
|
||||||
private UserOption alwaysOnTop;
|
private UserOption alwaysOnTop;
|
||||||
private UserOption lockPosition;
|
private UserOption lockPosition;
|
||||||
|
|
||||||
private Font largeFont;
|
private Font largeFont;
|
||||||
private Font smallFont;
|
private Font smallFont;
|
||||||
private Brush darkWhite = new SolidBrush(Color.FromArgb(0xF0, 0xF0, 0xF0));
|
private Brush darkWhite;
|
||||||
|
private StringFormat trimStringFormat;
|
||||||
|
private StringFormat alignRightStringFormat;
|
||||||
|
|
||||||
public SensorGadget(IComputer computer, PersistentSettings settings,
|
public SensorGadget(IComputer computer, PersistentSettings settings,
|
||||||
UnitManager unitManager)
|
UnitManager unitManager)
|
||||||
@@ -78,7 +81,14 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
|
|
||||||
this.largeFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 7.5f,
|
this.largeFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 7.5f,
|
||||||
FontStyle.Bold);
|
FontStyle.Bold);
|
||||||
this.smallFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 6.5f);
|
this.smallFont = new Font(SystemFonts.MessageBoxFont.FontFamily, 7.5f);
|
||||||
|
this.darkWhite = new SolidBrush(Color.FromArgb(0xF0, 0xF0, 0xF0));
|
||||||
|
|
||||||
|
this.trimStringFormat = new StringFormat();
|
||||||
|
this.trimStringFormat.Trimming = StringTrimming.EllipsisCharacter;
|
||||||
|
|
||||||
|
this.alignRightStringFormat = new StringFormat();
|
||||||
|
this.alignRightStringFormat.Alignment = StringAlignment.Far;
|
||||||
|
|
||||||
this.Location = new Point(
|
this.Location = new Point(
|
||||||
settings.GetValue("sensorGadget.Location.X", 100),
|
settings.GetValue("sensorGadget.Location.X", 100),
|
||||||
@@ -89,6 +99,9 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ContextMenu contextMenu = new ContextMenu();
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
|
MenuItem hardwareNamesItem = new MenuItem("Hardware Names");
|
||||||
|
contextMenu.MenuItems.Add(hardwareNamesItem);
|
||||||
|
contextMenu.MenuItems.Add(new MenuItem("-"));
|
||||||
MenuItem lockItem = new MenuItem("Lock Position");
|
MenuItem lockItem = new MenuItem("Lock Position");
|
||||||
contextMenu.MenuItems.Add(lockItem);
|
contextMenu.MenuItems.Add(lockItem);
|
||||||
contextMenu.MenuItems.Add(new MenuItem("-"));
|
contextMenu.MenuItems.Add(new MenuItem("-"));
|
||||||
@@ -111,6 +124,13 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
}
|
}
|
||||||
this.ContextMenu = contextMenu;
|
this.ContextMenu = contextMenu;
|
||||||
|
|
||||||
|
hardwareNames = new UserOption("sensorGadget.Hardwarenames", true,
|
||||||
|
hardwareNamesItem, settings);
|
||||||
|
hardwareNames.Changed += delegate(object sender, EventArgs e) {
|
||||||
|
Resize();
|
||||||
|
Redraw();
|
||||||
|
};
|
||||||
|
|
||||||
alwaysOnTop = new UserOption("sensorGadget.AlwaysOnTop", false,
|
alwaysOnTop = new UserOption("sensorGadget.AlwaysOnTop", false,
|
||||||
alwaysOnTopItem, settings);
|
alwaysOnTopItem, settings);
|
||||||
alwaysOnTop.Changed += delegate(object sender, EventArgs e) {
|
alwaysOnTop.Changed += delegate(object sender, EventArgs e) {
|
||||||
@@ -125,6 +145,26 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
Resize();
|
Resize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Dispose() {
|
||||||
|
|
||||||
|
largeFont.Dispose();
|
||||||
|
largeFont = null;
|
||||||
|
|
||||||
|
smallFont.Dispose();
|
||||||
|
smallFont = null;
|
||||||
|
|
||||||
|
darkWhite.Dispose();
|
||||||
|
darkWhite = null;
|
||||||
|
|
||||||
|
trimStringFormat.Dispose();
|
||||||
|
trimStringFormat = null;
|
||||||
|
|
||||||
|
alignRightStringFormat.Dispose();
|
||||||
|
alignRightStringFormat = null;
|
||||||
|
|
||||||
|
base.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void HardwareRemoved(IHardware hardware) {
|
private void HardwareRemoved(IHardware hardware) {
|
||||||
hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
|
hardware.SensorAdded -= new SensorEventHandler(SensorAdded);
|
||||||
hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
|
hardware.SensorRemoved -= new SensorEventHandler(SensorRemoved);
|
||||||
@@ -215,10 +255,14 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
private void Resize() {
|
private void Resize() {
|
||||||
int y = topBorder + 1;
|
int y = topBorder + 1;
|
||||||
foreach (KeyValuePair<IHardware, IList<ISensor>> pair in sensors) {
|
foreach (KeyValuePair<IHardware, IList<ISensor>> pair in sensors) {
|
||||||
|
if (hardwareNames.Value) {
|
||||||
|
if (y > topBorder + 1)
|
||||||
|
y += 2;
|
||||||
y += hardwareLineHeight;
|
y += hardwareLineHeight;
|
||||||
|
}
|
||||||
y += pair.Value.Count * sensorLineHeight;
|
y += pair.Value.Count * sensorLineHeight;
|
||||||
}
|
}
|
||||||
y += bottomBorder + 2;
|
y += bottomBorder + 3;
|
||||||
y = Math.Max(y, topBorder + bottomBorder + 10);
|
y = Math.Max(y, topBorder + bottomBorder + 10);
|
||||||
this.Size = new Size(130, y);
|
this.Size = new Size(130, y);
|
||||||
}
|
}
|
||||||
@@ -277,24 +321,23 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
|
|
||||||
DrawBackground(g);
|
DrawBackground(g);
|
||||||
|
|
||||||
StringFormat stringFormat = new StringFormat();
|
|
||||||
stringFormat.Alignment = StringAlignment.Far;
|
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
int y = topBorder + 1;
|
int y = topBorder + 1;
|
||||||
foreach (KeyValuePair<IHardware, IList<ISensor>> pair in sensors) {
|
foreach (KeyValuePair<IHardware, IList<ISensor>> pair in sensors) {
|
||||||
|
if (hardwareNames.Value) {
|
||||||
|
if (y > topBorder + 1)
|
||||||
|
y += 2;
|
||||||
x = leftBorder + 1;
|
x = leftBorder + 1;
|
||||||
g.DrawImage(HardwareTypeImage.Instance.GetImage(pair.Key.HardwareType),
|
g.DrawImage(HardwareTypeImage.Instance.GetImage(pair.Key.HardwareType),
|
||||||
new Rectangle(x, y + 2, iconSize, iconSize));
|
new Rectangle(x, y + 1, iconSize, iconSize));
|
||||||
x += iconSize + 1;
|
x += iconSize + 1;
|
||||||
g.DrawString(pair.Key.Name, largeFont, Brushes.White,
|
g.DrawString(pair.Key.Name, largeFont, Brushes.White,
|
||||||
new Rectangle(x, y, w - rightBorder - x, 15));
|
new Rectangle(x, y - 1, w - rightBorder - x, 15));
|
||||||
y += hardwareLineHeight;
|
y += hardwareLineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (ISensor sensor in pair.Value) {
|
foreach (ISensor sensor in pair.Value) {
|
||||||
|
int restWidth;
|
||||||
g.DrawString(sensor.Name + ":", smallFont, darkWhite,
|
|
||||||
new Rectangle(9, y, 64, 15));
|
|
||||||
|
|
||||||
if (sensor.SensorType != SensorType.Load &&
|
if (sensor.SensorType != SensorType.Load &&
|
||||||
sensor.SensorType != SensorType.Control)
|
sensor.SensorType != SensorType.Control)
|
||||||
@@ -327,14 +370,25 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
formattedValue = string.Format(format, sensor.Value);
|
formattedValue = string.Format(format, sensor.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
x = 75;
|
int rightMargin = 8;
|
||||||
g.DrawString(formattedValue, smallFont, darkWhite,
|
g.DrawString(formattedValue, smallFont, darkWhite,
|
||||||
new RectangleF(x, y, w - x - 9, 15), stringFormat);
|
new RectangleF(-1, y - 1, w - rightMargin + 2, 15),
|
||||||
|
alignRightStringFormat);
|
||||||
|
|
||||||
|
restWidth = w - (int)Math.Floor(g.MeasureString(formattedValue,
|
||||||
|
smallFont, w, StringFormat.GenericTypographic).Width) -
|
||||||
|
rightMargin;
|
||||||
} else {
|
} else {
|
||||||
x = 80;
|
restWidth = 80;
|
||||||
DrawProgress(g, x, y + 4, w - x - 9, 6, 0.01f * sensor.Value.Value);
|
DrawProgress(g, restWidth, y + 4, w - restWidth - 9, 6,
|
||||||
|
0.01f * sensor.Value.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int leftMargin = 8;
|
||||||
|
g.DrawString(sensor.Name, smallFont, darkWhite,
|
||||||
|
new RectangleF(leftMargin - 1, y - 1, restWidth - leftMargin + 2,
|
||||||
|
15), trimStringFormat);
|
||||||
|
|
||||||
y += sensorLineHeight;
|
y += sensorLineHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,5 +38,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
[assembly: AssemblyVersion("0.1.37.11")]
|
[assembly: AssemblyVersion("0.1.37.12")]
|
||||||
[assembly: AssemblyFileVersion("0.1.37.11")]
|
[assembly: AssemblyFileVersion("0.1.37.12")]
|
||||||
|
Reference in New Issue
Block a user