public override void MouseUp(object sender, MouseButtonEventArgs e) { base.MouseUp(sender, e); var position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e); var selectedRect = new Rect(MouseDownStartPosition, position); // Get selected LEDs var selectedLeds = new List <ArtemisLed>(); foreach (var device in ProfileViewModel.DeviceViewModels) { foreach (var ledViewModel in device.Leds) { if (ledViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1).IntersectsWith(selectedRect)) { selectedLeds.Add(ledViewModel.Led); } // Unselect everything ledViewModel.IsSelected = false; } } // Apply the selection to the selected layer layer if (ProfileEditorService.SelectedProfileElement is Layer layer) { // If the layer has a shape, save it's size var shapeSize = Rect.Empty; if (layer.LayerShape != null) { shapeSize = _layerEditorService.GetShapeRenderRect(layer.LayerShape); } layer.ClearLeds(); layer.AddLeds(selectedLeds); // Restore the saved size if (layer.LayerShape != null) { _layerEditorService.SetShapeRenderRect(layer.LayerShape, shapeSize); } ProfileEditorService.UpdateSelectedProfileElement(); } // If no layer selected, apply it to a new layer in the selected folder else if (ProfileEditorService.SelectedProfileElement is Folder folder) { var newLayer = folder.AddLayer("New layer"); newLayer.AddLeds(selectedLeds); ProfileEditorService.ChangeSelectedProfileElement(newLayer); ProfileEditorService.UpdateSelectedProfileElement(); } // If no folder selected, apply it to a new layer in the root folder else { var rootFolder = ProfileEditorService.SelectedProfile.GetRootFolder(); var newLayer = rootFolder.AddLayer("New layer"); newLayer.AddLeds(selectedLeds); ProfileEditorService.ChangeSelectedProfileElement(newLayer); ProfileEditorService.UpdateSelectedProfileElement(); } }
public void ShapeEditMouseUp(object sender, MouseButtonEventArgs e) { ProfileEditorService.UpdateSelectedProfileElement(); _isDragging = false; _draggingHorizontally = false; _draggingVertically = false; ((IInputElement)sender).ReleaseMouseCapture(); e.Handled = true; }
public override void MouseUp(object sender, MouseButtonEventArgs e) { base.MouseUp(sender, e); if (ProfileEditorService.SelectedProfileElement is Layer layer) { // Ensure the shape is a rectangle if (!(layer.LayerShape is Rectangle)) { layer.LayerShape = new Rectangle(layer); } // Apply the drag rectangle _layerEditorService.SetShapeRenderRect(layer.LayerShape, DragRectangle); ProfileEditorService.UpdateSelectedProfileElement(); } }
public override void MouseUp(object sender, MouseButtonEventArgs e) { base.MouseUp(sender, e); // Find out if the click is inside a layer and if so, fill it var position = e.GetPosition((IInputElement)sender); var panZoomVm = ProfileViewModel.PanZoomViewModel; var layer = ProfileEditorService.SelectedProfile .GetAllLayers() .FirstOrDefault(l => l.Leds.Any( led => panZoomVm.TransformContainingRect(led.RgbLed.AbsoluteLedRectangle).Contains(position)) ); if (layer == null) { return; } layer.LayerShape = new Fill(layer); ProfileEditorService.UpdateSelectedProfileElement(); }