TickPos() public method

public TickPos ( int i ) : TVec3
i int
return TVec3
Beispiel #1
0
 public void PaintAxisGridAndTicks(Graphics g, Axis a, bool marks, TVec3 o, TVec3 o_, TVec3 L)
 {
     a.MinorGridEnabled = false;
     a.MinorTicksEnabled = false;
     int nTicks = (int)(L.NormInf / 10.0);
     if (nTicks < 3)
         nTicks = 3;
     if (nTicks > 10)
         nTicks = 10;
     TAxisCalc taxisCalc = new TAxisCalc(o, o + L, a.Min, a.Max, nTicks);
     TVec3 tvec3_1 = o_ - o;
     TVec3 tvec3_2 = TVec3.O;
     TVec3 tvec3_3 = -0.04 * tvec3_1;
     if (o_.y > o.y)
     {
         tvec3_2 = tvec3_1;
         tvec3_3 = -tvec3_3;
     }
     TVec3 tvec3_4 = tvec3_2 + 1.04 * tvec3_3;
     if (a.GridEnabled)
     {
         Pen pen = new Pen(a.GridColor, a.GridWidth);
         for (int i = 0; i < taxisCalc.nTicks; ++i)
             g.DrawLine(pen, (Point)taxisCalc.TickPos(i), (Point)(taxisCalc.TickPos(i) + tvec3_1));
     }
     if (a.Position == EAxisPosition.Right && tvec3_3.x <= 0.0)
         marks = false;
     if (!marks)
         return;
     int num1 = a.Position == EAxisPosition.Bottom ? 0 : 1;
     int num2 = a.Position == EAxisPosition.Bottom ? taxisCalc.nTicks - 1 : taxisCalc.nTicks;
     float num3 = 0.0f;
     if (a.MajorTicksEnabled)
     {
         Pen pen = new Pen(a.GridColor, a.GridWidth);
         for (int i = num1; i < num2; ++i)
             g.DrawLine(pen, (Point)(taxisCalc.TickPos(i) + tvec3_2), (Point)(taxisCalc.TickPos(i) + tvec3_2 + tvec3_3));
     }
     if (a.LabelEnabled)
     {
         Font labelFont = a.LabelFont;
         float height = labelFont.GetHeight(g);
         SolidBrush solidBrush = new SolidBrush(a.LabelColor);
         StringFormat format = new StringFormat();
         float num4;
         if (a.Position == EAxisPosition.Bottom)
         {
             format.FormatFlags = StringFormatFlags.DirectionVertical;
             num4 = (float)Math.Abs(taxisCalc.TickPos(1).x - taxisCalc.TickPos(0).x);
         }
         else
         {
             tvec3_4.y -= 0.5 * (double)a.LabelFont.GetHeight();
             num4 = (float)Math.Abs(taxisCalc.TickPos(1).y - taxisCalc.TickPos(0).y);
         }
         if (tvec3_3.x < 0.0)
             tvec3_4.x -= (double)a.LabelFont.GetHeight();
         if ((double)num4 > 0.0)
         {
             int num5 = (int)((double)height / (double)num4 + 1.0);
             if (num1 + num5 < num2)
             {
                 int i = num1;
                 while (i < num2)
                 {
                     if (i + num5 >= num2)
                         i = num2 - 1;
                     TVec3 tvec3_5 = taxisCalc.TickPos(i) + tvec3_4;
                     string str = taxisCalc.TickVal(i).ToString();
                     g.DrawString(str, labelFont, (Brush)solidBrush, (PointF)tvec3_5, format);
                     SizeF sizeF = g.MeasureString(str, labelFont);
                     if ((double)sizeF.Width > (double)num3)
                         num3 = sizeF.Width;
                     i += num5;
                 }
             }
             else if (num2 > 0)
             {
                 int i = num2 - 1;
                 TVec3 tvec3_5 = taxisCalc.TickPos(i) + tvec3_4;
                 string str = taxisCalc.TickVal(i).ToString();
                 g.DrawString(str, labelFont, (Brush)solidBrush, (PointF)tvec3_5, format);
                 num3 = g.MeasureString(str, labelFont).Width;
             }
         }
     }
     if (!a.TitleEnabled)
         return;
     SizeF sizeF1 = g.MeasureString(a.Title, a.TitleFont);
     PointF point1;
     PointF point2;
     float angle;
     if (a.Position == EAxisPosition.Bottom)
     {
         if (tvec3_3.x < 0.0)
         {
             point1 = taxisCalc.TickPos(0).x > taxisCalc.TickPos(1).x ? (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4) : (PointF)(taxisCalc.TickPos(0) + tvec3_4);
             point1.Y += num3;
             point2 = point1;
             angle = (float)(Math.Atan2(Math.Abs(L.y), Math.Abs(L.x)) * 180.0 / Math.PI);
         }
         else
         {
             point1 = taxisCalc.TickPos(0).x > taxisCalc.TickPos(1).x ? (PointF)(taxisCalc.TickPos(0) + tvec3_4) : (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4);
             point1.X += a.LabelFont.GetHeight(g);
             point1.Y += num3;
             point2 = point1;
             point2.X -= sizeF1.Width;
             angle = (float)(-Math.Atan2(Math.Abs(L.y), Math.Abs(L.x)) * 180.0 / Math.PI);
         }
     }
     else
     {
         point1 = taxisCalc.TickPos(0).z > taxisCalc.TickPos(1).z ? (PointF)(taxisCalc.TickPos(0) + tvec3_4) : (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4);
         point1.X += num3;
         point2 = point1;
         point2.X -= sizeF1.Width;
         angle = -90f;
     }
     Matrix matrix = new Matrix();
     matrix.RotateAt(angle, point1, MatrixOrder.Append);
     g.Transform = matrix;
     g.DrawString(a.Title, a.LabelFont, (Brush)new SolidBrush(a.LabelColor), point2);
     matrix.Reset();
     g.Transform = matrix;
 }
