Example #1
0
        private void RenderCanvasPreview(CanvasLayoutModel canvas)
        {
            Body.RowDefinitions.Clear();
            Body.ColumnDefinitions.Clear();

            Viewbox viewbox = new Viewbox
            {
                Stretch = Stretch.Uniform,
            };

            Body.Children.Add(viewbox);
            Canvas frame = new Canvas();

            viewbox.Child = frame;
            frame.Width   = canvas.ReferenceWidth;
            frame.Height  = canvas.ReferenceHeight;
            foreach (Int32Rect zone in canvas.Zones)
            {
                Rectangle rect = new Rectangle();
                Canvas.SetTop(rect, zone.Y);
                Canvas.SetLeft(rect, zone.X);
                rect.MinWidth        = zone.Width;
                rect.MinHeight       = zone.Height;
                rect.StrokeThickness = 5;
                rect.Stroke          = Brushes.DarkGray;
                rect.Fill            = Brushes.LightGray;
                frame.Children.Add(rect);
            }
        }
Example #2
0
        private void NewLayoutDialog_PrimaryButtonClick(ModernWpf.Controls.ContentDialog sender, ModernWpf.Controls.ContentDialogButtonClickEventArgs args)
        {
            LayoutModel selectedLayoutModel;

            if (GridLayoutRadioButton.IsChecked == true)
            {
                GridLayoutModel gridModel = new GridLayoutModel(LayoutNameText.Text, LayoutType.Custom)
                {
                    Rows        = 1,
                    RowPercents = new List <int>(1)
                    {
                        GridLayoutModel.GridMultiplier
                    },
                };
                selectedLayoutModel = gridModel;
            }
            else
            {
                selectedLayoutModel = new CanvasLayoutModel(LayoutNameText.Text, LayoutType.Custom)
                {
                    TemplateZoneCount = 0,
                };
            }

            selectedLayoutModel.InitTemplateZones();

            App.Overlay.CurrentDataContext = selectedLayoutModel;
            var mainEditor = App.Overlay;

            Hide();
            mainEditor.OpenEditor(selectedLayoutModel);
        }
        private void RenderCanvasPreview(CanvasLayoutModel canvas)
        {
            Viewbox viewbox = new Viewbox
            {
                Stretch = Stretch.Uniform,
            };

            Body.Children.Add(viewbox);
            Canvas frame = new Canvas
            {
                Width  = Settings.WorkArea.Width,
                Height = Settings.WorkArea.Height,
            };

            viewbox.Child = frame;
            foreach (Int32Rect zone in canvas.Zones)
            {
                Rectangle rect = new Rectangle();
                Canvas.SetTop(rect, zone.Y);
                Canvas.SetLeft(rect, zone.X);
                rect.MinWidth        = zone.Width;
                rect.MinHeight       = zone.Height;
                rect.StrokeThickness = 5;
                rect.Stroke          = Brushes.DarkGray;
                rect.Fill            = Brushes.LightGray;
                frame.Children.Add(rect);
            }
        }
Example #4
0
        private CanvasLayoutModel ParseCanvasInfo(CustomLayoutWrapper wrapper)
        {
            var info = JsonSerializer.Deserialize <CanvasInfoWrapper>(wrapper.Info.GetRawText(), _options);

            var zones = new List <Int32Rect>();

            foreach (var zone in info.Zones)
            {
                if (zone.Width < 0 || zone.Height < 0)
                {
                    // Malformed data
                    return(null);
                }

                zones.Add(new Int32Rect {
                    X = zone.X, Y = zone.Y, Width = zone.Width, Height = zone.Height
                });
            }

            var layout = new CanvasLayoutModel(wrapper.Uuid, wrapper.Name, LayoutType.Custom, zones, Math.Max(info.RefWidth, 0), Math.Max(info.RefHeight, 0));

            layout.SensitivityRadius = info.SensitivityRadius;

            return(layout);
        }
Example #5
0
        public CanvasEditorWindow()
        {
            InitializeComponent();

            KeyUp += CanvasEditorWindow_KeyUp;

            _model        = App.Overlay.CurrentDataContext as CanvasLayoutModel;
            _stashedModel = (CanvasLayoutModel)_model.Clone();
        }
Example #6
0
        private void CanvasEditor_Loaded(object sender, RoutedEventArgs e)
        {
            CanvasLayoutModel model = (CanvasLayoutModel)DataContext;

            if (model != null)
            {
                Model = model;
                UpdateZoneRects();

                model.PropertyChanged += OnModelChanged;
            }
        }
