Пример #1
0
        private void DrawText(FRPaintEventArgs e, string text, Brush brush, float x, float y, HorAlign hAlign, VertAlign vAlign)
        {
            Graphics g       = e.Graphics;
            Font     font    = RadialUtils.GetFont(e, Parent, Font);
            SizeF    strSize = RadialUtils.GetStringSize(e, Parent, Font, text);
            float    dx      = 0;
            float    dy      = 0;

            if (hAlign == HorAlign.Middle)
            {
                dx = -strSize.Width / 2;
            }
            else if (hAlign == HorAlign.Left)
            {
                dx = 0;
            }
            else if (hAlign == HorAlign.Right)
            {
                dx = -strSize.Width;
            }

            if (vAlign == VertAlign.Bottom)
            {
                dy = -strSize.Height;
            }
            else if (vAlign == VertAlign.Middle)
            {
                dy = -strSize.Height / 2;
            }
            else if (vAlign == VertAlign.Top)
            {
                dy = 0;
            }
            g.DrawString(text, font, brush, x + dx, y + dy);
        }
Пример #2
0
        public override void Draw(FRPaintEventArgs e)
        {
            if ((Parent as RadialGauge).Type == RadialGaugeType.Circle)
            {
                base.Draw(e);
                float x  = (Parent.AbsLeft + Parent.Border.Width / 2) * e.ScaleX;
                float y  = (Parent.AbsTop + Parent.Border.Width / 2) * e.ScaleY;
                float dx = (Parent.Width - Parent.Border.Width) * e.ScaleX - 1;
                float dy = (Parent.Height - Parent.Border.Width) * e.ScaleY - 1;

                PointF lblPt   = new PointF(x + dx / 2, y + dy - ((Parent.Scale as RadialScale).AvrTick.Y - y));
                SizeF  txtSize = RadialUtils.GetStringSize(e, Parent, Font, Text);
                Font   font    = RadialUtils.GetFont(e, Parent, Font);
                Brush  brush   = e.Cache.GetBrush(Color);
                e.Graphics.DrawString(Text, font, brush, lblPt.X - txtSize.Width / 2, lblPt.Y - txtSize.Height / 2);
            }
        }
