# HG changeset patch # User StephaneLenclud # Date 1365806605 -7200 # Node ID 21a9e232561758e716dccb87394657699469ebbd # Parent df649224ba4d0485e3e71eb97f8267a65833480e Sensors can now be displayed in FrontView. diff -r df649224ba4d -r 21a9e2325617 GUI/MainForm.cs --- a/GUI/MainForm.cs Fri Apr 12 02:30:14 2013 +0200 +++ b/GUI/MainForm.cs Sat Apr 13 00:43:25 2013 +0200 @@ -519,6 +519,8 @@ if (soundGraphDisplay != null) { + soundGraphDisplay.Redraw(); + /* displayTick=!displayTick; if (displayTick) { @@ -528,6 +530,7 @@ { soundGraphDisplay.SetText(" -+-", ""); } + */ } } @@ -653,7 +656,7 @@ } { MenuItem item = new MenuItem("Show in iMON FrontView"); - item.Checked = systemTray.Contains(node.Sensor); + item.Checked = soundGraphDisplay.Contains(node.Sensor); item.Click += delegate(object obj, EventArgs args) { if (item.Checked) diff -r df649224ba4d -r 21a9e2325617 GUI/SensorFrontView.cs --- a/GUI/SensorFrontView.cs Fri Apr 12 02:30:14 2013 +0200 +++ b/GUI/SensorFrontView.cs Sat Apr 13 00:43:25 2013 +0200 @@ -26,15 +26,13 @@ private UnitManager unitManager; private ISensor sensor; - private Bitmap bitmap; - private Graphics graphics; private Color color; private Color darkColor; - private Brush brush; - private Brush darkBrush; - private Pen pen; private Font font; private Font smallFont; + public string iFirstLine; + public string iSecondLine; + public SensorFrontView(SoundGraphDisplay soundGraphDisplay, ISensor sensor, bool balloonTip, PersistentSettings settings, UnitManager unitManager) @@ -73,14 +71,6 @@ this.smallFont = new Font(family, 0.75f * baseSize * width / 16.0f, GraphicsUnit.Pixel); - this.bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); - this.graphics = Graphics.FromImage(this.bitmap); - - if (Environment.OSVersion.Version.Major > 5) - { - this.graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; - this.graphics.SmoothingMode = SmoothingMode.HighQuality; - } } public ISensor Sensor @@ -98,32 +88,16 @@ this.color.R / 3, this.color.G / 3, this.color.B / 3); - Brush brush = this.brush; - this.brush = new SolidBrush(this.color); - if (brush != null) - brush.Dispose(); - Brush darkBrush = this.darkBrush; - this.darkBrush = new SolidBrush(this.darkColor); - if (darkBrush != null) - darkBrush.Dispose(); } } public void Dispose() { - - if (brush != null) - brush.Dispose(); - if (darkBrush != null) - darkBrush.Dispose(); - pen.Dispose(); - graphics.Dispose(); - bitmap.Dispose(); font.Dispose(); smallFont.Dispose(); } - private string GetString() + public string GetString() { if (!sensor.Value.HasValue) return "-"; @@ -160,73 +134,6 @@ return "-"; } - private Icon CreateTransparentIcon() - { - string text = GetString(); - int count = 0; - for (int i = 0; i < text.Length; i++) - if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-') - count++; - bool small = count > 2; - - graphics.Clear(Color.Black); - TextRenderer.DrawText(graphics, text, small ? smallFont : font, - new Point(-2, small ? 1 : 0), Color.White, Color.Black); - - BitmapData data = bitmap.LockBits( - new Rectangle(0, 0, bitmap.Width, bitmap.Height), - ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); - - IntPtr Scan0 = data.Scan0; - - int numBytes = bitmap.Width * bitmap.Height * 4; - byte[] bytes = new byte[numBytes]; - Marshal.Copy(Scan0, bytes, 0, numBytes); - bitmap.UnlockBits(data); - - byte red, green, blue; - for (int i = 0; i < bytes.Length; i += 4) - { - blue = bytes[i]; - green = bytes[i + 1]; - red = bytes[i + 2]; - - bytes[i] = color.B; - bytes[i + 1] = color.G; - bytes[i + 2] = color.R; - bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue); - } - - return IconFactory.Create(bytes, bitmap.Width, bitmap.Height, - PixelFormat.Format32bppArgb); - } - - private Icon CreatePercentageIcon() - { - try - { - graphics.Clear(Color.Transparent); - } - catch (ArgumentException) - { - graphics.Clear(Color.Black); - } - graphics.FillRectangle(darkBrush, 0.5f, -0.5f, bitmap.Width - 2, bitmap.Height); - float value = sensor.Value.GetValueOrDefault(); - float y = 0.16f * (100 - value); - graphics.FillRectangle(brush, 0.5f, -0.5f + y, bitmap.Width - 2, bitmap.Height - y); - graphics.DrawRectangle(pen, 1, 0, bitmap.Width - 3, bitmap.Height - 1); - - BitmapData data = bitmap.LockBits( - new Rectangle(0, 0, bitmap.Width, bitmap.Height), - ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); - byte[] bytes = new byte[bitmap.Width * bitmap.Height * 4]; - Marshal.Copy(data.Scan0, bytes, 0, bytes.Length); - bitmap.UnlockBits(data); - - return IconFactory.Create(bytes, bitmap.Width, bitmap.Height, - PixelFormat.Format32bppArgb); - } public void Update() { @@ -248,35 +155,30 @@ string format = ""; switch (sensor.SensorType) { - case SensorType.Voltage: format = "\n{0}: {1:F2} V"; break; - case SensorType.Clock: format = "\n{0}: {1:F0} MHz"; break; - case SensorType.Load: format = "\n{0}: {1:F1} %"; break; - case SensorType.Temperature: format = "\n{0}: {1:F1} °C"; break; - case SensorType.Fan: format = "\n{0}: {1:F0} RPM"; break; - case SensorType.Flow: format = "\n{0}: {1:F0} L/h"; break; - case SensorType.Control: format = "\n{0}: {1:F1} %"; break; - case SensorType.Level: format = "\n{0}: {1:F1} %"; break; - case SensorType.Power: format = "\n{0}: {1:F0} W"; break; - case SensorType.Data: format = "\n{0}: {1:F0} GB"; break; - case SensorType.Factor: format = "\n{0}: {1:F3} GB"; break; + case SensorType.Voltage: format = "{0}: {1:F2} V"; break; + case SensorType.Clock: format = "{0}: {1:F0} MHz"; break; + case SensorType.Load: format = "{0}: {1:F1} %"; break; + case SensorType.Temperature: format = "{0}: {1:F1} °C"; break; + case SensorType.Fan: format = "{0}: {1:F0} RPM"; break; + case SensorType.Flow: format = "{0}: {1:F0} L/h"; break; + case SensorType.Control: format = "{0}: {1:F1} %"; break; + case SensorType.Level: format = "{0}: {1:F1} %"; break; + case SensorType.Power: format = "{0}: {1:F0} W"; break; + case SensorType.Data: format = "{0}: {1:F0} GB"; break; + case SensorType.Factor: format = "{0}: {1:F3} GB"; break; } string formattedValue = string.Format(format, sensor.Name, sensor.Value); if (sensor.SensorType == SensorType.Temperature && unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) { - format = "\n{0}: {1:F1} °F"; + format = "{0}: {1:F1} °F"; formattedValue = string.Format(format, sensor.Name, UnitManager.CelsiusToFahrenheit(sensor.Value)); } - string hardwareName = sensor.Hardware.Name; - hardwareName = hardwareName.Substring(0, - Math.Min(63 - formattedValue.Length, hardwareName.Length)); - string text = hardwareName + formattedValue; - if (text.Length > 63) - text = null; - + iFirstLine = sensor.Hardware.Name; + iSecondLine = formattedValue; } } diff -r df649224ba4d -r 21a9e2325617 GUI/SoundGraphDisplay.cs --- a/GUI/SoundGraphDisplay.cs Fri Apr 12 02:30:14 2013 +0200 +++ b/GUI/SoundGraphDisplay.cs Sat Apr 13 00:43:25 2013 +0200 @@ -36,6 +36,8 @@ private List list = new List(); private SoundGraph.Server iServer; + private int nextSensorToDisplay=0; + public SoundGraphDisplay(IComputer computer, PersistentSettings settings, UnitManager unitManager) @@ -88,7 +90,7 @@ private void SensorAdded(ISensor sensor) { if (settings.GetValue(new Identifier(sensor.Identifier, - "tray").ToString(), false)) + "FrontView").ToString(), false)) Add(sensor, false); } @@ -110,8 +112,29 @@ public void Redraw() { - foreach (SensorFrontView icon in list) - icon.Update(); + //TODO: construct our two lines of texts, scroll or alternate sensors + foreach (SensorFrontView sensor in list) + { + sensor.Update(); + //SetText(sensor.iFirstLine, sensor.iSecondLine); + } + + //Alternate between sensors + if (list.Count > 0) + { + SetText(list[nextSensorToDisplay].iFirstLine, list[nextSensorToDisplay].iSecondLine); + nextSensorToDisplay++; + } + + if (nextSensorToDisplay == list.Count) + { + //Go back to first sensor + nextSensorToDisplay = 0; + } + + + // + } public bool Contains(ISensor sensor) @@ -131,15 +154,18 @@ else { //SL: - //list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager)); + list.Add(new SensorFrontView(this, sensor, balloonTip, settings, unitManager)); //UpdateMainIconVisibilty(); - //settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true); + settings.SetValue(new Identifier(sensor.Identifier, "FrontView").ToString(), true); + nextSensorToDisplay = 0; } + } public void Remove(ISensor sensor) { Remove(sensor, true); + nextSensorToDisplay = 0; } private void Remove(ISensor sensor, bool deleteConfig) @@ -147,9 +173,7 @@ if (deleteConfig) { settings.Remove( - new Identifier(sensor.Identifier, "tray").ToString()); - settings.Remove( - new Identifier(sensor.Identifier, "traycolor").ToString()); + new Identifier(sensor.Identifier, "FrontView").ToString()); } SensorFrontView instance = null; foreach (SensorFrontView icon in list) @@ -158,7 +182,7 @@ if (instance != null) { list.Remove(instance); - UpdateMainIconVisibilty(); + //UpdateMainIconVisibilty(); instance.Dispose(); } } @@ -191,7 +215,7 @@ public void SetText(string aUpperLine, string aLowerLine) { - iServer.SendMessage("set-vfd-text:" + aUpperLine); + iServer.SendMessage("set-vfd-text:" + aUpperLine + "\n" + aLowerLine); } public void Quit()