Example #7
0
        private void RenderCanvasPreview(CanvasLayoutModel canvas)
        {
            var workArea = canvas.CanvasRect;

            if (workArea.Width == 0 || workArea.Height == 0 || App.Overlay.SpanZonesAcrossMonitors)
            {
                workArea = App.Overlay.WorkArea;
            }

            Viewbox viewbox = new Viewbox
            {
                Stretch = Stretch.Uniform,
            };

            Body.Children.Add(viewbox);
            Canvas frame = new Canvas
            {
                Width  = workArea.Width,
                Height = workArea.Height,
            };

            viewbox.Child = frame;

            foreach (Int32Rect zone in canvas.Zones)
            {
                Border rect = new Border();
                Canvas.SetTop(rect, zone.Y);
                Canvas.SetLeft(rect, zone.X);
                rect.MinWidth  = zone.Width;
                rect.MinHeight = zone.Height;

                if (IsActualSize)
                {
                    rect.Style = (Style)FindResource("CanvasLayoutPreviewActualSizeStyle");
                }
                else
                {
                    rect.Style = (Style)FindResource("CanvasLayoutPreviewStyle");
                }

                frame.Children.Add(rect);
            }

            if (App.DebugMode)
            {
                TextBlock text = new TextBlock();
                text.Text     = "(" + App.Overlay.WorkArea.X + "," + App.Overlay.WorkArea.Y + ")";
                text.FontSize = 42;
                frame.Children.Add(text);
            }
        }
Example #8
0
        public MainWindowSettingsModel()
        {
            // Initialize default layout models: Blank, Focus, Columns, Rows, Grid, and PriorityGrid
            var blankModel = new CanvasLayoutModel(Properties.Resources.Template_Layout_Blank, LayoutType.Blank)
            {
                TemplateZoneCount = 0,
                SensitivityRadius = 0,
            };

            DefaultModels.Insert((int)LayoutType.Blank, blankModel);

            var focusModel = new CanvasLayoutModel(Properties.Resources.Template_Layout_Focus, LayoutType.Focus);

            focusModel.InitTemplateZones();
            DefaultModels.Insert((int)LayoutType.Focus, focusModel);

            var columnsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Columns, LayoutType.Columns)
            {
                Rows        = 1,
                RowPercents = new List <int>(1)
                {
                    GridLayoutModel.GridMultiplier
                },
            };

            columnsModel.InitTemplateZones();
            DefaultModels.Insert((int)LayoutType.Columns, columnsModel);

            var rowsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Rows, LayoutType.Rows)
            {
                Columns        = 1,
                ColumnPercents = new List <int>(1)
                {
                    GridLayoutModel.GridMultiplier
                },
            };

            rowsModel.InitTemplateZones();
            DefaultModels.Insert((int)LayoutType.Rows, rowsModel);

            var gridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Grid, LayoutType.Grid);

            gridModel.InitTemplateZones();
            DefaultModels.Insert((int)LayoutType.Grid, gridModel);

            var priorityGridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Priority_Grid, LayoutType.PriorityGrid);

            priorityGridModel.InitTemplateZones();
            DefaultModels.Insert((int)LayoutType.PriorityGrid, priorityGridModel);
        }
