コード例 #1
0
        private ProTransformation FixTranslation(ProTransformation value)

        {
            var maxScale = Math.Max((double)Image.Width / ClientRectangle.Width, (double)Image.Height / ClientRectangle.Height);

            if (value.Scale > maxScale)
            {
                value = value.SetScale(maxScale);
            }

            if (value.Scale < 0.3)
            {
                value = value.SetScale(0.3);
            }

            var rectSize = value.ConvertToIm(ClientRectangle.Size);

            var max = new Size(Image.Width - rectSize.Width, Image.Height - rectSize.Height);



            value = value.SetTranslate((new Point(Math.Min(value.Translation.X, max.Width), Math.Min(value.Translation.Y, max.Height))));

            if (value.Translation.X < 0 || value.Translation.Y < 0)

            {
                value = value.SetTranslate(new Point(Math.Max(value.Translation.X, 0), Math.Max(value.Translation.Y, 0)));
            }

            return(value);
        }
コード例 #2
0
        private void OnResize(object sender, EventArgs eventArgs)

        {
            if (Image == null)
            {
                return;
            }

            Transformation = Transformation;
        }
コード例 #3
0
        private void OnMouseMove(object sender, MouseEventArgs e)

        {
            if (_clickedPoint == null)
            {
                return;
            }

            var p = _transformation.ConvertToIm((Size)e.Location);

            Transformation = _transformation.SetTranslate(_clickedPoint.Value - p);
        }
コード例 #4
0
        public ProPictureBox()

        {
            _transformation = new ProTransformation(new Point(100, 0), .5f);

            MouseDown += OnMouseDown;

            MouseMove += OnMouseMove;

            MouseUp += OnMouseUp;

            MouseWheel += OnMouseWheel;

            Resize += OnResize;
        }
コード例 #5
0
        private void OnMouseWheel(object sender, MouseEventArgs e)

        {
            var transformation = _transformation;

            var pos1 = transformation.ConvertToIm(e.Location);

            if (e.Delta > 0)
            {
                transformation = (transformation.SetScale(Transformation.Scale / 1.25));
            }

            else
            {
                transformation = (transformation.SetScale(Transformation.Scale * 1.25));
            }

            var pos2 = transformation.ConvertToIm(e.Location);

            transformation = transformation.AddTranslate(pos1 - (Size)pos2);

            Transformation = transformation;
        }
コード例 #6
0
        public void DecideInitialTransformation()

        {
            Transformation = new ProTransformation(Point.Empty, int.MaxValue);
        }