public void DrawText(Graphics canvas, double opacity, SolidBrush brushFill, PointF o, IImageToViewportTransformer transformer, CalibrationHelper calibrationHelper, StyleHelper styleHelper)
        {
            float value = calibrationHelper.ConvertAngle(CalibratedAngle);

            string label = "";

            if (tenth || calibrationHelper.AngleUnit == AngleUnit.Radian)
            {
                label = string.Format("{0:0.0} {1}", value, calibrationHelper.GetAngleAbbreviation());
            }
            else
            {
                label = string.Format("{0} {1}", (int)Math.Round(value), calibrationHelper.GetAngleAbbreviation());
            }

            if (!string.IsNullOrEmpty(symbol))
            {
                label = string.Format("{0} = {1}", symbol, label);
            }

            SolidBrush fontBrush = styleHelper.GetForegroundBrush((int)(opacity * 255));

            Font  tempFont  = styleHelper.GetFont(1.0F);
            SizeF labelSize = canvas.MeasureString(label, tempFont);

            Font  tempFontTransformed  = styleHelper.GetFont(Math.Max((float)transformer.Scale, 1.0F));
            SizeF labelSizeTransformed = canvas.MeasureString(label, tempFontTransformed);

            // Background
            PointF textPosition = GetTextPosition(textDistance, labelSize);

            textPosition = textPosition.Scale((float)transformer.Scale);

            PointF     backgroundOrigin = o.Translate(textPosition.X, textPosition.Y);
            RectangleF backRectangle    = new RectangleF(backgroundOrigin, labelSizeTransformed);

            RoundedRectangle.Draw(canvas, backRectangle, brushFill, tempFontTransformed.Height / 4, false, false, null);

            // Text
            canvas.DrawString(label, tempFontTransformed, fontBrush, backgroundOrigin);

            tempFont.Dispose();
            tempFontTransformed.Dispose();
            fontBrush.Dispose();
        }
Beispiel #2
0
        public void Draw(Graphics canvas, IImageToViewportTransformer transformer, long timestamp, StyleHelper styleHelper)
        {
            double fOpacityFactor = infosFading.GetOpacityFactor(timestamp);

            if (fOpacityFactor <= 0)
            {
                return;
            }

            int alpha = (int)(255 * fOpacityFactor);

            //SetText(styleHelper);

            using (SolidBrush brushBack = styleHelper.GetBackgroundBrush((int)(fOpacityFactor * 255)))
                using (SolidBrush brushFront = styleHelper.GetForegroundBrush((int)(fOpacityFactor * 255)))
                    using (Pen penContour = styleHelper.GetForegroundPen((int)(fOpacityFactor * 255)))
                        using (Font f = styleHelper.GetFont((float)transformer.Scale))
                        {
                            // Note: recompute the background size each time in case font floored.
                            string text = value.ToString();
                            penContour.Width = 2;
                            SizeF textSize      = canvas.MeasureString(text, f);
                            Point bgLocation    = transformer.Transform(background.Rectangle.Location);
                            SizeF untransformed = transformer.Untransform(textSize);
                            background.Rectangle = new RectangleF(background.Rectangle.Location, untransformed);

                            Size bgSize;
                            if (value < 10)
                            {
                                bgSize = new Size((int)textSize.Height, (int)textSize.Height);
                                Rectangle rect = new Rectangle(bgLocation, bgSize);
                                canvas.FillEllipse(brushBack, rect);
                                canvas.DrawEllipse(penContour, rect);
                            }
                            else
                            {
                                bgSize = new Size((int)textSize.Width, (int)textSize.Height);
                                Rectangle rect = new Rectangle(bgLocation, bgSize);
                                RoundedRectangle.Draw(canvas, rect, brushBack, f.Height / 4, false, true, penContour);
                            }

                            int   verticalShift = (int)(textSize.Height / 10);
                            Point textLocation  = new Point(bgLocation.X + (int)((bgSize.Width - textSize.Width) / 2), bgLocation.Y + verticalShift);
                            canvas.DrawString(text, f, brushFront, textLocation);
                        }
        }
Beispiel #3
0
        public void Draw(Graphics canvas, IImageToViewportTransformer transformer, long timestamp, StyleHelper styleHelper)
        {
            double opacityFactor = infosFading.GetOpacityFactor(timestamp);

            if (opacityFactor <= 0)
            {
                return;
            }

            using (SolidBrush brushBack = styleHelper.GetBackgroundBrush((int)(opacityFactor * 255)))
                using (SolidBrush brushText = styleHelper.GetForegroundBrush((int)(opacityFactor * 255)))
                    using (Font fontText = styleHelper.GetFont((float)transformer.Scale))
                        using (Pen penContour = styleHelper.GetForegroundPen((int)(opacityFactor * 255)))
                        {
                            // Note: recompute background size in case the font floored.
                            string text     = value.ToString();
                            SizeF  textSize = canvas.MeasureString(text, fontText);

                            Point bgLocation = transformer.Transform(background.Rectangle.Location);
                            Size  bgSize     = new Size((int)textSize.Width, (int)textSize.Height);

                            SizeF untransformed = transformer.Untransform(textSize);
                            background.Rectangle = new RectangleF(background.Rectangle.Location, untransformed);

                            penContour.Width = 2;
                            Rectangle rect = new Rectangle(bgLocation, bgSize);
                            RoundedRectangle.Draw(canvas, rect, brushBack, fontText.Height / 4, false, true, penContour);
                            canvas.DrawString(text, fontText, brushText, rect.Location);
                        }
        }
 public void Bind(AbstractStyleElement original)
 {
     // This function is used in the context of cloning, to clone the target data.
     bindTarget         = original.bindTarget;
     bindTargetProperty = original.bindTargetProperty;
 }