/// <summary> /// Second handler for clicking, selects a the layer the user clicked on /// if the used clicked on an empty spot, deselects the current layer /// </summary> /// <param name="e"></param> public void MouseUpKeyboardPreview(MouseButtonEventArgs e) { if (SelectedProfile == null || SelectedProfile.IsDefault) { return; } var timeSinceDown = DateTime.Now - _downTime; if (!(timeSinceDown.TotalMilliseconds < 500)) { return; } if (_draggingLayer != null) { return; } var keyboard = _deviceManager.ActiveKeyboard; var pos = e.GetPosition((Image)e.OriginalSource); var x = pos.X / ((double)keyboard.PreviewSettings.Width / keyboard.Width); var y = pos.Y / ((double)keyboard.PreviewSettings.Height / keyboard.Height); var hoverLayer = SelectedProfile.GetLayers() .Where(l => l.MustDraw()) .FirstOrDefault(l => ((KeyboardPropertiesModel)l.Properties) .GetRect(1) .Contains(x, y)); SelectedLayer = hoverLayer; }
private List <LayerModel> GetLayers() { if (SelectedLayer == null) { return(new List <LayerModel>()); } lock (SelectedLayer) { // Get the layers that must be drawn List <LayerModel> drawLayers; if (ShowAll) { drawLayers = SelectedProfile.GetLayers(); } else if (SelectedLayer.LayerType is FolderType) { drawLayers = SelectedLayer.GetLayers().ToList(); } else { drawLayers = new List <LayerModel> { SelectedLayer } }; return(drawLayers); } } #endregion }
/// <summary> /// Handler for resizing and moving the currently selected layer /// </summary> /// <param name="e"></param> 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 = SelectedProfile.GetLayers() .Where(l => l.MustDraw()) .FirstOrDefault(l => ((KeyboardPropertiesModel)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 = ((KeyboardPropertiesModel)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; } }
private List <LayerModel> GetLayers() { if (ShowAll) { return(SelectedProfile.GetLayers()); } if (SelectedLayer == null) { return(new List <LayerModel>()); } lock (SelectedLayer) { // Get the layers that must be drawn if (SelectedLayer.LayerType is FolderType) { return(SelectedLayer.GetLayers().ToList()); } return(new List <LayerModel> { SelectedLayer }); } }