Esempio n. 1
0
        protected override void OnPaintOffScreen(PaintEventArgs e)
        {
            PolarGraphics f = base.CreatePolarGraphics(e.Graphics);

            // What altitude are we drawing?
#if PocketPC
            Distance AltitudeToRender = _Altitude;
#else
            Distance AltitudeToRender = new Distance(_ValueInterpolator[_InterpolationIndex], _Altitude.Units);
#endif

            // There are 100 tick marks in 360 degrees.   3.6° per tick mark
            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);

#if PocketPC
            f.DrawCenteredString(AltitudeString, _ValueFont,
                                 _ValueBrush, new PolarCoordinate(45.0f, 0.0, Azimuth.North, PolarCoordinateOrientation.Clockwise));
#else
            f.DrawRotatedString(AltitudeString, _ValueFont,
                                _ValueBrush, new PolarCoordinate(45.0f, Angle.Empty, Azimuth.North, PolarCoordinateOrientation.Clockwise));
#endif
            // Draw an ellipse at the center
            f.DrawEllipse(_CenterPen, PolarCoordinate.Empty, 10);

#if !PocketPC
            f.Graphics.TranslateTransform(_NeedleShadowSize.Width, _NeedleShadowSize.Height, MatrixOrder.Append);

            f.FillPolygon(_NeedleShadowBrush, Needle1);
            f.FillPolygon(_NeedleShadowBrush, Needle2);
            f.FillPolygon(_NeedleShadowBrush, Needle3);

            f.Graphics.ResetTransform();
#endif

            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);
        }
Esempio n. 2
0
        protected override void OnPaintOffScreen(PaintEventArgs e)
        {
            PolarGraphics f = CreatePolarGraphics(e.Graphics);

            // What bearing are we drawing?
#if PocketPC
            Azimuth BearingToRender = _Bearing;
#else
            Azimuth BearingToRender;
            try
            {
                BearingToRender = new Azimuth(_ValueInterpolator[_InterpolationIndex]);
            }
            catch
            {
                throw;
            }
#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
            for (int index = 0; index < NeedleNorth.Length; index++)
            {
                NeedleNorth[index] = NeedleNorth[index].Rotate(BearingToRender.DecimalDegrees);
                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);
        }