Beispiel #1
0
        public GraphicsPath GetTextPath(GaugeGraphics g)
        {
            if (!this.Visible)
            {
                return(null);
            }
            RectangleF   absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
            GraphicsPath graphicsPath      = new GraphicsPath();
            string       noImageString     = SR.NoImageString;
            Font         font         = new Font("Microsoft Sans Serif", 8.25f);
            SizeF        sizeF        = g.MeasureString(noImageString, font);
            SizeF        absoluteSize = g.GetAbsoluteSize(new SizeF(100f, 100f));
            float        num          = absoluteSize.Width / sizeF.Width;
            float        num2         = absoluteSize.Height / sizeF.Height;
            float        emSize       = (float)((!(num < num2)) ? (font.SizeInPoints * num2 * 1.2999999523162842) : (font.SizeInPoints * num * 1.2999999523162842));
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            graphicsPath.AddString(noImageString, font.FontFamily, (int)font.Style, emSize, absoluteRectangle, stringFormat);
            if (this.Angle != 0.0)
            {
                PointF point = new PointF((float)(absoluteRectangle.X + absoluteRectangle.Width / 2.0), (float)(absoluteRectangle.Y + absoluteRectangle.Height / 2.0));
                using (Matrix matrix = new Matrix())
                {
                    matrix.RotateAt(this.Angle, point);
                    graphicsPath.Transform(matrix);
                    return(graphicsPath);
                }
            }
            return(graphicsPath);
        }
Beispiel #2
0
 public override void RenderDynamicElements(GaugeGraphics g)
 {
     if (base.Visible)
     {
         if (this.Common != null && this.Common.GaugeCore.renderContent == RenderContent.Dynamic)
         {
             this.AbsoluteSize = g.GetAbsoluteSize(base.Size);
         }
         GraphicsState gstate = g.Save();
         if (base.ClipContent && base.BackFrame.FrameStyle != 0 && base.BackFrame.Image == string.Empty)
         {
             GraphicsPath graphicsPath = null;
             try
             {
                 graphicsPath = ((base.BackFrame.FrameStyle != 0) ? base.BackFrame.GetBackPath(g) : base.BackFrame.GetFramePath(g, 0f));
                 g.SetClip(graphicsPath, CombineMode.Intersect);
             }
             finally
             {
                 if (graphicsPath != null)
                 {
                     graphicsPath.Dispose();
                 }
             }
         }
         this.RenderDynamicShadows(g);
         foreach (LinearPointer pointer in this.Pointers)
         {
             pointer.Render(g);
         }
         foreach (LinearScale scale in this.Scales)
         {
             scale.RenderDynamicElements(g);
         }
         if (base.ClipContent && base.BackFrame.FrameStyle != 0 && base.BackFrame.Image == string.Empty)
         {
             g.Restore(gstate);
         }
         base.BackFrame.RenderGlassEffect(g);
         this.RenderTopImage(g);
     }
 }
