Artemis.ViewModels.Profiles.ProfileViewModel.MouseMoveKeyboardPreview C# (CSharp) Method

MouseMoveKeyboardPreview() public method

Handler for resizing and moving the currently selected layer
public MouseMoveKeyboardPreview ( System.Windows.Input.MouseEventArgs e ) : void
e System.Windows.Input.MouseEventArgs
return void
        public void MouseMoveKeyboardPreview(MouseEventArgs e)
        {
            if (SelectedProfile == null)
                return;

            var pos = e.GetPosition((Image) e.OriginalSource);
            var keyboard = _deviceManager.ActiveKeyboard;
            var x = pos.X/((double) keyboard.PreviewSettings.Width/keyboard.Width);
            var y = pos.Y/((double) keyboard.PreviewSettings.Height/keyboard.Height);
            var hoverLayer = GetLayers().Where(l => l.MustDraw())
                .FirstOrDefault(l => l.Properties.GetRect(1).Contains(x, y));

            HandleDragging(e, x, y, hoverLayer);

            if (hoverLayer == null)
            {
                KeyboardPreviewCursor = Cursors.Arrow;
                return;
            }

            // Turn the mouse pointer into a hand if hovering over an active layer
            if (hoverLayer == SelectedLayer)
            {
                var rect = hoverLayer.Properties.GetRect(1);
                KeyboardPreviewCursor =
                    Math.Sqrt(Math.Pow(x - rect.BottomRight.X, 2) + Math.Pow(y - rect.BottomRight.Y, 2)) < 0.6
                        ? Cursors.SizeNWSE
                        : Cursors.SizeAll;
            }
            else
                KeyboardPreviewCursor = Cursors.Hand;
        }

Usage Example

Example #1
0
 /// <summary>
 ///     Handler for resizing and moving the currently selected layer
 /// </summary>
 /// <param name="e"></param>
 public void MouseMoveKeyboardPreview(MouseEventArgs e)
 {
     ProfileViewModel.MouseMoveKeyboardPreview(e);
 }