//----------------------------------------------------------------------- // // Copyright © 2012 Nils Hammar. All rights reserved. // //----------------------------------------------------------------------- /* * Software to access vehicle information via the OBD-II connector. * * Copyright © 2012 Nils Hammar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Alternative licensing is possible, see the licensing document. * * The above text may not be removed or modified. */ namespace UserInterface.GUI.Popup { using System.Drawing; using System.Windows.Forms; /// /// A speak balloon for hints. /// public partial class SpeakBalloon : Form { /// /// Height of text field. /// private int textHeight = 50; /// /// X-Position for speak point. /// private int speakPointX = 165; /// /// Y-Position for speak point. /// private int speakPointY = 270; /// /// Graphics instance. /// private Graphics g; /// /// Initializes a new instance of the class. /// public SpeakBalloon() { this.InitializeComponent(); this.g = this.CreateGraphics(); this.richTextBox1.Height = this.textHeight + 10; } /// /// Initializes a new instance of the class. /// /// Height of text field. /// RTF text to display. /// Plain text to display. /// X-Position to point at. /// Y-Position to point at. public SpeakBalloon(int textHeight, string rtfText, string text, int speakPointX, int speakPointY) { this.InitializeComponent(); this.textHeight = textHeight; if (speakPointX >= 0) { this.speakPointX = speakPointX; if (this.speakPointX > (this.Width - 4)) { this.Width = this.speakPointX + 4; } } if (speakPointY < this.textHeight + 60) { speakPointY = this.textHeight + 60; } this.speakPointY = speakPointY; this.Height = speakPointY + 4; this.richTextBox1.Height = this.textHeight + 10; if (rtfText != null) { this.richTextBox1.Rtf = rtfText; } else { this.richTextBox1.Text = text; } this.g = this.CreateGraphics(); } /// /// Locate the balloon. /// /// Called when the main window is moved. /// /// /// Origin point to relate to. /// Relative X-position to use. /// Relative Y-position to use. public void locate(Point origin, int xOffset, int yOffset) { int x = origin.X + xOffset; int y = origin.Y + yOffset; if (y < 0) { y = 0; } this.Location = new Point(x, y); } /// /// Paint the balloon. /// /// Sending object. /// Event data. [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Reviewed.")] private void SpeakBallon_Paint(object sender, PaintEventArgs e) { this.g.Clear(Color.Lavender); // Background. using (SolidBrush myBrush = new SolidBrush(Color.LightYellow)) { this.g.FillRectangle(myBrush, 3, 12, 225, this.textHeight + 9); this.g.FillRectangle(myBrush, 12, 3, 209, this.textHeight + 25); this.g.FillPie(myBrush, new Rectangle(3, 3, 25, 25), 180, 90); this.g.FillPie(myBrush, new Rectangle(203, 3, 25, 25), 270, 90); this.g.FillPie(myBrush, new Rectangle(203, this.textHeight + 3, 25, 25), 0, 90); this.g.FillPie(myBrush, new Rectangle(3, this.textHeight + 3, 25, 25), 90, 90); this.g.FillPolygon( myBrush, new PointF[] { new PointF(185, this.textHeight + 28), new PointF(205, this.textHeight + 28), new PointF(this.speakPointX, this.speakPointY), }); } // Enclosing lines. using (Pen myPen = new Pen(Color.Black)) { myPen.Width = 1; this.g.DrawArc(myPen, new Rectangle(3, 3, 25, 25), 180, 90); this.g.DrawArc(myPen, new Rectangle(203, 3, 25, 25), 270, 90); this.g.DrawArc(myPen, new Rectangle(203, this.textHeight + 3, 25, 25), 0, 90); this.g.DrawArc(myPen, new Rectangle(3, this.textHeight + 3, 25, 25), 90, 90); this.g.DrawLine(myPen, 12, 3, 217, 3); this.g.DrawLine(myPen, 228, 15, 228, this.textHeight + 17); this.g.DrawLine(myPen, 12, this.textHeight + 28, 185, this.textHeight + 28); this.g.DrawLine(myPen, 185, this.textHeight + 28, this.speakPointX, this.speakPointY); this.g.DrawLine(myPen, this.speakPointX, this.speakPointY, 205, this.textHeight + 28); this.g.DrawLine(myPen, 205, this.textHeight + 28, 217, this.textHeight + 28); this.g.DrawLine(myPen, 3, 12, 3, this.textHeight + 17); } } /// /// Capture mouse click. /// /// Sending object. /// Event data. private void richTextBox1_MouseClick(object sender, MouseEventArgs e) { this.Dispose(); } /// /// Capture mouse click. /// /// Sending object. /// Event data. private void SpeakBalloon_MouseClick(object sender, MouseEventArgs e) { this.Dispose(); } } }