예제 #1
0
        internal static Bitmap GetVerticalVelocityTapeBitmap(int widthPixels, int heightPixels)
        {
            const float verticalVelocity = 0; //override passed-in vertical velocity so tape doesn't move
            const int   verticalSeparationBetweenTicks = 20;

            if (_vviTape == null)
            {
                _vviTape = ValuesTapeGenerator.GenerateValuesTape(
                    Color.White,                                    //positiveBackgroundColor
                    Color.Black,                                    //positiveForegroundColor
                    Color.Black,                                    //negativeBackgroundColor
                    Color.White,                                    //positiveBackgroundColor
                    2,                                              //majorUnitInterval
                    1,                                              //minorUnitInterval
                    11,                                             //majorUnitLineLengthInPixels
                    7,                                              //minorUnitLineLengthInPixels
                    true,                                           //negativeUnitsLabelled
                    verticalSeparationBetweenTicks,                 //verticalSeparationBetweenTicksInPixels
                    7,                                              //scaleMaxVal
                    -7,                                             //scaleMinVal
                    widthPixels,                                    //tapeWidthInPixels
                    HAlignment.Left,                                //ticksAlignment
                    0,                                              //textPaddingPixels
                    new Font("Lucida Console", 10, FontStyle.Bold), //majorUnitFont
                    HAlignment.Right,                               //textAlignment
                    false,                                          //negativeUnitsHaveNegativeSign
                    null
                    );
                var         start       = _vviTape;
                var         centerPoint = new Point(start.Width / 2, start.Height / 2);
                const int   velocityBetweenTicksInHundredFps = 1;
                const float pixelsSeparationPerHundredFps    = verticalSeparationBetweenTicks /
                                                               (float)velocityBetweenTicksInHundredFps;
                var currentValY = centerPoint.Y - ((int)((verticalVelocity * pixelsSeparationPerHundredFps)));
                var topY        = (currentValY - (heightPixels / 2));
                var bottomY     = (currentValY + (heightPixels / 2));

                var topLeftCrop     = new Point(0, topY);
                var bottomRightCrop = new Point(start.Width, bottomY);

                if (topLeftCrop.Y < 0)
                {
                    topLeftCrop.Y = 0;
                }
                if (topLeftCrop.Y > start.Height)
                {
                    topLeftCrop.Y = start.Height;
                }
                if (bottomRightCrop.Y < 0)
                {
                    bottomRightCrop.Y = 0;
                }
                if (bottomRightCrop.Y > start.Height)
                {
                    bottomRightCrop.Y = start.Height;
                }

                var cropRectangle = new Rectangle(topLeftCrop.X, topLeftCrop.Y, bottomRightCrop.X - topLeftCrop.X,
                                                  bottomRightCrop.Y - topLeftCrop.Y);
                var cropped = (Bitmap)Common.Imaging.Util.CropBitmap(start, cropRectangle);

                //cut zero-mark cutout into tape
                using (var g = Graphics.FromImage(cropped))
                {
                    var       centerY = (cropped.Height / 2);
                    var       rightX  = cropped.Width;
                    const int leftX   = 0;
                    var       upperRightTriangleCorner = new Point(rightX, centerY - 20);
                    var       lowerRightTriangleCorner = new Point(rightX, centerY + 20);
                    var       middleLeftTriangleCorner = new Point(leftX, centerY);
                    g.FillPolygon(Brushes.Fuchsia,
                                  new[] { upperRightTriangleCorner, middleLeftTriangleCorner, lowerRightTriangleCorner });
                }
                cropped.MakeTransparent(Color.Fuchsia);
                _vviTape = cropped;
            }
            return(_vviTape);
        }
        internal static Bitmap GetAltitudeTapeBitmap(float altitudeInFeet, int widthPixels, int heightPixels, float altitudeIndexInFeet)
        {
            const int verticalSeparationBetweenTicks = 10;

            var thousands = (int)(altitudeInFeet / 1000.0f);

            if (AltitudeTapes[thousands + 4] == null)
            {
                AltitudeTapes[thousands + 4] = ValuesTapeGenerator.GenerateValuesTape(
                    Color.FromArgb(160, Color.Gray), //positiveBackgroundColor
                    Color.White,                     //positiveForegroundColor
                    Color.FromArgb(160, Color.Gray), //negativeBackgroundColor
                    Color.White,                     //negativeForegroundColor
                    100,                             //majorUnitInterval
                    20,                              //minorUnitInterval
                    12,                              //majorUnitLineLengthPixels
                    5,                               //minorUnitLineLengthPixels
                    true,                            //negativeUnitsLabelled
                    verticalSeparationBetweenTicks,  //verticalSeparationBetweenTicksInPixels
                    (thousands * 1000) + 2000,       //scaleMaxVal
                    (thousands * 1000) - 2000,       //scaleMinVal
                    widthPixels,                     //tapeWidthInPixels
                    HAlignment.Left,                 //ticksAlignment
                    0,                               //textPaddingPixels
                    _majorUnitFont,                  //majorUnitFont
                    HAlignment.Left,                 //textAlignment
                    true,                            //negativeUnitsHaveSign
                    null
                    );
            }

            var         start       = (Bitmap)AltitudeTapes[thousands + 4].Clone();
            var         centerPoint = new Point(start.Width / 2, start.Height / 2);
            const int   altitudeBetweenTicksInFeet        = 20;
            const float pixelsSeparationPerFootOfAltitude =
                verticalSeparationBetweenTicks / (float)altitudeBetweenTicksInFeet;
            var currentValY = centerPoint.Y -
                              ((int)(((altitudeInFeet - (thousands * 1000)) * pixelsSeparationPerFootOfAltitude)));
            var topY    = (currentValY - (heightPixels / 2));
            var bottomY = (currentValY + (heightPixels / 2));

            var topLeftCrop     = new Point(0, topY);
            var bottomRightCrop = new Point(start.Width, bottomY);

            if (topLeftCrop.Y < 0)
            {
                topLeftCrop.Y = 0;
            }
            if (topLeftCrop.Y > start.Height)
            {
                topLeftCrop.Y = start.Height;
            }
            if (bottomRightCrop.Y < 0)
            {
                bottomRightCrop.Y = 0;
            }
            if (bottomRightCrop.Y > start.Height)
            {
                bottomRightCrop.Y = start.Height;
            }

            var cropRectangle = new Rectangle(topLeftCrop.X, topLeftCrop.Y, bottomRightCrop.X - topLeftCrop.X,
                                              bottomRightCrop.Y - topLeftCrop.Y);

            //add index bug to altitude tape
            var   bugA                  = new Point(-2, 0);
            var   bugB                  = new Point(-2, 21);
            var   bugC                  = new Point(10, 21);
            var   bugD                  = new Point(10, 16);
            var   bugE                  = new Point(3, 11);
            var   bugF                  = new Point(3, 10);
            var   bugG                  = new Point(10, 5);
            var   bugH                  = new Point(10, 0);
            var   bugPoints             = new[] { bugA, bugB, bugC, bugD, bugE, bugF, bugG, bugH };
            var   altitudeIndexBugColor = Color.Magenta;
            Brush altitudeIndexBugBrush = new SolidBrush(altitudeIndexBugColor);

            using (var h = Graphics.FromImage(start))
            {
                var origTransform = h.Transform;
                h.SmoothingMode = SmoothingMode.AntiAlias;
                var altitudeIndexBugY = centerPoint.Y -
                                        ((int)
                                         (((altitudeIndexInFeet - (thousands * 1000)) *
                                           pixelsSeparationPerFootOfAltitude)));
                if (altitudeIndexBugY < (cropRectangle.Top + 3))
                {
                    altitudeIndexBugY = cropRectangle.Top + 3;
                }
                if (altitudeIndexBugY > (cropRectangle.Bottom - 3))
                {
                    altitudeIndexBugY = cropRectangle.Bottom - 3;
                }
                h.TranslateTransform(0, altitudeIndexBugY - 11);
                h.FillPolygon(altitudeIndexBugBrush, bugPoints);
                h.Transform = origTransform;
            }

            var cropped = (Bitmap)Common.Imaging.Util.CropBitmap(start, cropRectangle);

            return(cropped);
        }
        internal static Bitmap GetAoATapeBitmap(float aoaInDegrees, int widthPixels, int heightPixels)
        {
            const int verticalSeparationBetweenTicks = 10;
            const int scaleMaxVal = 90;
            const int scaleMinVal = -90;

            if (aoaInDegrees > scaleMaxVal)
            {
                aoaInDegrees = scaleMaxVal;
            }
            if (aoaInDegrees < scaleMinVal)
            {
                aoaInDegrees = scaleMinVal;
            }
            if (_aoaTape == null)
            {
                var aoaYellow = new TapeEdgeColoringInstruction
                {
                    Color  = Color.Yellow,
                    MinVal = AOA_YELLOW_RANGE_MIN_ANGLE_DEGREES,
                    MaxVal = AOA_YELLOW_RANGE_MAX_ANGLE_DEGREES
                };

                var aoaGreen = new TapeEdgeColoringInstruction
                {
                    Color  = Color.Green,
                    MinVal = AOA_GREEN_RANGE_MIN_ANGLE_DEGREES,
                    MaxVal = AOA_GREEN_RANGE_MAX_ANGLE_DEGREES
                };


                var aoaRed = new TapeEdgeColoringInstruction
                {
                    Color  = Color.Red,
                    MinVal = AOA_RED_RANGE_MIN_ANGLE_DEGREES,
                    MaxVal = AOA_RED_RANGE_MAX_ANGLE_DEGREES
                };

                _aoaTape = ValuesTapeGenerator.GenerateValuesTape(
                    Color.FromArgb(160, Color.Gray),                //positiveBackgroundColor
                    Color.White,                                    //postiveForegroundColor
                    Color.FromArgb(160, Color.Gray),                //negativeBackgroundColor
                    Color.White,                                    //negativeForegroundColor
                    5,                                              //majorUnitInterval
                    1,                                              //minorUnitInterval
                    0,                                              //majorUnitLineLengthPixels
                    21,                                             //minorUnitLineLengthPixels
                    true,                                           //negativeUnitsLabelled
                    verticalSeparationBetweenTicks,                 //verticalSeparationBetweenTicksPixels
                    scaleMaxVal,                                    //scaleMaxVal
                    scaleMinVal,                                    //scaleMinVal
                    widthPixels,                                    //tapeWidthPixels
                    HAlignment.Center,                              //ticksAlignment
                    0,                                              //textPaddingPixels
                    new Font("Lucida Console", 12, FontStyle.Bold), //majorUnitFont
                    HAlignment.Right,                               //textAlignment
                    true,                                           //negativeUnitsHaveNegativeSign
                    new[] { aoaYellow, aoaGreen, aoaRed }
                    );
            }

            var         start       = _aoaTape;
            var         centerPoint = new Point(start.Width / 2, start.Height / 2);
            const int   quantityBetweenTicksInDegreesAoa = 1;
            const float pixelsSeparationPerDegreeAoa     =
                verticalSeparationBetweenTicks / (float)quantityBetweenTicksInDegreesAoa;
            var currentValY = centerPoint.Y - ((int)((aoaInDegrees * pixelsSeparationPerDegreeAoa)));
            var topY        = (currentValY - (heightPixels / 2));
            var bottomY     = (currentValY + (heightPixels / 2));

            var topLeftCrop     = new Point(0, topY);
            var bottomRightCrop = new Point(start.Width, bottomY);

            if (topLeftCrop.Y < 0)
            {
                topLeftCrop.Y = 0;
            }
            if (topLeftCrop.Y > start.Height)
            {
                topLeftCrop.Y = start.Height;
            }
            if (bottomRightCrop.Y < 0)
            {
                bottomRightCrop.Y = 0;
            }
            if (bottomRightCrop.Y > start.Height)
            {
                bottomRightCrop.Y = start.Height;
            }

            var cropRectangle = new Rectangle(topLeftCrop.X, topLeftCrop.Y, bottomRightCrop.X - topLeftCrop.X,
                                              bottomRightCrop.Y - topLeftCrop.Y);
            var cropped = (Bitmap)Common.Imaging.Util.CropBitmap(start, cropRectangle);

            return(cropped);
        }
