Beispiel #1
0
 public PointerCursolAutoHideBehavior()
 {
     _AutoHideTimer             = DispatcherQueue.GetForCurrentThread().CreateTimer();
     _AutoHideTimer.Tick       += AutoHideTimer_Tick;
     _AutoHideTimer.IsRepeating = false;
     _DefaultCursor             = Window.Current.CoreWindow.PointerCursor;
 }
Beispiel #2
0
        /// <summary>
        /// The pointer entered event handler.
        /// We do not capture pointer on this event.
        /// </summary>
        /// <param name="sender">Source of the pointer event.</param>
        /// <param name="e">Event args for the pointer routed event.</param>
        private void Target_PointerEntered(object sender, PointerRoutedEventArgs e)
        {
            // Prevent most handlers along the event route from handling the same event again.
            e.Handled = true;

            PointerPoint ptrPt = e.GetCurrentPoint(Target);

            // Update event log.
            UpdateEventLog("Entered: " + ptrPt.PointerId);

            // Cache the cursor set before pointer enter on button.
            cursorBeforePointerEntered = Window.Current.CoreWindow.PointerCursor;
            // Set button cursor.
            Window.Current.CoreWindow.PointerCursor = buttonCursor;

            // Check if pointer already exists (if enter occurred prior to down).
            if (!pointers.ContainsKey(ptrPt.PointerId))
            {
                // Add contact to dictionary.
                pointers[ptrPt.PointerId] = e.Pointer;
            }

            if (pointers.Count == 0)
            {
                // Change background color of target when pointer contact detected.
                Target.Fill = new SolidColorBrush(Windows.UI.Colors.Blue);
            }

            // Display pointer details.
            CreateInfoPop(ptrPt);
        }
Beispiel #3
0
            // Constructors
            public Resizer(ViewWidthProvider widthProvider, IChartState chartState)
            {
                this.widthProvider = widthProvider;
                this.chartState    = chartState;

                this.resizeCursor = new CoreCursor(CoreCursorType.SizeWestEast, 0);
            }
Beispiel #4
0
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                rootFrame = new Frame();
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    try {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException) {}
                }
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null)
            {
                if (!rootFrame.Navigate(typeof(MainPage)))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            Window.Current.Activate();
            cursor = Window.Current.CoreWindow.PointerCursor;
            PopulateRecentlyUsed();
            PopulateLibrary();
            SettingsPane.GetForCurrentView().CommandsRequested += CommandsRequested;
        }
