Exemplo n.º 1
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);
                        }
        }
Exemplo n.º 2
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacityFactor <= 0 || editing)
            {
                return;
            }

            using (SolidBrush brushBack = styleHelper.GetBackgroundBrush((int)(opacityFactor * 128)))
                using (SolidBrush brushText = styleHelper.GetForegroundBrush((int)(opacityFactor * 255)))
                    using (Font fontText = styleHelper.GetFont((float)transformer.Scale))
                    {
                        // Note: recompute background size in case the font floored.
                        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);

                        Rectangle rect = new Rectangle(bgLocation, bgSize);
                        RoundedRectangle.Draw(canvas, rect, brushBack, fontText.Height / 4, false, false, null);
                        canvas.DrawString(text, fontText, brushText, rect.Location);
                    }
        }
        private void DrawDebugText(PointF location, PointF offset, string label, Graphics canvas, double opacity, IImageToViewportTransformer transformer)
        {
            SizeF  labelSize  = canvas.MeasureString(label, debugFont);
            PointF textOrigin = new PointF(location.X - (labelSize.Width / 2) + offset.X, location.Y - (labelSize.Height / 2) + offset.Y);

            RectangleF backRectangle  = new RectangleF(textOrigin, labelSize);
            int        roundingRadius = (int)(debugFont.Height * 0.25f);

            RoundedRectangle.Draw(canvas, backRectangle, debugBrush, roundingRadius, false, false, null);

            canvas.DrawString(label, debugFont, Brushes.White, backRectangle.Location);
        }
Exemplo n.º 4
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            if (currentTimestamp < visibleTimestamp)
            {
                return;
            }

            double opacityFactor = 1.0;

            if (currentTimestamp > invisibleTimestamp)
            {
                opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);
            }

            if (opacityFactor <= 0)
            {
                return;
            }

            timecode = GetTimecode(currentTimestamp);
            string text = timecode;

            using (SolidBrush brushBack = styleHelper.GetBackgroundBrush((int)(opacityFactor * 128)))
                using (SolidBrush brushText = styleHelper.GetForegroundBrush((int)(opacityFactor * 255)))
                    using (Font fontText = styleHelper.GetFont((float)transformer.Scale))
                    {
                        SizeF textSize   = canvas.MeasureString(text, fontText);
                        Point bgLocation = transformer.Transform(mainBackground.Rectangle.Location);
                        Size  bgSize     = new Size((int)textSize.Width, (int)textSize.Height);

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

                        Rectangle rect           = new Rectangle(bgLocation, bgSize);
                        int       roundingRadius = fontText.Height / 4;
                        RoundedRectangle.Draw(canvas, rect, brushBack, roundingRadius, false, false, null);
                        canvas.DrawString(text, fontText, brushText, rect.Location);

                        if (showLabel && name.Length > 0)
                        {
                            using (Font fontLabel = styleHelper.GetFont((float)transformer.Scale * 0.5f))
                            {
                                // Note: the alignment here assumes fixed margins of the rounded rectangle class.
                                SizeF     lblTextSize         = canvas.MeasureString(name, fontLabel);
                                int       labelRoundingRadius = fontLabel.Height / 3;
                                int       top     = rect.Location.Y - (int)lblTextSize.Height - roundingRadius - labelRoundingRadius;
                                Rectangle lblRect = new Rectangle(rect.Location.X, top, (int)lblTextSize.Width, (int)lblTextSize.Height);
                                RoundedRectangle.Draw(canvas, lblRect, brushBack, labelRoundingRadius, true, false, null);
                                canvas.DrawString(name, fontLabel, brushText, lblRect.Location);
                            }
                        }
                    }
        }
