Пример #1
0
        // Panning MemoBoard
        void OnPanMemoBoard(object sender, PanUpdatedEventArgs e)
        {
            AbsoluteLayout PannedObject = (AbsoluteLayout)sender;

            switch (e.StatusType)
            {
            case GestureStatus.Started:
                StatusLabel.Text = "Panning MemoBoard";
                break;

            case GestureStatus.Running:
                PannedObject.TranslationX
                    = memoBoard.Offset.X + e.TotalX * PannedObject.Scale;
                PannedObject.TranslationY
                    = memoBoard.Offset.Y + e.TotalY * PannedObject.Scale;
                break;

            case GestureStatus.Completed:
                // Store the translation applied during the pan
                memoBoard.Offset.X = PannedObject.TranslationX;
                memoBoard.Offset.Y = PannedObject.TranslationY;

                // Update Display Position
                memoBoard.Display.X = memoBoard.OffsetMax.X - PannedObject.TranslationX;
                memoBoard.Display.Y = memoBoard.OffsetMax.Y - PannedObject.TranslationY;

                // If dx1, dy1 > 0, memoBoard should be expanded to Left and Up
                double dx1 = PannedObject.TranslationX - memoBoard.OffsetMax.X;
                double dy1 = PannedObject.TranslationY - memoBoard.OffsetMax.Y;

                // If dx2, dy2 > 0, memoBoard should be expanded to Right and Down
                double dx2 = memoBoard.Display.X + memoBoard.OriginalW
                             - PannedObject.WidthRequest;
                double dy2 = memoBoard.Display.Y + memoBoard.OriginalH
                             - PannedObject.HeightRequest;
                //- (PannedObject.TranslationY + PannedObject.Height);


                Label2.Text = PannedObject.TranslationY.ToString();
                //Label3.Text = string.Format("(dx, dy) = ( {0:0.00} , {1:0.00} )", dx, dy);
                //Label2.Text = string.Format("e.Totoal X, Y = ( {0:0.00} , {1:0.00} )",
                //                            e.TotalX, e.TotalY);


                // Expand MemoBoard
                if (dx1 > 0)      // expand to Left
                {
                    PannedObject.WidthRequest = PannedObject.Width + dx1;
                    memoBoard.Display.X       = 0;

#if BoxDisplay
                    // Green BoxView
                    box3.TranslationX = PannedObject.WidthRequest - 10;
#endif
                }
                else      // dx1 <= 0
                {
#if BoxDisplay
                    // Green BoxView
                    box3.TranslationX = PannedObject.Width - 10;
#endif
                    if (dx2 > 0)      // expand to Right
                    {
                        PannedObject.WidthRequest =
                            memoBoard.Display.X + memoBoard.OriginalW;
                    }
                }

                if (dy1 > 0)      // expand to Up
                {
                    PannedObject.HeightRequest = PannedObject.Height + dy1;
                    memoBoard.Display.Y        = 0;

#if BoxDisplay
                    // Green BoxView
                    box3.TranslationY = PannedObject.HeightRequest - 10;
#endif
                }
                else      // dy1 <= 0
                {
#if BoxDisplay
                    // Green BoxView
                    box3.TranslationY = PannedObject.Height - 10;
#endif

                    //if (PannedObject.TranslationY + PannedObject.Height
                    //< memoBoard.Display.Y + memoBoard.OriginalH)
                    if (dy2 > 0)      // expand to Down
                    {
                        PannedObject.HeightRequest =
                            memoBoard.Display.Y + memoBoard.OriginalH;
                    }
                }


#if BoxDisplay
                // Red BoxView
                box1.TranslationX = memoBoard.Display.X;
                box1.TranslationY = memoBoard.Display.Y;
                // Blue BoxView
                box2.TranslationX = memoBoard.Display.X + memoBoard.OriginalW - 15;
                box2.TranslationY = memoBoard.Display.Y + memoBoard.OriginalH - 15;
#endif


                //Label2.Text = string.Format("MemoBoard Size = ( {0:0.0} , {1:0.0} )",
                //                    PannedObject.Width, PannedObject.Height);
                Label3.Text = string.Format("Display X, Y = ( {0:0.0} , {1:0.0} )",
                                            memoBoard.Display.X, memoBoard.Display.Y);

                // Shift MemoBoard to Left and Up
                if (dx1 > 0)
                {
                    memoBoard.OffsetMax.X = PannedObject.TranslationX;
                    ScrollBoard.ScrollToAsync(PannedObject.TranslationX,
                                              ScrollBoard.ScrollY, false);
                }
                if (dy1 > 0)
                {
                    memoBoard.OffsetMax.Y = PannedObject.TranslationY;
                    ScrollBoard.ScrollToAsync(ScrollBoard.ScrollX,
                                              PannedObject.TranslationY, false);
                }


                //Label2.Text = string.Format("OffsetMax = ( {0:0.0} , {1:0.0} )",
                //                            memoBoard.OffsetMax.X, memoBoard.OffsetMax.Y);


                // Shift all Memos and Arrows
                foreach (Memo memo in Memos)
                {
                    if (dx1 > 0)
                    {
                        memo.Body.TranslationX += dx1;
                    }
                    if (dy1 > 0)
                    {
                        memo.Body.TranslationY += dy1;
                    }
                    memo.Offset.X = memo.Body.TranslationX;
                    memo.Offset.Y = memo.Body.TranslationY;

                    foreach (Arrow arrow in memo.Arrows)
                    {
                        if (dx1 > 0)
                        {
                            arrow.Body.TranslationX += dx1;
                        }
                        if (dy1 > 0)
                        {
                            arrow.Body.TranslationY += dy1;
                        }
                        UpdateArrow(arrow);
                    }
                }

                StatusLabel.Text = "";
                break;
            }

            Label1.Text = string.Format("(X, Y) = ( {0:0.00} , {1:0.00} )",
                                        PannedObject.TranslationX, PannedObject.TranslationY);
            //Label2.Text = string.Format("e.Total = ( {0:0.00} , {1:0.00} )",
            //                            e.TotalX, e.TotalY);
        }
