From 44ae40350860cc2e4817856d527dfdf9355fc94c Mon Sep 17 00:00:00 2001 From: mandrolic Date: Mon, 28 Feb 2011 22:01:48 +0000 Subject: [PATCH] Configurator.Net: Added heading visualisation git-svn-id: https://arducopter.googlecode.com/svn/trunk@1734 f9c3cf11-9bcb-44bc-f272-b75c42450872 --- .../ArducopterConfigurator.csproj | 9 + .../Views/FlightDataView.Designer.cs | 37 +++- .../Views/controls/CompassControl.Designer.cs | 45 ++++ .../Views/controls/CompassControl.cs | 196 ++++++++++++++++++ .../Views/controls/CompassControl.resx | 120 +++++++++++ 5 files changed, 397 insertions(+), 10 deletions(-) create mode 100644 Configurator/Configurator.Net/Views/controls/CompassControl.Designer.cs create mode 100644 Configurator/Configurator.Net/Views/controls/CompassControl.cs create mode 100644 Configurator/Configurator.Net/Views/controls/CompassControl.resx diff --git a/Configurator/Configurator.Net/ArducopterConfigurator.csproj b/Configurator/Configurator.Net/ArducopterConfigurator.csproj index 866c225108..db2be45e89 100644 --- a/Configurator/Configurator.Net/ArducopterConfigurator.csproj +++ b/Configurator/Configurator.Net/ArducopterConfigurator.csproj @@ -87,6 +87,12 @@ CircularIndicatorControl.cs + + UserControl + + + CompassControl.cs + Component @@ -247,6 +253,9 @@ CircularIndicatorControl.cs + + CompassControl.cs + PropControl.cs diff --git a/Configurator/Configurator.Net/Views/FlightDataView.Designer.cs b/Configurator/Configurator.Net/Views/FlightDataView.Designer.cs index 2f6bf27db0..ef6e01e048 100644 --- a/Configurator/Configurator.Net/Views/FlightDataView.Designer.cs +++ b/Configurator/Configurator.Net/Views/FlightDataView.Designer.cs @@ -73,6 +73,7 @@ this.label1 = new System.Windows.Forms.Label(); this.textBox14 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); + this.compassControl1 = new ArducopterConfigurator.Views.controls.CompassControl(); ((System.ComponentModel.ISupportInitialize)(this.FlightDataVmBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); @@ -431,7 +432,7 @@ // this.button2.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.FlightDataVmBindingSource, "RefreshCalibrationOffsetsCommand", true)); this.button2.Image = ((System.Drawing.Image)(resources.GetObject("button2.Image"))); - this.button2.Location = new System.Drawing.Point(311, 214); + this.button2.Location = new System.Drawing.Point(304, 139); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(26, 26); this.button2.TabIndex = 46; @@ -441,7 +442,7 @@ // this.button1.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.FlightDataVmBindingSource, "UpdateCalibrationOffsetsCommand", true)); this.button1.Image = ((System.Drawing.Image)(resources.GetObject("button1.Image"))); - this.button1.Location = new System.Drawing.Point(311, 185); + this.button1.Location = new System.Drawing.Point(304, 110); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(26, 26); this.button1.TabIndex = 45; @@ -451,7 +452,7 @@ // this.button3.DataBindings.Add(new System.Windows.Forms.Binding("Tag", this.FlightDataVmBindingSource, "CalculateCalibrationOffsetsCommand", true)); this.button3.Image = ((System.Drawing.Image)(resources.GetObject("button3.Image"))); - this.button3.Location = new System.Drawing.Point(311, 156); + this.button3.Location = new System.Drawing.Point(304, 81); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(26, 26); this.button3.TabIndex = 47; @@ -461,7 +462,7 @@ // label11 // this.label11.AutoSize = true; - this.label11.Location = new System.Drawing.Point(343, 163); + this.label11.Location = new System.Drawing.Point(336, 88); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(78, 13); this.label11.TabIndex = 48; @@ -470,7 +471,7 @@ // label12 // this.label12.AutoSize = true; - this.label12.Location = new System.Drawing.Point(343, 192); + this.label12.Location = new System.Drawing.Point(336, 117); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(84, 13); this.label12.TabIndex = 49; @@ -479,7 +480,7 @@ // label13 // this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(343, 223); + this.label13.Location = new System.Drawing.Point(336, 148); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(96, 13); this.label13.TabIndex = 50; @@ -612,29 +613,44 @@ // // textBox14 // - this.textBox14.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.textBox14.BorderStyle = System.Windows.Forms.BorderStyle.None; this.textBox14.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.FlightDataVmBindingSource, "CompassHeadingDegrees", true, System.Windows.Forms.DataSourceUpdateMode.OnValidation, null, "N0")); this.textBox14.Enabled = false; - this.textBox14.Location = new System.Drawing.Point(102, 244); + this.textBox14.Location = new System.Drawing.Point(264, 222); this.textBox14.Name = "textBox14"; this.textBox14.ReadOnly = true; - this.textBox14.Size = new System.Drawing.Size(35, 20); + this.textBox14.Size = new System.Drawing.Size(35, 13); this.textBox14.TabIndex = 58; this.textBox14.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(44, 246); + this.label2.Location = new System.Drawing.Point(255, 205); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(47, 13); this.label2.TabIndex = 59; this.label2.Text = "Heading"; // + // compassControl1 + // + this.compassControl1.BarBackgroundDark = System.Drawing.Color.FromArgb(((int)(((byte)(199)))), ((int)(((byte)(200)))), ((int)(((byte)(201))))); + this.compassControl1.BarBackgroundLight = System.Drawing.Color.WhiteSmoke; + this.compassControl1.BarBorderColor = System.Drawing.Color.Black; + this.compassControl1.BarDark = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(68)))), ((int)(((byte)(202))))); + this.compassControl1.BarLight = System.Drawing.Color.LightBlue; + this.compassControl1.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.FlightDataVmBindingSource, "CompassHeadingDegrees", true)); + this.compassControl1.Location = new System.Drawing.Point(308, 192); + this.compassControl1.Name = "compassControl1"; + this.compassControl1.Size = new System.Drawing.Size(50, 50); + this.compassControl1.TabIndex = 0; + this.compassControl1.Value = 90; + // // FlightDataView // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.compassControl1); this.Controls.Add(this.label2); this.Controls.Add(this.textBox14); this.Controls.Add(this.label1); @@ -731,5 +747,6 @@ private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox14; private System.Windows.Forms.Label label2; + private ArducopterConfigurator.Views.controls.CompassControl compassControl1; } } diff --git a/Configurator/Configurator.Net/Views/controls/CompassControl.Designer.cs b/Configurator/Configurator.Net/Views/controls/CompassControl.Designer.cs new file mode 100644 index 0000000000..6ad3a08a50 --- /dev/null +++ b/Configurator/Configurator.Net/Views/controls/CompassControl.Designer.cs @@ -0,0 +1,45 @@ +namespace ArducopterConfigurator.Views.controls +{ + partial class CompassControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // CirularIndicatorControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Name = "CirularIndicatorControl"; + this.Size = new System.Drawing.Size(50, 50); + this.ResumeLayout(false); + + } + + #endregion + } +} diff --git a/Configurator/Configurator.Net/Views/controls/CompassControl.cs b/Configurator/Configurator.Net/Views/controls/CompassControl.cs new file mode 100644 index 0000000000..2afed3a25c --- /dev/null +++ b/Configurator/Configurator.Net/Views/controls/CompassControl.cs @@ -0,0 +1,196 @@ +using System; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; + +namespace ArducopterConfigurator.Views.controls +{ + /// + /// + [ToolboxBitmap(typeof(System.Windows.Forms.ProgressBar))] + public partial class CompassControl : UserControl + { + public static readonly Color preSweepLight = Color.FromArgb(102, 144, 252); + public static readonly Color preSweepDark = Color.FromArgb(40, 68, 202); + public static readonly Color PreBorderColor = Color.DarkGray; + public static readonly Color PreBarBaseDark = Color.FromArgb(199, 200, 201); + public static readonly Color PreBarBaseLight = Color.WhiteSmoke; + + private Color _sweepLightColour = preSweepLight; + private Color _sweepDarkColour = preSweepDark; + private Color _borderColor = PreBorderColor; + private Color _barBgLightColour = PreBarBaseLight; + private Color _barBgDarkColor = PreBarBaseDark; + + private float _borderWidth = 1.0F; + + private int _val = 50; + + public CompassControl() + { + SetStyle(ControlStyles.OptimizedDoubleBuffer | + ControlStyles.AllPaintingInWmPaint | + ControlStyles.UserPaint | + ControlStyles.ResizeRedraw, true); + + InitializeComponent(); + Width = 50; + Height = 50; + } + + + /// + /// Raises the event. + /// + /// A that contains the event data. + protected override void OnPaint(PaintEventArgs e) + { + var g = e.Graphics; + g.SmoothingMode = SmoothingMode.AntiAlias; + g.Clear(BackColor); + + var bmp = GenerateBitmap(Width, Height); + g.DrawImage(bmp, 0, 0); + } + + + private void GenerateCircle(Graphics g, float x, float y, float width, float height, int heading) + { + var outerRect = new RectangleF(x, y, width, height); + + // Fill the background of the whole control + using (var bg = new SolidBrush(BackColor)) + g.FillRectangle(bg, outerRect); + + // Fill the background of the circle + var circleRect = outerRect; + circleRect.Inflate((_borderWidth/-2), (_borderWidth/-2)); + + using (var white = new LinearGradientBrush(outerRect, _barBgLightColour, _barBgDarkColor, 0F)) + { + g.FillEllipse(white, circleRect); + } + + var gp = new GraphicsPath(); + gp.AddEllipse(circleRect); + + var pgb = new PathGradientBrush(gp); + + pgb.CenterPoint = new PointF(circleRect.Width/2, circleRect.Height/2); + pgb.CenterColor = _sweepDarkColour; + pgb.SurroundColors = new[] {_sweepLightColour}; + + heading = (heading + 270 -5) %360; + + g.FillPie(pgb, circleRect.Left, circleRect.Top, circleRect.Width, circleRect.Height, heading, 10); + + pgb.Dispose(); + + using (var borderPen = new Pen(_borderColor, _borderWidth)) + { + g.DrawEllipse(borderPen, circleRect); + } + } + + + private Bitmap GenerateBitmap(int width, int height) + { + var bmp = new Bitmap(width, height); + using (var g1 = Graphics.FromImage(bmp)) + { + GenerateCircle(g1, 0.0F, 0.0F, width, height, _val); + } + return bmp; + } + + + /// + /// Gets or sets the width of the border. + /// + /// The width of the border. + [System.ComponentModel.Description("Gets or sets the with of the borders")] + [System.ComponentModel.DefaultValue(1.0f)] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public float BarBorderWidth + { + get { return _borderWidth; } + set { _borderWidth = value; Refresh(); } + } + + /// + /// Gets or sets the bar background light. + /// + /// The bar background light. + [System.ComponentModel.Description("Gets or sets the lighter background color")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public Color BarBackgroundLight + { + get { return _barBgLightColour; } + set { _barBgLightColour = value; Refresh(); } + } + + /// + /// Gets or sets the bar background dark. + /// + /// The bar background dark. + [System.ComponentModel.Description("Gets or sets the darker background color")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public Color BarBackgroundDark + { + get { return _barBgDarkColor; } + set { _barBgDarkColor = value; Refresh(); } + } + + /// + /// Gets or sets the bar light. + /// + /// The bar light. + [System.ComponentModel.Description("Gets or sets the light bar color")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public Color BarLight + { + get { return _sweepLightColour; } + set { _sweepLightColour = value; Refresh(); } + } + + /// + /// Gets or sets the bar dark. + /// + /// The bar dark. + [System.ComponentModel.Description("Gets or sets the dark bar color")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public Color BarDark + { + get { return _sweepDarkColour; } + set { _sweepDarkColour = value; Refresh(); } + } + + /// + /// Gets or sets the color of the border. + /// + /// The color of the border. + [System.ComponentModel.Description("The border color")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public Color BarBorderColor + { + get { return _borderColor; } + set { _borderColor = value; Refresh(); } + } + + + [System.ComponentModel.Description("Gets or sets the Value")] + [System.ComponentModel.RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)] + public int Value + { + get { return _val; } + set + { + if (_val != value) + { + _val = value; + Refresh(); + } + } + } + } +} diff --git a/Configurator/Configurator.Net/Views/controls/CompassControl.resx b/Configurator/Configurator.Net/Views/controls/CompassControl.resx new file mode 100644 index 0000000000..ff31a6db56 --- /dev/null +++ b/Configurator/Configurator.Net/Views/controls/CompassControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file