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


            // What altitude are we drawing?
#if PocketPC
            Speed SpeedToRender = pSpeed;
#else
            Speed SpeedToRender = new Speed(ValueInterpolator[InterpolationIndex], pSpeed.Units);
#endif

            // Cache drawing intervals and such to prevent a race condition
            double MinorInterval            = pMinorTickInterval.Value;
            double MajorInterval            = pMajorTickInterval.Value;
            double CachedSpeedLabelInterval = pSpeedLabelInterval.ToUnitType(pMaximumSpeed.Units).Value;
            Speed  MaxSpeed  = pMaximumSpeed.Clone();
            double MinorStep = pMinorTickInterval.ToUnitType(pMaximumSpeed.Units).Value;
            double MajorStep = pMajorTickInterval.ToUnitType(pMaximumSpeed.Units).Value;

            // Draw tick marks
            double          angle;
            PolarCoordinate start;
            PolarCoordinate end;

            #region Draw minor tick marks

            if (MinorInterval > 0)
            {
                for (double speed = 0; speed < MaxSpeed.Value; speed += MinorStep)
                {
                    // Convert the speed to an angle
                    angle = speed * ConversionFactor + pMinimumAngle.DecimalDegrees;
                    // Get the coordinate of the line's start
                    start = new PolarCoordinate(95, angle, Azimuth.South, PolarCoordinateOrientation.Clockwise);
                    end   = new PolarCoordinate(100, angle, Azimuth.South, PolarCoordinateOrientation.Clockwise);
                    // And draw a line
                    f.DrawLine(pMinorTickPen, start, end);
                }
            }

            #endregion

            #region Draw major tick marks

            if (MajorInterval > 0)
            {
                for (double speed = 0; speed < MaxSpeed.Value; speed += MajorStep)
                {
                    // Convert the speed to an angle
                    angle = speed * ConversionFactor + pMinimumAngle.DecimalDegrees;
                    // Get the coordinate of the line's start
                    start = new PolarCoordinate(90, angle, Azimuth.South, PolarCoordinateOrientation.Clockwise);
                    end   = new PolarCoordinate(100, angle, Azimuth.South, PolarCoordinateOrientation.Clockwise);
                    // And draw a line
                    f.DrawLine(pMajorTickPen, start, end);
                }

                #region Draw a major tick mark at the maximum speed

                // Convert the speed to an angle
                angle = MaxSpeed.Value * ConversionFactor + pMinimumAngle.DecimalDegrees;
                // Get the coordinate of the line's start
                start = new PolarCoordinate(90, angle, Azimuth.South, PolarCoordinateOrientation.Clockwise);
                end   = new PolarCoordinate(100, angle, Azimuth.South, PolarCoordinateOrientation.Clockwise);
                // And draw a line
                f.DrawLine(pMajorTickPen, start, end);

                #endregion
            }

            #endregion

            if (CachedSpeedLabelInterval > 0)
            {
                for (double speed = 0; speed < MaxSpeed.Value; speed += CachedSpeedLabelInterval)
                {
                    // Convert the speed to an angle
                    angle = speed * ConversionFactor + pMinimumAngle.DecimalDegrees;
                    // And draw a line
                    f.DrawCenteredString(new Speed(speed, MaxSpeed.Units).ToString(pSpeedLabelFormat, CultureInfo.CurrentCulture), pSpeedLabelFont, pSpeedLabelBrush,
                                         new PolarCoordinate(75, angle, Azimuth.South, PolarCoordinateOrientation.Clockwise));
                }

                // Convert the speed to an angle
                angle = MaxSpeed.Value * ConversionFactor + pMinimumAngle.DecimalDegrees;

                // And draw the speed label
                f.DrawCenteredString(MaxSpeed.ToString(pSpeedLabelFormat, CultureInfo.CurrentCulture), pSpeedLabelFont, pSpeedLabelBrush,
                                     new PolarCoordinate(75, angle, Azimuth.South, PolarCoordinateOrientation.Clockwise));
            }

            // Draw the units for the speedometer
            if (pIsUnitLabelVisible)
            {
                f.DrawCenteredString(pMaximumSpeed.ToString("u", CultureInfo.CurrentCulture), pSpeedLabelFont, pSpeedLabelBrush,
                                     new PolarCoordinate(90, Angle.Empty, Azimuth.South, PolarCoordinateOrientation.Clockwise));
            }

            PolarCoordinate[] Needle = new PolarCoordinate[SpeedometerNeedle.Length];
            for (int index = 0; index < Needle.Length; index++)
            {
                Needle[index] = SpeedometerNeedle[index].Rotate((SpeedToRender.ToUnitType(pMaximumSpeed.Units).Value *this.ConversionFactor) + pMinimumAngle.DecimalDegrees);
            }

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

#if !PocketPC
            // Now draw a shadow
            f.Graphics.TranslateTransform(pNeedleShadowSize.Width, pNeedleShadowSize.Height, MatrixOrder.Append);
            f.FillPolygon(pNeedleShadowBrush, Needle);
            f.Graphics.ResetTransform();
#endif

            // Then draw the actual needle
            f.FillPolygon(pNeedleFillBrush, Needle);
            f.DrawPolygon(pNeedleOutlinePen, Needle);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
//#if !PocketPC || Framework20
//        protected override void OnHandleCreated(EventArgs e)
//        {

//            // Subscribe to events
//            try
//            {
//                base.OnHandleCreated(e);