Exemplo n.º 5
0
        public override void Draw(Graphics _canvas, CoordinateSystem _transformer, bool _bSelected, long _iCurrentTimestamp)
        {
            if (_iCurrentTimestamp < m_iVisibleTimestamp)
            {
                return;
            }

            double fOpacityFactor = 1.0;

            if (_iCurrentTimestamp > m_iInvisibleTimestamp)
            {
                fOpacityFactor = m_InfosFading.GetOpacityFactor(_iCurrentTimestamp);
            }

            if (fOpacityFactor <= 0)
            {
                return;
            }

            m_Timecode = GetTimecode(_iCurrentTimestamp);

            // Update unscaled backround size according to timecode text. Needed for hit testing.
            Font  f         = m_StyleHelper.GetFont(1F);
            SizeF totalSize = _canvas.MeasureString(" " + m_Timecode + " ", f);
            SizeF textSize  = _canvas.MeasureString(m_Timecode, f);

            f.Dispose();
            m_MainBackground.Rectangle = new Rectangle(m_MainBackground.Rectangle.Location, new Size((int)totalSize.Width, (int)totalSize.Height));

            using (SolidBrush brushBack = m_StyleHelper.GetBackgroundBrush((int)(fOpacityFactor * 128)))
                using (SolidBrush brushText = m_StyleHelper.GetForegroundBrush((int)(fOpacityFactor * 255)))
                    using (Font fontText = m_StyleHelper.GetFont((float)_transformer.Scale))
                    {
                        Rectangle rect = _transformer.Transform(m_MainBackground.Rectangle);
                        RoundedRectangle.Draw(_canvas, rect, brushBack, fontText.Height / 4, false);

                        int   margin       = (int)((totalSize.Width - textSize.Width) / 2);
                        Point textLocation = new Point(rect.X + margin, rect.Y);
                        _canvas.DrawString(m_Timecode, fontText, brushText, textLocation);

                        if (m_bShowLabel && m_Label.Length > 0)
                        {
                            using (Font fontLabel = m_StyleHelper.GetFont((float)_transformer.Scale * 0.5f))
                            {
                                SizeF     lblTextSize = _canvas.MeasureString(m_Label, fontLabel);
                                Rectangle lblRect     = new Rectangle(rect.Location.X, rect.Location.Y - (int)lblTextSize.Height, (int)lblTextSize.Width, (int)lblTextSize.Height);
                                RoundedRectangle.Draw(_canvas, lblRect, brushBack, fontLabel.Height / 3, true);
                                _canvas.DrawString(m_Label, fontLabel, brushText, lblRect.Location);
                            }
                        }
                    }
        }
Exemplo n.º 6
0
 public void Draw(Graphics _canvas)
 {
     if (m_Message != "" && m_CanvasHolder != null)
     {
         SizeF bgSize = _canvas.MeasureString(m_Message, m_Font);
         bgSize = new SizeF(bgSize.Width, bgSize.Height + 3);
         PointF     location = new PointF((m_CanvasHolder.Width - bgSize.Width) / 2, (m_CanvasHolder.Height - bgSize.Height) / 2);
         RectangleF bg       = new RectangleF(location.X - 5, location.Y - 5, bgSize.Width + 10, bgSize.Height + 5);
         int        radius   = (int)(m_Font.Size / 2);
         RoundedRectangle.Draw(_canvas, bg, (SolidBrush)m_BackBrush, radius, false);
         _canvas.DrawString(m_Message, m_Font, m_ForeBrush, location.X, location.Y);
     }
 }
Exemplo n.º 7
0
        public override void Draw(Graphics _canvas, CoordinateSystem _transformer, bool _bSelected, long _iCurrentTimestamp)
        {
            double fOpacityFactor = m_InfosFading.GetOpacityFactor(_iCurrentTimestamp);

            if (fOpacityFactor <= 0)
            {
                return;
            }

            Point     pointO      = _transformer.Transform(m_PointO);
            Point     pointA      = _transformer.Transform(m_PointA);
            Point     pointB      = _transformer.Transform(m_PointB);
            Rectangle boundingBox = _transformer.Transform(m_BoundingBox);

            using (Pen penEdges = m_StyleHelper.GetBackgroundPen((int)(fOpacityFactor * 255)))
                using (SolidBrush brushEdges = m_StyleHelper.GetBackgroundBrush((int)(fOpacityFactor * 255)))
                    using (SolidBrush brushFill = m_StyleHelper.GetBackgroundBrush((int)(fOpacityFactor * m_iDefaultBackgroundAlpha)))
                    {
                        // Disk section
                        _canvas.FillPie(brushFill, boundingBox, m_fStartAngle, m_fSweepAngle);
                        _canvas.DrawPie(penEdges, boundingBox, m_fStartAngle, m_fSweepAngle);

                        // Edges
                        _canvas.DrawLine(penEdges, pointO, pointA);
                        _canvas.DrawLine(penEdges, pointO, pointB);

                        // Handlers
                        _canvas.DrawEllipse(penEdges, pointO.Box(3));
                        _canvas.FillEllipse(brushEdges, pointA.Box(3));
                        _canvas.FillEllipse(brushEdges, pointB.Box(3));

                        SolidBrush fontBrush = m_StyleHelper.GetForegroundBrush((int)(fOpacityFactor * 255));
                        int        angle     = (int)Math.Floor(-m_fSweepAngle);
                        string     label     = angle.ToString() + "°";
                        Font       tempFont  = m_StyleHelper.GetFont((float)_transformer.Scale);
                        SizeF      labelSize = _canvas.MeasureString(label, tempFont);

                        // Background
                        float      shiftx        = (float)(_transformer.Scale * m_TextShift.X);
                        float      shifty        = (float)(_transformer.Scale * m_TextShift.Y);
                        PointF     textOrigin    = new PointF(shiftx + pointO.X - labelSize.Width / 2, shifty + pointO.Y - labelSize.Height / 2);
                        RectangleF backRectangle = new RectangleF(textOrigin, labelSize);
                        RoundedRectangle.Draw(_canvas, backRectangle, brushFill, tempFont.Height / 4, false);

                        // Text
                        _canvas.DrawString(label, tempFont, fontBrush, backRectangle.Location);

                        tempFont.Dispose();
                        fontBrush.Dispose();
                    }
        }