Пример #2
0
        // Panning Memo, and Update the Memo and the Arrows linked it
        void OnPanMemo(object sender, PanUpdatedEventArgs e)
        {
            ContentView PannedObject = (ContentView)sender;
            Memo        PannedMemo   = (Memo)WhichObject(PannedObject);

            switch (e.StatusType)
            {
            case GestureStatus.Started:
                PannedObject.BackgroundColor = Color.Black;
                StatusLabel.Text             = "Panning Memo";
                break;

            case GestureStatus.Running:
                PannedObject.TranslationX
                    = PannedMemo.Offset.X + e.TotalX * PannedObject.Scale;
                PannedObject.TranslationY
                    = PannedMemo.Offset.Y + e.TotalY * PannedObject.Scale;

                foreach (Arrow arrow in PannedMemo.Arrows)
                {
                    UpdateArrow(arrow);
                }

                Label1.Text = string.Format("Memo Position (X, Y) = ( {0:0.0} , {1:0.0} )",
                                            PannedObject.TranslationX, PannedObject.TranslationY);
                Label2.Text = string.Format("Memo Moved (dX, dY) = ( {0:0.0} , {1:0.0} )",
                                            e.TotalX, e.TotalY);
                break;

            case GestureStatus.Completed:
                PannedObject.BackgroundColor = Color.Gray;

                // Store the translation applied during the pan
                PannedMemo.Offset.X = PannedObject.TranslationX;
                PannedMemo.Offset.Y = PannedObject.TranslationY;

#if !MemoBoardPan
                // If thie object is moved out of the ScrollBoard, expand the ScrollBoard
                if (PannedMemo.Offset.X + PannedObject.Width > MemoBoard.Width)     // expand to Right
                {
                    MemoBoard.WidthRequest = MemoBoard.Width +
                                             PannedMemo.Offset.X + PannedObject.Width - MemoBoard.Width + 10;
                }
                if (PannedMemo.Offset.Y + PannedObject.Height > MemoBoard.Height)       // expand to
                {
                    MemoBoard.HeightRequest = MemoBoard.Height +
                                              PannedMemo.Offset.Y + PannedObject.Height - MemoBoard.Height + 10;
                }
                if (PannedMemo.Offset.X < 0)
                {
                    double dx = (-PannedMemo.Offset.X) + 10;
                    MemoBoard.WidthRequest = MemoBoard.Width + dx;
                    ScrollBoard.ScrollToAsync(dx, ScrollBoard.ScrollY, false);

                    // Shift all Memos and Arrows
                    foreach (Memo memo in Memos)
                    {
                        memo.Body.TranslationX += dx;
                        memo.Offset.X           = memo.Body.TranslationX;
                        foreach (Arrow arrow in memo.Arrows)
                        {
                            arrow.Body.TranslationX += dx;
                            UpdateArrow(arrow);
                        }
                    }
                }
                if (PannedMemo.Offset.Y < 0)
                {
                    double dy = (-PannedMemo.Offset.Y) + 10;
                    MemoBoard.HeightRequest = MemoBoard.Height + dy;
                    ScrollBoard.ScrollToAsync(ScrollBoard.ScrollX, dy, false);

                    // Shift all Memos and Arrows
                    foreach (Memo memo in Memos)
                    {
                        memo.Body.TranslationY += dy;
                        memo.Offset.Y           = memo.Body.TranslationY;
                        foreach (Arrow arrow in memo.Arrows)
                        {
                            arrow.Body.TranslationY += dy;
                            UpdateArrow(arrow);
                        }
                    }
                }
#endif
                StatusLabel.Text = "Pan Completed";
                break;

                // If this Memo is removed, Cancel event is raised
                //case GestureStatus.Canceled:
                //    DisplayAlert("", "Canceled", "Ok");
                //    break;
            }
        }