Exemplo n.º 1
0
        private void CenterBasedOnHighlightView(HighlightView hv)
        {
            var drawRect = hv.DrawRect;

            float width  = drawRect.Width();
            float height = drawRect.Height();

            float thisWidth  = Width;
            float thisHeight = Height;

            var z1 = thisWidth / width * .6F;
            var z2 = thisHeight / height * .6F;

            var zoom = Math.Min(z1, z2);

            zoom = zoom * GetScale();
            zoom = Math.Max(1F, zoom);
            if ((Math.Abs(zoom - GetScale()) / zoom) > .1)
            {
                float[] coordinates =
                {
                    hv.CropRect.CenterX(),
                    hv.CropRect.CenterY()
                };

                ImageMatrix.MapPoints(coordinates);
                ZoomTo(zoom, coordinates[0], coordinates[1], 300F);
            }

            EnsureVisible(hv);
        }
Exemplo n.º 2
0
        private void AddHighlightView()
        {
            Crop = new HighlightView(_imageView);

            var width  = _bitmap.Width;
            var height = _bitmap.Height;

            var imageRect = new Rect(0, 0, width, height);

            var cropWidth  = Math.Min(width, height) * 4 / 5;
            var cropHeight = cropWidth;

            if (_aspectX != 0 && _aspectY != 0)
            {
                if (_aspectX > _aspectY)
                {
                    cropHeight = cropWidth * _aspectY / _aspectX;
                }
                else
                {
                    cropWidth = cropHeight * _aspectX / _aspectY;
                }
            }

            var x = (width - cropWidth) / 2;
            var y = (height - cropHeight) / 2;

            var cropRect = new RectF(x, y, x + cropWidth, y + cropHeight);

            Crop.Setup(_imageView.ImageMatrix, imageRect, cropRect, _aspectX != 0 && _aspectY != 0);

            _imageView.ClearHighlightViews();
            Crop.Focused = true;
            _imageView.AddHighlightView(Crop);
        }
Exemplo n.º 3
0
        private void EnsureVisible(HighlightView hv)
        {
            var r = hv.DrawRect;

            var panDeltaX1 = Math.Max(0, IvLeft - r.Left);
            var panDeltaX2 = Math.Min(0, IvRight - r.Right);

            var panDeltaY1 = Math.Max(0, IvTop - r.Top);
            var panDeltaY2 = Math.Min(0, IvBottom - r.Bottom);

            var panDeltaX = panDeltaX1 != 0 ? panDeltaX1 : panDeltaX2;
            var panDeltaY = panDeltaY1 != 0 ? panDeltaY1 : panDeltaY2;

            if (panDeltaX != 0 || panDeltaY != 0)
            {
                PanBy(panDeltaX, panDeltaY);
            }
        }
Exemplo n.º 4
0
 public void AddHighlightView(HighlightView hv)
 {
     _hightlightViews.Add(hv);
     Invalidate();
 }
Exemplo n.º 5
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            var cropImage = (CropImage)_context;

            if (cropImage.Saving)
            {
                return(false);
            }

            switch (ev.Action)
            {
            case MotionEventActions.Down:

                foreach (var hv in _hightlightViews)
                {
                    var edge = hv.GetHit(ev.GetX(), ev.GetY());
                    if (edge != HighlightView.HitPosition.None)
                    {
                        _motionEdge           = edge;
                        _mMotionHighlightView = hv;
                        _mLastX = ev.GetX();
                        _mLastY = ev.GetY();
                        _mMotionHighlightView.Mode =
                            (edge == HighlightView.HitPosition.Move)
                                                                        ? HighlightView.ModifyMode.Move
                                                                        : HighlightView.ModifyMode.Grow;
                        break;
                    }
                }
                break;

            case MotionEventActions.Up:
                if (_mMotionHighlightView != null)
                {
                    CenterBasedOnHighlightView(_mMotionHighlightView);
                    _mMotionHighlightView.Mode = HighlightView.ModifyMode.None;
                }

                _mMotionHighlightView = null;
                break;

            case MotionEventActions.Move:
                if (_mMotionHighlightView != null)
                {
                    _mMotionHighlightView.HandleMotion(_motionEdge,
                                                       ev.GetX() - _mLastX,
                                                       ev.GetY() - _mLastY);
                    _mLastX = ev.GetX();
                    _mLastY = ev.GetY();

                    if (true)
                    {
                        EnsureVisible(_mMotionHighlightView);
                    }
                }
                break;
            }

            switch (ev.Action)
            {
            case MotionEventActions.Up:
                Center(true, true);
                break;

            case MotionEventActions.Move:
                if (Math.Abs(GetScale() - 1F) < double.Epsilon)
                {
                    Center(true, true);
                }
                break;
            }

            return(true);
        }