コード例 #1
0
ファイル: MetadataRenderer.cs プロジェクト: weblate/Kinovea
        private void RenderExtraDrawings(Metadata metadata, long timestamp, Graphics canvas, ImageToViewportTransformer transformer)
        {
            DistortionHelper distorter = null;

            metadata.DrawingCoordinateSystem.Draw(canvas, distorter, transformer, false, timestamp);
            metadata.DrawingTestGrid.Draw(canvas, distorter, transformer, false, timestamp);

            if (renderTimedDrawings)
            {
                metadata.SpotlightManager.Draw(canvas, distorter, transformer, false, timestamp);
                metadata.AutoNumberManager.Draw(canvas, distorter, transformer, false, timestamp);
            }

            if (renderTimedDrawings)
            {
                foreach (AbstractDrawing ad in metadata.ChronoManager.Drawings)
                {
                    ad.Draw(canvas, distorter, transformer, false, timestamp);
                }
            }

            if (renderTimedDrawings)
            {
                foreach (AbstractDrawing ad in metadata.TrackManager.Drawings)
                {
                    ad.Draw(canvas, distorter, transformer, false, timestamp);
                }
            }
        }
コード例 #2
0
ファイル: DrawingText.cs プロジェクト: jfpk/kinoveaIDS
        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);
                    }
        }
コード例 #3
0
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            int    result        = -1;
            double opacityFactor = infosFading.GetOpacityTrackable(trackingTimestamps, currentTimestamp);

            if (opacityFactor > 0)
            {
                if (trackExtraData != TrackExtraData.None && miniLabel.HitTest(point, transformer))
                {
                    result = 3;
                }
                else if (HitTester.HitTest(points["a"], point, transformer))
                {
                    result = 1;
                }
                else if (HitTester.HitTest(points["b"], point, transformer))
                {
                    result = 2;
                }
                else if (IsPointInObject(point, distorter, transformer))
                {
                    result = 0;
                }
            }

            return(result);
        }
コード例 #4
0
ファイル: DrawingLine.cs プロジェクト: jfpk/kinoveaIDS
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            int    result  = -1;
            double opacity = infosFading.GetOpacityFactor(currentTimestamp);

            if (tracking || opacity > 0)
            {
                if (ShowMeasurableInfo && labelMeasure.HitTest(point, transformer))
                {
                    result = 3;
                }
                else if (HitTester.HitTest(points["a"], point, transformer))
                {
                    result = 1;
                }
                else if (HitTester.HitTest(points["b"], point, transformer))
                {
                    result = 2;
                }
                else if (IsPointInObject(point, distorter, transformer))
                {
                    result = 0;
                }
            }

            return(result);
        }
コード例 #5
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;
            }

            int   iAlpha = (int)(opacityFactor * 255);
            Point c      = transformer.Transform(points["0"]);

            using (Pen p = styleHelper.GetPen(iAlpha))
                using (SolidBrush b = styleHelper.GetBrush((int)(opacityFactor * defaultBackgroundAlpha)))
                {
                    canvas.DrawLine(p, c.X - defaultRadius, c.Y, c.X + defaultRadius, c.Y);
                    canvas.DrawLine(p, c.X, c.Y - defaultRadius, c.X, c.Y + defaultRadius);
                    canvas.FillEllipse(b, c.Box(defaultRadius + 1));
                }

            if (ShowMeasurableInfo)
            {
                labelCoordinates.SetText(CalibrationHelper.GetPointText(new PointF(points["0"].X, points["0"].Y), true, true, infosFading.ReferenceTimestamp));
                labelCoordinates.Draw(canvas, transformer, opacityFactor);
            }
        }
コード例 #6
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;
            }

            int   iAlpha = (int)(opacityFactor * 255);
            Point c      = transformer.Transform(points["0"]);

            using (Pen p = styleHelper.GetPen(iAlpha))
                using (SolidBrush b = styleHelper.GetBrush((int)(opacityFactor * defaultBackgroundAlpha)))
                {
                    canvas.DrawLine(p, c.X - defaultRadius, c.Y, c.X + defaultRadius, c.Y);
                    canvas.DrawLine(p, c.X, c.Y - defaultRadius, c.X, c.Y + defaultRadius);
                    canvas.FillEllipse(b, c.Box(defaultRadius + 1));
                }

            if (trackExtraData != TrackExtraData.None)
            {
                string text = GetExtraDataText(infosFading.ReferenceTimestamp);
                miniLabel.SetText(text);
                miniLabel.Draw(canvas, transformer, opacityFactor);
            }
        }
