예제 #1
0
        //TODO (CR May 2010): we could simplify the mouse and cursor handling by putting it in the mousehelper.
        private void OnCursorChanged(AppServiceReference.Cursor cursor)
        {
            ServerEntity.Cursor = cursor ?? new AppServiceReference.Cursor();
            if (!_mouseInside)
            {
                _serverCursorImage.Source = null;
                ApplicationRootVisual.Children.Remove(_serverCursorImage);
            }
            else
            {
                var theTilePoint = new Point((double)ServerEntity.MousePosition.X - ServerEntity.Cursor.HotSpot.X,
                                             (double)ServerEntity.MousePosition.Y - ServerEntity.Cursor.HotSpot.Y);
                var absolutePoint = TileImage.GetAbsolutePosition(theTilePoint);
                var rootPoint     = ApplicationRootVisual.GetAbsolutePosition(new Point());

                _serverCursorImage.SetValue(Canvas.LeftProperty, absolutePoint.X - rootPoint.X);
                _serverCursorImage.SetValue(Canvas.TopProperty, absolutePoint.Y - rootPoint.Y);

                if (ServerEntity.Cursor.Icon == null)
                {
                    if (_serverCursorImage.Source != null)
                    {
                        _serverCursorImage.Source = null;
                        ApplicationRootVisual.Children.Remove(_serverCursorImage);
                    }
                }
                else
                {
                    var bmp = new BitmapImage();
                    bmp.SetSource(new MemoryStream(ServerEntity.Cursor.Icon));
                    _serverCursorImage.Source  = bmp;
                    _serverCursorImage.Stretch = Stretch.None;
                    if (!ApplicationRootVisual.Children.Contains(_serverCursorImage))
                    {
                        ApplicationRootVisual.Children.Add(_serverCursorImage);
                    }
                }

                _serverCursorImage.UpdateLayout();
            }

            //TODO (CR May 2010): we're already removing it from the AppRootVisual, but this is used in a number of places.
            UpdateClientCursor();
        }
예제 #2
0
        private void OnMousePositionChanged(Position mousePosition)
        {
            if (ServerEntity.Cursor == null)
            {
                ServerEntity.Cursor = new AppServiceReference.Cursor();
            }

            ServerEntity.MousePosition = mousePosition;

            var theTilePoint = new Point((double)ServerEntity.MousePosition.X - ServerEntity.Cursor.HotSpot.X,
                                         (double)ServerEntity.MousePosition.Y - ServerEntity.Cursor.HotSpot.Y);
            var   absolutePoint = TileImage.GetAbsolutePosition(theTilePoint);
            Point rootPoint     = ApplicationRootVisual.GetAbsolutePosition(new Point());

            _serverCursorImage.SetValue(Canvas.LeftProperty, absolutePoint.X - rootPoint.X);
            _serverCursorImage.SetValue(Canvas.TopProperty, absolutePoint.Y - rootPoint.Y);

            _serverCursorImage.UpdateLayout();

            UpdateClientCursor();
        }