private string GetLabelCaption(int swatchColorIndex, bool getFromValue, SwatchLabelType currentLabelType)
        {
            SwatchColor swatchColor = this.Colors[swatchColorIndex];

            if (swatchColor.NoData)
            {
                return(this.NoDataText);
            }
            string result = "";

            if (currentLabelType == SwatchLabelType.ShowBorderValue)
            {
                if (!swatchColor.HasTextValue)
                {
                    double num = (!getFromValue) ? swatchColor.ToValue : swatchColor.FromValue;
                    result = ((base.GetMapCore().MapControl.FormatNumberHandler == null) ? num.ToString(this.NumericLabelFormat, CultureInfo.CurrentCulture) : base.GetMapCore().MapControl.FormatNumberHandler(base.GetMapCore().MapControl, num, this.NumericLabelFormat));
                }
            }
            else
            {
                if (swatchColor.HasTextValue)
                {
                    return(swatchColor.TextValue);
                }
                double num2 = (swatchColor.FromValue + swatchColor.ToValue) / 2.0;
                result = ((base.GetMapCore().MapControl.FormatNumberHandler == null) ? num2.ToString(this.NumericLabelFormat, CultureInfo.CurrentCulture) : base.GetMapCore().MapControl.FormatNumberHandler(base.GetMapCore().MapControl, num2, this.NumericLabelFormat));
            }
            return(result);
        }
        private int[] GetColorsRef(SwatchLabelType currentLabelType)
        {
            if (this.Colors.Count == 0)
            {
                return(new int[0]);
            }
            int num = this.Colors.Count;

            if (currentLabelType == SwatchLabelType.ShowBorderValue)
            {
                for (int i = 1; i < this.Colors.Count; i++)
                {
                    if (!this.Colors[i - 1].NoData || !this.Colors[i].NoData)
                    {
                        if (this.Colors[i - 1].NoData || this.Colors[i].NoData)
                        {
                            num++;
                        }
                        else if (!this.Colors[i - 1].HasTextValue && !this.Colors[i].HasTextValue && this.Colors[i - 1].ToValue != this.Colors[i].FromValue)
                        {
                            num++;
                        }
                    }
                }
            }
            int[] array = new int[num];
            array[0] = 0;
            int num2 = 1;

            for (int j = 1; j < this.Colors.Count; j++)
            {
                if (currentLabelType == SwatchLabelType.ShowBorderValue && (!this.Colors[j - 1].NoData || !this.Colors[j].NoData))
                {
                    if (this.Colors[j - 1].NoData || this.Colors[j].NoData)
                    {
                        array[num2++] = -1;
                    }
                    else if (!this.Colors[j - 1].HasTextValue && !this.Colors[j].HasTextValue && this.Colors[j - 1].ToValue != this.Colors[j].FromValue)
                    {
                        array[num2++] = -1;
                    }
                }
                array[num2++] = j;
            }
            return(array);
        }
        public SwatchLabelType GetLabelType()
        {
            if (this.LabelType != 0)
            {
                return(this.LabelType);
            }
            SwatchLabelType result = SwatchLabelType.ShowBorderValue;

            foreach (SwatchColor color in this.Colors)
            {
                if (color.HasTextValue)
                {
                    return(SwatchLabelType.ShowMiddleValue);
                }
            }
            return(result);
        }
        private SizeF GetLabelMaxSize(MapGraphics g, SizeF layoutArea, SwatchLabelType currentLabelType)
        {
            float num  = 0f;
            float num2 = 0f;

            for (int i = 0; i < this.Colors.Count; i++)
            {
                string labelCaption = this.GetLabelCaption(i, true, currentLabelType);
                SizeF  sizeF        = g.MeasureString(labelCaption, this.Font, layoutArea, StringFormat.GenericTypographic);
                num  = Math.Max(num, sizeF.Height);
                num2 = Math.Max(num2, sizeF.Width + this.TrimmingProtector);
                if (currentLabelType == SwatchLabelType.ShowBorderValue)
                {
                    labelCaption = this.GetLabelCaption(i, false, currentLabelType);
                    sizeF        = g.MeasureString(labelCaption, this.Font, layoutArea, StringFormat.GenericTypographic);
                    num          = Math.Max(num, sizeF.Height);
                    num2         = Math.Max(num2, sizeF.Width + this.TrimmingProtector);
                }
            }
            return(System.Drawing.Size.Round(new SizeF(num2, num)));
        }
        private bool MustPrintLabel(int[] colorsRef, int colorRefIndex, bool isFromValue, SwatchLabelType currentLabelType)
        {
            if (this.LabelInterval <= 0)
            {
                return(false);
            }
            int num = colorRefIndex + ((currentLabelType == SwatchLabelType.ShowBorderValue && !isFromValue) ? 1 : 0);

            if (colorRefIndex == 0 && isFromValue)
            {
                if (this.ShowEndLabels)
                {
                    return(true);
                }
                return(this.Colors[colorsRef[colorRefIndex]].NoData);
            }
            if (colorRefIndex == colorsRef.Length - 1 && !this.ShowEndLabels && (currentLabelType == SwatchLabelType.ShowMiddleValue || !isFromValue))
            {
                return(false);
            }
            if (currentLabelType == SwatchLabelType.ShowMiddleValue && num % this.LabelInterval == 0)
            {
                return(true);
            }
            if (colorsRef[colorRefIndex] != -1 && (this.Colors[colorsRef[colorRefIndex]].NoData || !this.Colors[colorsRef[colorRefIndex]].HasTextValue) && num % this.LabelInterval == 0)
            {
                if (!isFromValue)
                {
                    if (!this.Colors[colorsRef[colorRefIndex]].NoData)
                    {
                        return(true);
                    }
                    return(false);
                }
                if (this.MustPrintLabel(colorsRef, colorRefIndex - 1, false, currentLabelType))
                {
                    return(this.Colors[colorsRef[colorRefIndex]].NoData);
                }
                return(true);
            }
            return(false);
        }
        private RectangleF CalculateMaxColorBarBounds(MapGraphics g, RectangleF bounds, float endCaptionWidth, int colorsNumber, SwatchLabelType currentLabelType)
        {
            if (this.LabelInterval == 0)
            {
                return(bounds);
            }
            LabelAlignment labelAlignment2 = this.LabelAlignment;
            float          num             = endCaptionWidth;

            if (currentLabelType == SwatchLabelType.ShowMiddleValue)
            {
                num = ((this.Colors.Count != 1) ? (((float)this.Colors.Count * endCaptionWidth - bounds.Width) / (float)(this.Colors.Count - 1)) : (num - bounds.Width / (float)colorsNumber));
                num = (float)((num < 0.0) ? 0.0 : num);
            }
            bounds.Inflate((float)((0.0 - num) / 2.0), 0f);
            return(bounds);
        }
        private RectangleF GetLabelBounds(int colorIndex, int[] colorRef, RectangleF panelBounds, RectangleF colorBarBounds, SizeF labelBoxSize, SizeF colorBoxSize, float longestEndLabelWidth, bool getFromValue, SwatchLabelType curLabelType, bool alignedBottom, SizeF firstCaptionSize, SizeF lastCaptionSize, out StringAlignment horizontalAlignemnt)
        {
            RectangleF rectangleF = new RectangleF(colorBarBounds.Location, labelBoxSize);
            float      num        = 0f;

            if (colorIndex == 0 && getFromValue)
            {
                goto IL_002e;
            }
            if (colorIndex == colorRef.Length - 1 && (!getFromValue || curLabelType == SwatchLabelType.ShowMiddleValue))
            {
                goto IL_002e;
            }
            goto IL_0074;
IL_0074:
            if (alignedBottom)
            {
                rectangleF.Offset(0f, colorBarBounds.Height + (float)this.TickMarkLength + (float)this.TickMarkLabelGapSize);
            }
            else
            {
                rectangleF.Offset(0f, (float)(0.0 - (labelBoxSize.Height + (float)this.TickMarkLength + (float)this.TickMarkLabelGapSize)));
            }
            int num2 = Array.IndexOf(colorRef, colorIndex);

            rectangleF.X += (float)num2 * colorBoxSize.Width;
            rectangleF.X += (float)((colorBoxSize.Width - rectangleF.Width) / 2.0);
            rectangleF.X += num;
            if (rectangleF.Bottom >= panelBounds.Bottom)
            {
                rectangleF.Height = Math.Max(1f, rectangleF.Height - (rectangleF.Bottom - panelBounds.Bottom));
                rectangleF.Y      = panelBounds.Bottom - rectangleF.Height;
            }
            if (!this.Colors[colorIndex].NoData && curLabelType == SwatchLabelType.ShowBorderValue)
            {
                rectangleF.Offset((float)(getFromValue ? ((0.0 - colorBoxSize.Width) / 2.0) : (colorBoxSize.Width / 2.0)), 0f);
            }
            float num3  = panelBounds.Left - rectangleF.Left;
            bool  flag  = false;
            bool  flag2 = false;

            if (num3 > 0.0)
            {
                RectangleF rectangleF2 = rectangleF;
                rectangleF2.Inflate((float)(0.0 - num3), 0f);
                if (rectangleF2.Width > firstCaptionSize.Width)
                {
                    rectangleF = rectangleF2;
                }
                else
                {
                    rectangleF.X     += num3;
                    rectangleF.Width -= num3;
                    flag              = true;
                }
            }
            float num4 = rectangleF.Right - panelBounds.Right;

            if (num4 > 0.0)
            {
                RectangleF rectangleF3 = rectangleF;
                rectangleF3.Inflate((float)(0.0 - num4), 0f);
                if (rectangleF3.Width > lastCaptionSize.Width)
                {
                    rectangleF = rectangleF3;
                }
                else
                {
                    rectangleF.Width -= num4;
                    flag2             = true;
                }
            }
            if (flag && flag2)
            {
                horizontalAlignemnt = StringAlignment.Center;
            }
            else if (flag)
            {
                horizontalAlignemnt = StringAlignment.Near;
            }
            else if (flag2)
            {
                horizontalAlignemnt = StringAlignment.Far;
            }
            else
            {
                horizontalAlignemnt = StringAlignment.Center;
            }
            rectangleF.Height += 1f;
            return(Rectangle.Round(rectangleF));

IL_002e:
            rectangleF.Width = Math.Max(rectangleF.Width, longestEndLabelWidth);
            num = (float)((rectangleF.Width - labelBoxSize.Width) / 2.0);
            num = (float)((!(num > 0.0)) ? 0.0 : (num * (float)((colorIndex != 0) ? 1 : (-1))));
            goto IL_0074;
        }
        private void CreateColorBarPath(RectangleF panelBounds, RectangleF colorBarBounds, int[] colorsRef, SwatchLabelType currentLabelType, out GraphicsPath outlinePath, out GraphicsPath fillPath)
        {
            colorBarBounds = Rectangle.Round(colorBarBounds);
            float      width = colorBarBounds.Width / (float)colorsRef.Length;
            RectangleF rect  = new RectangleF(colorBarBounds.X, colorBarBounds.Y, width, colorBarBounds.Height);

            outlinePath = new GraphicsPath();
            fillPath    = new GraphicsPath();
            PointF pointF  = new PointF(colorBarBounds.Left, colorBarBounds.Bottom);
            PointF pointF2 = new PointF(colorBarBounds.Left, colorBarBounds.Top);
            float  num     = Math.Min((float)(this.TickMarkLength + 1), panelBounds.Bottom - pointF.Y);
            float  num2    = Math.Min((float)this.TickMarkLength, pointF.Y - panelBounds.Top);

            pointF2.Y -= num2;
            if (!(colorBarBounds.Width <= 0.0) && !(colorBarBounds.Width <= 0.0))
            {
                outlinePath.AddRectangle(colorBarBounds);
                for (int i = 0; i < colorsRef.Length; i++)
                {
                    fillPath.StartFigure();
                    fillPath.AddRectangle(rect);
                    outlinePath.StartFigure();
                    outlinePath.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom);
                    rect.Offset(rect.Width, 0f);
                }
                bool flag = this.LabelAlignment != LabelAlignment.Top;
                if (this.LabelInterval > 0 && this.TickMarkLength > 0)
                {
                    switch (currentLabelType)
                    {
                    case SwatchLabelType.ShowMiddleValue:
                        pointF.X  += (float)(rect.Width / 2.0);
                        pointF2.X += (float)(rect.Width / 2.0);
                        for (int k = 0; k < colorsRef.Length; k += this.LabelInterval)
                        {
                            if (this.MustPrintLabel(colorsRef, k, true, currentLabelType))
                            {
                                PointF pointF4 = PointF.Empty;
                                float  num5    = 0f;
                                if (flag)
                                {
                                    pointF4 = pointF;
                                    num5    = num;
                                }
                                else
                                {
                                    pointF4 = pointF2;
                                    num5    = num2;
                                }
                                outlinePath.StartFigure();
                                outlinePath.AddLine(pointF4.X + (float)k * rect.Width, pointF4.Y, pointF4.X + (float)k * rect.Width, pointF4.Y + num5);
                                flag = ((this.LabelAlignment == LabelAlignment.Alternate) ? (!flag) : flag);
                            }
                        }
                        break;

                    case SwatchLabelType.ShowBorderValue:
                    {
                        PointF pointF3 = PointF.Empty;
                        float  num3    = 0f;
                        for (int j = 0; j < colorsRef.Length * 2; j++)
                        {
                            if (flag)
                            {
                                pointF3 = pointF;
                                num3    = num;
                            }
                            else
                            {
                                pointF3 = pointF2;
                                num3    = num2;
                            }
                            if (this.MustPrintLabel(colorsRef, j / 2, j % 2 == 0, currentLabelType))
                            {
                                float num4 = 0f;
                                if (this.Colors[colorsRef[j / 2]].NoData)
                                {
                                    num4 = (float)(rect.Width / 2.0);
                                }
                                outlinePath.StartFigure();
                                outlinePath.AddLine(pointF3.X + num4 + (float)(j / 2 + j % 2) * rect.Width, pointF3.Y, pointF3.X + num4 + (float)(j / 2 + j % 2) * rect.Width, pointF3.Y + num3);
                                flag = ((this.LabelAlignment == LabelAlignment.Alternate) ? (!flag) : flag);
                            }
                        }
                        break;
                    }
                    }
                }
            }
        }
 public override void Render(MapGraphics g)
 {
     base.Render(g);
     if (!this.IsEmpty)
     {
         RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
         bool       flag = false;
         try
         {
             if (this.Colors.Count == 0 && this.Common != null && this.Common.MapCore.IsDesignMode())
             {
                 this.PopulateDummyData();
                 flag = true;
             }
             int             num              = (this.LabelAlignment != LabelAlignment.Alternate) ? 1 : 2;
             SwatchLabelType swatchLabelType  = this.GetLabelType();
             SizeF           colorBoxSize     = default(SizeF);
             SizeF           labelBoxSize     = default(SizeF);
             SizeF           firstCaptionSize = default(SizeF);
             SizeF           lastCaptionSize  = default(SizeF);
             this.CalculateFontDependentData(g, absoluteRectangle.Size);
             absoluteRectangle.Inflate((float)(-this.PanelPadding), (float)(-this.PanelPadding));
             if (!(absoluteRectangle.Width < 1.0) && !(absoluteRectangle.Height < 1.0))
             {
                 int[] colorsRef = this.GetColorsRef(swatchLabelType);
                 float num2      = 0f;
                 if (this.LabelInterval > 0 && this.ShowEndLabels)
                 {
                     firstCaptionSize        = g.MeasureString(this.GetLabelCaption(0, true, swatchLabelType), this.Font, absoluteRectangle.Size, StringFormat.GenericTypographic);
                     firstCaptionSize.Width += this.TrimmingProtector;
                     lastCaptionSize         = g.MeasureString(this.GetLabelCaption(this.Colors.Count - 1, false, swatchLabelType), this.Font, absoluteRectangle.Size, StringFormat.GenericTypographic);
                     lastCaptionSize.Width  += this.TrimmingProtector;
                     num2 = Math.Max(firstCaptionSize.Width, lastCaptionSize.Width);
                 }
                 bool       flag2           = !string.IsNullOrEmpty(this.Title);
                 RectangleF layoutRectangle = absoluteRectangle;
                 if (flag2)
                 {
                     float height = absoluteRectangle.Height;
                     SizeF sizeF  = g.MeasureString(this.Title, this.TitleFont, layoutRectangle.Size, StringFormat.GenericTypographic);
                     float num4   = layoutRectangle.Height = Math.Min(height, sizeF.Height + (float)this.TitleSeparatorSize);
                     absoluteRectangle.Y      += num4;
                     absoluteRectangle.Height -= num4;
                     this.titlePosition        = layoutRectangle;
                 }
                 RectangleF colorBarBounds = this.CalculateMaxColorBarBounds(g, absoluteRectangle, num2, colorsRef.Length, swatchLabelType);
                 float      num5           = 0f;
                 float      num6           = 0f;
                 if (this.LabelInterval > 0)
                 {
                     num5 = this.GetLabelMaxSize(g, absoluteRectangle.Size, swatchLabelType).Height;
                     num6 = (float)(this.TickMarkLength + this.TickMarkLabelGapSize);
                 }
                 float val = Math.Max(3f, (float)((absoluteRectangle.Height - num6) / 5.0));
                 colorBoxSize.Height   = Math.Max(val, absoluteRectangle.Height - (float)num * (num6 + num5));
                 colorBoxSize.Width    = colorBarBounds.Width / (float)colorsRef.Length;
                 colorBarBounds.Height = colorBoxSize.Height;
                 labelBoxSize.Height   = Math.Max(0f, absoluteRectangle.Height - colorBoxSize.Height) / (float)num - num6;
                 labelBoxSize.Width    = colorBoxSize.Width * (float)this.LabelInterval * (float)num;
                 if (this.LabelAlignment == LabelAlignment.Top || this.LabelAlignment == LabelAlignment.Alternate)
                 {
                     colorBarBounds.Y += labelBoxSize.Height + num6;
                 }
                 AntiAliasing antiAliasing = g.AntiAliasing;
                 try
                 {
                     g.AntiAliasing = AntiAliasing.None;
                     GraphicsPath graphicsPath  = default(GraphicsPath);
                     GraphicsPath graphicsPath2 = default(GraphicsPath);
                     this.CreateColorBarPath(absoluteRectangle, colorBarBounds, colorsRef, swatchLabelType, out graphicsPath, out graphicsPath2);
                     GraphicsPathIterator graphicsPathIterator = new GraphicsPathIterator(graphicsPath2);
                     GraphicsPath         graphicsPath3        = new GraphicsPath();
                     Pen pen = new Pen(this.OutlineColor);
                     try
                     {
                         int[] array = colorsRef;
                         foreach (int colorIndex in array)
                         {
                             graphicsPath3.Reset();
                             bool flag3 = default(bool);
                             graphicsPathIterator.NextSubpath(graphicsPath3, out flag3);
                             if (flag3)
                             {
                                 using (Brush brush = this.CreateColorBoxBrush(g, graphicsPath3.GetBounds(), colorIndex))
                                 {
                                     g.FillPath(brush, graphicsPath3);
                                 }
                             }
                         }
                         g.DrawPath(pen, graphicsPath);
                     }
                     finally
                     {
                         graphicsPath.Dispose();
                         graphicsPath2.Dispose();
                         graphicsPathIterator.Dispose();
                         graphicsPath3.Dispose();
                         pen.Dispose();
                     }
                 }
                 finally
                 {
                     g.AntiAliasing = antiAliasing;
                 }
                 if (flag2)
                 {
                     using (Brush brush2 = new SolidBrush(this.TitleColor))
                     {
                         using (StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone())
                         {
                             stringFormat.Alignment     = this.TitleAlignment;
                             stringFormat.LineAlignment = StringAlignment.Near;
                             stringFormat.Trimming      = StringTrimming.EllipsisCharacter;
                             stringFormat.FormatFlags   = StringFormatFlags.NoWrap;
                             g.DrawString(this.Title, this.TitleFont, brush2, layoutRectangle, stringFormat);
                         }
                     }
                 }
                 if (this.Colors.Count != 0 && this.LabelInterval != 0)
                 {
                     using (StringFormat stringFormat2 = (StringFormat)StringFormat.GenericTypographic.Clone())
                     {
                         stringFormat2.Alignment     = StringAlignment.Center;
                         stringFormat2.LineAlignment = StringAlignment.Near;
                         stringFormat2.Trimming      = StringTrimming.EllipsisCharacter;
                         stringFormat2.FormatFlags   = StringFormatFlags.NoWrap;
                         using (Brush brush3 = new SolidBrush(this.LabelColor))
                         {
                             bool flag4 = this.LabelAlignment != LabelAlignment.Top;
                             if (swatchLabelType == SwatchLabelType.ShowMiddleValue)
                             {
                                 for (int j = 0; j < colorsRef.Length; j++)
                                 {
                                     if (this.MustPrintLabel(colorsRef, j, true, swatchLabelType))
                                     {
                                         StringAlignment alignment    = default(StringAlignment);
                                         RectangleF      labelBounds  = this.GetLabelBounds(j, colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, true, swatchLabelType, flag4, firstCaptionSize, lastCaptionSize, out alignment);
                                         string          labelCaption = this.GetLabelCaption(j, true, swatchLabelType);
                                         if (labelBounds.Width > 1.0 && labelBounds.Height > 1.0)
                                         {
                                             if (flag4)
                                             {
                                                 labelBounds.Offset(0f, 1f);
                                             }
                                             stringFormat2.Alignment = alignment;
                                             g.DrawString(labelCaption, this.Font, brush3, labelBounds, stringFormat2);
                                         }
                                         flag4 = ((this.LabelAlignment == LabelAlignment.Alternate) ? (!flag4) : flag4);
                                     }
                                 }
                             }
                             else
                             {
                                 for (int k = 0; k < colorsRef.Length; k++)
                                 {
                                     RectangleF labelBounds2;
                                     if (this.MustPrintLabel(colorsRef, k, true, swatchLabelType))
                                     {
                                         StringAlignment alignment2 = default(StringAlignment);
                                         labelBounds2 = this.GetLabelBounds(colorsRef[k], colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, true, swatchLabelType, flag4, firstCaptionSize, lastCaptionSize, out alignment2);
                                         string labelCaption2 = this.GetLabelCaption(colorsRef[k], true, swatchLabelType);
                                         if (labelBounds2.Width > 1.0 && labelBounds2.Height > 1.0)
                                         {
                                             if (flag4)
                                             {
                                                 labelBounds2.Offset(0f, 1f);
                                             }
                                             stringFormat2.Alignment = alignment2;
                                             g.DrawString(labelCaption2, this.Font, brush3, labelBounds2, stringFormat2);
                                         }
                                         flag4 = ((this.LabelAlignment == LabelAlignment.Alternate) ? (!flag4) : flag4);
                                     }
                                     if (this.MustPrintLabel(colorsRef, k, false, swatchLabelType))
                                     {
                                         StringAlignment alignment3 = default(StringAlignment);
                                         labelBounds2 = this.GetLabelBounds(colorsRef[k], colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, false, swatchLabelType, flag4, firstCaptionSize, lastCaptionSize, out alignment3);
                                         string labelCaption2 = this.GetLabelCaption(colorsRef[k], false, swatchLabelType);
                                         if (labelBounds2.Width > 1.0 && labelBounds2.Height > 1.0)
                                         {
                                             if (flag4)
                                             {
                                                 labelBounds2.Offset(0f, 1f);
                                             }
                                             stringFormat2.Alignment = alignment3;
                                             g.DrawString(labelCaption2, this.Font, brush3, labelBounds2, stringFormat2);
                                         }
                                         flag4 = ((this.LabelAlignment == LabelAlignment.Alternate) ? (!flag4) : flag4);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         finally
         {
             if (flag)
             {
                 this.Colors.Clear();
             }
         }
     }
 }
        public override SizeF GetOptimalSize(MapGraphics g, SizeF maxSizeAbs)
        {
            if (!this.IsVisible())
            {
                return(SizeF.Empty);
            }
            bool flag = false;

            try
            {
                if (this.Colors.Count == 0 && this.Common != null && this.Common.MapCore.IsDesignMode())
                {
                    this.PopulateDummyData();
                    flag = true;
                }
                this.CalculateFontDependentData(g, maxSizeAbs);
                SwatchLabelType swatchLabelType = this.GetLabelType();
                float           num             = (float)(2 * this.PanelPadding);
                float           val             = 0f;
                SizeF           sizeF           = default(SizeF);
                SizeF           sizeF2          = default(SizeF);
                float           num2            = 0f;
                if (this.LabelInterval > 0 && this.ShowEndLabels)
                {
                    sizeF         = g.MeasureString(this.GetLabelCaption(0, true, swatchLabelType), this.Font, maxSizeAbs, StringFormat.GenericTypographic);
                    sizeF.Width  += this.TrimmingProtector;
                    sizeF2        = g.MeasureString(this.GetLabelCaption(this.Colors.Count - 1, false, swatchLabelType), this.Font, maxSizeAbs, StringFormat.GenericTypographic);
                    sizeF2.Width += this.TrimmingProtector;
                    num2          = (float)Math.Round((double)Math.Max(sizeF.Width, sizeF2.Width));
                }
                int   num3         = (this.LabelAlignment != LabelAlignment.Alternate) ? 1 : 2;
                int[] colorsRef    = this.GetColorsRef(swatchLabelType);
                SizeF labelMaxSize = this.GetLabelMaxSize(g, maxSizeAbs, swatchLabelType);
                float height       = labelMaxSize.Height;
                float num4         = Math.Max((float)(2.0 * height), labelMaxSize.Width / (float)(num3 * this.LabelInterval));
                num += height + (float)num3 * (labelMaxSize.Height + (float)this.TickMarkLength + (float)this.TickMarkLabelGapSize);
                if (!string.IsNullOrEmpty(this.Title))
                {
                    SizeF sizeF3 = g.MeasureString(this.Title, this.TitleFont, maxSizeAbs, StringFormat.GenericTypographic);
                    num += sizeF3.Height + (float)this.TitleSeparatorSize;
                    val  = sizeF3.Width + this.TrimmingProtector;
                }
                val = Math.Max(val, num4 * (float)colorsRef.Length);
                float num5 = num2;
                if (swatchLabelType == SwatchLabelType.ShowMiddleValue)
                {
                    num5 -= num4;
                    num5  = (float)((num5 < 0.0) ? 0.0 : num5);
                }
                val += num5;
                val += (float)(2 * this.PanelPadding + 2 * this.BorderWidth);
                num += (float)(2 * this.BorderWidth);
                SizeF result = new SizeF(Math.Min(maxSizeAbs.Width, val), Math.Min(maxSizeAbs.Height, num));
                result.Width  = Math.Max(2f, result.Width);
                result.Height = Math.Max(2f, result.Height);
                return(result);
            }
            finally
            {
                if (flag)
                {
                    this.Colors.Clear();
                }
            }
        }
Exemplo n.º 11
0
        private bool MustPrintLabel(int[] colorsRef, int colorRefIndex, bool isFromValue, SwatchLabelType currentLabelType)
        {
            if (LabelInterval <= 0)
            {
                return(false);
            }
            int num = colorRefIndex + ((currentLabelType == SwatchLabelType.ShowBorderValue && !isFromValue) ? 1 : 0);

            if (colorRefIndex == 0 && isFromValue)
            {
                if (ShowEndLabels)
                {
                    return(true);
                }
                return(Colors[colorsRef[colorRefIndex]].NoData);
            }
            if (colorRefIndex == colorsRef.Length - 1 && !ShowEndLabels && (currentLabelType == SwatchLabelType.ShowMiddleValue || !isFromValue))
            {
                return(false);
            }
            if (currentLabelType == SwatchLabelType.ShowMiddleValue && num % LabelInterval == 0)
            {
                return(true);
            }
            if (colorsRef[colorRefIndex] == -1 || (!Colors[colorsRef[colorRefIndex]].NoData && Colors[colorsRef[colorRefIndex]].HasTextValue) || num % LabelInterval != 0)
            {
                return(false);
            }
            if (!isFromValue)
            {
                if (!Colors[colorsRef[colorRefIndex]].NoData)
                {
                    return(true);
                }
                return(false);
            }
            if (MustPrintLabel(colorsRef, colorRefIndex - 1, isFromValue: false, currentLabelType))
            {
                return(Colors[colorsRef[colorRefIndex]].NoData);
            }
            return(true);
        }
Exemplo n.º 12
0
        private void CreateColorBarPath(RectangleF panelBounds, RectangleF colorBarBounds, int[] colorsRef, SwatchLabelType currentLabelType, out GraphicsPath outlinePath, out GraphicsPath fillPath)
        {
            colorBarBounds = Rectangle.Round(colorBarBounds);
            float      width = colorBarBounds.Width / (float)colorsRef.Length;
            RectangleF rect  = new RectangleF(colorBarBounds.X, colorBarBounds.Y, width, colorBarBounds.Height);

            outlinePath = new GraphicsPath();
            fillPath    = new GraphicsPath();
            PointF pointF  = new PointF(colorBarBounds.Left, colorBarBounds.Bottom);
            PointF pointF2 = new PointF(colorBarBounds.Left, colorBarBounds.Top);
            float  num     = Math.Min(TickMarkLength + 1, panelBounds.Bottom - pointF.Y);
            float  num2    = Math.Min(TickMarkLength, pointF.Y - panelBounds.Top);

            pointF2.Y -= num2;
            if (colorBarBounds.Width <= 0f || colorBarBounds.Width <= 0f)
            {
                return;
            }
            outlinePath.AddRectangle(colorBarBounds);
            for (int i = 0; i < colorsRef.Length; i++)
            {
                fillPath.StartFigure();
                fillPath.AddRectangle(rect);
                outlinePath.StartFigure();
                outlinePath.AddLine(rect.Right, rect.Top, rect.Right, rect.Bottom);
                rect.Offset(rect.Width, 0f);
            }
            bool flag = LabelAlignment != LabelAlignment.Top;

            if (LabelInterval <= 0 || TickMarkLength <= 0)
            {
                return;
            }
            switch (currentLabelType)
            {
            case SwatchLabelType.ShowMiddleValue:
            {
                pointF.X  += rect.Width / 2f;
                pointF2.X += rect.Width / 2f;
                for (int k = 0; k < colorsRef.Length; k += LabelInterval)
                {
                    if (MustPrintLabel(colorsRef, k, isFromValue: true, currentLabelType))
                    {
                        PointF empty2 = PointF.Empty;
                        float  num5   = 0f;
                        if (flag)
                        {
                            empty2 = pointF;
                            num5   = num;
                        }
                        else
                        {
                            empty2 = pointF2;
                            num5   = num2;
                        }
                        outlinePath.StartFigure();
                        outlinePath.AddLine(empty2.X + (float)k * rect.Width, empty2.Y, empty2.X + (float)k * rect.Width, empty2.Y + num5);
                        flag = ((LabelAlignment == LabelAlignment.Alternate) ? (!flag) : flag);
                    }
                }
                break;
            }

            case SwatchLabelType.ShowBorderValue:
            {
                PointF empty = PointF.Empty;
                float  num3  = 0f;
                for (int j = 0; j < colorsRef.Length * 2; j++)
                {
                    if (flag)
                    {
                        empty = pointF;
                        num3  = num;
                    }
                    else
                    {
                        empty = pointF2;
                        num3  = num2;
                    }
                    if (MustPrintLabel(colorsRef, j / 2, j % 2 == 0, currentLabelType))
                    {
                        float num4 = 0f;
                        if (Colors[colorsRef[j / 2]].NoData)
                        {
                            num4 = rect.Width / 2f;
                        }
                        outlinePath.StartFigure();
                        outlinePath.AddLine(empty.X + num4 + (float)(j / 2 + j % 2) * rect.Width, empty.Y, empty.X + num4 + (float)(j / 2 + j % 2) * rect.Width, empty.Y + num3);
                        flag = ((LabelAlignment == LabelAlignment.Alternate) ? (!flag) : flag);
                    }
                }
                break;
            }
            }
        }
Exemplo n.º 13
0
        internal override void Render(MapGraphics g)
        {
            base.Render(g);
            if (IsEmpty)
            {
                return;
            }
            RectangleF absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
            bool       flag = false;

            try
            {
                if (Colors.Count == 0 && Common != null && Common.MapCore.IsDesignMode())
                {
                    PopulateDummyData();
                    flag = true;
                }
                int             num              = (LabelAlignment != LabelAlignment.Alternate) ? 1 : 2;
                SwatchLabelType swatchLabelType  = GetLabelType();
                SizeF           colorBoxSize     = default(SizeF);
                SizeF           labelBoxSize     = default(SizeF);
                SizeF           firstCaptionSize = default(SizeF);
                SizeF           lastCaptionSize  = default(SizeF);
                CalculateFontDependentData(g, absoluteRectangle.Size);
                absoluteRectangle.Inflate(-PanelPadding, -PanelPadding);
                if (absoluteRectangle.Width < 1f || absoluteRectangle.Height < 1f)
                {
                    return;
                }
                int[] colorsRef = GetColorsRef(swatchLabelType);
                float num2      = 0f;
                if (LabelInterval > 0 && ShowEndLabels)
                {
                    firstCaptionSize        = g.MeasureString(GetLabelCaption(0, getFromValue: true, swatchLabelType), Font, absoluteRectangle.Size, StringFormat.GenericTypographic);
                    firstCaptionSize.Width += TrimmingProtector;
                    lastCaptionSize         = g.MeasureString(GetLabelCaption(Colors.Count - 1, getFromValue: false, swatchLabelType), Font, absoluteRectangle.Size, StringFormat.GenericTypographic);
                    lastCaptionSize.Width  += TrimmingProtector;
                    num2 = Math.Max(firstCaptionSize.Width, lastCaptionSize.Width);
                }
                bool       flag2           = !string.IsNullOrEmpty(Title);
                RectangleF layoutRectangle = absoluteRectangle;
                if (flag2)
                {
                    float num4 = layoutRectangle.Height = Math.Min(absoluteRectangle.Height, g.MeasureString(Title, TitleFont, layoutRectangle.Size, StringFormat.GenericTypographic).Height + (float)TitleSeparatorSize);
                    absoluteRectangle.Y      += num4;
                    absoluteRectangle.Height -= num4;
                    titlePosition             = layoutRectangle;
                }
                RectangleF colorBarBounds = CalculateMaxColorBarBounds(g, absoluteRectangle, num2, colorsRef.Length, swatchLabelType);
                float      num5           = 0f;
                float      num6           = 0f;
                if (LabelInterval > 0)
                {
                    num5 = GetLabelMaxSize(g, absoluteRectangle.Size, swatchLabelType).Height;
                    num6 = TickMarkLength + TickMarkLabelGapSize;
                }
                float val = Math.Max(3f, (absoluteRectangle.Height - num6) / 5f);
                colorBoxSize.Height   = Math.Max(val, absoluteRectangle.Height - (float)num * (num6 + num5));
                colorBoxSize.Width    = colorBarBounds.Width / (float)colorsRef.Length;
                colorBarBounds.Height = colorBoxSize.Height;
                labelBoxSize.Height   = Math.Max(0f, absoluteRectangle.Height - colorBoxSize.Height) / (float)num - num6;
                labelBoxSize.Width    = colorBoxSize.Width * (float)LabelInterval * (float)num;
                if (LabelAlignment == LabelAlignment.Top || LabelAlignment == LabelAlignment.Alternate)
                {
                    colorBarBounds.Y += labelBoxSize.Height + num6;
                }
                AntiAliasing antiAliasing = g.AntiAliasing;
                try
                {
                    g.AntiAliasing = AntiAliasing.None;
                    CreateColorBarPath(absoluteRectangle, colorBarBounds, colorsRef, swatchLabelType, out GraphicsPath outlinePath, out GraphicsPath fillPath);
                    GraphicsPathIterator graphicsPathIterator = new GraphicsPathIterator(fillPath);
                    GraphicsPath         graphicsPath         = new GraphicsPath();
                    Pen pen = new Pen(OutlineColor);
                    try
                    {
                        int[] array = colorsRef;
                        foreach (int colorIndex in array)
                        {
                            graphicsPath.Reset();
                            graphicsPathIterator.NextSubpath(graphicsPath, out bool isClosed);
                            if (isClosed)
                            {
                                using (Brush brush = CreateColorBoxBrush(g, graphicsPath.GetBounds(), colorIndex))
                                {
                                    g.FillPath(brush, graphicsPath);
                                }
                            }
                        }
                        g.DrawPath(pen, outlinePath);
                    }
                    finally
                    {
                        outlinePath.Dispose();
                        fillPath.Dispose();
                        graphicsPathIterator.Dispose();
                        graphicsPath.Dispose();
                        pen.Dispose();
                    }
                }
                finally
                {
                    g.AntiAliasing = antiAliasing;
                }
                if (flag2)
                {
                    using (Brush brush2 = new SolidBrush(TitleColor))
                    {
                        using (StringFormat stringFormat = (StringFormat)StringFormat.GenericTypographic.Clone())
                        {
                            stringFormat.Alignment     = TitleAlignment;
                            stringFormat.LineAlignment = StringAlignment.Near;
                            stringFormat.Trimming      = StringTrimming.EllipsisCharacter;
                            stringFormat.FormatFlags   = StringFormatFlags.NoWrap;
                            g.DrawString(Title, TitleFont, brush2, layoutRectangle, stringFormat);
                        }
                    }
                }
                if (Colors.Count == 0 || LabelInterval == 0)
                {
                    return;
                }
                using (StringFormat stringFormat2 = (StringFormat)StringFormat.GenericTypographic.Clone())
                {
                    stringFormat2.Alignment     = StringAlignment.Center;
                    stringFormat2.LineAlignment = StringAlignment.Near;
                    stringFormat2.Trimming      = StringTrimming.EllipsisCharacter;
                    stringFormat2.FormatFlags   = StringFormatFlags.NoWrap;
                    using (Brush brush3 = new SolidBrush(LabelColor))
                    {
                        bool flag3 = LabelAlignment != LabelAlignment.Top;
                        if (swatchLabelType == SwatchLabelType.ShowMiddleValue)
                        {
                            for (int j = 0; j < colorsRef.Length; j++)
                            {
                                if (!MustPrintLabel(colorsRef, j, isFromValue: true, swatchLabelType))
                                {
                                    continue;
                                }
                                StringAlignment horizontalAlignemnt;
                                RectangleF      labelBounds  = GetLabelBounds(j, colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, getFromValue: true, swatchLabelType, flag3, firstCaptionSize, lastCaptionSize, out horizontalAlignemnt);
                                string          labelCaption = GetLabelCaption(j, getFromValue: true, swatchLabelType);
                                if (labelBounds.Width > 1f && labelBounds.Height > 1f)
                                {
                                    if (flag3)
                                    {
                                        labelBounds.Offset(0f, 1f);
                                    }
                                    stringFormat2.Alignment = horizontalAlignemnt;
                                    g.DrawString(labelCaption, Font, brush3, labelBounds, stringFormat2);
                                }
                                flag3 = ((LabelAlignment == LabelAlignment.Alternate) ? (!flag3) : flag3);
                            }
                            return;
                        }
                        for (int k = 0; k < colorsRef.Length; k++)
                        {
                            RectangleF labelBounds2;
                            string     labelCaption2;
                            if (MustPrintLabel(colorsRef, k, isFromValue: true, swatchLabelType))
                            {
                                labelBounds2  = GetLabelBounds(colorsRef[k], colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, getFromValue: true, swatchLabelType, flag3, firstCaptionSize, lastCaptionSize, out StringAlignment horizontalAlignemnt2);
                                labelCaption2 = GetLabelCaption(colorsRef[k], getFromValue: true, swatchLabelType);
                                if (labelBounds2.Width > 1f && labelBounds2.Height > 1f)
                                {
                                    if (flag3)
                                    {
                                        labelBounds2.Offset(0f, 1f);
                                    }
                                    stringFormat2.Alignment = horizontalAlignemnt2;
                                    g.DrawString(labelCaption2, Font, brush3, labelBounds2, stringFormat2);
                                }
                                flag3 = ((LabelAlignment == LabelAlignment.Alternate) ? (!flag3) : flag3);
                            }
                            if (!MustPrintLabel(colorsRef, k, isFromValue: false, swatchLabelType))
                            {
                                continue;
                            }
                            labelBounds2  = GetLabelBounds(colorsRef[k], colorsRef, absoluteRectangle, colorBarBounds, labelBoxSize, colorBoxSize, num2, getFromValue: false, swatchLabelType, flag3, firstCaptionSize, lastCaptionSize, out StringAlignment horizontalAlignemnt3);
                            labelCaption2 = GetLabelCaption(colorsRef[k], getFromValue: false, swatchLabelType);
                            if (labelBounds2.Width > 1f && labelBounds2.Height > 1f)
                            {
                                if (flag3)
                                {
                                    labelBounds2.Offset(0f, 1f);
                                }
                                stringFormat2.Alignment = horizontalAlignemnt3;
                                g.DrawString(labelCaption2, Font, brush3, labelBounds2, stringFormat2);
                            }
                            flag3 = ((LabelAlignment == LabelAlignment.Alternate) ? (!flag3) : flag3);
                        }
                    }
                }
            }
            finally
            {
                if (flag)
                {
                    Colors.Clear();
                }
            }
        }