Пример #3
0
        private void DrawMajorTicks(FRPaintEventArgs e)
        {
            center    = (Parent as RadialGauge).Center;
            stepValue = (Parent.Maximum - Parent.Minimum) / (MajorTicks.Count - 1);
            if (RadialUtils.IsQuadrant(Parent))
            {
                stepValue *= 2;
            }

            avrValue = Parent.Minimum + (Parent.Maximum - Parent.Minimum) / 2;

            bool   isRightPart = true;
            bool   isLeftPart  = false;
            PointF txtPoint;

            Graphics g     = e.Graphics;
            Pen      pen   = e.Cache.GetPen(MajorTicks.Color, MajorTicks.Width * e.ScaleX, DashStyle.Solid);
            Brush    brush = TextFill.CreateBrush(new RectangleF(Parent.AbsLeft * e.ScaleX, Parent.AbsTop * e.ScaleY,
                                                                 Parent.Width * e.ScaleX, Parent.Height * e.ScaleY), e.ScaleX, e.ScaleY);

            sideTicksCount    = (MajorTicks.Count - 1) / 2;
            MajorTicks.Length = width / 12;

            SizeF maxTxt       = RadialUtils.GetStringSize(e, Parent, Font, Parent.Maximum.ToString());
            SizeF minTxt       = RadialUtils.GetStringSize(e, Parent, Font, Parent.Minimum.ToString());
            float maxTxtOffset = maxTxt.Height > maxTxt.Width ? maxTxt.Height : maxTxt.Width;
            float minTxtOffset = minTxt.Height > minTxt.Width ? minTxt.Height : minTxt.Width;

            majorTicksOffset = maxTxtOffset > minTxtOffset ? maxTxtOffset : minTxtOffset;

            PointF[] tick0 = new PointF[2];
            avrTick = new PointF(left + width / 2, top + majorTicksOffset);
            //first tick
            tick0[0] = avrTick;
            tick0[1] = new PointF(tick0[0].X, tick0[0].Y + MajorTicks.Length);

            double    angle      = 0;
            HorAlign  horAlign   = HorAlign.Middle;
            VertAlign vertAlign  = VertAlign.Bottom;
            double    startValue = avrValue;

            if (RadialUtils.IsSemicircle(Parent))
            {
                drawRight = true;
                drawLeft  = true;
                if (RadialUtils.IsBottom(Parent))
                {
                    angle       = 180 * RadialGauge.Radians;
                    horAlign    = HorAlign.Middle;
                    vertAlign   = VertAlign.Top;
                    majorStep  *= -1;
                    isRightPart = true;
                    isLeftPart  = false;
                }
                else if (RadialUtils.IsLeft(Parent))
                {
                    angle       = -90 * RadialGauge.Radians;
                    horAlign    = HorAlign.Right;
                    vertAlign   = VertAlign.Middle;
                    isRightPart = false;
                    isLeftPart  = false;
                }
                else if (RadialUtils.IsRight(Parent))
                {
                    angle       = 90 * RadialGauge.Radians;
                    horAlign    = HorAlign.Left;
                    vertAlign   = VertAlign.Middle;
                    majorStep  *= -1;
                    isRightPart = true; //false
                    isLeftPart  = true; // false
                }
            }


            else if (RadialUtils.IsQuadrant(Parent))
            {
                if (RadialUtils.IsTop(Parent) && RadialUtils.IsLeft(Parent))
                {
                    startValue = Parent.Maximum;
                    //angle = 180 * RadialGauge.Radians;
                    horAlign  = HorAlign.Middle;
                    vertAlign = VertAlign.Bottom;
                    //majorStep *= -1;
                    //isRightPart = true;
                    //isLeftPart = false;
                    drawRight = false;
                    drawLeft  = true;

                    isRightPart = false;
                    isLeftPart  = false;
                }
                else if (RadialUtils.IsBottom(Parent) && RadialUtils.IsLeft(Parent))
                {
                    startValue = Parent.Minimum;
                    angle      = 180 * RadialGauge.Radians;
                    horAlign   = HorAlign.Middle;
                    vertAlign  = VertAlign.Top;
                    drawRight  = true;
                    drawLeft   = false;

                    isRightPart = false;
                    isLeftPart  = false;
                }
                else if (RadialUtils.IsTop(Parent) && RadialUtils.IsRight(Parent))
                {
                    stepValue *= -1;
                    startValue = Parent.Maximum;
                    angle      = 0;
                    horAlign   = HorAlign.Middle;
                    vertAlign  = VertAlign.Bottom;
                    drawRight  = true;
                    drawLeft   = false;

                    isRightPart = true;
                    isLeftPart  = true;
                }
                else if (RadialUtils.IsBottom(Parent) && RadialUtils.IsRight(Parent))
                {
                    stepValue *= -1;
                    startValue = Parent.Minimum;
                    angle      = 180 * RadialGauge.Radians;
                    horAlign   = HorAlign.Middle;
                    vertAlign  = VertAlign.Top;
                    drawRight  = false;
                    drawLeft   = true;

                    isRightPart = true;
                    isLeftPart  = true;
                }
            }
            else
            {
                drawRight = true;
                drawLeft  = true;
            }

            tick0 = RadialUtils.RotateVector(tick0, angle, center);

            g.DrawLine(pen, tick0[0].X, tick0[0].Y, tick0[1].X, tick0[1].Y);
            string text = startValue.ToString();

            DrawText(e, text, brush, tick0[0].X, tick0[0].Y, horAlign, vertAlign);

            //rest of ticks
            PointF[] tick = new PointF[2];
            angle = majorStep * RadialGauge.Radians;

            for (int i = 0; i < sideTicksCount; i++)
            {
                //right side
                if (drawRight)
                {
                    tick = RadialUtils.RotateVector(tick0, angle, center);
                    g.DrawLine(pen, tick[0].X, tick[0].Y, tick[1].X, tick[1].Y);
                    text = Convert.ToString(Math.Round(startValue + stepValue * (i + 1)));

                    if (i == sideTicksCount / 2)
                    {
                        if (RadialUtils.IsSemicircle(Parent) || RadialUtils.IsQuadrant(Parent))
                        {
                            if (RadialUtils.IsLeft(Parent) && RadialUtils.IsTop(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsLeft(Parent) && RadialUtils.IsBottom(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsRight(Parent) && RadialUtils.IsTop(Parent))
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsLeft(Parent))
                            {
                                horAlign  = HorAlign.Middle;
                                vertAlign = VertAlign.Bottom;
                            }
                            else if (RadialUtils.IsRight(Parent))
                            {
                                horAlign  = HorAlign.Middle;
                                vertAlign = VertAlign.Bottom;
                            }
                            else
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Middle;
                            }
                        }
                        else
                        {
                            horAlign  = HorAlign.Left;
                            vertAlign = VertAlign.Middle;
                        }
                    }
                    else if (i < sideTicksCount / 2)
                    {
                        horAlign = HorAlign.Left;
                        if (RadialUtils.IsSemicircle(Parent) || RadialUtils.IsQuadrant(Parent))
                        {
                            if (RadialUtils.IsLeft(Parent) && RadialUtils.IsTop(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            if (RadialUtils.IsLeft(Parent) && RadialUtils.IsBottom(Parent))
                            {
                                vertAlign = VertAlign.Top;
                                horAlign  = HorAlign.Right;
                            }
                            else if (RadialUtils.IsBottom(Parent))
                            {
                                vertAlign = VertAlign.Top;
                            }
                            else if (RadialUtils.IsLeft(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Bottom;
                            }
                            else if (RadialUtils.IsRight(Parent))
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Bottom;
                            }
                        }
                        else
                        {
                            vertAlign = VertAlign.Bottom;
                        }
                    }
                    else
                    {
                        horAlign  = HorAlign.Left;
                        vertAlign = VertAlign.Top;
                    }
                    txtPoint = GetTextPoint(tick, -1 * e.ScaleX, isNegative(i, true), isRightPart);
                    DrawText(e, text, brush, txtPoint.X, txtPoint.Y, horAlign, vertAlign);
                }

                if (drawLeft)
                {
                    //left side
                    angle *= -1;
                    tick   = RadialUtils.RotateVector(tick0, angle, center);
                    g.DrawLine(pen, tick[0].X, tick[0].Y, tick[1].X, tick[1].Y);
                    text = Convert.ToString(Math.Round(startValue - stepValue * (i + 1)));

                    if (i == sideTicksCount / 2)
                    {
                        if (RadialUtils.IsSemicircle(Parent) || RadialUtils.IsQuadrant(Parent))
                        {
                            if ((RadialUtils.IsTop(Parent) || RadialUtils.IsBottom(Parent)) && RadialUtils.IsSemicircle(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsLeft(Parent) && RadialUtils.IsTop(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsRight(Parent) && RadialUtils.IsBottom(Parent))
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Middle;
                            }
                            else if (RadialUtils.IsLeft(Parent))
                            {
                                horAlign  = HorAlign.Middle;
                                vertAlign = VertAlign.Top;
                            }
                            else if (RadialUtils.IsRight(Parent))
                            {
                                horAlign  = HorAlign.Middle;
                                vertAlign = VertAlign.Top;
                            }
                        }
                        else
                        {
                            horAlign  = HorAlign.Right;
                            vertAlign = VertAlign.Middle;
                        }
                    }
                    else if (i < sideTicksCount / 2)
                    {
                        horAlign = HorAlign.Right;

                        if (RadialUtils.IsSemicircle(Parent) || RadialUtils.IsQuadrant(Parent))
                        {
                            if (RadialUtils.IsRight(Parent) && RadialUtils.IsBottom(Parent))
                            {
                                vertAlign = VertAlign.Top;
                                horAlign  = HorAlign.Left;
                            }
                            else if (RadialUtils.IsTop(Parent) && RadialUtils.IsLeft(Parent))
                            {
                                vertAlign = VertAlign.Bottom;
                                horAlign  = HorAlign.Right;
                            }
                            else if (RadialUtils.IsBottom(Parent))
                            {
                                vertAlign = VertAlign.Top;
                            }
                            else if (RadialUtils.IsLeft(Parent))
                            {
                                horAlign  = HorAlign.Right;
                                vertAlign = VertAlign.Top;
                            }
                            else if (RadialUtils.IsRight(Parent))
                            {
                                horAlign  = HorAlign.Left;
                                vertAlign = VertAlign.Top;
                            }
                        }
                        else
                        {
                            vertAlign = VertAlign.Bottom;
                        }
                    }
                    else
                    {
                        horAlign  = HorAlign.Right;
                        vertAlign = VertAlign.Top;
                    }
                    txtPoint = GetTextPoint(tick, -1 * e.ScaleX, isNegative(i, false), isLeftPart);
                    DrawText(e, text, brush, txtPoint.X, txtPoint.Y, horAlign, vertAlign);
                    angle *= -1;
                }

                angle += majorStep * RadialGauge.Radians;
            }
        }