コード例 #7
0
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            // Convention: miss = -1, object = 0, handle = n.
            int  result           = -1;
            long maxHitTimeStamps = invisibleTimestamp;

            if (maxHitTimeStamps != long.MaxValue)
            {
                maxHitTimeStamps += (allowedFramesOver * parentMetadata.AverageTimeStampsPerFrame);
            }

            if (currentTimestamp >= visibleTimestamp && currentTimestamp <= maxHitTimeStamps)
            {
                using (Font fontText = styleHelper.GetFont(1.0f))
                {
                    int roundingRadius = fontText.Height / 4;
                    result = mainBackground.HitTest(point, true, (int)(roundingRadius * 1.8f), transformer);
                }

                if (result < 0)
                {
                    result = lblBackground.HitTest(point, false, 0, transformer);
                }
            }

            return(result);
        }
コード例 #8
0
ファイル: DrawingAngle.cs プロジェクト: abhinavbharti/Kinovea
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            // Convention: miss = -1, object = 0, handle = n.
            int    result        = -1;
            double opacityFactor = infosFading.GetOpacityTrackable(trackingTimestamps, currentTimestamp);

            if (opacityFactor > 0)
            {
                if (HitTester.HitTest(points["o"], point, transformer))
                {
                    result = 1;
                }
                else if (HitTester.HitTest(points["a"], point, transformer))
                {
                    result = 2;
                }
                else if (HitTester.HitTest(points["b"], point, transformer))
                {
                    result = 3;
                }
                else if (IsPointInObject(point))
                {
                    result = 0;
                }
            }

            return(result);
        }
コード例 #9
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacityFactor <= 0)
            {
                return;
            }

            QuadrilateralF quad = transformer.Transform(quadImage);

            int alpha = (int)(opacityFactor * 255);

            using (Pen p = styleHelper.GetPen(alpha, transformer.Scale))
            {
                p.EndCap = LineCap.Square;
                if (styleHelper.PenShape == PenShape.Dash)
                {
                    p.DashStyle = DashStyle.Dash;
                }

                canvas.DrawLine(p, quad.A, quad.B);
                canvas.DrawLine(p, quad.B, quad.C);
                canvas.DrawLine(p, quad.C, quad.D);
                canvas.DrawLine(p, quad.D, quad.A);
            }
        }
コード例 #10
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacityFactor <= 0)
            {
                return;
            }

            using (Pen penLine = styleHelper.GetPen(opacityFactor, transformer.Scale))
            {
                Point[] points = transformer.Transform(pointList).ToArray();

                if (!initializing)
                {
                    penLine.EndCap   = LineCap.Round;
                    penLine.StartCap = LineCap.Round;

                    if (styleHelper.PenShape == PenShape.Dash)
                    {
                        penLine.DashStyle = DashStyle.Dash;
                    }

                    canvas.DrawCurve(penLine, points, 0.5f);
                }
                else
                {
                    penLine.Width = 1.0f;
                    canvas.DrawLines(penLine, points);
                }
            }
        }
コード例 #11
0
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            // Convention: miss = -1, object = 0, handle = n.
            if (!Visible)
            {
                return(-1);
            }

            int result = -1;

            if (HitTester.HitTest(points["0"], point, transformer))
            {
                return(1);
            }

            if (showGrid || showGraduations || showAxis)
            {
                CoordinateSystemGrid grid = CalibrationHelper.GetCoordinateSystemGrid();
                if (grid == null)
                {
                    return(-1);
                }

                if (grid.HorizontalAxis != null && IsPointOnRectifiedLine(point, grid.HorizontalAxis.Start, grid.HorizontalAxis.End, distorter, transformer))
                {
                    result = 2;
                }
                else if (grid.VerticalAxis != null && IsPointOnRectifiedLine(point, grid.VerticalAxis.Start, grid.VerticalAxis.End, distorter, transformer))
                {
                    result = 3;
                }
            }

            return(result);
        }
