Exemplo n.º 1
0
        /// <inheritdocs/>
        protected override void OnPaintOffScreen(PaintEventArgs e)
        {
            PolarGraphics f = CreatePolarGraphics(e.Graphics);

            // What bearing are we drawing?
#if PocketPC
            Azimuth BearingToRender = _Bearing;
#else
            Azimuth bearingToRender = new Azimuth(_valueInterpolator[_interpolationIndex]);
#endif

            // Cache drawing options in order to prevent race conditions during
            // drawing!
            double minorInterval     = _minorTickInterval.DecimalDegrees;
            double majorInterval     = _majorTickInterval.DecimalDegrees;
            double directionInterval = _directionLabelInterval.DecimalDegrees;
            double angleInterval     = _angleLabelInterval.DecimalDegrees;

            // Draw tick marks
            if (minorInterval > 0)
            {
                for (double angle = 0; angle < 360; angle += minorInterval)
                {
                    // And draw a line
                    f.DrawLine(_minorTickPen, new PolarCoordinate(98, angle), new PolarCoordinate(100, angle));
                }
            }
            // Draw tick marks
            if (majorInterval > 0)
            {
                for (double angle = 0; angle < 360; angle += majorInterval)
                {
                    // And draw a line
                    f.DrawLine(_majorTickPen, new PolarCoordinate(95, angle), new PolarCoordinate(100, angle));
                }
            }
            if (directionInterval > 0)
            {
                for (double angle = 0; angle < 360; angle += directionInterval)
                {
                    // And draw a line
                    f.DrawLine(_directionTickPen, new PolarCoordinate(92, angle), new PolarCoordinate(100, angle));
                }
            }
            if (angleInterval > 0)
            {
                for (double angle = 0; angle < 360; angle += angleInterval)
                {
                    // Get the coordinate of the line's start
                    PolarCoordinate start = new PolarCoordinate(60, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);
#if PocketPC
                    f.DrawCenteredString(((Angle)angle).ToString(_AngleLabelFormat, CultureInfo.CurrentCulture), _AngleLabelFont, _AngleLabelBrush, start);
#else
                    f.DrawRotatedString(((Angle)angle).ToString(_angleLabelFormat, CultureInfo.CurrentCulture), _angleLabelFont, _angleLabelBrush, start);
#endif
                }
            }
            if (directionInterval > 0)
            {
                for (double angle = 0; angle < 360; angle += directionInterval)
                {
                    // Get the coordinate of the line's start
                    PolarCoordinate start = new PolarCoordinate(80, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);
#if PocketPC
                    f.DrawCenteredString(((Azimuth)angle).ToString("c", CultureInfo.CurrentCulture), _DirectionLabelFont, _DirectionLabelBrush, start);
#else
                    f.DrawRotatedString(((Azimuth)angle).ToString("c", CultureInfo.CurrentCulture), _directionLabelFont, _directionLabelBrush, start);
#endif
                }
            }

            // Draw an ellipse at the center
            f.DrawEllipse(_centerPen, PolarCoordinate.Empty, 10);

            // Now draw the needle shadow
            PolarCoordinate[] needleNorth = _needlePointsNorth.Clone() as PolarCoordinate[];
            PolarCoordinate[] needleSouth = _needlePointsSouth.Clone() as PolarCoordinate[];

            // Adjust the needle to the current bearing
            if (needleNorth != null)
            {
                for (int index = 0; index < needleNorth.Length; index++)
                {
                    needleNorth[index] = needleNorth[index].Rotate(bearingToRender.DecimalDegrees);
                    if (needleSouth != null)
                    {
                        needleSouth[index] = needleSouth[index].Rotate(bearingToRender.DecimalDegrees);
                    }
                }
            }

#if !PocketPC
            // Now draw a shadow
            f.Graphics.TranslateTransform(_pNeedleShadowSize.Width, _pNeedleShadowSize.Height, MatrixOrder.Append);

            f.FillPolygon(_pNeedleShadowBrush, needleNorth);
            f.FillPolygon(_pNeedleShadowBrush, needleSouth);

            f.Graphics.ResetTransform();
#endif

            f.FillPolygon(_pNorthNeedleBrush, needleNorth);
            f.DrawPolygon(_pNorthNeedlePen, needleNorth);
            f.FillPolygon(_pSouthNeedleBrush, needleSouth);
            f.DrawPolygon(_pSouthNeedlePen, needleSouth);
        }