Beispiel #3
0
 public override void RenderStaticElements(GaugeGraphics g)
 {
     if (base.Visible)
     {
         this.AbsoluteSize = g.GetAbsoluteSize(base.Size);
         g.StartHotRegion(this);
         base.BackFrame.RenderFrame(g);
         GraphicsState gstate = g.Save();
         if (base.ClipContent && base.BackFrame.FrameStyle != 0 && base.BackFrame.Image == string.Empty)
         {
             GraphicsPath graphicsPath = null;
             try
             {
                 graphicsPath = ((base.BackFrame.FrameStyle != 0) ? base.BackFrame.GetBackPath(g) : base.BackFrame.GetFramePath(g, 0f));
                 g.SetClip(graphicsPath, CombineMode.Intersect);
             }
             finally
             {
                 if (graphicsPath != null)
                 {
                     graphicsPath.Dispose();
                 }
             }
         }
         this.Common.GaugeCore.HotRegionList.SetHotRegion(this, PointF.Empty, base.BackFrame.GetFramePath(g, 0f));
         g.EndHotRegion();
         this.RenderStaticShadows(g);
         foreach (LinearRange range in this.Ranges)
         {
             range.Render(g);
         }
         foreach (LinearScale scale in this.Scales)
         {
             scale.RenderStaticElements(g);
         }
         if (base.ClipContent && base.BackFrame.FrameStyle != 0 && base.BackFrame.Image == string.Empty)
         {
             g.Restore(gstate);
         }
     }
 }
        public GraphicsPath GetTextPath(GaugeGraphics g)
        {
            if (!this.Visible)
            {
                return(null);
            }
            if (this.Text.Length == 0)
            {
                return(null);
            }
            RectangleF   absoluteRectangle = g.GetAbsoluteRectangle(new RectangleF(0f, 0f, 100f, 100f));
            GraphicsPath graphicsPath      = new GraphicsPath();
            string       text = this.Text;
            Font         font = this.Font;

            text = text.Replace("\\n", "\n");
            float emSize;

            if (this.ResizeMode == ResizeMode.AutoFit)
            {
                SizeF sizeF        = g.MeasureString(text, font);
                SizeF absoluteSize = g.GetAbsoluteSize(new SizeF(100f, 100f));
                float num          = absoluteSize.Width / sizeF.Width;
                float num2         = absoluteSize.Height / sizeF.Height;
                emSize = (float)((!(num < num2)) ? (font.SizeInPoints * num2 * 1.2999999523162842 * g.Graphics.DpiY / 96.0) : (font.SizeInPoints * num * 1.2999999523162842 * g.Graphics.DpiY / 96.0));
            }
            else
            {
                if (this.FontUnit == FontUnit.Percent)
                {
                    g.RestoreDrawRegion();
                    emSize = g.GetAbsoluteDimension(font.Size);
                    RectangleF boundRect = ((IRenderable)this).GetBoundRect(g);
                    g.CreateDrawRegion(boundRect);
                }
                else
                {
                    emSize = (float)(font.SizeInPoints * g.Graphics.DpiY / 96.0);
                }
                emSize = (float)(emSize * 1.2999999523162842);
            }
            StringFormat stringFormat = new StringFormat();

            if (this.TextAlignment == ContentAlignment.TopLeft)
            {
                stringFormat.Alignment     = StringAlignment.Near;
                stringFormat.LineAlignment = StringAlignment.Near;
            }
            else if (this.TextAlignment == ContentAlignment.TopCenter)
            {
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Near;
            }
            else if (this.TextAlignment == ContentAlignment.TopRight)
            {
                stringFormat.Alignment     = StringAlignment.Far;
                stringFormat.LineAlignment = StringAlignment.Near;
            }
            else if (this.TextAlignment == ContentAlignment.MiddleLeft)
            {
                stringFormat.Alignment     = StringAlignment.Near;
                stringFormat.LineAlignment = StringAlignment.Center;
            }
            else if (this.TextAlignment == ContentAlignment.MiddleCenter)
            {
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;
            }
            else if (this.TextAlignment == ContentAlignment.MiddleRight)
            {
                stringFormat.Alignment     = StringAlignment.Far;
                stringFormat.LineAlignment = StringAlignment.Center;
            }
            else if (this.TextAlignment == ContentAlignment.BottomLeft)
            {
                stringFormat.Alignment     = StringAlignment.Near;
                stringFormat.LineAlignment = StringAlignment.Far;
            }
            else if (this.TextAlignment == ContentAlignment.BottomCenter)
            {
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Far;
            }
            else
            {
                stringFormat.Alignment     = StringAlignment.Far;
                stringFormat.LineAlignment = StringAlignment.Far;
            }
            graphicsPath.AddString(text, font.FontFamily, (int)font.Style, emSize, absoluteRectangle, stringFormat);
            if (this.Angle != 0.0)
            {
                PointF point = new PointF((float)(absoluteRectangle.X + absoluteRectangle.Width / 2.0), (float)(absoluteRectangle.Y + absoluteRectangle.Height / 2.0));
                using (Matrix matrix = new Matrix())
                {
                    matrix.RotateAt(this.Angle, point);
                    graphicsPath.Transform(matrix);
                    return(graphicsPath);
                }
            }
            return(graphicsPath);
        }
