internal static bool IsExistsInArray(ArrayList array, MarkerPosition markerPos)
 {
     foreach (MarkerPosition item in array)
     {
         if (markerPos.position == item.position)
         {
             return(markerPos.placement == item.placement);
         }
     }
     return(false);
 }
 internal static double Snap(ArrayList array, double value)
 {
     for (int i = 0; i < array.Count - 1; i++)
     {
         MarkerPosition markerPosition  = (MarkerPosition)array[i];
         MarkerPosition markerPosition2 = (MarkerPosition)array[i + 1];
         if (markerPosition.value <= value && value <= markerPosition2.value)
         {
             if (markerPosition2.value - value < value - markerPosition.value)
             {
                 return(markerPosition2.value);
             }
             return(markerPosition.value);
         }
     }
     return(value);
 }
Пример #3
0
        private void DrawLabel(Placement placement, string labelStr, double position, float labelPos, float rotateLabelAngle, Font font, Color color, bool rotateLabels, bool allowUpsideDown, FontUnit fontUnit)
        {
            float num = GetPositionFromValueNormalized(position);

            if (rotateLabels)
            {
                rotateLabelAngle += num + 180f;
                rotateLabelAngle %= 360f;
                if (!allowUpsideDown && rotateLabelAngle > 90f && rotateLabelAngle < 270f)
                {
                    rotateLabelAngle += 180f;
                    rotateLabelAngle %= 360f;
                }
            }
            MarkerPosition markerPosition = new MarkerPosition((float)Math.Round(num), position, placement);

            if (MarkerPosition.IsExistsInArray(labels, markerPosition))
            {
                return;
            }
            if (labelStr.Length > 0)
            {
                labels.Add(markerPosition);
            }
            GaugeGraphics graph        = Common.Graph;
            StringFormat  stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            using (Brush brush2 = new SolidBrush(color))
            {
                Font resizedFont = GetResizedFont(font, fontUnit);
                try
                {
                    SizeF relativeSize = graph.GetRelativeSize(graph.MeasureString(labelStr, resizedFont));
                    relativeSize.Height -= relativeSize.Height / 8f;
                    float contactPointOffset = Utils.GetContactPointOffset(relativeSize, num - rotateLabelAngle);
                    float offset             = labelPos;
                    switch (placement)
                    {
                    case Placement.Inside:
                        offset = labelPos - Math.Max(0f, contactPointOffset);
                        break;

                    case Placement.Outside:
                        offset = labelPos + Math.Max(0f, contactPointOffset);
                        break;
                    }
                    PointF absolutePoint = graph.GetAbsolutePoint(GetPoint(num, offset));
                    relativeSize = graph.GetAbsoluteSize(relativeSize);
                    RectangleF layoutRectangle = new RectangleF(absolutePoint, new SizeF(0f, 0f));
                    layoutRectangle.Inflate(relativeSize.Width / 2f, relativeSize.Height / 2f);
                    Matrix transform = graph.Transform;
                    Matrix matrix    = graph.Transform.Clone();
                    try
                    {
                        TextRenderingHint textRenderingHint = graph.TextRenderingHint;
                        try
                        {
                            if (textRenderingHint == TextRenderingHint.ClearTypeGridFit)
                            {
                                graph.TextRenderingHint = TextRenderingHint.AntiAlias;
                            }
                            if (base.ShadowOffset != 0f)
                            {
                                using (Brush brush = graph.GetShadowBrush())
                                {
                                    using (Matrix matrix2 = matrix.Clone())
                                    {
                                        matrix2.Translate(base.ShadowOffset, base.ShadowOffset);
                                        matrix2.RotateAt(rotateLabelAngle, absolutePoint);
                                        graph.Transform = matrix2;
                                        graph.DrawString(labelStr, resizedFont, brush, layoutRectangle, stringFormat);
                                    }
                                }
                            }
                            matrix.RotateAt(rotateLabelAngle, absolutePoint);
                            graph.Transform = matrix;
                            graph.DrawString(labelStr, resizedFont, brush2, layoutRectangle, stringFormat);
                        }
                        finally
                        {
                            graph.TextRenderingHint = textRenderingHint;
                        }
                    }
                    finally
                    {
                        matrix.Dispose();
                        graph.Transform = transform;
                    }
                }
                finally
                {
                    if (resizedFont != font)
                    {
                        resizedFont.Dispose();
                    }
                }
            }
        }
