From 9479c08df9f0ee1e4d4b34a1a9715c5f7f6136f9 Mon Sep 17 00:00:00 2001 From: shrddr Date: Wed, 13 Jul 2016 21:17:01 +0300 Subject: [PATCH 1/2] Added customizable pen colors New node property, penColor, is null by default; this means that color will be picked using the existing plotColorPalette method. New node context menu item, Pen color, lets user choose the color to be used when plotting this particular node. This property is also saved/loaded from settings based on sensor identifier. --- GUI/HardwareNode.cs | 2 ++ GUI/MainForm.Designer.cs | 2 ++ GUI/MainForm.cs | 27 ++++++++++++++++++++++++--- GUI/MainForm.resx | 3 +++ GUI/SensorNode.cs | 4 +++- OpenHardwareMonitor.csproj | 1 + 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/GUI/HardwareNode.cs b/GUI/HardwareNode.cs index a68289e..0e2e463 100644 --- a/GUI/HardwareNode.cs +++ b/GUI/HardwareNode.cs @@ -89,6 +89,8 @@ namespace OpenHardwareMonitor.GUI { ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index) i++; SensorNode sensorNode = new SensorNode(sensor, settings, unitManager); + if (settings.Contains(sensor.Identifier + "/PenColor")) + sensorNode.penColor = settings.GetValue(sensor.Identifier + "/PenColor", Color.Black); sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged; node.Nodes.Insert(i, sensorNode); } diff --git a/GUI/MainForm.Designer.cs b/GUI/MainForm.Designer.cs index f602030..ffc345e 100644 --- a/GUI/MainForm.Designer.cs +++ b/GUI/MainForm.Designer.cs @@ -111,6 +111,7 @@ namespace OpenHardwareMonitor.GUI { this.log1hMenuItem = new System.Windows.Forms.MenuItem(); this.log2hMenuItem = new System.Windows.Forms.MenuItem(); this.log6hMenuItem = new System.Windows.Forms.MenuItem(); + this.colorDialog = new System.Windows.Forms.ColorDialog(); this.splitContainer.Panel1.SuspendLayout(); this.splitContainer.SuspendLayout(); this.SuspendLayout(); @@ -762,6 +763,7 @@ namespace OpenHardwareMonitor.GUI { private System.Windows.Forms.MenuItem log1hMenuItem; private System.Windows.Forms.MenuItem log2hMenuItem; private System.Windows.Forms.MenuItem log6hMenuItem; + private System.Windows.Forms.ColorDialog colorDialog; } } diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 7f11cca..bee6263 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -494,8 +494,10 @@ namespace OpenHardwareMonitor.GUI { SensorNode sensorNode = node.Tag as SensorNode; if (sensorNode != null) { if (sensorNode.Plot) { - colors.Add(sensorNode.Sensor, - plotColorPalette[colorIndex % plotColorPalette.Length]); + if (sensorNode.penColor == null) { + colors.Add(sensorNode.Sensor, + plotColorPalette[colorIndex % plotColorPalette.Length]); + } selected.Add(sensorNode.Sensor); } colorIndex++; @@ -509,6 +511,7 @@ namespace OpenHardwareMonitor.GUI { // from the plot var usedColors = new List(); foreach (var curSelectedSensor in selected) { + if (!colors.ContainsKey(curSelectedSensor)) continue; var curColor = colors[curSelectedSensor]; if (usedColors.Contains(curColor)) { foreach (var potentialNewColor in plotColorPalette) { @@ -521,7 +524,13 @@ namespace OpenHardwareMonitor.GUI { } else { usedColors.Add(curColor); } - } + } + + foreach (TreeNodeAdv node in treeView.AllNodes) { + SensorNode sensorNode = node.Tag as SensorNode; + if (sensorNode != null && sensorNode.Plot && sensorNode.penColor != null) + colors.Add(sensorNode.Sensor, sensorNode.penColor.Value); + } sensorPlotColors = colors; plotPanel.SetSensors(selected, colors); @@ -673,6 +682,18 @@ namespace OpenHardwareMonitor.GUI { treeContextMenu.MenuItems.Add(item); } treeContextMenu.MenuItems.Add(new MenuItem("-")); + { + MenuItem item = new MenuItem("Pen color"); + item.Click += delegate(object obj, EventArgs args) { + colorDialog.Color = node.penColor.GetValueOrDefault(); + if (colorDialog.ShowDialog() == DialogResult.OK) { + node.penColor = colorDialog.Color; + settings.SetValue(node.Sensor.Identifier + "/PenColor", colorDialog.Color); + PlotSelectionChanged(this, null); + } + }; + treeContextMenu.MenuItems.Add(item); + } { MenuItem item = new MenuItem("Show in Tray"); item.Checked = systemTray.Contains(node.Sensor); diff --git a/GUI/MainForm.resx b/GUI/MainForm.resx index 9cb27cf..1a380ff 100644 --- a/GUI/MainForm.resx +++ b/GUI/MainForm.resx @@ -129,6 +129,9 @@ 293, 17 + + 483, 17 + diff --git a/GUI/SensorNode.cs b/GUI/SensorNode.cs index 876ccba..7493b8b 100644 --- a/GUI/SensorNode.cs +++ b/GUI/SensorNode.cs @@ -9,6 +9,7 @@ */ using System; +using System.Drawing; using System.Collections.Generic; using OpenHardwareMonitor.Hardware; using OpenHardwareMonitor.Utilities; @@ -20,7 +21,8 @@ namespace OpenHardwareMonitor.GUI { private PersistentSettings settings; private UnitManager unitManager; private string format; - private bool plot = false; + private bool plot = false; + public Color? penColor = null; public string ValueToString(float? value) { if (value.HasValue) { diff --git a/OpenHardwareMonitor.csproj b/OpenHardwareMonitor.csproj index 35e749b..68a994c 100644 --- a/OpenHardwareMonitor.csproj +++ b/OpenHardwareMonitor.csproj @@ -66,6 +66,7 @@ + From bb45f65447ecd3acdf6fbf4386c5132483dd54b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=B6ller?= Date: Sun, 6 Nov 2016 14:51:24 +0100 Subject: [PATCH 2/2] Added a menu item to reset the pen color (to use again the plotColorPalette based color). Moved the saving/loading code to the SensorNode class (as with the other properties). --- GUI/HardwareNode.cs | 2 -- GUI/MainForm.Designer.cs | 2 -- GUI/MainForm.cs | 26 ++++++++++++++++---------- GUI/MainForm.resx | 3 --- GUI/SensorNode.cs | 24 ++++++++++++++++++++++-- OpenHardwareMonitor.csproj | 1 - 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/GUI/HardwareNode.cs b/GUI/HardwareNode.cs index 0e2e463..a68289e 100644 --- a/GUI/HardwareNode.cs +++ b/GUI/HardwareNode.cs @@ -89,8 +89,6 @@ namespace OpenHardwareMonitor.GUI { ((SensorNode)node.Nodes[i]).Sensor.Index < sensor.Index) i++; SensorNode sensorNode = new SensorNode(sensor, settings, unitManager); - if (settings.Contains(sensor.Identifier + "/PenColor")) - sensorNode.penColor = settings.GetValue(sensor.Identifier + "/PenColor", Color.Black); sensorNode.PlotSelectionChanged += SensorPlotSelectionChanged; node.Nodes.Insert(i, sensorNode); } diff --git a/GUI/MainForm.Designer.cs b/GUI/MainForm.Designer.cs index ffc345e..f602030 100644 --- a/GUI/MainForm.Designer.cs +++ b/GUI/MainForm.Designer.cs @@ -111,7 +111,6 @@ namespace OpenHardwareMonitor.GUI { this.log1hMenuItem = new System.Windows.Forms.MenuItem(); this.log2hMenuItem = new System.Windows.Forms.MenuItem(); this.log6hMenuItem = new System.Windows.Forms.MenuItem(); - this.colorDialog = new System.Windows.Forms.ColorDialog(); this.splitContainer.Panel1.SuspendLayout(); this.splitContainer.SuspendLayout(); this.SuspendLayout(); @@ -763,7 +762,6 @@ namespace OpenHardwareMonitor.GUI { private System.Windows.Forms.MenuItem log1hMenuItem; private System.Windows.Forms.MenuItem log2hMenuItem; private System.Windows.Forms.MenuItem log6hMenuItem; - private System.Windows.Forms.ColorDialog colorDialog; } } diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index bee6263..9340faf 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -494,7 +494,7 @@ namespace OpenHardwareMonitor.GUI { SensorNode sensorNode = node.Tag as SensorNode; if (sensorNode != null) { if (sensorNode.Plot) { - if (sensorNode.penColor == null) { + if (!sensorNode.PenColor.HasValue) { colors.Add(sensorNode.Sensor, plotColorPalette[colorIndex % plotColorPalette.Length]); } @@ -528,8 +528,8 @@ namespace OpenHardwareMonitor.GUI { foreach (TreeNodeAdv node in treeView.AllNodes) { SensorNode sensorNode = node.Tag as SensorNode; - if (sensorNode != null && sensorNode.Plot && sensorNode.penColor != null) - colors.Add(sensorNode.Sensor, sensorNode.penColor.Value); + if (sensorNode != null && sensorNode.Plot && sensorNode.PenColor.HasValue) + colors.Add(sensorNode.Sensor, sensorNode.PenColor.Value); } sensorPlotColors = colors; @@ -683,17 +683,23 @@ namespace OpenHardwareMonitor.GUI { } treeContextMenu.MenuItems.Add(new MenuItem("-")); { - MenuItem item = new MenuItem("Pen color"); + MenuItem item = new MenuItem("Pen Color..."); item.Click += delegate(object obj, EventArgs args) { - colorDialog.Color = node.penColor.GetValueOrDefault(); - if (colorDialog.ShowDialog() == DialogResult.OK) { - node.penColor = colorDialog.Color; - settings.SetValue(node.Sensor.Identifier + "/PenColor", colorDialog.Color); - PlotSelectionChanged(this, null); - } + ColorDialog dialog = new ColorDialog(); + dialog.Color = node.PenColor.GetValueOrDefault(); + if (dialog.ShowDialog() == DialogResult.OK) + node.PenColor = dialog.Color; }; treeContextMenu.MenuItems.Add(item); } + { + MenuItem item = new MenuItem("Reset Pen Color"); + item.Click += delegate(object obj, EventArgs args) { + node.PenColor = null; + }; + treeContextMenu.MenuItems.Add(item); + } + treeContextMenu.MenuItems.Add(new MenuItem("-")); { MenuItem item = new MenuItem("Show in Tray"); item.Checked = systemTray.Contains(node.Sensor); diff --git a/GUI/MainForm.resx b/GUI/MainForm.resx index 1a380ff..9cb27cf 100644 --- a/GUI/MainForm.resx +++ b/GUI/MainForm.resx @@ -129,9 +129,6 @@ 293, 17 - - 483, 17 - diff --git a/GUI/SensorNode.cs b/GUI/SensorNode.cs index 7493b8b..a4fdc99 100644 --- a/GUI/SensorNode.cs +++ b/GUI/SensorNode.cs @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2012 Michael Möller + Copyright (C) 2009-2016 Michael Möller */ @@ -22,7 +22,7 @@ namespace OpenHardwareMonitor.GUI { private UnitManager unitManager; private string format; private bool plot = false; - public Color? penColor = null; + private Color? penColor = null; public string ValueToString(float? value) { if (value.HasValue) { @@ -61,6 +61,10 @@ namespace OpenHardwareMonitor.GUI { this.Plot = settings.GetValue(new Identifier(sensor.Identifier, "plot").ToString(), false); + + string id = new Identifier(sensor.Identifier, "penColor").ToString(); + if (settings.Contains(id)) + this.PenColor = settings.GetValue(id, Color.Black); } public override string Text { @@ -77,6 +81,22 @@ namespace OpenHardwareMonitor.GUI { } } + public Color? PenColor { + get { return penColor; } + set { + penColor = value; + + string id = new Identifier(sensor.Identifier, "penColor").ToString(); + if (value.HasValue) + settings.SetValue(id, value.Value); + else + settings.Remove(id); + + if (PlotSelectionChanged != null) + PlotSelectionChanged(this, null); + } + } + public bool Plot { get { return plot; } set { diff --git a/OpenHardwareMonitor.csproj b/OpenHardwareMonitor.csproj index 68a994c..35e749b 100644 --- a/OpenHardwareMonitor.csproj +++ b/OpenHardwareMonitor.csproj @@ -66,7 +66,6 @@ -