Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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();
                    }
        }