public void Draw(Bitmap bitmap, Graphics canvas, ImageTransform imageTransform, bool mirrored, Size originalSize)
        {
            if (mode == MagnifierMode.None)
            {
                return;
            }

            source.Draw(canvas, imageTransform.Transform(source.Rectangle), Pens.White, (SolidBrush)Brushes.White, 4);
            DrawInsert(bitmap, canvas, imageTransform, mirrored, originalSize);
        }
        public int HitTest(PointF point, ImageTransform transformer)
        {
            int result = -1;

            if (insert.Contains(point))
            {
                result = 5;
            }
            else
            {
                result = source.HitTest(point, transformer);
            }

            return(result);
        }
        public bool OnMouseDown(PointF location, ImageTransform transformer)
        {
            if (mode != MagnifierMode.Indirect)
            {
                return(false);
            }

            hitHandle = HitTest(location, transformer);

            if (hitHandle == 0)
            {
                sourceLastLocation = location;
            }
            else if (hitHandle == 5)
            {
                insertLastLocation = location;
            }

            return(hitHandle >= 0);
        }
        private void DrawInsert(Bitmap bitmap, Graphics canvas, ImageTransform imageTransform, bool mirrored, Size originalSize)
        {
            // The bitmap passed in is the image decoded, so it might be at a different size than the original image size.
            // We also need to take mirroring into account (until it's included in the ImageTransform).

            double    scaleX       = (double)bitmap.Size.Width / originalSize.Width;
            double    scaleY       = (double)bitmap.Size.Height / originalSize.Height;
            Rectangle scaledSource = source.Rectangle.Scale(scaleX, scaleY);

            Rectangle src;

            if (mirrored)
            {
                src = new Rectangle(bitmap.Width - scaledSource.Left, scaledSource.Top, -scaledSource.Width, scaledSource.Height);
            }
            else
            {
                src = scaledSource;
            }

            canvas.DrawImage(bitmap, imageTransform.Transform(insert), src, GraphicsUnit.Pixel);
            canvas.DrawRectangle(Pens.White, imageTransform.Transform(insert));
        }
 public bool IsOnObject(PointF location, ImageTransform transformer)
 {
     return(HitTest(location, transformer) >= 0);
 }
        private bool DrawingHitTest(Metadata metadata, int keyFrameIndex, PointF mouseCoordinates, long currentTimeStamp, DistortionHelper distorter, ImageTransform transformer)
        {
            bool isOnDrawing    = false;
            int  hitResult      = -1;
            int  currentDrawing = 0;

            Keyframe kf = metadata.Keyframes[keyFrameIndex];

            while (hitResult < 0 && currentDrawing < kf.Drawings.Count)
            {
                hitResult = kf.Drawings[currentDrawing].HitTest(mouseCoordinates, currentTimeStamp, distorter, transformer, transformer.Zooming);

                if (hitResult < 0)
                {
                    currentDrawing++;
                    continue;
                }

                isOnDrawing        = true;
                selectedObjectType = SelectedObjectType.Drawing;
                metadata.SelectDrawing(kf.Drawings[currentDrawing]);
                metadata.SelectKeyframe(kf);

                if (hitResult > 0)
                {
                    manipulationType = ManipulationType.Resize;
                    resizingHandle   = hitResult;
                }
                else
                {
                    manipulationType = ManipulationType.Move;
                }
            }

            return(isOnDrawing);
        }