Exemplo n.º 8
0
        private void DrawAngleText(Graphics canvas, double opacity, IImageToViewportTransformer transformer, AngleHelper angle, SolidBrush brushFill)
        {
            //-------------------------------------------------
            // FIXME: function duplicated. Move to AngleHelper.
            // This version is already more generic.
            //-------------------------------------------------
            double value = CalibrationHelper.ConvertAngleFromDegrees(angle.CalibratedAngle.Sweep);

            if (value < 0)
            {
                value = -value;
            }

            string label = "";

            if (angle.Tenth)
            {
                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(angle.Symbol))
            {
                label = string.Format("{0} = {1}", angle.Symbol, label);
            }

            SolidBrush fontBrush = styleHelper.GetForegroundBrush((int)(opacity * 255));
            Font       tempFont  = styleHelper.GetFont(Math.Max((float)transformer.Scale, 1.0F));
            SizeF      labelSize = canvas.MeasureString(label, tempFont);

            // Background
            float      shiftx        = (float)(transformer.Scale * angle.TextPosition.X);
            float      shifty        = (float)(transformer.Scale * angle.TextPosition.Y);
            Point      origin        = transformer.Transform(angle.Origin);
            PointF     textOrigin    = new PointF(shiftx + origin.X - labelSize.Width / 2, shifty + origin.Y - labelSize.Height / 2);
            RectangleF backRectangle = new RectangleF(textOrigin, labelSize);

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

            // Text
            canvas.DrawString(label, tempFont, fontBrush, backRectangle.Location);

            tempFont.Dispose();
            fontBrush.Dispose();
        }
Exemplo n.º 9
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);
                        }
        }
Exemplo n.º 10
0
        public void Draw(Graphics canvas)
        {
            if (!enabled || string.IsNullOrEmpty(message) || canvasHolder == null)
            {
                return;
            }

            SizeF bgSize = canvas.MeasureString(message, font);

            bgSize = new SizeF(bgSize.Width, bgSize.Height + 3);
            PointF     location = new PointF((canvasHolder.Width - bgSize.Width) / 2, (canvasHolder.Height - bgSize.Height) / 2);
            RectangleF bg       = new RectangleF(location.X - 5, location.Y - 5, bgSize.Width + 10, bgSize.Height + 5);
            int        radius   = (int)(font.Size / 2);

            RoundedRectangle.Draw(canvas, bg, (SolidBrush)backBrush, radius, false, false, null);
            canvas.DrawString(message, font, foreBrush, location.X, location.Y);
        }
Exemplo n.º 11
0
        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();
        }
