Added an option to show the plot in a separate window or on the right of the tree-view.
1.1 --- a/GUI/MainForm.Designer.cs Sun May 22 11:27:57 2011 +0000
1.2 +++ b/GUI/MainForm.Designer.cs Sun May 22 19:15:27 2011 +0000
1.3 @@ -110,6 +110,10 @@
1.4 this.splitContainer = new OpenHardwareMonitor.GUI.SplitContainerAdv();
1.5 this.treeView = new Aga.Controls.Tree.TreeViewAdv();
1.6 this.plotPanel = new OpenHardwareMonitor.GUI.PlotPanel();
1.7 + this.plotLocationMenuItem = new System.Windows.Forms.MenuItem();
1.8 + this.plotWindowMenuItem = new System.Windows.Forms.MenuItem();
1.9 + this.plotBottomMenuItem = new System.Windows.Forms.MenuItem();
1.10 + this.plotRightMenuItem = new System.Windows.Forms.MenuItem();
1.11 this.splitContainer.Panel1.SuspendLayout();
1.12 this.splitContainer.Panel2.SuspendLayout();
1.13 this.splitContainer.SuspendLayout();
1.14 @@ -326,6 +330,7 @@
1.15 this.startupMenuItem,
1.16 this.separatorMenuItem,
1.17 this.temperatureUnitsMenuItem,
1.18 + this.plotLocationMenuItem,
1.19 this.MenuItem4,
1.20 this.hddMenuItem});
1.21 this.optionsMenuItem.Text = "Options";
1.22 @@ -377,12 +382,12 @@
1.23 //
1.24 // MenuItem4
1.25 //
1.26 - this.MenuItem4.Index = 6;
1.27 + this.MenuItem4.Index = 7;
1.28 this.MenuItem4.Text = "-";
1.29 //
1.30 // hddMenuItem
1.31 //
1.32 - this.hddMenuItem.Index = 7;
1.33 + this.hddMenuItem.Index = 8;
1.34 this.hddMenuItem.Text = "Read HDD sensors";
1.35 //
1.36 // helpMenuItem
1.37 @@ -475,6 +480,30 @@
1.38 this.plotPanel.Size = new System.Drawing.Size(386, 124);
1.39 this.plotPanel.TabIndex = 0;
1.40 //
1.41 + // plotLocationMenuItem
1.42 + //
1.43 + this.plotLocationMenuItem.Index = 6;
1.44 + this.plotLocationMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
1.45 + this.plotWindowMenuItem,
1.46 + this.plotBottomMenuItem,
1.47 + this.plotRightMenuItem});
1.48 + this.plotLocationMenuItem.Text = "Plot Location";
1.49 + //
1.50 + // plotWindowMenuItem
1.51 + //
1.52 + this.plotWindowMenuItem.Index = 0;
1.53 + this.plotWindowMenuItem.Text = "Window";
1.54 + //
1.55 + // plotBottomMenuItem
1.56 + //
1.57 + this.plotBottomMenuItem.Index = 1;
1.58 + this.plotBottomMenuItem.Text = "Bottom";
1.59 + //
1.60 + // plotRightMenuItem
1.61 + //
1.62 + this.plotRightMenuItem.Index = 2;
1.63 + this.plotRightMenuItem.Text = "Right";
1.64 + //
1.65 // MainForm
1.66 //
1.67 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
1.68 @@ -547,6 +576,10 @@
1.69 private System.Windows.Forms.MenuItem minCloseMenuItem;
1.70 private System.Windows.Forms.MenuItem resetMenuItem;
1.71 private System.Windows.Forms.MenuItem menuItem6;
1.72 + private System.Windows.Forms.MenuItem plotLocationMenuItem;
1.73 + private System.Windows.Forms.MenuItem plotWindowMenuItem;
1.74 + private System.Windows.Forms.MenuItem plotBottomMenuItem;
1.75 + private System.Windows.Forms.MenuItem plotRightMenuItem;
1.76 }
1.77 }
1.78
2.1 --- a/GUI/MainForm.cs Sun May 22 11:27:57 2011 +0000
2.2 +++ b/GUI/MainForm.cs Sun May 22 19:15:27 2011 +0000
2.3 @@ -62,6 +62,7 @@
2.4 private StartupManager startupManager = new StartupManager();
2.5 private UpdateVisitor updateVisitor = new UpdateVisitor();
2.6 private SensorGadget gadget;
2.7 + private Form plotForm;
2.8
2.9 private UserOption showHiddenSensors;
2.10 private UserOption showPlot;
2.11 @@ -74,6 +75,7 @@
2.12 private UserOption autoStart;
2.13 private UserOption readHddSensors;
2.14 private UserOption showGadget;
2.15 + private UserRadioGroup plotLocation;
2.16
2.17 private WmiProvider wmiProvider;
2.18
2.19 @@ -149,8 +151,8 @@
2.20 gadget.HideShowCommand += hideShowClick;
2.21
2.22 wmiProvider = new WmiProvider(computer);
2.23 - }
2.24 -
2.25 + }
2.26 +
2.27 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
2.28 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
2.29
2.30 @@ -179,12 +181,6 @@
2.31 treeModel.ForceVisible = showHiddenSensors.Value;
2.32 };
2.33
2.34 - showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings);
2.35 - showPlot.Changed += delegate(object sender, EventArgs e) {
2.36 - splitContainer.Panel2Collapsed = !showPlot.Value;
2.37 - treeView.Invalidate();
2.38 - };
2.39 -
2.40 showValue = new UserOption("valueMenuItem", true, valueMenuItem,
2.41 settings);
2.42 showValue.Changed += delegate(object sender, EventArgs e) {
2.43 @@ -243,6 +239,8 @@
2.44 unitManager.TemperatureUnit == TemperatureUnit.Celcius;
2.45 fahrenheitMenuItem.Checked = !celciusMenuItem.Checked;
2.46
2.47 + InitializePlotForm();
2.48 +
2.49 startupMenuItem.Visible = startupManager.IsAvailable;
2.50
2.51 if (startMinMenuItem.Checked) {
2.52 @@ -262,6 +260,98 @@
2.53 SaveConfiguration();
2.54 };
2.55 }
2.56 +
2.57 + private void InitializePlotForm() {
2.58 + plotForm = new Form();
2.59 + plotForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
2.60 + plotForm.ShowInTaskbar = false;
2.61 + plotForm.StartPosition = FormStartPosition.Manual;
2.62 + this.AddOwnedForm(plotForm);
2.63 + plotForm.Bounds = new Rectangle {
2.64 + X = settings.GetValue("plotForm.Location.X", -100000),
2.65 + Y = settings.GetValue("plotForm.Location.Y", 100),
2.66 + Width = settings.GetValue("plotForm.Width", 600),
2.67 + Height = settings.GetValue("plotForm.Height", 400)
2.68 + };
2.69 +
2.70 + showPlot = new UserOption("plotMenuItem", false, plotMenuItem, settings);
2.71 + plotLocation = new UserRadioGroup("plotLocation", 0,
2.72 + new[] { plotWindowMenuItem, plotBottomMenuItem, plotRightMenuItem },
2.73 + settings);
2.74 +
2.75 + showPlot.Changed += delegate(object sender, EventArgs e) {
2.76 + if (plotLocation.Value == 0) {
2.77 + if (showPlot.Value && this.Visible)
2.78 + plotForm.Show();
2.79 + else
2.80 + plotForm.Hide();
2.81 + } else {
2.82 + splitContainer.Panel2Collapsed = !showPlot.Value;
2.83 + }
2.84 + treeView.Invalidate();
2.85 + };
2.86 + plotLocation.Changed += delegate(object sender, EventArgs e) {
2.87 + switch (plotLocation.Value) {
2.88 + case 0:
2.89 + splitContainer.Panel2.Controls.Clear();
2.90 + splitContainer.Panel2Collapsed = true;
2.91 + plotForm.Controls.Add(plotPanel);
2.92 + if (showPlot.Value && this.Visible)
2.93 + plotForm.Show();
2.94 + break;
2.95 + case 1:
2.96 + plotForm.Controls.Clear();
2.97 + plotForm.Hide();
2.98 + splitContainer.Orientation = Orientation.Horizontal;
2.99 + splitContainer.Panel2.Controls.Add(plotPanel);
2.100 + splitContainer.Panel2Collapsed = !showPlot.Value;
2.101 + break;
2.102 + case 2:
2.103 + plotForm.Controls.Clear();
2.104 + plotForm.Hide();
2.105 + splitContainer.Orientation = Orientation.Vertical;
2.106 + splitContainer.Panel2.Controls.Add(plotPanel);
2.107 + splitContainer.Panel2Collapsed = !showPlot.Value;
2.108 + break;
2.109 + }
2.110 + };
2.111 + plotForm.Closing += delegate(object sender, CancelEventArgs e) {
2.112 + if (plotLocation.Value == 0) {
2.113 + showPlot.Value = false;
2.114 + }
2.115 + e.Cancel = true;
2.116 + };
2.117 + EventHandler moveOrResizePlotForm = delegate(object sender, EventArgs e) {
2.118 + if (plotForm.WindowState != FormWindowState.Minimized) {
2.119 + settings.SetValue("plotForm.Location.X", plotForm.Bounds.X);
2.120 + settings.SetValue("plotForm.Location.Y", plotForm.Bounds.Y);
2.121 + settings.SetValue("plotForm.Width", plotForm.Bounds.Width);
2.122 + settings.SetValue("plotForm.Height", plotForm.Bounds.Height);
2.123 + }
2.124 + };
2.125 + plotForm.Move += moveOrResizePlotForm;
2.126 + plotForm.Resize += moveOrResizePlotForm;
2.127 +
2.128 + plotForm.VisibleChanged += delegate(object sender, EventArgs e) {
2.129 + Rectangle bounds = new Rectangle(plotForm.Location, plotForm.Size);
2.130 + Screen screen = Screen.FromRectangle(bounds);
2.131 + Rectangle intersection =
2.132 + Rectangle.Intersect(screen.WorkingArea, bounds);
2.133 + if (intersection.Width < Math.Min(16, bounds.Width) ||
2.134 + intersection.Height < Math.Min(16, bounds.Height)) {
2.135 + plotForm.Location = new Point(
2.136 + screen.WorkingArea.Width / 2 - bounds.Width / 2,
2.137 + screen.WorkingArea.Height / 2 - bounds.Height / 2);
2.138 + }
2.139 + };
2.140 +
2.141 + this.VisibleChanged += delegate(object sender, EventArgs e) {
2.142 + if (this.Visible && showPlot.Value && plotLocation.Value == 0)
2.143 + plotForm.Show();
2.144 + else
2.145 + plotForm.Hide();
2.146 + };
2.147 + }
2.148
2.149 private void SubHardwareAdded(IHardware hardware, Node node) {
2.150 Node hardwareNode = new HardwareNode(hardware, settings, unitManager);
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/GUI/UserRadioGroup.cs Sun May 22 19:15:27 2011 +0000
3.3 @@ -0,0 +1,97 @@
3.4 +/*
3.5 +
3.6 + Version: MPL 1.1/GPL 2.0/LGPL 2.1
3.7 +
3.8 + The contents of this file are subject to the Mozilla Public License Version
3.9 + 1.1 (the "License"); you may not use this file except in compliance with
3.10 + the License. You may obtain a copy of the License at
3.11 +
3.12 + http://www.mozilla.org/MPL/
3.13 +
3.14 + Software distributed under the License is distributed on an "AS IS" basis,
3.15 + WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
3.16 + for the specific language governing rights and limitations under the License.
3.17 +
3.18 + The Original Code is the Open Hardware Monitor code.
3.19 +
3.20 + The Initial Developer of the Original Code is
3.21 + Michael Möller <m.moeller@gmx.ch>.
3.22 + Portions created by the Initial Developer are Copyright (C) 20011
3.23 + the Initial Developer. All Rights Reserved.
3.24 +
3.25 + Contributor(s):
3.26 +
3.27 + Alternatively, the contents of this file may be used under the terms of
3.28 + either the GNU General Public License Version 2 or later (the "GPL"), or
3.29 + the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
3.30 + in which case the provisions of the GPL or the LGPL are applicable instead
3.31 + of those above. If you wish to allow use of your version of this file only
3.32 + under the terms of either the GPL or the LGPL, and not to allow others to
3.33 + use your version of this file under the terms of the MPL, indicate your
3.34 + decision by deleting the provisions above and replace them with the notice
3.35 + and other provisions required by the GPL or the LGPL. If you do not delete
3.36 + the provisions above, a recipient may use your version of this file under
3.37 + the terms of any one of the MPL, the GPL or the LGPL.
3.38 +
3.39 +*/
3.40 +
3.41 +using System;
3.42 +using System.Collections.Generic;
3.43 +using System.Windows.Forms;
3.44 +using OpenHardwareMonitor.Utilities;
3.45 +
3.46 +namespace OpenHardwareMonitor.GUI {
3.47 + public class UserRadioGroup {
3.48 + private string name;
3.49 + private int value;
3.50 + private MenuItem[] menuItems;
3.51 + private event EventHandler changed;
3.52 + private PersistentSettings settings;
3.53 +
3.54 + public UserRadioGroup(string name, int value,
3.55 + MenuItem[] menuItems, PersistentSettings settings) {
3.56 + this.settings = settings;
3.57 + this.name = name;
3.58 + if (name != null)
3.59 + this.value = settings.GetValue(name, value);
3.60 + else
3.61 + this.value = value;
3.62 + this.menuItems = menuItems;
3.63 + this.value = Math.Max(Math.Min(this.value, menuItems.Length - 1), 0);
3.64 +
3.65 + for (int i = 0; i < this.menuItems.Length; i++) {
3.66 + this.menuItems[i].Checked = i == this.value;
3.67 + int index = i;
3.68 + this.menuItems[i].Click += delegate(object sender, EventArgs e) {
3.69 + this.Value = index;
3.70 + };
3.71 + }
3.72 + }
3.73 +
3.74 + public int Value {
3.75 + get { return value; }
3.76 + set {
3.77 + if (this.value != value) {
3.78 + this.value = value;
3.79 + if (this.name != null)
3.80 + settings.SetValue(name, value);
3.81 + for (int i = 0; i < this.menuItems.Length; i++)
3.82 + this.menuItems[i].Checked = i == value;
3.83 + if (changed != null)
3.84 + changed(this, null);
3.85 + }
3.86 + }
3.87 + }
3.88 +
3.89 + public event EventHandler Changed {
3.90 + add {
3.91 + changed += value;
3.92 + if (changed != null)
3.93 + changed(this, null);
3.94 + }
3.95 + remove {
3.96 + changed -= value;
3.97 + }
3.98 + }
3.99 + }
3.100 +}
4.1 --- a/OpenHardwareMonitor.csproj Sun May 22 11:27:57 2011 +0000
4.2 +++ b/OpenHardwareMonitor.csproj Sun May 22 19:15:27 2011 +0000
4.3 @@ -108,6 +108,7 @@
4.4 <Compile Include="GUI\UnitManager.cs" />
4.5 <Compile Include="GUI\UpdateVisitor.cs" />
4.6 <Compile Include="GUI\UserOption.cs" />
4.7 + <Compile Include="GUI\UserRadioGroup.cs" />
4.8 <Compile Include="Properties\AssemblyVersion.cs" />
4.9 <Compile Include="Utilities\PersistentSettings.cs" />
4.10 <Compile Include="Properties\AssemblyInfo.cs" />