예제 #4
0
        internal static Bitmap GetAirspeedTapeBitmap(float indicatedAirspeedKnots, int widthPixels, int heightPixels, float airspeedIndexInKnots)
        {
            const int verticalSeparationBetweenTicks = 9;
            const int scaleMaxVal = 1200;
            const int scaleMinVal = -1200;

            if (indicatedAirspeedKnots > scaleMaxVal)
            {
                indicatedAirspeedKnots = scaleMaxVal;
            }
            if (indicatedAirspeedKnots < scaleMinVal)
            {
                indicatedAirspeedKnots = scaleMinVal;
            }


            if (_airspeedTape == null)
            {
                _airspeedTape = ValuesTapeGenerator.GenerateValuesTape(
                    Color.FromArgb(160, Color.Gray),                //positiveBackgroundColor
                    Color.White,                                    //positiveForegroundColor
                    Color.FromArgb(160, Color.Gray),                //negativeBackgroundColor
                    Color.White,                                    //negativeForegroundColor
                    100,                                            //majorUnitInterval
                    20,                                             //minorUnitInterval
                    12,                                             //majorUnitLineLengthInPixels
                    7,                                              //minorUnitLineLengthInPixels,
                    false,                                          //negativeUnitsLabelled
                    verticalSeparationBetweenTicks,                 //verticalSeparationBetweenTicksInPixels
                    scaleMaxVal,                                    //scaleMaxVal
                    scaleMinVal,                                    //scaleMinVal
                    widthPixels,                                    //tapeWidthInPixels
                    HAlignment.Right,                               //ticsAlignment
                    3,                                              //paddingPixels
                    new Font("Lucida Console", 11, FontStyle.Bold), //majorUnitFont
                    HAlignment.Right,                               //textAlignment
                    true,                                           //negativeUnitsHaveNegativeSign
                    null
                    );
            }

            var start = (Bitmap)_airspeedTape.Clone();

            var         centerPoint             = new Point(start.Width / 2, start.Height / 2);
            const int   knotsBetweenTicks       = 20;
            const float pixelsSeparationPerKnot = verticalSeparationBetweenTicks / (float)knotsBetweenTicks;
            var         currentAirspeedY        = centerPoint.Y - ((int)((indicatedAirspeedKnots * pixelsSeparationPerKnot)));


            var topY    = (currentAirspeedY - (heightPixels / 2));
            var bottomY = (currentAirspeedY + (heightPixels / 2));

            var topLeftCrop     = new Point(0, topY);
            var bottomRightCrop = new Point(start.Width, bottomY);

            if (topLeftCrop.Y < 0)
            {
                topLeftCrop.Y = 0;
            }
            if (topLeftCrop.Y > start.Height)
            {
                topLeftCrop.Y = start.Height;
            }
            if (bottomRightCrop.Y < 0)
            {
                bottomRightCrop.Y = 0;
            }
            if (bottomRightCrop.Y > start.Height)
            {
                bottomRightCrop.Y = start.Height;
            }

            var cropRectangle = new Rectangle(topLeftCrop.X, topLeftCrop.Y, bottomRightCrop.X - topLeftCrop.X,
                                              bottomRightCrop.Y - topLeftCrop.Y);


            //add index bug to airspeed tape
            var bugA = new Point(-2, 0);
            var bugB = new Point(-2, 5);
            var bugC = new Point(5, 10);
            var bugD = new Point(5, 11);
            var bugE = new Point(-2, 16);
            var bugF = new Point(-2, 21);
            var bugG = new Point(10, 21);
            var bugH = new Point(10, 0);

            var   bugPoints             = new[] { bugA, bugB, bugC, bugD, bugE, bugF, bugG, bugH };
            var   airspeedIndexBugColor = Color.Magenta;
            Brush airspeedIndexBugBrush = new SolidBrush(airspeedIndexBugColor);

            using (var h = Graphics.FromImage(start))
            {
                h.SmoothingMode = SmoothingMode.AntiAlias;
                var origTransform     = h.Transform;
                var airspeedIndexBugY = centerPoint.Y - ((int)((airspeedIndexInKnots * pixelsSeparationPerKnot)));
                if (airspeedIndexBugY < (cropRectangle.Top + 3))
                {
                    airspeedIndexBugY = cropRectangle.Top + 3;
                }
                if (airspeedIndexBugY > (cropRectangle.Bottom - 3))
                {
                    airspeedIndexBugY = cropRectangle.Bottom - 3;
                }

                h.TranslateTransform(start.Width - 10, airspeedIndexBugY - 11);
                h.FillPolygon(airspeedIndexBugBrush, bugPoints);
                h.Transform = origTransform;
            }


            var cropped = (Bitmap)Common.Imaging.Util.CropBitmap(start, cropRectangle);

            return(cropped);
        }