Beispiel #2
0
        public void PaintAxisGridAndTicks(Graphics g, Axis a, bool marks, TVec3 o, TVec3 o_, TVec3 L)
        {
            a.MinorGridEnabled  = false;
            a.MinorTicksEnabled = false;
            int nTicks = (int)(L.NormInf / 10.0);

            if (nTicks < 3)
            {
                nTicks = 3;
            }
            if (nTicks > 10)
            {
                nTicks = 10;
            }
            TAxisCalc taxisCalc = new TAxisCalc(o, o + L, a.Min, a.Max, nTicks);
            TVec3     tvec3_1   = o_ - o;
            TVec3     tvec3_2   = TVec3.O;
            TVec3     tvec3_3   = -0.04 * tvec3_1;

            if (o_.y > o.y)
            {
                tvec3_2 = tvec3_1;
                tvec3_3 = -tvec3_3;
            }
            TVec3 tvec3_4 = tvec3_2 + 1.04 * tvec3_3;

            if (a.GridEnabled)
            {
                Pen pen = new Pen(a.GridColor, a.GridWidth);
                for (int i = 0; i < taxisCalc.nTicks; ++i)
                {
                    g.DrawLine(pen, (Point)taxisCalc.TickPos(i), (Point)(taxisCalc.TickPos(i) + tvec3_1));
                }
            }
            if (a.Position == EAxisPosition.Right && tvec3_3.x <= 0.0)
            {
                marks = false;
            }
            if (!marks)
            {
                return;
            }
            int   num1 = a.Position == EAxisPosition.Bottom ? 0 : 1;
            int   num2 = a.Position == EAxisPosition.Bottom ? taxisCalc.nTicks - 1 : taxisCalc.nTicks;
            float num3 = 0.0f;

            if (a.MajorTicksEnabled)
            {
                Pen pen = new Pen(a.GridColor, a.GridWidth);
                for (int i = num1; i < num2; ++i)
                {
                    g.DrawLine(pen, (Point)(taxisCalc.TickPos(i) + tvec3_2), (Point)(taxisCalc.TickPos(i) + tvec3_2 + tvec3_3));
                }
            }
            if (a.LabelEnabled)
            {
                Font         labelFont  = a.LabelFont;
                float        height     = labelFont.GetHeight(g);
                SolidBrush   solidBrush = new SolidBrush(a.LabelColor);
                StringFormat format     = new StringFormat();
                float        num4;
                if (a.Position == EAxisPosition.Bottom)
                {
                    format.FormatFlags = StringFormatFlags.DirectionVertical;
                    num4 = (float)Math.Abs(taxisCalc.TickPos(1).x - taxisCalc.TickPos(0).x);
                }
                else
                {
                    tvec3_4.y -= 0.5 * (double)a.LabelFont.GetHeight();
                    num4       = (float)Math.Abs(taxisCalc.TickPos(1).y - taxisCalc.TickPos(0).y);
                }
                if (tvec3_3.x < 0.0)
                {
                    tvec3_4.x -= (double)a.LabelFont.GetHeight();
                }
                if ((double)num4 > 0.0)
                {
                    int num5 = (int)((double)height / (double)num4 + 1.0);
                    if (num1 + num5 < num2)
                    {
                        int i = num1;
                        while (i < num2)
                        {
                            if (i + num5 >= num2)
                            {
                                i = num2 - 1;
                            }
                            TVec3  tvec3_5 = taxisCalc.TickPos(i) + tvec3_4;
                            string str     = taxisCalc.TickVal(i).ToString();
                            g.DrawString(str, labelFont, (Brush)solidBrush, (PointF)tvec3_5, format);
                            SizeF sizeF = g.MeasureString(str, labelFont);
                            if ((double)sizeF.Width > (double)num3)
                            {
                                num3 = sizeF.Width;
                            }
                            i += num5;
                        }
                    }
                    else if (num2 > 0)
                    {
                        int    i       = num2 - 1;
                        TVec3  tvec3_5 = taxisCalc.TickPos(i) + tvec3_4;
                        string str     = taxisCalc.TickVal(i).ToString();
                        g.DrawString(str, labelFont, (Brush)solidBrush, (PointF)tvec3_5, format);
                        num3 = g.MeasureString(str, labelFont).Width;
                    }
                }
            }
            if (!a.TitleEnabled)
            {
                return;
            }
            SizeF  sizeF1 = g.MeasureString(a.Title, a.TitleFont);
            PointF point1;
            PointF point2;
            float  angle;

            if (a.Position == EAxisPosition.Bottom)
            {
                if (tvec3_3.x < 0.0)
                {
                    point1    = taxisCalc.TickPos(0).x > taxisCalc.TickPos(1).x ? (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4) : (PointF)(taxisCalc.TickPos(0) + tvec3_4);
                    point1.Y += num3;
                    point2    = point1;
                    angle     = (float)(Math.Atan2(Math.Abs(L.y), Math.Abs(L.x)) * 180.0 / Math.PI);
                }
                else
                {
                    point1    = taxisCalc.TickPos(0).x > taxisCalc.TickPos(1).x ? (PointF)(taxisCalc.TickPos(0) + tvec3_4) : (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4);
                    point1.X += a.LabelFont.GetHeight(g);
                    point1.Y += num3;
                    point2    = point1;
                    point2.X -= sizeF1.Width;
                    angle     = (float)(-Math.Atan2(Math.Abs(L.y), Math.Abs(L.x)) * 180.0 / Math.PI);
                }
            }
            else
            {
                point1    = taxisCalc.TickPos(0).z > taxisCalc.TickPos(1).z ? (PointF)(taxisCalc.TickPos(0) + tvec3_4) : (PointF)(taxisCalc.TickPos(taxisCalc.nTicks - 1) + tvec3_4);
                point1.X += num3;
                point2    = point1;
                point2.X -= sizeF1.Width;
                angle     = -90f;
            }
            Matrix matrix = new Matrix();

            matrix.RotateAt(angle, point1, MatrixOrder.Append);
            g.Transform = matrix;
            g.DrawString(a.Title, a.LabelFont, (Brush) new SolidBrush(a.LabelColor), point2);
            matrix.Reset();
            g.Transform = matrix;
        }