public List <LayerModel> GetRenderLayers()
        {
            // Get the layers that must be drawn
            List <LayerModel> drawLayers;

            if (ShowAll)
            {
                return(SelectedProfile.GetRenderLayers(null, false, true));
            }

            if (SelectedLayer == null || !SelectedLayer.Enabled)
            {
                return(new EditableList <LayerModel>());
            }

            if (SelectedLayer.LayerType is FolderType)
            {
                drawLayers = SelectedLayer.GetRenderLayers(null, false, true);
            }
            else
            {
                drawLayers = new List <LayerModel> {
                    SelectedLayer
                }
            };

            return(drawLayers);
        }
Exemple #2
0
        private void InvokeUpdateKeyboardPreview(object sender, ElapsedEventArgs e)
        {
            if (_blurProgress > 2)
            {
                _blurProgress = 0;
            }
            _blurProgress = _blurProgress + 0.025;
            BlurRadius    = (Math.Sin(_blurProgress * Math.PI) + 1) * 10 + 10;

            if (SelectedProfile == null || _deviceManager.ActiveKeyboard == null)
            {
                var preview = new DrawingImage();
                preview.Freeze();
                KeyboardPreview = preview;
                return;
            }

            var keyboardRect = _deviceManager.ActiveKeyboard.KeyboardRectangle(4);
            var visual       = new DrawingVisual();

            using (var drawingContext = visual.RenderOpen())
            {
                // Setup the DrawingVisual's size
                drawingContext.PushClip(new RectangleGeometry(keyboardRect));
                drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, keyboardRect);

                // Draw the layers
                var drawLayers = SelectedProfile.GetRenderLayers <ProfilePreviewDataModel>(
                    new ProfilePreviewDataModel(), false, false, true);
                foreach (var layer in drawLayers)
                {
                    layer.Draw(null, drawingContext, true, false);
                }

                // Get the selection color
                var accentColor = ThemeManager.DetectAppStyle(Application.Current)?.Item2?.Resources["AccentColor"];
                if (accentColor == null)
                {
                    return;
                }

                var pen = new Pen(new SolidColorBrush((Color)accentColor), 0.4);

                // Draw the selection outline and resize indicator
                if (SelectedLayer != null && SelectedLayer.MustDraw())
                {
                    var layerRect = ((KeyboardPropertiesModel)SelectedLayer.Properties).GetRect();
                    // Deflate the rect so that the border is drawn on the inside
                    layerRect.Inflate(-0.2, -0.2);

                    // Draw an outline around the selected layer
                    drawingContext.DrawRectangle(null, pen, layerRect);
                    // Draw a resize indicator in the bottom-right
                    drawingContext.DrawLine(pen,
                                            new Point(layerRect.BottomRight.X - 1, layerRect.BottomRight.Y - 0.5),
                                            new Point(layerRect.BottomRight.X - 1.2, layerRect.BottomRight.Y - 0.7));
                    drawingContext.DrawLine(pen,
                                            new Point(layerRect.BottomRight.X - 0.5, layerRect.BottomRight.Y - 1),
                                            new Point(layerRect.BottomRight.X - 0.7, layerRect.BottomRight.Y - 1.2));
                    drawingContext.DrawLine(pen,
                                            new Point(layerRect.BottomRight.X - 0.5, layerRect.BottomRight.Y - 0.5),
                                            new Point(layerRect.BottomRight.X - 0.7, layerRect.BottomRight.Y - 0.7));
                }

                // Remove the clip
                drawingContext.Pop();
            }
            var drawnPreview = new DrawingImage(visual.Drawing);

            drawnPreview.Freeze();
            KeyboardPreview = drawnPreview;
        }