示例#1
0
        /// <summary>
        /// //  Creates the old style coverage scale used to generate a new style coverage scale...
        /// </summary>
        /// <param name="ccaRequiredMinimumPasses"></param>
        /// <param name="ccaColorScale"></param>
        public static void CreateInitialCoverageScale(short ccaRequiredMinimumPasses, ref CCAColorScale ccaColorScale)
        {
            const short CCV_COLOR_SCALE_COUNT = 4;

            var requiredColors = (ccaRequiredMinimumPasses * 2) - 1;

            var colorsArray = new Color [CCV_COLOR_SCALE_COUNT + 1];

            colorsArray[0] = Color.DarkGray;
            colorsArray[1] = Color.Green;
            colorsArray[2] = Color.Aqua;
            colorsArray[3] = Color.Red;
            colorsArray[4] = Color.Yellow;

            if (requiredColors > 1)
            {
                requiredColors--;
            }

            ccaColorScale.IsSolidColors  = false;
            ccaColorScale.InvertGradient = false;

            // How many color points are we going to use?..
            var numberOfColorPoints = requiredColors < CCV_COLOR_SCALE_COUNT + 1 ? requiredColors : CCV_COLOR_SCALE_COUNT;

            var colorSegments = ccaColorScale.ColorSegments;

            for (var i = 1; i <= numberOfColorPoints; i++)
            {
                colorSegments.Add(new CCAColorScaleSegment {
                    Color = ColorUtility.ColorToUInt(colorsArray[i].R, colorsArray[i].G, colorsArray[i].B)
                });
            }

            // Max value of this is always the required passes...
            colorSegments[0].SetValueRange(ccaRequiredMinimumPasses, ccaRequiredMinimumPasses);

            float passesLeft = ccaRequiredMinimumPasses - 1;
            var   step       = passesLeft / (colorSegments.Count - 1);

            // Scale rest of colors evenly over passes left...
            for (var i = 1; i <= colorSegments.Count - 1; i++)
            {
                var value1 = (short)(passesLeft + 1);
                passesLeft -= step;
                var value2 = (short)passesLeft;

                if (value2 != 0 || i == colorSegments.Count - 2)
                {
                    value2++;
                }

                colorSegments[i].SetValueRange(value1, value2);
            }
        }
示例#2
0
        /// <summary>
        /// Looks up for the colour in the list of the colour segments.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="isHatched"></param>
        /// <returns></returns>
        public uint Lookup(int value, ref bool isHatched)
        {
            if (ColorSegments.Count == 0)
            {
                return(ColorUtility.ColorToUInt(COLOR_RED_VALUE, COLOR_GREEN_VALUE, COLOR_BLUE_VALUE));
            }

            int minValue;
            int maxValue;

            for (var i = ColorSegments.Count - 1; i >= 0; i--)
            {
                if (ColorSegments[i].IsValueWithinRange(value))
                {
                    isHatched = ColorSegments[i].IsHatched;

                    if (!IsSolidColors)
                    {
                        minValue = ColorSegments[i].MinValue;
                        maxValue = ColorSegments[i].MaxValue;

                        return(ScaleColor(value, minValue, maxValue, ColorSegments[i].Color));
                    }

                    return(ColorSegments[i].Color);
                }
            }

            // Off the top, scaled to max...
            var tempColor = ColorSegments[0].Color;

            minValue = ColorSegments[0].MinValue;
            maxValue = ColorSegments[0].MaxValue;

            isHatched = ColorSegments[0].IsHatched;

            if (minValue != maxValue)
            {
                tempColor = ScaleColor(maxValue, minValue, maxValue, ColorSegments[0].Color);
            }

            return(tempColor);
        }
示例#3
0
        /// <summary>
        /// This function interpolates shades of the color scale.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="rangeMin"></param>
        /// <param name="rangeMax"></param>
        /// <param name="baseColor"></param>
        /// <returns></returns>
        private uint ScaleColor(int value, int rangeMin, int rangeMax, uint baseColor)
        {
            // Mix with 50% black at max, and 0% black at min...
            var blackMix = 0;

            if (rangeMin != rangeMax)
            {
                var colorValue = !InvertGradient ? value - rangeMin : rangeMax - value;

                blackMix = 50 * colorValue / (rangeMax - rangeMin);
            }

            var color = ColorUtility.UIntToColor(baseColor);

            var r = color.R - (blackMix * color.R) / 100;
            var g = color.G - (blackMix * color.G) / 100;
            var b = color.B - (blackMix * color.B) / 100;

            return(ColorUtility.ColorToUInt(r, g, b));
        }