public bool CorrectCornerPosition(CGPoint point, CornerView corner)
        {
            CGRect rect = WholeImageRectInView();

            point.X -= corner.CenterOffset.X;
            point.Y -= corner.CenterOffset.Y;

            point.X = Math.Max((float)rect.Location.X, Math.Min((float)point.X, (float)(rect.Location.X + rect.Size.Width)));
            point.Y = Math.Max((float)rect.Location.Y, Math.Min((float)point.Y, (float)(rect.Location.Y + rect.Size.Height)));

            point = ConvertFromViewToImagePt(point);

            {
                CGPoint[] points = new CGPoint[4];

                GetCornersCoordinates(points, true);

                for (int i = 0; i < 4; ++i)
                {
                    if (corner == corners[i])
                    {
                        points[i] = point;
                        break;
                    }
                }
            }

            point = ConvertFromViewToImagePt(point);

            point.X += corner.CenterOffset.X;
            point.Y += corner.CenterOffset.Y;

            return(true);
        }
        public CornerView NearestCornerView(CGPoint point)
        {
            const float distToSelect = 100.0f * 100.0f;

            CornerView nearest = null;

            float distMin = float.MaxValue;

            for (int i = 0; i < 4; ++i)
            {
                CornerView c = corners[i];

                CGPoint pt = c.Center;

                float dx = (float)(pt.X - point.X);
                float dy = (float)(pt.Y - point.Y);

                float dist = dx * dx + dy * dy;

                if (dist < distMin)
                {
                    distMin = dist;

                    nearest = c;
                }
            }

            return(distMin >= distToSelect ? null : nearest);
        }
        public CGPoint GetCornerPoint(CornerView corner)
        {
            CGPoint pt = corner.Center;

            pt.X -= corners[(uint)CornerType.LeftTop].CenterOffset.X;
            pt.Y -= corners[(uint)CornerType.LeftTop].CenterOffset.Y;

            return(pt);
        }
        private CornerView CreateCorner(CornerType type, string normalImageName, string selectedImageName)
        {
            CornerView cv = new CornerView(
                new UIImage(normalImageName),
                new UIImage(selectedImageName)
                );

            cv.CornerType = type;

            corners[(uint)type] = cv;

            AddSubview(cv);

            return(cv);
        }
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            CGPoint pt = (touches.AnyObject as UITouch).LocationInView(this);

            startLocation = pt;

            UIView view = this.Superview;

            view.BringSubviewToFront(this);

            view.ViewWithTag(kPageEditorNavBar).Hidden  = true;
            view.ViewWithTag(kPageEditorToolBar).Hidden = true;

            AnimateZoomInAtPoint(startLocation);

            corverDragged = NearestCornerView(startLocation);
            if (corverDragged != null)
            {
                corverDragged.PushCenter = corverDragged.Center;
                corverDragged.IsSelected = true;
            }
        }