コード例 #12
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacityFactor = infosFading.GetOpacityTrackable(trackingTimestamps, currentTimestamp);

            if (opacityFactor <= 0)
            {
                return;
            }

            Point start = transformer.Transform(points["a"]);
            Point end   = transformer.Transform(points["b"]);

            using (Pen penEdges = styleHelper.GetPen(opacityFactor, transformer.Scale))
                using (Brush brush = styleHelper.GetBrush(opacityFactor))
                {
                    if (distorter != null && distorter.Initialized)
                    {
                        DrawDistorted(canvas, distorter, transformer, penEdges, brush, start, end);
                    }
                    else
                    {
                        DrawStraight(canvas, transformer, penEdges, brush, start, end);
                    }
                }

            if (trackExtraData != TrackExtraData.None)
            {
                string text = GetExtraDataText();
                miniLabel.SetText(text);
                miniLabel.Draw(canvas, transformer, opacityFactor);
            }
        }
コード例 #13
0
ファイル: AutoNumberManager.cs プロジェクト: jfpk/kinoveaIDS
 public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
 {
     foreach (AutoNumber number in autoNumbers)
     {
         number.Draw(canvas, transformer, currentTimestamp, styleHelper);
     }
 }
コード例 #14
0
ファイル: DrawingText.cs プロジェクト: sandeepbeniwal/Kinovea
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            double opacity = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacity <= 0)
            {
                return(-1);
            }

            // Background label: 0, hidden resizer: 1, arrow end: 2.
            if (showArrow)
            {
                if (HitTester.HitTest(arrowEnd, point, transformer))
                {
                    return(2);
                }

                if (IsPointOnSegment(point, background.Rectangle.Center(), arrowEnd, transformer))
                {
                    return(0);
                }
            }

            // Compute the size of the hidden handle zone based on the font size.
            using (Font fontText = styleHelper.GetFont(1.0f))
            {
                int roundingRadius = fontText.Height / 4;
                return(background.HitTest(point, true, (int)(roundingRadius * 1.8f), transformer));
            }
        }
コード例 #15
0
ファイル: DrawingCircle.cs プロジェクト: jfpk/kinoveaIDS
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacityFactor <= 0)
            {
                return;
            }

            int alpha = (int)(opacityFactor * 255);

            this.selected = selected;

            using (Pen p = styleHelper.GetPen(alpha, transformer.Scale))
            {
                Rectangle boundingBox = transformer.Transform(center.Box(radius));
                canvas.DrawEllipse(p, boundingBox);

                if (selected)
                {
                    // Handler: arc in lower right quadrant.
                    p.Color = p.Color.Invert();
                    canvas.DrawArc(p, boundingBox, 25, 40);
                }
            }
        }
コード例 #16
0
ファイル: DrawingSVG.cs プロジェクト: jfpk/kinoveaIDS
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);

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

            Rectangle rect = transformer.Transform(boundingBox.Rectangle);

            if (finishedResizing)
            {
                finishedResizing = false;
                RenderAtNewScale(rect.Size, transformer.Scale);
            }

            if (svgRendered == null)
            {
                return;
            }

            fadingColorMatrix.Matrix33 = (float)opacityFactor;
            fadingImgAttr.SetColorMatrix(fadingColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            canvas.DrawImage(svgRendered, rect, 0, 0, svgRendered.Width, svgRendered.Height, GraphicsUnit.Pixel, fadingImgAttr);

            if (selected)
            {
                boundingBox.Draw(canvas, rect, penBoundingBox, brushBoundingBox, 4);
            }
        }
コード例 #17
0
ファイル: DrawingPolyline.cs プロジェクト: jfpk/kinoveaIDS
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            int    result  = -1;
            double opacity = infosFading.GetOpacityFactor(currentTimestamp);

            if (!tracking && opacity <= 0)
            {
                return(-1);
            }

            foreach (KeyValuePair <string, PointF> p in points)
            {
                if (HitTester.HitTest(p.Value, point, transformer))
                {
                    result = int.Parse(p.Key) + 1;
                }
            }

            if (result == -1 && IsPointInObject(point, distorter, transformer))
            {
                result = 0;
            }

            return(result);
        }
コード例 #18
0
ファイル: DrawingBitmap.cs プロジェクト: wyj64852999/Kinovea
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            if (!valid)
            {
                return;
            }

            double opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacityFactor <= 0)
            {
                return;
            }

            Rectangle rect = transformer.Transform(boundingBox.Rectangle);

            fadingColorMatrix.Matrix33 = (float)opacityFactor;
            fadingImgAttr.SetColorMatrix(fadingColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            canvas.DrawImage(bitmap, rect, 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, fadingImgAttr);

            if (selected)
            {
                boundingBox.Draw(canvas, rect, penBoundingBox, brushBoundingBox, 4);
            }
        }