Example #9
0
        public Settings()
        {
            string tmpDirPath = Path.GetTempPath();

            ActiveZoneSetTmpFile         = tmpDirPath + ActiveZoneSetsTmpFileName;
            AppliedZoneSetTmpFile        = tmpDirPath + AppliedZoneSetsTmpFileName;
            DeletedCustomZoneSetsTmpFile = tmpDirPath + DeletedCustomZoneSetsTmpFileName;

            var localAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            FancyZonesSettingsFile = localAppDataDir + ZonesSettingsFile;

            ParseCommandLineArgs();

            // Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
            DefaultModels = new List <LayoutModel>(5);
            _focusModel   = new CanvasLayoutModel(FocusLayoutID, LayoutType.Focus);
            DefaultModels.Add(_focusModel);

            _columnsModel = new GridLayoutModel(ColumnsLayoutID, LayoutType.Columns)
            {
                Rows        = 1,
                RowPercents = new List <int>(1)
                {
                    _multiplier
                },
            };
            DefaultModels.Add(_columnsModel);

            _rowsModel = new GridLayoutModel(RowsLayoutID, LayoutType.Rows)
            {
                Columns        = 1,
                ColumnPercents = new List <int>(1)
                {
                    _multiplier
                },
            };
            DefaultModels.Add(_rowsModel);

            _gridModel = new GridLayoutModel(GridLayoutID, LayoutType.Grid);
            DefaultModels.Add(_gridModel);

            _priorityGridModel = new GridLayoutModel(PriorityGridLayoutID, LayoutType.PriorityGrid);
            DefaultModels.Add(_priorityGridModel);

            _blankCustomModel = new CanvasLayoutModel(CreateNewCustomLabel, LayoutType.Blank);

            UpdateLayoutModels();
        }
        private void RenderCanvasPreview(CanvasLayoutModel canvas)
        {
            var screenWorkArea = App.Overlay.WorkArea;

            canvas.ScaleLayout(workAreaWidth: screenWorkArea.Width, workAreaHeight: screenWorkArea.Height);

            Viewbox viewbox = new Viewbox
            {
                Stretch = Stretch.Uniform,
            };

            Body.Children.Add(viewbox);
            Canvas frame = new Canvas
            {
                Width  = screenWorkArea.Width,
                Height = screenWorkArea.Height,
            };

            viewbox.Child = frame;

            foreach (Int32Rect zone in canvas.Zones)
            {
                Border rect = new Border();
                Canvas.SetTop(rect, zone.Y);
                Canvas.SetLeft(rect, zone.X);
                rect.MinWidth  = zone.Width;
                rect.MinHeight = zone.Height;

                if (IsActualSize)
                {
                    rect.Style = (Style)FindResource("CanvasLayoutActualScalePreviewStyle");
                }
                else
                {
                    rect.Style = (Style)FindResource("CanvasLayoutSmallScalePreviewStyle");
                }

                frame.Children.Add(rect);
            }

            if (App.DebugMode)
            {
                TextBlock text = new TextBlock();
                text.Text     = "(" + App.Overlay.WorkArea.X + "," + App.Overlay.WorkArea.Y + ")";
                text.FontSize = 42;
                frame.Children.Add(text);
            }
        }
Example #11
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            CanvasLayoutModel model = (CanvasLayoutModel)DataContext;

            if (model != null)
            {
                _model = model;

                var workArea = App.Overlay.WorkArea;
                _model.ScaleLayout(workAreaWidth: workArea.Width, workAreaHeight: workArea.Height);

                UpdateZoneRects();

                _model.PropertyChanged += OnModelChanged;
            }
        }
Example #12
0
        private void RenderCanvasPreview(CanvasLayoutModel canvas)
        {
            var workArea = canvas.CanvasRect;

            if (workArea.Width == 0 || workArea.Height == 0 || App.Overlay.SpanZonesAcrossMonitors)
            {
                workArea = App.Overlay.WorkArea;
            }

            Viewbox viewbox = new Viewbox
            {
                Stretch = Stretch.Uniform,
            };

            Body.Children.Add(viewbox);
            Canvas frame = new Canvas
            {
                Width  = workArea.Width,
                Height = workArea.Height,
            };

            viewbox.Child = frame;

            foreach (Int32Rect zone in canvas.Zones)
            {
                Rectangle rect = new Rectangle();
                Canvas.SetTop(rect, zone.Y);
                Canvas.SetLeft(rect, zone.X);
                rect.MinWidth        = zone.Width;
                rect.MinHeight       = zone.Height;
                rect.StrokeThickness = 5;
                rect.Stroke          = Brushes.DarkGray;
                rect.Fill            = Brushes.LightGray;
                frame.Children.Add(rect);
            }

            if (App.DebugMode)
            {
                TextBlock text = new TextBlock();
                text.Text     = "(" + App.Overlay.WorkArea.X + "," + App.Overlay.WorkArea.Y + ")";
                text.FontSize = 42;
                frame.Children.Add(text);
            }
        }
Example #13
0
        private void NewLayoutDialog_PrimaryButtonClick(ModernWpf.Controls.ContentDialog sender, ModernWpf.Controls.ContentDialogButtonClickEventArgs args)
        {
            Logger.LogTrace();

            LayoutModel selectedLayoutModel;

            if (GridLayoutRadioButton.IsChecked == true)
            {
                GridLayoutModel gridModel = new GridLayoutModel(LayoutNameText.Text, LayoutType.Custom)
                {
                    Rows        = 1,
                    RowPercents = new List <int>(1)
                    {
                        GridLayoutModel.GridMultiplier
                    },
                };
                selectedLayoutModel = gridModel;
            }
            else
            {
                var area = App.Overlay.WorkArea;
                CanvasLayoutModel canvasModel = new CanvasLayoutModel(LayoutNameText.Text, LayoutType.Custom, (int)area.Width, (int)area.Height);
                canvasModel.AddZone();
                selectedLayoutModel = canvasModel;
            }

            selectedLayoutModel.InitTemplateZones();

            try
            {
                Hide();
            }
            catch
            {
                // See https://github.com/microsoft/PowerToys/issues/9396
                Hide();
            }

            App.Overlay.CurrentDataContext = selectedLayoutModel;
            App.Overlay.OpenEditor(selectedLayoutModel);
        }
