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(transformer); List <Rectangle> boxes = new List <Rectangle>(); foreach (AngleHelper angle in angles) { boxes.Add(transformer.Transform(angle.BoundingBox)); } penEdge.Width = 2; penEdge.DashStyle = DashStyle.Solid; for (int i = 0; i < angles.Count; i++) { if (!HasActiveOption(genericPosture.Angles[i].OptionGroup)) { continue; } AngleHelper angle = angles[i]; Rectangle box = boxes[i]; try { brushFill.Color = angle.Color == Color.Transparent ? baseBrushFillColor : Color.FromArgb(alphaBackground, angle.Color); canvas.FillPie(brushFill, box, angles[i].Angle.Start, angles[i].Angle.Sweep); penEdge.Color = angle.Color == Color.Transparent ? basePenEdgeColor : Color.FromArgb(alpha, angle.Color); canvas.DrawArc(penEdge, box, angles[i].Angle.Start, angles[i].Angle.Sweep); } catch (Exception e) { log.DebugFormat(e.ToString()); } DrawAngleText(canvas, opacity, transformer, angles[i], brushFill); } brushFill.Color = baseBrushFillColor; penEdge.Width = 1; penEdge.Color = basePenEdgeColor; }
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; }
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(); }