예제 #1
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 = this.GetPositionFromValueNormalized(position);

            if (rotateLabels)
            {
                rotateLabelAngle = (float)(rotateLabelAngle + (num + 180.0));
                rotateLabelAngle = (float)(rotateLabelAngle % 360.0);
                if (!allowUpsideDown && rotateLabelAngle > 90.0 && rotateLabelAngle < 270.0)
                {
                    rotateLabelAngle = (float)(rotateLabelAngle + 180.0);
                    rotateLabelAngle = (float)(rotateLabelAngle % 360.0);
                }
            }
            MarkerPosition markerPosition = new MarkerPosition((float)Math.Round((double)num), position, placement);

            if (!MarkerPosition.IsExistsInArray(base.labels, markerPosition))
            {
                if (labelStr.Length > 0)
                {
                    base.labels.Add(markerPosition);
                }
                GaugeGraphics graph        = this.Common.Graph;
                StringFormat  stringFormat = new StringFormat();
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;
                using (Brush brush2 = new SolidBrush(color))
                {
                    Font resizedFont = base.GetResizedFont(font, fontUnit);
                    try
                    {
                        SizeF sizeF = graph.GetRelativeSize(graph.MeasureString(labelStr, resizedFont));
                        sizeF.Height -= (float)(sizeF.Height / 8.0);
                        float contactPointOffset = Utils.GetContactPointOffset(sizeF, 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(this.GetPoint(num, offset));
                        sizeF = graph.GetAbsoluteSize(sizeF);
                        RectangleF layoutRectangle = new RectangleF(absolutePoint, new SizeF(0f, 0f));
                        layoutRectangle.Inflate((float)(sizeF.Width / 2.0), (float)(sizeF.Height / 2.0));
                        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 != 0.0)
                                {
                                    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();
                        }
                    }
                }
            }
        }
예제 #2
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            = this.GetPositionFromValue(value);
            MarkerPosition markerPosition = new MarkerPosition((float)Math.Round((double)num), value, placement);

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

                        case Placement.Outside:
                            if (this.ParentGauge.GetOrientation() == GaugeOrientation.Vertical)
                            {
                                absolutePoint.X += contactPointOffset;
                            }
                            else
                            {
                                absolutePoint.Y += contactPointOffset;
                            }
                            break;
                        }
                        RectangleF rectangleF = new RectangleF(absolutePoint, new SizeF(0f, 0f));
                        rectangleF.Inflate((float)(size.Width / 2.0), (float)(size.Height / 2.0));
                        Matrix transform = graph.Transform;
                        Matrix matrix    = graph.Transform.Clone();
                        try
                        {
                            if (rotateLabelAngle == 0.0)
                            {
                                if (base.ShadowOffset != 0.0)
                                {
                                    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);
                            }
                            else
                            {
                                TextRenderingHint textRenderingHint = graph.TextRenderingHint;
                                try
                                {
                                    if (textRenderingHint == TextRenderingHint.ClearTypeGridFit)
                                    {
                                        graph.TextRenderingHint = TextRenderingHint.AntiAlias;
                                    }
                                    if (base.ShadowOffset != 0.0)
                                    {
                                        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();
                        }
                    }
                }
            }
        }