Example #14
0
        public Settings()
        {
            ParseCommandLineArgs();

            // Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
            DefaultModels = new List <LayoutModel>(5);
            _focusModel   = new CanvasLayoutModel("Focus", _focusModelId, (int)_workArea.Width, (int)_workArea.Height);
            DefaultModels.Add(_focusModel);

            _columnsModel = new GridLayoutModel("Columns", _columnsModelId)
            {
                Rows        = 1,
                RowPercents = new int[1] {
                    _multiplier
                },
            };
            DefaultModels.Add(_columnsModel);

            _rowsModel = new GridLayoutModel("Rows", _rowsModelId)
            {
                Columns        = 1,
                ColumnPercents = new int[1] {
                    _multiplier
                },
            };
            DefaultModels.Add(_rowsModel);

            _gridModel = new GridLayoutModel("Grid", _gridModelId);
            DefaultModels.Add(_gridModel);

            _priorityGridModel = new GridLayoutModel("Priority Grid", _priorityGridModelId);
            DefaultModels.Add(_priorityGridModel);

            _blankCustomModel = new CanvasLayoutModel("Create new custom", _blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height);

            _zoneCount   = ReadRegistryInt("ZoneCount", 3);
            _spacing     = ReadRegistryInt("Spacing", 16);
            _showSpacing = ReadRegistryInt("ShowSpacing", 1) == 1;

            UpdateLayoutModels();
        }
Example #15
0
        public Settings()
        {
            ParseCommandLineArgs();

            // Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
            _defaultModels = new List <LayoutModel>(5);
            _focusModel    = new CanvasLayoutModel("Focus", c_focusModelId, (int)_workArea.Width, (int)_workArea.Height);
            _defaultModels.Add(_focusModel);

            _columnsModel             = new GridLayoutModel("Columns", c_columnsModelId);
            _columnsModel.Rows        = 1;
            _columnsModel.RowPercents = new int[1] {
                c_multiplier
            };
            _defaultModels.Add(_columnsModel);

            _rowsModel                = new GridLayoutModel("Rows", c_rowsModelId);
            _rowsModel.Columns        = 1;
            _rowsModel.ColumnPercents = new int[1] {
                c_multiplier
            };
            _defaultModels.Add(_rowsModel);

            _gridModel = new GridLayoutModel("Grid", c_gridModelId);
            _defaultModels.Add(_gridModel);

            _priorityGridModel = new GridLayoutModel("Priority Grid", c_priorityGridModelId);
            _defaultModels.Add(_priorityGridModel);

            _blankCustomModel = new CanvasLayoutModel("Create new custom", c_blankCustomModelId, (int)_workArea.Width, (int)_workArea.Height);

            _zoneCount   = (int)Registry.GetValue(_uniqueRegistryPath, "ZoneCount", 3);
            _spacing     = (int)Registry.GetValue(_uniqueRegistryPath, "Spacing", 16);
            _showSpacing = (int)Registry.GetValue(_uniqueRegistryPath, "ShowSpacing", 1) == 1;

            UpdateLayoutModels();
        }
        public MainWindowSettingsModel()
        {
            // Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
            DefaultModels = new List <LayoutModel>(5);
            _focusModel   = new CanvasLayoutModel(Properties.Resources.Template_Layout_Focus, LayoutType.Focus);
            DefaultModels.Add(_focusModel);

            _columnsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Columns, LayoutType.Columns)
            {
                Rows        = 1,
                RowPercents = new List <int>(1)
                {
                    _multiplier
                },
            };
            DefaultModels.Add(_columnsModel);

            _rowsModel = new GridLayoutModel(Properties.Resources.Template_Layout_Rows, LayoutType.Rows)
            {
                Columns        = 1,
                ColumnPercents = new List <int>(1)
                {
                    _multiplier
                },
            };
            DefaultModels.Add(_rowsModel);

            _gridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Grid, LayoutType.Grid);
            DefaultModels.Add(_gridModel);

            _priorityGridModel = new GridLayoutModel(Properties.Resources.Template_Layout_Priority_Grid, LayoutType.PriorityGrid);
            DefaultModels.Add(_priorityGridModel);

            _blankCustomModel = new CanvasLayoutModel(Properties.Resources.Custom_Layout_Create_New, LayoutType.Blank);

            UpdateTemplateLayoutModels();
        }