コード例 #19
0
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            // Convention: miss = -1, object = 0, handle = n.
            // We do not need a special case to hit the radius or diameter line as they are inside the circle and
            // don't have special handling compared to just moving the whole thing.
            double opacity = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacity <= 0)
            {
                return(-1);
            }

            if (trackExtraData != TrackExtraData.None && miniLabel.HitTest(point, transformer))
            {
                return(2);
            }

            if (IsPointOnHandler(point, transformer))
            {
                return(1);
            }

            if (IsPointInObject(point, transformer))
            {
                return(0);
            }

            return(-1);
        }
コード例 #20
0
ファイル: DrawingLine.cs プロジェクト: wyj64852999/Kinovea
        private void DrawDistorted(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, Pen penEdges, Brush brush, Point start, Point end)
        {
            List <PointF> curve            = distorter.DistortLine(points["a"], points["b"]);
            List <Point>  transformedCurve = transformer.Transform(curve);

            if (styleHelper.LineShape == LineShape.Squiggle)
            {
                canvas.DrawSquigglyLine(penEdges, start, end);
            }
            else if (styleHelper.LineShape == LineShape.Dash)
            {
                DashStyle oldDashStyle = penEdges.DashStyle;
                penEdges.DashStyle = DashStyle.Dash;
                canvas.DrawCurve(penEdges, transformedCurve.ToArray());
                penEdges.DashStyle = oldDashStyle;
            }
            else
            {
                canvas.DrawCurve(penEdges, transformedCurve.ToArray());
            }

            miniLabel.SetAttach(curve[curve.Count / 2], true);

            if (styleHelper.LineEnding == LineEnding.StartArrow || styleHelper.LineEnding == LineEnding.DoubleArrow)
            {
                ArrowHelper.Draw(canvas, penEdges, start, end);
            }

            if (styleHelper.LineEnding == LineEnding.EndArrow || styleHelper.LineEnding == LineEnding.DoubleArrow)
            {
                ArrowHelper.Draw(canvas, penEdges, end, start);
            }
        }
コード例 #21
0
        private bool IsOnDrawing(Metadata metadata, int activeKeyFrameIndex, PointF mouseCoordinates, long currentTimeStamp, bool allFrames)
        {
            if (metadata.Keyframes.Count == 0)
            {
                return(false);
            }

            bool bIsOnDrawing = false;

            DistortionHelper distorter = metadata.CalibrationHelper.DistortionHelper;

            if (allFrames && metadata.Keyframes.Count > 0)
            {
                int[] zOrder = metadata.GetKeyframesZOrder(currentTimeStamp);

                for (int i = 0; i < zOrder.Length; i++)
                {
                    bIsOnDrawing = DrawingHitTest(metadata, zOrder[i], mouseCoordinates, currentTimeStamp, distorter, metadata.CoordinateSystem);
                    if (bIsOnDrawing)
                    {
                        break;
                    }
                }
            }
            else if (activeKeyFrameIndex >= 0)
            {
                bIsOnDrawing = DrawingHitTest(metadata, activeKeyFrameIndex, mouseCoordinates, metadata[activeKeyFrameIndex].Position, distorter, metadata.CoordinateSystem);
            }

            return(bIsOnDrawing);
        }
コード例 #22
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            if (!Visible || imageSize == SizeF.Empty)
            {
                return;
            }

            DrawGrid(canvas, transformer);
        }
コード例 #23
0
ファイル: DrawingPencil.cs プロジェクト: jfpk/kinoveaIDS
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            int    result  = -1;
            double opacity = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacity > 0 && IsPointInObject(point, transformer))
            {
                result = 0;
            }

            return(result);
        }
コード例 #24
0
        private void RenderDrawings(Metadata metadata, long timestamp, Graphics canvas, ImageToViewportTransformer transformer)
        {
            DistortionHelper distorter = metadata.CalibrationHelper.DistortionHelper;

            foreach (Keyframe keyframe in metadata.Keyframes)
            {
                foreach (AbstractDrawing drawing in keyframe.Drawings)
                {
                    drawing.Draw(canvas, distorter, transformer, drawing == metadata.HitDrawing, timestamp);
                }
            }
        }
コード例 #25
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);
                            }
                        }
                    }
        }
