Example #1
0
        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();
            }
        }
Example #2
0
 private void Update()
 {
     if (ProfileEditorService.SelectedProfileElement is Layer layer)
     {
         if (layer.LayerShape != null)
         {
             ShapeSkRect   = _layerEditorService.GetShapeRenderRect(layer.LayerShape).ToSKRect();
             AnchorSkPoint = layer.LayerShape.GetUnscaledAnchor();
             Execute.PostToUIThread(() => LayerTransformChildren = _layerEditorService.GetLayerTransformGroup(layer).Children);
         }
     }
 }
Example #3
0
        private void CreateShapeGeometry()
        {
            if (Layer.LayerShape == null || !Layer.Leds.Any())
            {
                ShapeGeometry = Geometry.Empty;
                return;
            }

            Execute.PostToUIThread(() =>
            {
                var rect          = _layerEditorService.GetShapeRenderRect(Layer.LayerShape);
                var shapeGeometry = Geometry.Empty;
                switch (Layer.LayerShape)
                {
                case Ellipse _:
                    shapeGeometry = new EllipseGeometry(rect);
                    break;

                case Fill _:
                    shapeGeometry = LayerGeometry;
                    break;

                case Polygon _:
                    // TODO
                    shapeGeometry = new RectangleGeometry(rect);
                    break;

                case Rectangle _:
                    shapeGeometry = new RectangleGeometry(rect);
                    break;
                }

                shapeGeometry.Transform = _layerEditorService.GetLayerTransformGroup(Layer);
                shapeGeometry.Freeze();
                ShapeGeometry = shapeGeometry;
            });
        }