//                // Hook into the date/time changed event
//#if !PocketPC
//                if(DesignMode)
//                    return;
//#endif
//                DotSpatial.Positioning.Gps.IO.Devices.UtcDateTimeChanged += new EventHandler<DateTimeEventArgs>(Devices_CurrentUtcDateTimeChanged);
//            }
//            catch
//            {
//            }

//        }

//        protected override void OnHandleDestroyed(EventArgs e)
//        {
//            try
//            {
//#if !PocketPC
//                if(DesignMode)
//                    return;
//#endif
//                // Hook into the date/time changed event
//                DotSpatial.Positioning.Gps.IO.Devices.UtcDateTimeChanged -= new EventHandler<DateTimeEventArgs>(Devices_CurrentUtcDateTimeChanged);
//            }
//            catch
//            {
//            }
//            finally
//            {
//                base.OnHandleDestroyed(e);
//            }
//        }
//#endif

        /* This method is called whenever the control must be rendered.  All rendering takes
         * place off-screen, which prevents flickering.  The "PolarControl" base class automatically
         * handles tasks such as resizing and smoothing.  All you have to be concerned with is
         * calculating the polar coordinates to draw.
         */
        ////[CLSCompliant(false)]
        protected override void OnPaintOffScreen(PaintEventArgs e)
        {
            /* The DotSpatial.Positioning comes with a special class named "PolarGraphics," which works
             * almost identically to the "Graphics" class, except that coordinates are given
             * in polar form instead of (X, Y).
             *
             * Polar coordinates are given as an angle and a radius.  The angle is between 0°
             * and 360° clockwise from the top of the control.  The radius is zero (0) at the
             * center of the control, and 100 at the outer edge.  So, a polar coordinate of 90°
             * with a radius of 50 would mark a point straight to the right, half way to the
             * edge.  Mastering polar coordinates gives you the opportunity to create your
             * own controls.
             */

            // Make a PolarGraphics class for easier drawing using polar coordinates
            PolarGraphics f = CreatePolarGraphics(e.Graphics);

            #region Drawing of Tick Marks

            // Draw sixty small tick marks around the control
            for (double value = 0; value < 60; value += 1)
            {
                // There are 120 tick marks in 360°
                Angle angle = new Angle(value * (360 / 60));

                // Get the coordinate of the line's start and end
                PolarCoordinate start = new PolarCoordinate(96, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);
                PolarCoordinate end   = new PolarCoordinate(100, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);

                // And draw a line
                f.DrawLine(pMinorTickPen, start, end);
            }

            // Draw twelve tick marks
            for (double value = 1; value <= 12; value += 1)
            {
                // Convert the value to an angle
                Angle angle = new Angle(value * (360 / 12));

                // Get the coordinate of the line's start
                PolarCoordinate start = new PolarCoordinate(93, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);
                PolarCoordinate end   = new PolarCoordinate(100, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise);

                // And draw the tick mark
                f.DrawLine(pMajorTickPen, start, end);

                // Label the clock position around the circle
                if (pHoursFont != null)
                {
                    string s = Convert.ToString(value, CultureInfo.CurrentUICulture);
                    f.DrawCenteredString(s, pHoursFont, pValueLabelBrush,
                                         new PolarCoordinate(85, angle, Azimuth.North, PolarCoordinateOrientation.Clockwise));
                }
            }

            #endregion

            /* In order to make the control more appealing, we'll make the hours, minutes, and
             * seconds hand as accurate as possible.  For example, if the time is 5:30, the hours
             * hand should be halfway between 5 and 6, or 5.5.  To get these values, we'll
             * calculate "fractional" hours, minutes and seconds using the TimeSpan structure.
             *
             * when you look at the control, you'll see that the minutes hand moves slowly but
             * smoothly as time progresses.  With smoothing enabled, you almost can't tell it's
             * actually moving.
             */

            // Calculate the time elapsed since midnight
            DateTime Midnight          = new DateTime(pValue.Year, pValue.Month, pValue.Day);
            TimeSpan TimeSinceMidnight = pValue.Subtract(Midnight);

            #region Drawing of Hours

            // There are twelve hours in 360° of a circle
            Angle HourAngle = new Angle(TimeSinceMidnight.TotalHours * (360 / 12));

            // Draw the hour "needle"
            f.DrawLine(pHoursPen, PolarCoordinate.Center,
                       new PolarCoordinate(30, HourAngle, Azimuth.North, PolarCoordinateOrientation.Clockwise));

            #endregion

            #region Drawing of Minutes

            // There are sixty minutes in 360° of a circle
            Angle MinuteAngle = new Angle(TimeSinceMidnight.TotalMinutes * (360 / 60));

            // Draw the Minute "needle"
            f.DrawLine(pMinutesPen, PolarCoordinate.Center,
                       new PolarCoordinate(80, MinuteAngle, Azimuth.North, PolarCoordinateOrientation.Clockwise));

            #endregion

            #region Drawing of Seconds

            // There are sixty seconds in 360° of a circle
            Angle SecondAngle = new Angle(TimeSinceMidnight.TotalSeconds * (360 / 60));

            // Draw the Seconds "needle"
            f.DrawLine(pSecondsPen, PolarCoordinate.Center,
                       new PolarCoordinate(90, SecondAngle, Azimuth.North, PolarCoordinateOrientation.Clockwise));

            #endregion
        }