コード例 #26
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            // We draw a single translucent black rectangle to cover the whole image.
            // (Opacity varies between 0% and 50%, depending on the opacity factor of the closest spotlight in time)
            if (spotlights.Count < 1)
            {
                return;
            }

            // Create a mask rectangle and obliterate spotlights from it.
            // FIXME: spots subtract from each other which is not desirable.
            // TODO: might be better to first get the opacity, then only ask for the path. In case opacity is 0.
            GraphicsPath globalPath = new GraphicsPath();

            globalPath.AddRectangle(canvas.ClipBounds);

            // Combine all spots into a single GraphicsPath.
            // Get their opacity in the process to compute the global opacity of the covering rectangle.
            double       maxOpacity = 0.0;
            GraphicsPath spotsPath  = new GraphicsPath();

            foreach (Spotlight spot in spotlights)
            {
                double opacity = spot.AddSpot(currentTimestamp, spotsPath, transformer);
                maxOpacity = Math.Max(maxOpacity, opacity);
            }

            if (maxOpacity <= 0)
            {
                return;
            }

            // Obliterate the spots from the mask.
            globalPath.AddPath(spotsPath, false);

            // Draw the mask with the spot holes on top of the frame.
            int backgroundAlpha = (int)((double)defaultBackgroundAlpha * maxOpacity);

            using (SolidBrush brushBackground = new SolidBrush(Color.FromArgb(backgroundAlpha, backgroundColor)))
            {
                canvas.FillPath(brushBackground, globalPath);
            }

            // Draw each spot border or any visuals.
            foreach (Spotlight spot in spotlights)
            {
                spot.Draw(canvas, currentTimestamp);
            }

            globalPath.Dispose();
            spotsPath.Dispose();
        }
コード例 #27
0
        public override void Draw(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, bool selected, long currentTimestamp)
        {
            double opacityFactor = infosFading.GetOpacityFactor(currentTimestamp);

            if (opacityFactor <= 0)
            {
                return;
            }

            List <Point> screenPoints = transformer.Transform(points);

            using (penEdges = styleHelper.GetPen(opacityFactor, 1.0))
                using (SolidBrush br = styleHelper.GetBrush(opacityFactor))
                {
                    int rows = subdivisions + 1;
                    int cols = rows;

                    // Rows
                    for (int i = 0; i < rows; i++)
                    {
                        int          row  = i;
                        List <Point> line = new List <Point>();
                        for (int j = 0; j < cols; j++)
                        {
                            int index = row * cols + j;
                            line.Add(screenPoints[index]);
                        }

                        canvas.DrawCurve(penEdges, line.ToArray());
                    }

                    // Columns
                    for (int i = 0; i < cols; i++)
                    {
                        int          col  = i;
                        List <Point> line = new List <Point>();
                        for (int j = 0; j < rows; j++)
                        {
                            int index = j * cols + col;
                            line.Add(screenPoints[index]);
                        }

                        canvas.DrawCurve(penEdges, line.ToArray());
                    }

                    // Handles
                    foreach (PointF p in screenPoints)
                    {
                        canvas.FillEllipse(br, p.Box(4));
                    }
                }
        }
コード例 #28
0
ファイル: DrawingBitmap.cs プロジェクト: wyj64852999/Kinovea
        public override int HitTest(PointF point, long currentTimestamp, DistortionHelper distorter, IImageToViewportTransformer transformer, bool zooming)
        {
            if (!valid)
            {
                return(-1);
            }

            if (infosFading.GetOpacityFactor(currentTimestamp) <= 0)
            {
                return(-1);
            }

            return(boundingBox.HitTest(point, transformer));
        }
コード例 #29
0
ファイル: DrawingAngle.cs プロジェクト: wyj64852999/Kinovea
        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);
                    }
        }
コード例 #30
0
 private void DrawGridLine(Graphics canvas, DistortionHelper distorter, IImageToViewportTransformer transformer, Pen penLine, PointF a, PointF b)
 {
     if (distorter != null && distorter.Initialized)
     {
         List <PointF> curve       = distorter.DistortRectifiedLine(a, b);
         List <Point>  transformed = transformer.Transform(curve);
         canvas.DrawCurve(penLine, transformed.ToArray());
     }
     else
     {
         PointF p1 = transformer.Transform(a);
         PointF p2 = transformer.Transform(b);
         canvas.DrawLine(penLine, p1, p2);
     }
 }