Exemplo n.º 2
0
        /// <inheritdocs/>
        protected override void OnPaintOffScreen(PaintEventArgs e)
        {
            PolarGraphics f = CreatePolarGraphics(e.Graphics);

            // What altitude are we drawing?

            Distance altitudeToRender = new Distance(_valueInterpolator[_interpolationIndex], _altitude.Units);

            // There are 100 tick marks in 360 degrees.   3.6° per tick mark
            const double conversionFactor = 3.6;

            // Draw tick marks
            if (_minorTickPen != null)
            {
                for (double alt = 0; alt < 100; alt += 1)
                {
                    // Convert the speed to an angle
                    Angle angle = new Angle(alt * conversionFactor);
                    // Get the coordinate of the line's start
                    PolarCoordinate start = new PolarCoordinate(95, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);
                    PolarCoordinate end   = new PolarCoordinate(100, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);
                    // And draw a line
                    f.DrawLine(_minorTickPen, start, end);
                }
            }
            // Draw tick marks
            if (_majorTickPen != null)
            {
                for (double alt = 0; alt < 100; alt += 10)
                {
                    // Convert the speed to an angle
                    Angle angle = new Angle(alt * conversionFactor);
                    // Get the coordinate of the line's start
                    PolarCoordinate start = new PolarCoordinate(94, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);
                    PolarCoordinate end   = new PolarCoordinate(100, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);
                    // And draw a line
                    f.DrawLine(_majorTickPen, start, end);
                    // And also a string
                    string s = Convert.ToString(alt * 0.1, CultureInfo.CurrentCulture);
                    f.DrawCenteredString(s, _altitudeLabelFont, _altitudeLabelBrush,
                                         new PolarCoordinate(85, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise));
                }
            }
            // Calculate all needle values
            double pTensOfThousandsValue = altitudeToRender.Value / 1000.0;
            double pThousandsValue       = altitudeToRender.Value / 100.0;
            double pValue = altitudeToRender.Value / 10.0;

            // Now draw the tens-of-thousands needle
            // Rotate the needle to the right place
            PolarCoordinate[] needle1 = new PolarCoordinate[_tensOfThousandsNeedle.Length];
            for (int index = 0; index < needle1.Length; index++)
            {
                needle1[index] = _tensOfThousandsNeedle[index].Rotate(pTensOfThousandsValue * conversionFactor);
            }

            // Now draw the tens-of-thousands needle
            // Rotate the needle to the right place
            PolarCoordinate[] needle2 = new PolarCoordinate[_thousandsNeedle.Length];
            for (int index = 0; index < needle2.Length; index++)
            {
                needle2[index] = _thousandsNeedle[index].Rotate(pThousandsValue * conversionFactor);
            }

            // Now draw the tens-of-Hundreds needle
            // Rotate the needle to the right place
            PolarCoordinate[] needle3 = new PolarCoordinate[_hundredsNeedle.Length];
            for (int index = 0; index < needle3.Length; index++)
            {
                needle3[index] = _hundredsNeedle[index].Rotate(pValue * conversionFactor);
            }

            string altitudeString = altitudeToRender.ToString(_valueFormat, CultureInfo.CurrentCulture);

            //SizeF FontSize = f.Graphics.MeasureString(AltitudeString, pValueFont);

            f.DrawRotatedString(altitudeString, _valueFont,
                                _valueBrush, new PolarCoordinate(45.0f, Angle.Empty, Azimuth.North, PolarCoordinateOrientation.Clockwise));

            // Draw an ellipse at the center
            f.DrawEllipse(_centerPen, PolarCoordinate.Empty, 10);

            f.Graphics.TranslateTransform(_needleShadowSize.Width, _needleShadowSize.Height, MatrixOrder.Append);

            f.FillPolygon(_needleShadowBrush, needle1);
            f.FillPolygon(_needleShadowBrush, needle2);
            f.FillPolygon(_needleShadowBrush, needle3);

            f.Graphics.ResetTransform();

            f.FillPolygon(_tensOfThousandsBrush, needle1);
            f.DrawPolygon(_tensOfThousandsPen, needle1);
            f.FillPolygon(_thousandsBrush, needle2);
            f.DrawPolygon(_thousandsPen, needle2);
            f.FillPolygon(_hundredsBrush, needle3);
            f.DrawPolygon(_hundredsPen, needle3);

            // Draw an ellipse at the center
            f.FillEllipse(_hundredsBrush, PolarCoordinate.Empty, 7);
            f.DrawEllipse(_hundredsPen, PolarCoordinate.Empty, 7);
        }