Example #1
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.SweepAngle.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)))
                    {
                        penEdges.Width = 2;

                        // Disk section
                        canvas.FillPie(brushFill, boundingBox, angleHelper.SweepAngle.Start, angleHelper.SweepAngle.Sweep);
                        canvas.DrawArc(penEdges, boundingBox, angleHelper.SweepAngle.Start, angleHelper.SweepAngle.Sweep);

                        // Edges
                        penEdges.DashStyle = DashStyle.Dash;
                        canvas.DrawLine(penEdges, pointO, pointA);
                        penEdges.DashStyle = DashStyle.Solid;
                        canvas.DrawLine(penEdges, pointO, pointB);

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

                        angleHelper.DrawText(canvas, opacityFactor, brushFill, pointO, transformer, CalibrationHelper, styleHelper);
                    }
        }
        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;
        }