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 KeyframeLabel(PointF attachPoint, Color color, IImageToViewportTransformer transformer) { this.attachLocation = attachPoint; int tx = -20; int ty = -50; if (transformer != null) { tx = transformer.Untransform(-20); ty = transformer.Untransform(-50); } background.Rectangle = new Rectangle(attachPoint.Translate(tx, ty).ToPoint(), Size.Empty); styleHelper.Font = new Font("Arial", 8, FontStyle.Bold); styleHelper.Bicolor = new Bicolor(Color.FromArgb(160, color)); }
public DrawingAngle(PointF origin, long timestamp, long averageTimeStampsPerFrame, DrawingStyle preset = null, IImageToViewportTransformer transformer = null) { int length = 50; if (transformer != null) { length = transformer.Untransform(50); } points.Add("o", origin); points.Add("a", origin.Translate(length, 0)); points.Add("b", origin.Translate(0, -length)); styleHelper.Bicolor = new Bicolor(Color.Empty); styleHelper.Font = new Font("Arial", 12, FontStyle.Bold); if (preset == null) { preset = ToolManager.GetStylePreset("Angle"); } style = preset.Clone(); BindStyle(); // Fading infosFading = new InfosFading(timestamp, averageTimeStampsPerFrame); mnuSignedAngle.Click += mnuSignedAngle_Click; mnuSignedAngle.Checked = signedAngle; mnuCounterClockwise.Click += mnuCounterClockwise_Click; mnuCounterClockwise.Checked = counterClockwise; mnuSupplementaryAngle.Click += mnuSupplementaryAngle_Click; mnuSupplementaryAngle.Checked = supplementaryAngle; }
public static bool HitTest(GraphicsPath path, PointF mouse, int lineSize, bool area, IImageToViewportTransformer transformer) { if (!area) { int expansion = 10; int enlarger = Math.Max(1, transformer.Untransform(expansion)); using (Pen pathPen = new Pen(Color.Black, lineSize + enlarger)) { if (path.PathPoints.Length == 1) { path.AddEllipse(path.PathPoints[0].Box(5)); } else { path.Widen(pathPen); } } } using (Region r = new Region(path)) { return(r.IsVisible(mouse)); } }
public DrawingAngle(PointF origin, long timestamp, long averageTimeStampsPerFrame, DrawingStyle preset = null, IImageToViewportTransformer transformer = null) { int length = 50; if (transformer != null) { length = transformer.Untransform(50); } points.Add("o", origin); points.Add("a", origin.Translate(0, -length)); points.Add("b", origin.Translate(length, 0)); styleHelper.Bicolor = new Bicolor(Color.Empty); styleHelper.Font = new Font("Arial", 12, FontStyle.Bold); if (preset == null) { preset = ToolManager.GetStylePreset("Angle"); } style = preset.Clone(); BindStyle(); // Fading infosFading = new InfosFading(timestamp, averageTimeStampsPerFrame); mnuInvertAngle.Click += mnuInvertAngle_Click; mnuInvertAngle.Image = Properties.Drawings.angleinvert; }
public static bool HitTest(PointF target, PointF mouse, IImageToViewportTransformer transformer) { int radius = 10; int boxRadius = Math.Max(1, transformer.Untransform(radius)); return(target.Box(boxRadius).Contains(mouse)); }
//------------------------------------------------------ // Note: // When using the planar calibration, the projection of the circle in world space and back in image space // creates an ellipse whose center is not exactly on the center of the original circle. // This is why there are extra checks to move the minilabel attachment point everytime the drawing moves, // changes size, or when the calibration changes. //------------------------------------------------------ #region Constructor public DrawingCircle(PointF center, long timestamp, long averageTimeStampsPerFrame, DrawingStyle preset = null, IImageToViewportTransformer transformer = null) { this.center = center; miniLabel.SetAttach(center, true); if (transformer != null) { this.radius = transformer.Untransform(25); } this.radius = Math.Min(radius, 10); this.infosFading = new InfosFading(timestamp, averageTimeStampsPerFrame); styleHelper.Color = Color.Empty; styleHelper.LineSize = 1; styleHelper.PenShape = PenShape.Solid; styleHelper.ValueChanged += StyleHelper_ValueChanged; if (preset == null) { preset = ToolManager.GetStylePreset("Circle"); } style = preset.Clone(); BindStyle(); ReinitializeMenu(); }
public static bool HitTest(GraphicsPath path, PointF mouse, int lineSize, bool area, IImageToViewportTransformer transformer) { if (!area) { int expansion = 10; int enlarger = Math.Max(1, transformer.Untransform(expansion)); try { using (Pen pathPen = new Pen(Color.Black, lineSize + enlarger)) { if (path.PathPoints.Length == 1) { path.AddEllipse(path.PathPoints[0].Box(5)); } else { path.Widen(pathPen); } } } catch { // Sometimes the path is invalid because it's too big or it collapsed. return(false); } } using (Region r = new Region(path)) { return(r.IsVisible(mouse)); } }
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 ComputeTextPosition(Angle angle, IImageToViewportTransformer transformer) { int imageTextDistance = transformer.Untransform(textDistance); double bissect = (angle.Start + angle.Sweep / 2) * MathHelper.DegreesToRadians; int adjacent = (int)(Math.Cos(bissect) * imageTextDistance); int opposed = (int)(Math.Sin(bissect) * imageTextDistance); TextPosition = new Point(adjacent, opposed); }
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); } } } }
private void FixIfNull(IImageToViewportTransformer transformer) { int length = transformer.Untransform(50); if (points["a"].NearlyCoincideWith(points["o"])) { points["a"] = points["o"].Translate(0, -length); } if (points["b"].NearlyCoincideWith(points["o"])) { points["b"] = points["o"].Translate(length, 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); } }
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); } } }
public DrawingCircle(PointF center, long timestamp, long averageTimeStampsPerFrame, DrawingStyle preset = null, IImageToViewportTransformer transformer = null) { this.center = center; if (transformer != null) { this.radius = transformer.Untransform(25); } this.radius = Math.Min(radius, 10); this.infosFading = new InfosFading(timestamp, averageTimeStampsPerFrame); styleHelper.Color = Color.Empty; styleHelper.LineSize = 1; if (preset == null) { preset = ToolManager.GetStylePreset("Circle"); } style = preset.Clone(); BindStyle(); }
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); } }