Example #1
0
        public void FitAllButton_Click(object sender, RoutedEventArgs e)
        {
            var    rect  = GetOperatingPixelRect();
            var    rateW = rect.Width / SpaceScrollViewer.ActualWidth;
            var    rateH = rect.Height / SpaceScrollViewer.ActualHeight;
            double rate;
            double AlignLeft = rect.Left;
            double AlignTop  = rect.Top;

            if (rateW > rateH)
            {
                rate      = rateW;
                AlignLeft = rect.Left / rate;
                var rectW_Mid          = rect.Height / rate / 2;
                var screenW_Mid        = SpaceScrollViewer.ActualHeight / 2;
                var moveOffsetToCenter = screenW_Mid - rectW_Mid;
                AlignTop = rect.Top / rate - moveOffsetToCenter;
            }
            else
            {
                rate = rateH;
                var rectH_Mid          = rect.Width / rate / 2;
                var screenH_Mid        = SpaceScrollViewer.ActualWidth / 2;
                var moveOffsetToCenter = screenH_Mid - rectH_Mid;
                AlignLeft = rect.Left / rate - moveOffsetToCenter;
                AlignTop  = rect.Top / rate;
            }

            SpaceScrollViewer.ChangeView(
                AlignLeft, AlignTop,
                (float)(1 / rate), true);
        }
Example #2
0
        private void SpaceGrid_PointerMovedForDraggingWindow(object sender, PointerRoutedEventArgs e)
        {
            var          fe       = sender as FrameworkElement;
            PointerPoint ptrPt    = e.GetCurrentPoint(fe);
            Point        position = ptrPt.Position;

            if (ptrPt.Properties.IsLeftButtonPressed)
            {
                double move_x = position.X - m_DragWindowPoint.X;
                double move_y = position.Y - m_DragWindowPoint.Y;

                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset - move_x,
                    SpaceScrollViewer.VerticalOffset - move_y, _spaceZoomFactor, true);
            }
        }
Example #3
0
        public void SetSpaceZoomPercent(float percent)
        {
            float newFactor = percent / SpaceZoomDefaultPercent;
            float rate      = newFactor / _spaceZoomFactor;

            Task t = Task.Factory.StartNew(async() =>
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    int expired = 10;
                    bool a;
                    do
                    {
                        a = SpaceScrollViewer.ChangeView(
                            SpaceScrollViewer.HorizontalOffset * rate,
                            SpaceScrollViewer.VerticalOffset * rate, newFactor, true);
                        await Task.Delay(100);
                        expired--;
                    }while (!a && expired != 0);
                });
            });

            _spaceZoomFactor = newFactor;
        }
Example #4
0
        private void Timer_Tick(object sender, object e)
        {
            int   offset          = 10;
            var   pointerPosition = Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerPosition;
            var   x        = pointerPosition.X - Window.Current.Bounds.X;
            var   y        = pointerPosition.Y - Window.Current.Bounds.Y;
            Point position = new Point(x, y);

            if (position.X > m_CurrentScreenRect.Right && position.Y > m_CurrentScreenRect.Bottom)
            {
                _mouseDirection = 9;
            }
            else if (position.X > m_CurrentScreenRect.Right && position.Y < m_CurrentScreenRect.Top)
            {
                _mouseDirection = 3;
            }
            else if (position.X > m_CurrentScreenRect.Right)
            {
                _mouseDirection = 6;
            }
            else if (position.X < m_CurrentScreenRect.Left && position.Y > m_CurrentScreenRect.Bottom)
            {
                _mouseDirection = 7;
            }
            else if (position.X < m_CurrentScreenRect.Left && position.Y < m_CurrentScreenRect.Top)
            {
                _mouseDirection = 1;
            }
            else if (position.X < m_CurrentScreenRect.Left)
            {
                _mouseDirection = 4;
            }
            else if (position.Y < m_CurrentScreenRect.Top)
            {
                _mouseDirection = 2;
            }
            else if (position.Y > m_CurrentScreenRect.Bottom)
            {
                _mouseDirection = 8;
            }
            else
            {
                _mouseDirection = 5;
            }

            if (_mouseDirection == 1)
            {
                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset - offset,
                    SpaceScrollViewer.VerticalOffset - offset,
                    _spaceZoomFactor, true);
            }
            else if (_mouseDirection == 2)
            {
                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset,
                    SpaceScrollViewer.VerticalOffset - offset,
                    _spaceZoomFactor, true);
            }
            else if (_mouseDirection == 3)
            {
                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset + offset,
                    SpaceScrollViewer.VerticalOffset - offset,
                    _spaceZoomFactor, true);
            }
            else if (_mouseDirection == 4)
            {
                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset - offset,
                    SpaceScrollViewer.VerticalOffset,
                    _spaceZoomFactor, true);
            }
            else if (_mouseDirection == 5)
            {
            }
            else if (_mouseDirection == 6)
            {
                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset + offset,
                    SpaceScrollViewer.VerticalOffset,
                    _spaceZoomFactor, true);
            }
            else if (_mouseDirection == 7)
            {
                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset - offset,
                    SpaceScrollViewer.VerticalOffset + offset,
                    _spaceZoomFactor, true);
            }
            else if (_mouseDirection == 8)
            {
                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset,
                    SpaceScrollViewer.VerticalOffset + offset,
                    _spaceZoomFactor, true);
            }
            else if (_mouseDirection == 9)
            {
                SpaceScrollViewer.ChangeView(
                    SpaceScrollViewer.HorizontalOffset + offset,
                    SpaceScrollViewer.VerticalOffset + offset,
                    _spaceZoomFactor, true);
            }
        }
Example #5
0
 public void DefaultViewButton_Click(object sender, RoutedEventArgs e)
 {
     SpaceScrollViewer.ChangeView(0, 0, 1, true);
 }