Exemplo n.º 12
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacity = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacity <= 0)
            {
                return;
            }

            //int backgroundOpacity = editing ? 255 : 192;
            int backgroundOpacity = 255;

            using (SolidBrush brushBack = styleHelper.GetBackgroundBrush((int)(opacity * backgroundOpacity)))
                using (SolidBrush brushText = styleHelper.GetForegroundBrush((int)(opacity * 255)))
                    using (Pen pen = styleHelper.GetPen(backgroundOpacity))
                        using (Font fontText = styleHelper.GetFont((float)transformer.Scale))
                        {
                            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);

                            Rectangle rect           = new Rectangle(bgLocation, bgSize);
                            int       roundingRadius = fontText.Height / 4;

                            if (showArrow)
                            {
                                pen.Color = brushBack.Color;
                                pen.Width = fontText.Height / 4;
                                Point arrowStartInScreen = rect.Center();
                                Point arrowEndInScreen   = transformer.Transform(arrowEnd);
                                canvas.DrawLine(pen, arrowStartInScreen, arrowEndInScreen);
                                ArrowHelper.Draw(canvas, pen, arrowEndInScreen, arrowStartInScreen);
                            }

                            RoundedRectangle.Draw(canvas, rect, brushBack, roundingRadius, false, false, null);

                            if (!editing)
                            {
                                canvas.DrawString(text, fontText, brushText, rect.Location);
                            }
                        }
        }
Exemplo n.º 13
0
        public override void Draw(Graphics _canvas, CoordinateSystem _transformer, bool _bSelected, long _iCurrentTimestamp)
        {
            double fOpacityFactor = m_InfosFading.GetOpacityFactor(_iCurrentTimestamp);

            if (fOpacityFactor <= 0 || m_bEditMode)
            {
                return;
            }

            using (SolidBrush brushBack = m_StyleHelper.GetBackgroundBrush((int)(fOpacityFactor * 128)))
                using (SolidBrush brushText = m_StyleHelper.GetForegroundBrush((int)(fOpacityFactor * 255)))
                    using (Font fontText = m_StyleHelper.GetFont((float)_transformer.Scale))
                    {
                        Rectangle rect = _transformer.Transform(m_Background.Rectangle);
                        RoundedRectangle.Draw(_canvas, rect, brushBack, fontText.Height / 4, false);
                        _canvas.DrawString(m_Text, fontText, brushText, rect.Location);
                    }
        }
Exemplo n.º 14
0
        private void DrawTextOnBackground(PointF location, PointF offset, string label, Graphics canvas, double opacity, IImageToViewportTransformer transformer, SolidBrush brushFill)
        {
            Font   tempFont   = styleHelper.GetFont(Math.Max((float)transformer.Scale, 1.0F));
            SizeF  labelSize  = canvas.MeasureString(label, tempFont);
            PointF textOrigin = new PointF(location.X - (labelSize.Width / 2) + offset.X, location.Y - (labelSize.Height / 2) + offset.Y);

            Bicolor    bicolor   = new Bicolor(brushFill.Color);
            SolidBrush fontBrush = new SolidBrush(Color.FromArgb((int)(opacity * 255), bicolor.Foreground));

            RectangleF backRectangle = new RectangleF(textOrigin, labelSize);

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

            // Text
            canvas.DrawString(label, tempFont, fontBrush, backRectangle.Location);

            fontBrush.Dispose();
            tempFont.Dispose();
        }
Exemplo n.º 15
0
        public void Draw(Graphics _canvas, CoordinateSystem _transformer, double _fOpacityFactor)
        {
            using (SolidBrush fillBrush = m_StyleHelper.GetBackgroundBrush((int)(_fOpacityFactor * 255)))
                using (Pen p = m_StyleHelper.GetBackgroundPen((int)(_fOpacityFactor * 64)))
                    using (Font f = m_StyleHelper.GetFont((float)_transformer.Scale))
                        using (SolidBrush fontBrush = m_StyleHelper.GetForegroundBrush((int)(_fOpacityFactor * 255)))
                        {
                            // Small dot and connector.
                            Point attch  = _transformer.Transform(m_AttachLocation);
                            Point center = _transformer.Transform(m_Background.Center);
                            _canvas.FillEllipse(fillBrush, attch.Box(2));
                            _canvas.DrawLine(p, attch, center);

                            // Background and text.
                            SizeF     textSize = _canvas.MeasureString(m_Text, f);
                            Point     location = _transformer.Transform(m_Background.Rectangle.Location);
                            Size      size     = new Size((int)textSize.Width, (int)textSize.Height);
                            Rectangle rect     = new Rectangle(location, size);
                            RoundedRectangle.Draw(_canvas, rect, fillBrush, f.Height / 4, false);
                            _canvas.DrawString(m_Text, f, fontBrush, rect.Location);
                        }
        }
        private void DrawTickMark(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, TickMark tick, SolidBrush brushFill, SolidBrush fontBrush, Font font)
        {
            string label = String.Format("{0}", Math.Round(tick.Value, 3));

            PointF location;

            if (distorter != null && distorter.Initialized)
            {
                location = distorter.Distort(tick.ImageLocation);
            }
            else
            {
                location = tick.ImageLocation;
            }

            PointF     transformed   = transformer.Transform(location);
            SizeF      labelSize     = canvas.MeasureString(label, font);
            PointF     textPosition  = GetTextPosition(transformed, tick.TextAlignment, labelSize);
            RectangleF backRectangle = new RectangleF(textPosition, labelSize);

            RoundedRectangle.Draw(canvas, backRectangle, brushFill, font.Height / 4, false, false, null);
            canvas.DrawString(label, font, fontBrush, backRectangle.Location);
        }
