From caeee35fce5bf6029b25ab7858f047fb754526ba Mon Sep 17 00:00:00 2001 From: mandrolic Date: Sun, 30 Jan 2011 21:49:14 +0000 Subject: [PATCH] Configurator.Net: Transmitter Calibration - Max/Min watermarks for indicator controls git-svn-id: https://arducopter.googlecode.com/svn/trunk@1580 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- .../Views/FlightDataView.Designer.cs | 46 ++++-- .../Views/TransmitterChannelsView.Designer.cs | 18 +++ .../Views/controls/LinearIndicatorControl.cs | 131 ++++++++++-------- 3 files changed, 127 insertions(+), 68 deletions(-) diff --git a/Configurator/Configurator.Net/Views/FlightDataView.Designer.cs b/Configurator/Configurator.Net/Views/FlightDataView.Designer.cs index 908e03cbc7..e21300e7ac 100644 --- a/Configurator/Configurator.Net/Views/FlightDataView.Designer.cs +++ b/Configurator/Configurator.Net/Views/FlightDataView.Designer.cs @@ -259,12 +259,15 @@ this.indicatorRollGyro.IsVertical = false; this.indicatorRollGyro.Location = new System.Drawing.Point(12, 28); this.indicatorRollGyro.Max = 500; + this.indicatorRollGyro.MaxWaterMark = 0; this.indicatorRollGyro.Min = -500; + this.indicatorRollGyro.MinWatermark = 0; this.indicatorRollGyro.Name = "indicatorRollGyro"; this.indicatorRollGyro.Offset = 0; this.indicatorRollGyro.Size = new System.Drawing.Size(109, 20); this.indicatorRollGyro.TabIndex = 32; this.indicatorRollGyro.Value = 100; + this.indicatorRollGyro.WatermarkLineColor = System.Drawing.Color.DarkGray; // // indicatorRollAccel // @@ -278,12 +281,15 @@ this.indicatorRollAccel.IsVertical = false; this.indicatorRollAccel.Location = new System.Drawing.Point(12, 78); this.indicatorRollAccel.Max = 500; + this.indicatorRollAccel.MaxWaterMark = 0; this.indicatorRollAccel.Min = -500; + this.indicatorRollAccel.MinWatermark = 0; this.indicatorRollAccel.Name = "indicatorRollAccel"; this.indicatorRollAccel.Offset = 0; this.indicatorRollAccel.Size = new System.Drawing.Size(109, 20); this.indicatorRollAccel.TabIndex = 33; this.indicatorRollAccel.Value = 100; + this.indicatorRollAccel.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl1 // @@ -297,12 +303,15 @@ this.linearIndicatorControl1.IsVertical = true; this.linearIndicatorControl1.Location = new System.Drawing.Point(199, 21); this.linearIndicatorControl1.Max = 500; + this.linearIndicatorControl1.MaxWaterMark = 0; this.linearIndicatorControl1.Min = -500; + this.linearIndicatorControl1.MinWatermark = 0; this.linearIndicatorControl1.Name = "linearIndicatorControl1"; this.linearIndicatorControl1.Offset = 0; this.linearIndicatorControl1.Size = new System.Drawing.Size(20, 82); this.linearIndicatorControl1.TabIndex = 34; this.linearIndicatorControl1.Value = 100; + this.linearIndicatorControl1.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl2 // @@ -316,12 +325,15 @@ this.linearIndicatorControl2.IsVertical = true; this.linearIndicatorControl2.Location = new System.Drawing.Point(264, 21); this.linearIndicatorControl2.Max = 500; + this.linearIndicatorControl2.MaxWaterMark = 0; this.linearIndicatorControl2.Min = -500; + this.linearIndicatorControl2.MinWatermark = 0; this.linearIndicatorControl2.Name = "linearIndicatorControl2"; this.linearIndicatorControl2.Offset = 0; this.linearIndicatorControl2.Size = new System.Drawing.Size(20, 82); this.linearIndicatorControl2.TabIndex = 35; this.linearIndicatorControl2.Value = 100; + this.linearIndicatorControl2.WatermarkLineColor = System.Drawing.Color.Red; // // linearIndicatorControl3 // @@ -334,13 +346,16 @@ this.linearIndicatorControl3.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.FlightDataVmBindingSource, "MotorLeft", true)); this.linearIndicatorControl3.IsVertical = true; this.linearIndicatorControl3.Location = new System.Drawing.Point(15, 157); - this.linearIndicatorControl3.Max = 1000; - this.linearIndicatorControl3.Min = 0; + this.linearIndicatorControl3.Max = 2000; + this.linearIndicatorControl3.MaxWaterMark = 0; + this.linearIndicatorControl3.Min = 1000; + this.linearIndicatorControl3.MinWatermark = 0; this.linearIndicatorControl3.Name = "linearIndicatorControl3"; this.linearIndicatorControl3.Offset = 0; this.linearIndicatorControl3.Size = new System.Drawing.Size(20, 84); this.linearIndicatorControl3.TabIndex = 36; this.linearIndicatorControl3.Value = 100; + this.linearIndicatorControl3.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl4 // @@ -353,13 +368,16 @@ this.linearIndicatorControl4.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.FlightDataVmBindingSource, "MotorFront", true)); this.linearIndicatorControl4.IsVertical = true; this.linearIndicatorControl4.Location = new System.Drawing.Point(71, 157); - this.linearIndicatorControl4.Max = 1000; - this.linearIndicatorControl4.Min = 0; + this.linearIndicatorControl4.Max = 2000; + this.linearIndicatorControl4.MaxWaterMark = 0; + this.linearIndicatorControl4.Min = 1000; + this.linearIndicatorControl4.MinWatermark = 0; this.linearIndicatorControl4.Name = "linearIndicatorControl4"; this.linearIndicatorControl4.Offset = 0; this.linearIndicatorControl4.Size = new System.Drawing.Size(20, 84); this.linearIndicatorControl4.TabIndex = 37; this.linearIndicatorControl4.Value = 100; + this.linearIndicatorControl4.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl5 // @@ -372,13 +390,16 @@ this.linearIndicatorControl5.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.FlightDataVmBindingSource, "MotorRear", true)); this.linearIndicatorControl5.IsVertical = true; this.linearIndicatorControl5.Location = new System.Drawing.Point(124, 157); - this.linearIndicatorControl5.Max = 1000; - this.linearIndicatorControl5.Min = 0; + this.linearIndicatorControl5.Max = 2000; + this.linearIndicatorControl5.MaxWaterMark = 0; + this.linearIndicatorControl5.Min = 1000; + this.linearIndicatorControl5.MinWatermark = 0; this.linearIndicatorControl5.Name = "linearIndicatorControl5"; this.linearIndicatorControl5.Offset = 0; this.linearIndicatorControl5.Size = new System.Drawing.Size(20, 84); this.linearIndicatorControl5.TabIndex = 38; this.linearIndicatorControl5.Value = 100; + this.linearIndicatorControl5.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl6 // @@ -391,13 +412,16 @@ this.linearIndicatorControl6.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.FlightDataVmBindingSource, "MotorRear", true)); this.linearIndicatorControl6.IsVertical = true; this.linearIndicatorControl6.Location = new System.Drawing.Point(179, 157); - this.linearIndicatorControl6.Max = 1000; - this.linearIndicatorControl6.Min = 0; + this.linearIndicatorControl6.Max = 2000; + this.linearIndicatorControl6.MaxWaterMark = 0; + this.linearIndicatorControl6.Min = 1000; + this.linearIndicatorControl6.MinWatermark = 0; this.linearIndicatorControl6.Name = "linearIndicatorControl6"; this.linearIndicatorControl6.Offset = 0; this.linearIndicatorControl6.Size = new System.Drawing.Size(20, 84); this.linearIndicatorControl6.TabIndex = 39; this.linearIndicatorControl6.Value = 100; + this.linearIndicatorControl6.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl7 // @@ -411,12 +435,15 @@ this.linearIndicatorControl7.IsVertical = false; this.linearIndicatorControl7.Location = new System.Drawing.Point(225, 157); this.linearIndicatorControl7.Max = 500; + this.linearIndicatorControl7.MaxWaterMark = 0; this.linearIndicatorControl7.Min = -500; + this.linearIndicatorControl7.MinWatermark = 0; this.linearIndicatorControl7.Name = "linearIndicatorControl7"; this.linearIndicatorControl7.Offset = 0; this.linearIndicatorControl7.Size = new System.Drawing.Size(109, 20); this.linearIndicatorControl7.TabIndex = 40; this.linearIndicatorControl7.Value = 100; + this.linearIndicatorControl7.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl8 // @@ -430,12 +457,15 @@ this.linearIndicatorControl8.IsVertical = true; this.linearIndicatorControl8.Location = new System.Drawing.Point(353, 21); this.linearIndicatorControl8.Max = 500; + this.linearIndicatorControl8.MaxWaterMark = 0; this.linearIndicatorControl8.Min = -500; + this.linearIndicatorControl8.MinWatermark = 0; this.linearIndicatorControl8.Name = "linearIndicatorControl8"; this.linearIndicatorControl8.Offset = 0; this.linearIndicatorControl8.Size = new System.Drawing.Size(20, 82); this.linearIndicatorControl8.TabIndex = 41; this.linearIndicatorControl8.Value = 100; + this.linearIndicatorControl8.WatermarkLineColor = System.Drawing.Color.DarkGray; // // FlightDataView // diff --git a/Configurator/Configurator.Net/Views/TransmitterChannelsView.Designer.cs b/Configurator/Configurator.Net/Views/TransmitterChannelsView.Designer.cs index 595654943e..f9444cabee 100644 --- a/Configurator/Configurator.Net/Views/TransmitterChannelsView.Designer.cs +++ b/Configurator/Configurator.Net/Views/TransmitterChannelsView.Designer.cs @@ -175,12 +175,15 @@ this.linearIndicatorControl3.IsVertical = true; this.linearIndicatorControl3.Location = new System.Drawing.Point(16, 30); this.linearIndicatorControl3.Max = 2000; + this.linearIndicatorControl3.MaxWaterMark = 0; this.linearIndicatorControl3.Min = 1000; + this.linearIndicatorControl3.MinWatermark = 0; this.linearIndicatorControl3.Name = "linearIndicatorControl3"; this.linearIndicatorControl3.Offset = 0; this.linearIndicatorControl3.Size = new System.Drawing.Size(20, 111); this.linearIndicatorControl3.TabIndex = 43; this.linearIndicatorControl3.Value = 1600; + this.linearIndicatorControl3.WatermarkLineColor = System.Drawing.Color.Red; // // linearIndicatorControl1 // @@ -194,12 +197,15 @@ this.linearIndicatorControl1.IsVertical = true; this.linearIndicatorControl1.Location = new System.Drawing.Point(67, 30); this.linearIndicatorControl1.Max = 2000; + this.linearIndicatorControl1.MaxWaterMark = 0; this.linearIndicatorControl1.Min = 1000; + this.linearIndicatorControl1.MinWatermark = 0; this.linearIndicatorControl1.Name = "linearIndicatorControl1"; this.linearIndicatorControl1.Offset = 0; this.linearIndicatorControl1.Size = new System.Drawing.Size(20, 111); this.linearIndicatorControl1.TabIndex = 44; this.linearIndicatorControl1.Value = 1100; + this.linearIndicatorControl1.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl2 // @@ -213,12 +219,15 @@ this.linearIndicatorControl2.IsVertical = true; this.linearIndicatorControl2.Location = new System.Drawing.Point(155, 131); this.linearIndicatorControl2.Max = 2000; + this.linearIndicatorControl2.MaxWaterMark = 0; this.linearIndicatorControl2.Min = 1000; + this.linearIndicatorControl2.MinWatermark = 0; this.linearIndicatorControl2.Name = "linearIndicatorControl2"; this.linearIndicatorControl2.Offset = 0; this.linearIndicatorControl2.Size = new System.Drawing.Size(20, 73); this.linearIndicatorControl2.TabIndex = 45; this.linearIndicatorControl2.Value = 1050; + this.linearIndicatorControl2.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl4 // @@ -232,12 +241,15 @@ this.linearIndicatorControl4.IsVertical = true; this.linearIndicatorControl4.Location = new System.Drawing.Point(206, 131); this.linearIndicatorControl4.Max = 2000; + this.linearIndicatorControl4.MaxWaterMark = 0; this.linearIndicatorControl4.Min = 1000; + this.linearIndicatorControl4.MinWatermark = 0; this.linearIndicatorControl4.Name = "linearIndicatorControl4"; this.linearIndicatorControl4.Offset = 0; this.linearIndicatorControl4.Size = new System.Drawing.Size(20, 73); this.linearIndicatorControl4.TabIndex = 46; this.linearIndicatorControl4.Value = 1900; + this.linearIndicatorControl4.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl5 // @@ -251,12 +263,15 @@ this.linearIndicatorControl5.IsVertical = false; this.linearIndicatorControl5.Location = new System.Drawing.Point(174, 80); this.linearIndicatorControl5.Max = 2000; + this.linearIndicatorControl5.MaxWaterMark = 0; this.linearIndicatorControl5.Min = 1000; + this.linearIndicatorControl5.MinWatermark = 0; this.linearIndicatorControl5.Name = "linearIndicatorControl5"; this.linearIndicatorControl5.Offset = 0; this.linearIndicatorControl5.Size = new System.Drawing.Size(100, 20); this.linearIndicatorControl5.TabIndex = 47; this.linearIndicatorControl5.Value = 1300; + this.linearIndicatorControl5.WatermarkLineColor = System.Drawing.Color.DarkGray; // // linearIndicatorControl6 // @@ -270,12 +285,15 @@ this.linearIndicatorControl6.IsVertical = false; this.linearIndicatorControl6.Location = new System.Drawing.Point(174, 30); this.linearIndicatorControl6.Max = 2000; + this.linearIndicatorControl6.MaxWaterMark = 0; this.linearIndicatorControl6.Min = 1000; + this.linearIndicatorControl6.MinWatermark = 0; this.linearIndicatorControl6.Name = "linearIndicatorControl6"; this.linearIndicatorControl6.Offset = 0; this.linearIndicatorControl6.Size = new System.Drawing.Size(100, 20); this.linearIndicatorControl6.TabIndex = 48; this.linearIndicatorControl6.Value = 1200; + this.linearIndicatorControl6.WatermarkLineColor = System.Drawing.Color.DarkGray; // // TransmitterChannelsView // diff --git a/Configurator/Configurator.Net/Views/controls/LinearIndicatorControl.cs b/Configurator/Configurator.Net/Views/controls/LinearIndicatorControl.cs index c6d2f1f29d..7d66e6e2d9 100644 --- a/Configurator/Configurator.Net/Views/controls/LinearIndicatorControl.cs +++ b/Configurator/Configurator.Net/Views/controls/LinearIndicatorControl.cs @@ -1,12 +1,6 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; using System.Drawing; -using System.Data; using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using System.Text; using System.Windows.Forms; /* @@ -21,55 +15,19 @@ namespace ArducopterConfigurator.Views.controls [ToolboxBitmap(typeof(System.Windows.Forms.ProgressBar))] public partial class LinearIndicatorControl : UserControl { - /// - /// This enum represents the diffrent states the control can take. - /// Animation for ex. makes the procent bar "Rubber band" to the new procent value - /// - public enum BarType - { - Static, // Plain and simple bar with procent display - Progressbar, // This makes the control act as a progressbar - Animated // This makes the control "Rubber band" to new procent values (Animated). - }; - - - #region Static Members public static readonly Color PreBarBaseDark = Color.FromArgb(199, 200, 201); public static readonly Color PreBarBaseLight = Color.WhiteSmoke; public static readonly Color PreBarLight = Color.FromArgb(102, 144, 252); public static readonly Color PreBarDark = Color.FromArgb(40, 68, 202); public static readonly Color PreBorderColor = Color.DarkGray; - #endregion - - #region Private Members - /// - /// The Light background color - /// + private Color _barBgLightColour = PreBarBaseLight; - - /// - /// The Dark background color - /// private Color _barBgDarkColor = PreBarBaseDark; - - /// - /// The Light bar color - /// private Color _barLightColour = PreBarLight; - - /// - /// The Dark bar color - /// private Color _barDarkColour = PreBarDark; - - /// - /// The Border color for the control - /// private Color _borderColor = PreBorderColor; + private Color _watermarkLineColor = PreBorderColor; - /// - /// The border width - /// private float _borderWidth = 1.0F; private int _min = 0; @@ -77,14 +35,12 @@ namespace ArducopterConfigurator.Views.controls private int _val = 50; private int _offset = 0; - /// - /// The number of dividers to draw in the bar - /// private int iNumDividers = 10; private bool _isVertical = false; + private int _minWatermark; + private int _maxWatermark; - #endregion public LinearIndicatorControl() @@ -119,8 +75,6 @@ namespace ArducopterConfigurator.Views.controls // g is the graphics of the whole control private void GenerateBar(Graphics g, float x, float y, float width, float height, bool isVertical) { - float totalWidth = width; - var rect = new RectangleF(x, y, width, height); // Fill the background @@ -155,16 +109,14 @@ namespace ArducopterConfigurator.Views.controls // Now the line that represents the Offset/Origin - if (_offset > _min && _offset < _max) - using (Pen p = new Pen(_borderColor, _borderWidth)) - { - var linePos = (float)(_offset - _min) / (_max - _min) * (isVertical ? height : width); + DrawLine(width, height, isVertical, g, _offset,_borderColor); - if (isVertical) - g.DrawLine(p, 0, linePos, width, linePos); - else - g.DrawLine(p, linePos, 0, linePos, height); - } + // Draw the high/low watermarks + if (_minWatermark!=_offset) + DrawLine(width, height, isVertical, g, _minWatermark, _watermarkLineColor); + + if (_maxWatermark!=_offset) + DrawLine(width, height, isVertical, g, _maxWatermark, _watermarkLineColor); // Border around the whole thing @@ -202,6 +154,20 @@ namespace ArducopterConfigurator.Views.controls // } } + private void DrawLine(float width, float height, bool isVertical, Graphics g, int position, Color color) + { + if (position > _min && _offset < _max) + using (Pen p = new Pen(color, _borderWidth)) + { + var linePos = (float)(position - _min) / (_max - _min) * (isVertical ? height : width); + + if (isVertical) + g.DrawLine(p, 0 ,height - linePos, width, height - linePos); + else + g.DrawLine(p, linePos, 0, linePos, height); + } + } + private Bitmap GenerateProcentBarBitmap(int width, int height,Color bgColor) { @@ -310,7 +276,7 @@ namespace ArducopterConfigurator.Views.controls /// Gets or sets the color of the border. /// /// The color of the border. - [System.ComponentModel.Description("Gets or sets the border color")] + [System.ComponentModel.Description("The border color")] [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] public Color BarBorderColor { @@ -318,6 +284,18 @@ namespace ArducopterConfigurator.Views.controls set { _borderColor = value; Refresh(); } } + /// + /// Gets or sets the color of the border. + /// + /// The color of the border. + [System.ComponentModel.Description("The color for the watermark lines")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public Color WatermarkLineColor + { + get { return _watermarkLineColor; } + set { _watermarkLineColor = value; Refresh(); } + } + [System.ComponentModel.Description("Gets or sets the Minimum Value")] [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] @@ -360,6 +338,39 @@ namespace ArducopterConfigurator.Views.controls } } + [System.ComponentModel.Description("The position of the Max watermark line. Set to Offset if not needed")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public int MaxWaterMark + { + get { return _maxWatermark; } + set + { + if (_maxWatermark != value) + { + _maxWatermark = value; + Refresh(); + } + + } + } + + + [System.ComponentModel.Description("The position of the Min watermark line. Set to Offset if not needed")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public int MinWatermark + { + get { return _minWatermark; } + set + { + if (_minWatermark != value) + { + _minWatermark = value; + Refresh(); + } + + } + } + [System.ComponentModel.Description("Gets or sets whether the indicator is vertical")] [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] public bool IsVertical