Beispiel #5
0
        /// <summary>
        /// Handles changes to the Cursor property.
        /// </summary>
        /// <param name="d">
        /// The <see cref="DependencyObject"/> on which
        /// the property has changed value.
        /// </param>
        /// <param name="e">
        /// Event data that is issued by any event that
        /// tracks changes to the effective value of this property.
        /// </param>
        private static void OnCursorChanged(
            DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CoreCursor oldCursor = (CoreCursor)e.OldValue;
            CoreCursor newCursor = (CoreCursor)d.GetValue(CursorProperty);

            if (oldCursor == null)
            {
                var handler = new CursorDisplayHandler();
                handler.Attach((FrameworkElement)d);
                SetCursorDisplayHandler(d, handler);
            }
            else
            {
                var handler = GetCursorDisplayHandler(d);

                if (newCursor == null)
                {
                    handler.Detach();
                    SetCursorDisplayHandler(d, null);
                }
                else
                {
                    handler.UpdateCursor();
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Called when the mouse button is pressed down.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The <see cref="PointerRoutedEventArgs"/> instance containing the event data.
        /// </param>
        protected virtual void OnMouseDown(object sender, PointerRoutedEventArgs e)
        {
            this.Started(e.GetCurrentPoint(this.Controller.Viewport).Position);

            this.OldCursor = Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor;
            Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new CoreCursor(this.GetCursor(), OldCursor.Id);
        }
 private void Button_PointerEntered(object sender, PointerRoutedEventArgs e)
 {
     // Cache the cursor set before pointer enter on button.
     cursorBeforePointerEntered = Window.Current.CoreWindow.PointerCursor;
     // Set button cursor.
     Window.Current.CoreWindow.PointerCursor = buttonCursor;
 }
Beispiel #8
0
        public Map()
        {
            this.InitializeComponent();
            CursorHand            = new CoreCursor(CoreCursorType.Hand, 0);
            CursorPin             = new CoreCursor(CoreCursorType.Pin, 0);
            Gamepad.GamepadAdded += (object sender, Gamepad e) =>
            {
                lock (myLock)
                {
                    bool gamepadInList = myGamepads.Contains(e);
                    if (!gamepadInList)
                    {
                        myGamepads.Add(e);
                    }
                }
            };

            Gamepad.GamepadRemoved += (object sender, Gamepad e) =>
            {
                lock (myLock)
                {
                    int indexRemoved = myGamepads.IndexOf(e);
                    if (indexRemoved > -1)
                    {
                        if (mainGamepad == myGamepads[indexRemoved])
                        {
                            mainGamepad = null;
                        }
                        myGamepads.RemoveAt(indexRemoved);
                    }
                }
            };
        }
Beispiel #9
0
        private static void CursorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var element = d as FrameworkElement;

            if (element == null)
            {
                throw new NullReferenceException(nameof(element));
            }

            var value = (CoreCursorType)e.NewValue;

            // lock ensures CoreCursor creation and event handlers attachment/detachment is atomic
            lock (_cursorLock)
            {
                if (!_cursors.ContainsKey(value))
                {
                    _cursors[value] = new CoreCursor(value, 1);
                }

                // make sure event handlers are not attached twice to element
                element.PointerEntered -= Element_PointerEntered;
                element.PointerEntered += Element_PointerEntered;
                element.PointerExited  -= Element_PointerExited;
                element.PointerExited  += Element_PointerExited;
                element.Unloaded       -= ElementOnUnloaded;
                element.Unloaded       += ElementOnUnloaded;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the AppShell, sets the static 'Current' reference,
        /// adds callbacks for Back requests and changes in the SplitView's DisplayMode, and
        /// provide the nav menu list with the data to display.
        public MainPage()
        {
            this.InitializeComponent();

            SystemNavigationManager.GetForCurrentView().BackRequested += SystemNavigationManager_BackRequested;
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            NavMenuList.ItemsSource = navlist;

            this.KeyDown += MainPage_KeyDown;

            _defaultCursor = CoreWindow.GetForCurrentThread().PointerCursor;

            UpdateTenFootMode();

            if (App.IsTenFoot) // Make sure the side panel is closed when in ten foot mode
            {
                SplitView_PaneClosed(null, null);
            }

            // Debugging helper!
            // NOTE: You don't really need this anymore with Visual Studio 2015 Update 3
            // TODO: 3.2 - Debugging Visual State selection can be hard
            //this.GotFocus += (object sender, RoutedEventArgs e) =>
            //{
            //    FrameworkElement focus = FocusManager.GetFocusedElement() as FrameworkElement;
            //    if (focus != null)
            //        Debug.WriteLine("got focus: " + focus.Name + " (" + focus.GetType().ToString() + ")");
            //};
        }
Beispiel #11
0
        private void CursorVisibilityChanged(bool isVisible)
        {
            if (_DefaultCursor == null)
            {
                _DefaultCursor = Window.Current.CoreWindow.PointerCursor;

                if (_DefaultCursor == null)
                {
                    throw new Exception();
                }
            }

            if (isVisible)
            {
                Window.Current.CoreWindow.PointerCursor = _DefaultCursor;

                ResetAutoHideTimer();
            }
            else
            {
                Window.Current.CoreWindow.PointerCursor = null;

                _AutoHideTimer.Stop();
            }
        }
Beispiel #12
0
        private async void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
        {
            using (var releaser = await _CursorDisplayUpdateLock.LockAsync())
            {
                _DefaultCursor = Window.Current.CoreWindow.PointerCursor;

                try
                {
                    _MouseDevice             = MouseDevice.GetForCurrentView();
                    _MouseDevice.MouseMoved += CursorSetter_MouseMoved;
                }
                catch { }

                Window.Current.Activated += Current_Activated;

                _AutoHideTimer.Tick += AutoHideTimer_Tick;

                _IsCursorInsideAssociatedObject = IsCursorInWindow();

                if (Window.Current.Visible)
                {
                    ResetAutoHideTimer();
                }
            }
        }
Beispiel #13
0
 public MainPage()
 {
     this.InitializeComponent();
     cursorHand            = new CoreCursor(CoreCursorType.Hand, 0);
     cursorPin             = new CoreCursor(CoreCursorType.Pin, 0);
     Gamepad.GamepadAdded += (object sender, Gamepad e) =>
     {
         lock (myLock)
         {
             int indexRemoved = myGamepads.IndexOf(e);
             if (indexRemoved > -1)
             {
                 if (mainGamepad == myGamepads[indexRemoved])
                 {
                     mainGamepad = null;
                 }
                 myGamepads.RemoveAt(indexRemoved);
             }
         }
     };
     //pointers = new Dictionary<uint, Windows.UI.Xaml.Input.Pointer>();
     //MiCanvas.PointerMoved += new PointerEventHandler(MiCanvas_PointerMoved);
     //MiCanvas.PointerReleased += new PointerEventHandler(MiCanvas_PointerReleased);
     //MiCanvas.PointerPressed += new PointerEventHandler(MiCanvas_PointerPressed);
 }
Beispiel #14
0
 public SyntaxHighlighter()
 {
     this.InitializeComponent();
     if (Window.Current.CoreWindow != null)
     {
         previousCursor = Window.Current.CoreWindow.PointerCursor;
     }
 }
Beispiel #15
0
 private void HideCursor()
 {
     if (Window.Current.CoreWindow.PointerCursor != null)
     {
         previousCursor = Window.Current.CoreWindow.PointerCursor;
         Window.Current.CoreWindow.PointerCursor = null;
     }
 }
Beispiel #16
0
        private void CaptureMouse()
        {
            // Hide the cursor
            oldCursor = Window.Current.CoreWindow.PointerCursor;
            Window.Current.CoreWindow.PointerCursor = null;

            capturingMouse = true;
        }
        protected override void OnAttached()
        {
            base.OnAttached();

            _DefaultCursor = Window.Current.CoreWindow.PointerCursor;

            AssociatedObject.Loaded   += AssociatedObject_Loaded;
            AssociatedObject.Unloaded += AssociatedObject_Unloaded;
        }
        public MainPage()
        {
            this.InitializeComponent();
            Input.Text      = " Open or Create new file....";
            Input.IsEnabled = false;
            buttonCursor    = new CoreCursor(CoreCursorType.Hand, 0);
            Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

            Window.Current.SetTitleBar(BackgroundElement);
        }
Beispiel #19
0
 public void UnlockPosition()
 {
     if (isPositionLocked)
     {
         MouseDevice.GetForCurrentView().MouseMoved -= OnRelativeMouseMoved;
         UIControl.PointerCursor = previousCursor;
         previousCursor          = null;
         isPositionLocked        = false;
     }
 }
Beispiel #20
0
        internal void SplitterManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            var splitter = sender as GridSplitter;

            if (splitter == null)
            {
                return;
            }

            _splitterPreviousPointer = splitter.PreviousCursor;
            _isDragging = true;
        }
Beispiel #21
0
        public MouseService()
        {
            _cursorTimer          = new DispatcherTimer();
            _cursorTimer.Interval = TimeSpan.FromSeconds(CursorHiddenAfterSeconds);
            _cursorTimer.Tick    += HideCursor;

            if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                _oldCursor = Window.Current.CoreWindow.PointerCursor;
                Windows.Devices.Input.MouseDevice.GetForCurrentView().MouseMoved += MouseMoved;
            }
        }
Beispiel #22
0
 private void Element_PointerExited(object sender, PointerRoutedEventArgs e)
 {
     if (_isDragging)
     {
         // if dragging don't update the curser just update the splitter cursor with the last window cursor,
         // because the splitter is still using the arrow cursor and will revert to original case when drag completes
         _splitterPreviousPointer = _previousCursor;
     }
     else
     {
         Window.Current.CoreWindow.PointerCursor = _previousCursor;
     }
 }
Beispiel #23
0
 public TaskPage()
 {
     NoteContainer   = null;
     StatusContainer = null;
     InitializeComponent();
     PointerCursor = new CoreCursor(CoreCursorType.Arrow, 0);
     HandCursor    = new CoreCursor(CoreCursorType.Hand, 1);
     LoadCursor    = new CoreCursor(CoreCursorType.Wait, 2);
     ClientImpl    = new HttpClientImpl(Client);
     RequestTimer  = new Timer(TimerCallback, null, (int)TimeSpan.FromSeconds(30).TotalMilliseconds,
                               Timeout.Infinite);
     TaskDescriptor = "Looking for tasks...";
 }
            internal void UpdateCursor()
            {
                if (_defaultCursor == null)
                {
                    _defaultCursor = Window.Current.CoreWindow.PointerCursor;
                }

                var cursor = MouseOverCursor.GetCursor(_frameworkElement);

                if (_isHovering)
                {
                    Window.Current.CoreWindow.PointerCursor = cursor ?? DefaultCursor;
                }
            }
Beispiel #25
0
        public void HideCursor()
        {
            if (!isMouseVisible)
            {
                return;
            }

            if (IsCursorInWindow())
            {
                _oldCursor = Window.Current.CoreWindow.PointerCursor;
                Window.Current.CoreWindow.PointerCursor = null;
                isMouseVisible = false;
            }
        }
Beispiel #26
0
        private void Element_PointerEntered(object sender, PointerRoutedEventArgs e)
        {
            // if not dragging
            if (!_isDragging)
            {
                _previousCursor = _splitterPreviousPointer = Window.Current.CoreWindow.PointerCursor;
                UpdateDisplayCursor();
            }

            // if dragging
            else
            {
                _previousCursor = _splitterPreviousPointer;
            }
        }
Beispiel #27
0
        public static Cursor ToCursor(this CoreCursor coreCursor)
        {
            CursorType GetCursorType(CoreCursorType?coreCursorType) =>
            coreCursorType switch
            {
                CoreCursorType.Arrow => CursorType.Arrow,
                CoreCursorType.Cross => CursorType.Cross,
                CoreCursorType.Hand => CursorType.Hand1,
                CoreCursorType.Help => CursorType.QuestionArrow,
                CoreCursorType.SizeAll => CursorType.Sizing,
                CoreCursorType.Wait => CursorType.Watch,
                _ => CursorType.Arrow,
            };

            return(new Cursor(GetCursorType(coreCursor?.Type)));
        }
Beispiel #28
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }



                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }

            SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested;;

            rootFrame.Navigated += (s, args) =>
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                    rootFrame.CanGoBack ? AppViewBackButtonVisibility.Visible : AppViewBackButtonVisibility.Collapsed;
            };
            _coreWindow    = CoreWindow.GetForCurrentThread();
            _pointerCursor = _coreWindow.PointerCursor;
        }