Exemplo n.º 17
0
        public void Draw(Graphics canvas, IImageToViewportTransformer transformer, double opacityFactor)
        {
            using (SolidBrush fillBrush = styleHelper.GetBackgroundBrush((int)(opacityFactor * 255)))
                using (Pen p = styleHelper.GetBackgroundPen((int)(opacityFactor * 64)))
                    using (Font f = styleHelper.GetFont((float)transformer.Scale))
                        using (SolidBrush fontBrush = styleHelper.GetForegroundBrush((int)(opacityFactor * 255)))
                        {
                            SizeF textSize = canvas.MeasureString(text, f);
                            Point location = transformer.Transform(background.Rectangle.Location);
                            Size  size     = new Size((int)textSize.Width, (int)textSize.Height);

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

                            Point attch  = transformer.Transform(attachLocation);
                            Point center = transformer.Transform(background.Center);
                            canvas.FillEllipse(fillBrush, attch.Box(2));
                            canvas.DrawLine(p, attch, center);

                            Rectangle rect = new Rectangle(location, size);
                            RoundedRectangle.Draw(canvas, rect, fillBrush, f.Height / 4, false, false, null);
                            canvas.DrawString(text, f, fontBrush, rect.Location);
                        }
        }
Exemplo n.º 18
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);

            if (tracking)
            {
                opacityFactor = 1.0;
            }

            if (opacityFactor <= 0)
            {
                return;
            }

            ComputeValues(transformer);

            Point     pointO      = transformer.Transform(points["o"]);
            Point     pointA      = transformer.Transform(points["a"]);
            Point     pointB      = transformer.Transform(points["b"]);
            Rectangle boundingBox = transformer.Transform(angleHelper.BoundingBox);

            if (boundingBox.Size == Size.Empty)
            {
                return;
            }

            using (Pen penEdges = styleHelper.GetBackgroundPen((int)(opacityFactor * 255)))
                using (SolidBrush brushEdges = styleHelper.GetBackgroundBrush((int)(opacityFactor * 255)))
                    using (SolidBrush brushFill = styleHelper.GetBackgroundBrush((int)(opacityFactor * defaultBackgroundAlpha)))
                    {
                        // Disk section
                        canvas.FillPie(brushFill, boundingBox, (float)angleHelper.Angle.Start, (float)angleHelper.Angle.Sweep);
                        canvas.DrawPie(penEdges, boundingBox, (float)angleHelper.Angle.Start, (float)angleHelper.Angle.Sweep);

                        // Edges
                        canvas.DrawLine(penEdges, pointO, pointA);
                        canvas.DrawLine(penEdges, pointO, pointB);

                        // Handlers
                        canvas.DrawEllipse(penEdges, pointO.Box(3));
                        canvas.FillEllipse(brushEdges, pointA.Box(3));
                        canvas.FillEllipse(brushEdges, pointB.Box(3));

                        SolidBrush fontBrush = styleHelper.GetForegroundBrush((int)(opacityFactor * 255));
                        float      angle     = CalibrationHelper.ConvertAngleFromDegrees(angleHelper.CalibratedAngle.Sweep);
                        string     label     = "";
                        if (CalibrationHelper.AngleUnit == AngleUnit.Degree)
                        {
                            label = string.Format("{0}{1}", (int)Math.Round(angle), CalibrationHelper.GetAngleAbbreviation());
                        }
                        else
                        {
                            label = string.Format("{0:0.00} {1}", angle, CalibrationHelper.GetAngleAbbreviation());
                        }

                        Font  tempFont  = styleHelper.GetFont((float)transformer.Scale);
                        SizeF labelSize = canvas.MeasureString(label, tempFont);

                        // Background
                        float      shiftx        = (float)(transformer.Scale * angleHelper.TextPosition.X);
                        float      shifty        = (float)(transformer.Scale * angleHelper.TextPosition.Y);
                        PointF     textOrigin    = new PointF(shiftx + pointO.X - labelSize.Width / 2, shifty + pointO.Y - labelSize.Height / 2);
                        RectangleF backRectangle = new RectangleF(textOrigin, labelSize);
                        RoundedRectangle.Draw(canvas, backRectangle, brushFill, tempFont.Height / 4, false, false, null);

                        // Text
                        canvas.DrawString(label, tempFont, fontBrush, backRectangle.Location);

                        tempFont.Dispose();
                        fontBrush.Dispose();
                    }
        }