Beispiel #5
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();
                    }
                }
            }
        }
        internal void RenderGlassEffect(GaugeGraphics g)
        {
            if (GlassEffect == GlassEffect.None || FrameStyle == BackFrameStyle.None)
            {
                return;
            }
            if (IsCustomXamlFrame())
            {
                GetCachedXamlRenderer(g).Layers[2].Render(g);
                return;
            }
            RectangleF bounds;

            using (GraphicsPath graphicsPath = GetFramePath(g, FrameWidth - 1f))
            {
                bounds = graphicsPath.GetBounds();
                using (Brush brush = new LinearGradientBrush(bounds, Color.FromArgb(15, Color.Black), Color.FromArgb(128, Color.Black), LinearGradientMode.ForwardDiagonal))
                {
                    if (bounds.Height > 0f && bounds.Width > 0f)
                    {
                        g.FillPath(brush, graphicsPath);
                    }
                }
            }
            if (FrameShape == BackFrameShape.Rectangular || FrameShape == BackFrameShape.RoundedRectangular)
            {
                _ = g.GetAbsoluteSize(new SizeF(8f, 0f)).Width;
                GraphicsPath graphicsPath2      = new GraphicsPath();
                float        absoluteDimension  = g.GetAbsoluteDimension(30f);
                float        absoluteDimension2 = g.GetAbsoluteDimension(10f);
                float        absoluteDimension3 = g.GetAbsoluteDimension(50f);
                float        absoluteDimension4 = g.GetAbsoluteDimension(5f);
                g.GetAbsoluteDimension(30f);
                g.GetAbsoluteDimension(5f);
                PointF[] points = new PointF[4]
                {
                    new PointF(bounds.X, bounds.Y + absoluteDimension),
                    new PointF(bounds.X + absoluteDimension, bounds.Y),
                    new PointF(bounds.X + absoluteDimension + absoluteDimension2, bounds.Y),
                    new PointF(bounds.X, bounds.Y + absoluteDimension + absoluteDimension2)
                };
                PointF[] points2 = new PointF[4]
                {
                    new PointF(bounds.X, bounds.Y + absoluteDimension3),
                    new PointF(bounds.X + absoluteDimension3, bounds.Y),
                    new PointF(bounds.X + absoluteDimension3 + absoluteDimension4, bounds.Y),
                    new PointF(bounds.X, bounds.Y + absoluteDimension3 + absoluteDimension4)
                };
                graphicsPath2.AddPolygon(points);
                graphicsPath2.AddPolygon(points2);
                Brush brush2 = new SolidBrush(Color.FromArgb(148, Color.White));
                g.FillPath(brush2, graphicsPath2);
            }
            else if ((FrameShape == BackFrameShape.Circular || FrameShape == BackFrameShape.AutoShape) && GlassEffect == GlassEffect.Simple)
            {
                float absoluteDimension5 = g.GetAbsoluteDimension(15f);
                bounds.X      += absoluteDimension5;
                bounds.Y      += absoluteDimension5;
                bounds.Width  -= absoluteDimension5 * 2f;
                bounds.Height -= absoluteDimension5 * 2f;
                GraphicsPath circularRangePath  = g.GetCircularRangePath(g.GetRelativeRectangle(bounds), 226f, 30f, 6f, 6f, Placement.Inside);
                GraphicsPath circularRangePath2 = g.GetCircularRangePath(g.GetRelativeRectangle(bounds), 224f, -30f, 6f, 6f, Placement.Inside);
                Brush        brush3             = new SolidBrush(Color.FromArgb(200, Color.White));
                g.FillPath(brush3, circularRangePath);
                g.FillPath(brush3, circularRangePath2);
            }
        }