Example #17
0
        public Settings()
        {
            ParseCommandLineArgs();

            // Initialize the five default layout models: Focus, Columns, Rows, Grid, and PriorityGrid
            DefaultModels = new List <LayoutModel>(5);
            _focusModel   = new CanvasLayoutModel("Focus", LayoutType.Focus, (int)_workArea.Width, (int)_workArea.Height);
            DefaultModels.Add(_focusModel);

            _columnsModel = new GridLayoutModel("Columns", LayoutType.Columns)
            {
                Rows        = 1,
                RowPercents = new int[1] {
                    _multiplier
                },
            };
            DefaultModels.Add(_columnsModel);

            _rowsModel = new GridLayoutModel("Rows", LayoutType.Rows)
            {
                Columns        = 1,
                ColumnPercents = new int[1] {
                    _multiplier
                },
            };
            DefaultModels.Add(_rowsModel);

            _gridModel = new GridLayoutModel("Grid", LayoutType.Grid);
            DefaultModels.Add(_gridModel);

            _priorityGridModel = new GridLayoutModel("Priority Grid", LayoutType.PriorityGrid);
            DefaultModels.Add(_priorityGridModel);

            _blankCustomModel = new CanvasLayoutModel("Create new custom", LayoutType.Blank, (int)_workArea.Width, (int)_workArea.Height);

            UpdateLayoutModels();
        }
Example #18
0
        private void RenderPreview()
        {
            if (_model == null)
            {
                return;
            }

            Body.Children.Clear();

            GridLayoutModel gridModel = _model as GridLayoutModel;

            if (gridModel != null)
            {
                RenderGridPreview(gridModel);
            }
            else
            {
                CanvasLayoutModel canvasModel = _model as CanvasLayoutModel;
                if (canvasModel != null)
                {
                    RenderCanvasPreview(canvasModel);
                }
            }
        }
        private bool SetCustomLayouts(List <CustomLayoutWrapper> customLayouts)
        {
            if (customLayouts == null)
            {
                return(false);
            }

            MainWindowSettingsModel.CustomModels.Clear();
            bool result = true;

            foreach (var zoneSet in customLayouts)
            {
                if (zoneSet.Uuid == null || zoneSet.Uuid.Length == 0)
                {
                    result = false;
                    continue;
                }

                LayoutModel layout;
                if (zoneSet.Type == CanvasLayoutModel.ModelTypeID)
                {
                    var info = JsonSerializer.Deserialize <CanvasInfoWrapper>(zoneSet.Info.GetRawText(), _options);

                    var zones = new List <Int32Rect>();
                    foreach (var zone in info.Zones)
                    {
                        zones.Add(new Int32Rect {
                            X = (int)zone.X, Y = (int)zone.Y, Width = (int)zone.Width, Height = (int)zone.Height
                        });
                    }

                    try
                    {
                        layout = new CanvasLayoutModel(zoneSet.Uuid, zoneSet.Name, LayoutType.Custom, zones, info.RefWidth, info.RefHeight);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    layout.SensitivityRadius = info.SensitivityRadius;
                }
                else if (zoneSet.Type == GridLayoutModel.ModelTypeID)
                {
                    var info = JsonSerializer.Deserialize <GridInfoWrapper>(zoneSet.Info.GetRawText(), _options);

                    var cells = new int[info.Rows, info.Columns];
                    for (int row = 0; row < info.Rows; row++)
                    {
                        for (int column = 0; column < info.Columns; column++)
                        {
                            cells[row, column] = info.CellChildMap[row][column];
                        }
                    }

                    try
                    {
                        layout = new GridLayoutModel(zoneSet.Uuid, zoneSet.Name, LayoutType.Custom, info.Rows, info.Columns, info.RowsPercentage, info.ColumnsPercentage, cells);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    layout.SensitivityRadius = info.SensitivityRadius;
                    (layout as GridLayoutModel).ShowSpacing = info.ShowSpacing;
                    (layout as GridLayoutModel).Spacing     = info.Spacing;
                }
                else
                {
                    result = false;
                    continue;
                }

                MainWindowSettingsModel.CustomModels.Add(layout);
            }

            return(result);
        }