Exemplo n.º 19
0
        private void DrawAngles(Pen penEdge, Color basePenEdgeColor, SolidBrush brushFill, Color baseBrushFillColor, int alpha, int alphaBackground, double opacity, Graphics canvas, IImageToViewportTransformer transformer, List <Point> points)
        {
            UpdateAngles();

            penEdge.Width     = 2;
            penEdge.DashStyle = DashStyle.Solid;

            for (int i = 0; i < angles.Count; i++)
            {
                if (!IsActive(genericPosture.Angles[i].OptionGroup))
                {
                    continue;
                }

                AngleHelper angleHelper = angles[i];
                Rectangle   box         = transformer.Transform(angleHelper.SweepAngle.BoundingBox);
                Color       color       = genericPosture.Angles[i].Color;

                try
                {
                    penEdge.Color   = color == Color.Transparent ? basePenEdgeColor : Color.FromArgb(alpha, color);
                    brushFill.Color = color == Color.Transparent ? baseBrushFillColor : Color.FromArgb(alphaBackground, color);

                    canvas.FillPie(brushFill, box, angleHelper.SweepAngle.Start, angleHelper.SweepAngle.Sweep);
                    canvas.DrawArc(penEdge, box, angleHelper.SweepAngle.Start, angleHelper.SweepAngle.Sweep);
                }
                catch (Exception e)
                {
                    log.DebugFormat(e.ToString());
                }

                Point origin = transformer.Transform(angleHelper.SweepAngle.Origin);

                if (!PreferencesManager.PlayerPreferences.EnableCustomToolsDebugMode)
                {
                    angleHelper.DrawText(canvas, opacity, brushFill, origin, transformer, CalibrationHelper, styleHelper);
                }
                else
                {
                    GenericPostureAngle gpa = genericPosture.Angles[i];

                    float  value      = CalibrationHelper.ConvertAngle(angleHelper.CalibratedAngle);
                    string debugLabel = string.Format("A{0} [P{1}, P{2}, P{3}]\n", i, gpa.Leg1, gpa.Origin, gpa.Leg2);
                    if (!string.IsNullOrEmpty(gpa.Name))
                    {
                        debugLabel += string.Format("Name:{0}\n", gpa.Name);
                    }

                    debugLabel += string.Format("Signed:{0}\n", gpa.Signed);
                    debugLabel += string.Format("CCW:{0}\n", gpa.CCW);
                    debugLabel += string.Format("Supplementary:{0}\n", gpa.Supplementary);
                    debugLabel += string.Format("Value: {0:0.0} {1}", value, CalibrationHelper.GetAngleAbbreviation());

                    SizeF  debugLabelSize             = canvas.MeasureString(debugLabel, debugFont);
                    int    debugLabelDistance         = (int)debugOffset.X * 8;
                    PointF debugLabelPositionRelative = angleHelper.GetTextPosition(debugLabelDistance, debugLabelSize);
                    debugLabelPositionRelative = debugLabelPositionRelative.Scale((float)transformer.Scale);
                    PointF debugLabelPosition = new PointF(origin.X + debugLabelPositionRelative.X, origin.Y + debugLabelPositionRelative.Y);

                    RectangleF backRectangle  = new RectangleF(debugLabelPosition, debugLabelSize);
                    int        roundingRadius = (int)(debugFont.Height * 0.25f);
                    RoundedRectangle.Draw(canvas, backRectangle, debugBrush, roundingRadius, false, false, null);
                    canvas.DrawString(debugLabel, debugFont, Brushes.White, backRectangle.Location);
                }
            }

            brushFill.Color = baseBrushFillColor;
            penEdge.Width   = 1;
            penEdge.Color   = basePenEdgeColor;
        }