Пример #4
0
        private void DrawLabel(Placement placement, string labelStr, double value, float labelPos, float rotateLabelAngle, Font font, Color color, FontUnit fontUnit)
        {
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Near;
            float          num            = GetPositionFromValue(value);
            MarkerPosition markerPosition = new MarkerPosition((float)Math.Round(num), value, placement);

            if (MarkerPosition.IsExistsInArray(labels, markerPosition))
            {
                return;
            }
            if (labelStr.Length > 0)
            {
                labels.Add(markerPosition);
            }
            GaugeGraphics graph = Common.Graph;

            using (Brush brush2 = new SolidBrush(color))
            {
                Font resizedFont = GetResizedFont(font, fontUnit);
                try
                {
                    float num2 = 0f;
                    if (ParentGauge.GetOrientation() == GaugeOrientation.Vertical)
                    {
                        num2 = 90f;
                    }
                    SizeF  size = graph.MeasureString(labelStr, resizedFont);
                    float  contactPointOffset = Utils.GetContactPointOffset(size, rotateLabelAngle - num2);
                    PointF absolutePoint      = graph.GetAbsolutePoint(GetPoint(num, labelPos));
                    switch (placement)
                    {
                    case Placement.Inside:
                        if (ParentGauge.GetOrientation() == GaugeOrientation.Vertical)
                        {
                            absolutePoint.X -= contactPointOffset;
                        }
                        else
                        {
                            absolutePoint.Y -= contactPointOffset;
                        }
                        break;

                    case Placement.Outside:
                        if (ParentGauge.GetOrientation() == GaugeOrientation.Vertical)
                        {
                            absolutePoint.X += contactPointOffset;
                        }
                        else
                        {
                            absolutePoint.Y += contactPointOffset;
                        }
                        break;
                    }
                    RectangleF rectangleF = new RectangleF(absolutePoint, new SizeF(0f, 0f));
                    rectangleF.Inflate(size.Width / 2f, size.Height / 2f);
                    Matrix transform = graph.Transform;
                    Matrix matrix    = graph.Transform.Clone();
                    try
                    {
                        if (rotateLabelAngle == 0f)
                        {
                            if (base.ShadowOffset != 0f)
                            {
                                using (Brush brush = graph.GetShadowBrush())
                                {
                                    RectangleF layoutRectangle = rectangleF;
                                    layoutRectangle.Offset(base.ShadowOffset, base.ShadowOffset);
                                    graph.DrawString(labelStr, resizedFont, brush, layoutRectangle, stringFormat);
                                }
                            }
                            graph.DrawString(labelStr, resizedFont, brush2, rectangleF, stringFormat);
                            return;
                        }
                        TextRenderingHint textRenderingHint = graph.TextRenderingHint;
                        try
                        {
                            if (textRenderingHint == TextRenderingHint.ClearTypeGridFit)
                            {
                                graph.TextRenderingHint = TextRenderingHint.AntiAlias;
                            }
                            if (base.ShadowOffset != 0f)
                            {
                                using (Brush brush3 = graph.GetShadowBrush())
                                {
                                    using (Matrix matrix2 = matrix.Clone())
                                    {
                                        matrix2.Translate(base.ShadowOffset, base.ShadowOffset);
                                        matrix2.RotateAt(rotateLabelAngle, absolutePoint);
                                        graph.Transform = matrix2;
                                        graph.DrawString(labelStr, resizedFont, brush3, rectangleF, stringFormat);
                                    }
                                }
                            }
                            matrix.RotateAt(rotateLabelAngle, absolutePoint);
                            graph.Transform = matrix;
                            graph.DrawString(labelStr, resizedFont, brush2, rectangleF, stringFormat);
                        }
                        finally
                        {
                            graph.TextRenderingHint = textRenderingHint;
                        }
                    }
                    finally
                    {
                        matrix.Dispose();
                        graph.Transform = transform;
                    }
                }
                finally
                {
                    if (resizedFont != font)
                    {
                        resizedFont.Dispose();
                    }
                }
            }
        }