context: namespace Steema.TeeChart.Styles
  {
      using Steema.TeeChart;
      using Steema.TeeChart.Drawing;
      using System;
      using System.ComponentModel;
      using System.Drawing;
  
      [ToolboxBitmap(typeof(Steema.TeeChart.Styles.Shape), "SeriesIcons.Shape.bmp")]
      public class Shape : Series
      {
          private TextShape shape;
          private ShapeStyles style;
          private ShapeTextHorizAlign textHorizAlign;
          private ShapeTextVertAlign textVertAlign;
          private int tmpMidX;
          private int tmpMidY;
          private ShapeXYStyles xyStyle;
  
          public Shape() : this(null)
          {
          }
  
          public Shape(Chart c) : base(c)
          {
              this.style = ShapeStyles.Circle;
              this.xyStyle = ShapeXYStyles.Axis;
              this.textVertAlign = ShapeTextVertAlign.Center;
              this.textHorizAlign = ShapeTextHorizAlign.Center;
              this.shape = new TextShape(c);
              this.AddDefaultPoints();
          }
  
          private void AddDefaultPoints()
          {
              base.Add((double) 0.0, (double) 0.0);
              base.Add((double) 100.0, (double) 100.0);
          }
  
          protected override void AddSampleValues(int numValues)
          {
              Series.SeriesRandom random = base.RandomBounds(1);
              if (random.StepX == 0.0)
              {
                  this.AddDefaultPoints();
              }
              else
              {
                  base.Add((double) (random.tmpX + (random.StepX / 8.0)), (double) (random.tmpY / 2.0));
                  base.Add((double) ((random.tmpX + random.StepX) - (random.StepX / 8.0)), (double) (random.tmpY + Utils.Round((double) (random.DifY * random.Random()))));
              }
          }
  
          protected internal override void CalcZOrder()
          {
              if (base.UseAxis)
              {
                  base.CalcZOrder();
              }
          }
  
          public override int Clicked(int x, int y)
          {
              int num;
              int num2;
              bool flag;
              if (base.chart != null)
              {
                  base.chart.graphics3D.Calculate2DPosition(ref x, ref y, base.StartZ);
              }
              Point p = new Point(x, y);
              Rectangle shapeRectangle = this.GetShapeRectangle();
              Graphics3D.RectCenter(shapeRectangle, out num, out num2);
              switch (this.style)
              {
                  case ShapeStyles.Circle:
                      flag = Graphics3D.PointInEllipse(p, shapeRectangle);
                      break;
  
                  case ShapeStyles.VertLine:
                      flag = Graphics3D.PointInLineTolerance(p, num, shapeRectangle.Y, num, shapeRectangle.Bottom, 3);
                      break;
  
                  case ShapeStyles.HorizLine:
                      flag = Graphics3D.PointInLineTolerance(p, shapeRectangle.X, num2, shapeRectangle.Right, num2, 3);
                      break;
  
                  case ShapeStyles.Triangle:
                  case ShapeStyles.Pyramid:
                      flag = Graphics3D.PointInTriangle(p, shapeRectangle.X, shapeRectangle.Right, shapeRectangle.Bottom, shapeRectangle.Y);
                      break;
  
                  case ShapeStyles.InvertTriangle:
                  case ShapeStyles.InvertPyramid:
                      flag = Graphics3D.PointInTriangle(p, shapeRectangle.X, shapeRectangle.Right, shapeRectangle.Y, shapeRectangle.Bottom);
                      break;
  
                  case ShapeStyles.Line:
                      flag = Graphics3D.PointInLineTolerance(p, shapeRectangle.X, shapeRectangle.Y, shapeRectangle.Right, shapeRectangle.Bottom, 3);
                      break;
  
                  case ShapeStyles.Diamond:
                  {
                      Point[] poly = new Point[] { new Point(num, shapeRectangle.Y), new Point(shapeRectangle.Right, num2), new Point(num, shapeRectangle.Bottom), new Point(shapeRectangle.X, num2) };
                      flag = Graphics3D.PointInPolygon(p, poly);
                      break;
                  }
                  default:
                      flag = shapeRectangle.Contains(x, y);
                      break;
              }
              if (!flag)
              {
                  return -1;
              }
              return 0;
          }
  
          protected internal override void CreateSubGallery(Series.SubGalleryEventHandler AddSubChart)
          {
              base.CreateSubGallery(AddSubChart);
              AddSubChart(Texts.Rectangle);
              AddSubChart(Texts.VertLine);
              AddSubChart(Texts.HorizLine);
              AddSubChart(Texts.Ellipse);
              AddSubChart(Texts.DownTri);
              AddSubChart(Texts.Line);
              AddSubChart(Texts.Diamond);
              AddSubChart(Texts.Cube);
              AddSubChart(Texts.Cross);
              AddSubChart(Texts.DiagCross);
              AddSubChart(Texts.Star);
              AddSubChart(Texts.Pyramid);
              AddSubChart(Texts.InvPyramid);
              AddSubChart(Texts.Hollow);
          }
  
          private void DoGradient(bool Is3D, Rectangle r)
          {
              if (!this.Transparent && this.Gradient.Visible)
              {
                  Rectangle rectangle = Is3D ? base.chart.graphics3D.CalcRect3D(r, base.MiddleZ) : r;
                  if (this.style == ShapeStyles.Circle)
                  {
                      base.chart.graphics3D.ClipEllipse(rectangle);
                  }
                  this.Gradient.Draw(base.chart.graphics3D, rectangle);
                  if (this.style == ShapeStyles.Circle)
                  {
                      base.chart.graphics3D.UnClip();
                  }
                  base.chart.graphics3D.Brush.Visible = false;
              }
          }
  
          private void DrawCross2D(Rectangle r)
          {
              base.chart.graphics3D.VerticalLine(this.tmpMidX, r.Y, r.Bottom + 1);
              base.chart.graphics3D.HorizontalLine(r.X, r.Right + 1, this.tmpMidY);
          }
  
          private void DrawCross3D(Rectangle r)
          {
              base.chart.Graphics3D.VerticalLine(this.tmpMidX, r.Y, r.Bottom, base.MiddleZ);
              base.chart.Graphics3D.HorizontalLine(r.X, r.Right, this.tmpMidY, base.MiddleZ);
          }
  
          private void DrawDiagonalCross2D(Rectangle r)
          {
              base.chart.graphics3D.Line(r.X, r.Y, r.Right + 1, r.Bottom + 1);
              base.chart.graphics3D.Line(r.X, r.Bottom, r.Right + 1, r.Y - 1);
          }
  
          private void DrawDiagonalCross3D(Rectangle r)
          {
              base.chart.graphics3D.Line(r.X, r.Y, r.Right, r.Bottom, base.MiddleZ);
              base.chart.graphics3D.Line(r.X, r.Bottom, r.Right, r.Y, base.MiddleZ);
          }
  
          protected override void DrawLegendShape(Graphics3D g, int valueIndex, Rectangle rect)
          {
              this.DrawShape(g, false, rect);
          }
  
          private void DrawShape(bool Is3D, Rectangle r)
          {
              this.DrawShape(base.chart.graphics3D, Is3D, r);
          }
  
          private void DrawShape(Graphics3D g, bool Is3D, Rectangle r)
          {
              g.Pen = this.Pen;
              if (this.Transparent)
              {
                  g.Brush.Visible = false;
              }
              else
              {
                  g.Brush = this.Brush;
                  g.Brush.Color = base.Color;
              }
              Graphics3D.RectCenter(r, out this.tmpMidX, out this.tmpMidY);
              if (Is3D)
              {
                  switch (this.style)
                  {
                      case ShapeStyles.Rectangle:
                          this.DoGradient(Is3D, r);
                          g.Rectangle(r, base.MiddleZ);
                          return;
  
                      case ShapeStyles.Circle:
                          this.DoGradient(Is3D, r);
                          g.Ellipse(r, base.MiddleZ);
                          return;
  
                      case ShapeStyles.VertLine:
                          g.VerticalLine(this.tmpMidX, r.Y, r.Bottom, base.MiddleZ);
                          return;
  
                      case ShapeStyles.HorizLine:
                          g.HorizontalLine(r.X, r.Right, this.tmpMidY, base.MiddleZ);
                          return;
  
                      case ShapeStyles.Triangle:
                          g.Triangle(new Point(r.X, r.Bottom), new Point(this.tmpMidX, r.Y), new Point(r.Right, r.Bottom), base.MiddleZ);
                          return;
  
                      case ShapeStyles.InvertTriangle:
                          g.Triangle(new Point(r.X, r.Y), new Point(this.tmpMidX, r.Bottom), new Point(r.Right, r.Y), base.MiddleZ);
                          return;
  
                      case ShapeStyles.Line:
  
gt:                         g.Line(r.X, r.Y, r.Right, r.Bottom, base.MiddleZ);