Beispiel #29
0
 public void LockPosition(bool forceCenter = false)
 {
     if (!isPositionLocked)
     {
         MouseDevice.GetForCurrentView().MouseMoved += OnRelativeMouseMoved;
         previousCursor          = UIControl.PointerCursor;
         UIControl.PointerCursor = null;
         if (forceCenter)
         {
             var capturedPosition = new PointUWP(UIControl.Bounds.Left, UIControl.Bounds.Top);
             capturedPosition.X       += UIControl.Bounds.Width / 2;
             capturedPosition.Y       += UIControl.Bounds.Height / 2;
             UIControl.PointerPosition = capturedPosition;
         }
         isPositionLocked = true;
     }
 }
Beispiel #30
0
 static Cursors()
 {
     _defaultCursor = new CoreCursor(CoreCursorType.Arrow, 0);
     _cursors       = new Dictionary <CoreCursorType, CoreCursor>();
     _cursors[CoreCursorType.Arrow]   = _defaultCursor;
     _cursors[CoreCursorType.Cross]   = new CoreCursor(CoreCursorType.Cross, 0);
     _cursors[CoreCursorType.Hand]    = new CoreCursor(CoreCursorType.Hand, 0);
     _cursors[CoreCursorType.Help]    = new CoreCursor(CoreCursorType.Help, 0);
     _cursors[CoreCursorType.IBeam]   = new CoreCursor(CoreCursorType.IBeam, 0);
     _cursors[CoreCursorType.SizeAll] = new CoreCursor(CoreCursorType.SizeAll, 0);
     _cursors[CoreCursorType.SizeNortheastSouthwest] = new CoreCursor(CoreCursorType.SizeNortheastSouthwest, 0);
     _cursors[CoreCursorType.SizeNorthSouth]         = new CoreCursor(CoreCursorType.SizeNorthSouth, 0);
     _cursors[CoreCursorType.SizeNorthwestSoutheast] = new CoreCursor(CoreCursorType.SizeNorthwestSoutheast, 0);
     _cursors[CoreCursorType.SizeWestEast]           = new CoreCursor(CoreCursorType.SizeWestEast, 0);
     _cursors[CoreCursorType.UniversalNo]            = new CoreCursor(CoreCursorType.UniversalNo, 0);
     _cursors[CoreCursorType.UpArrow] = new CoreCursor(CoreCursorType.UpArrow, 0);
     _cursors[CoreCursorType.Wait]    = new CoreCursor(CoreCursorType.Wait, 0);
 }
Beispiel #31
0
        /// <summary>
        /// Sets the cursor.
        /// </summary>
        /// <param name="cursor">The cursor.</param>
        public void SetCursorType(CursorType cursor)
        {
            if (cursorNotImplemented)
            {
                // setting the cursor has failed in a previous attempt, see code below
                return;
            }

            var type = CoreCursorType.Arrow;
            switch (cursor)
            {
                case CursorType.Default:
                    type = CoreCursorType.Arrow;
                    break;
                case CursorType.Pan:
                    type = CoreCursorType.Hand;
                    break;
                case CursorType.ZoomHorizontal:
                    type = CoreCursorType.SizeWestEast;
                    break;
                case CursorType.ZoomVertical:
                    type = CoreCursorType.SizeNorthSouth;
                    break;
                case CursorType.ZoomRectangle:
                    type = CoreCursorType.SizeNorthwestSoutheast;
                    break;
            }

            // TODO: determine if creating a CoreCursor is possible, do not use exception
            try
            {
                var newCursor = new CoreCursor(type, 1); // this line throws an exception on Windows Phone
                Window.Current.CoreWindow.PointerCursor = newCursor;
            }
            catch (NotImplementedException)
            {
                cursorNotImplemented = true;
            }
        }