MouseJumpThumbnailSize.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.ComponentModel; 7 using System.Runtime.CompilerServices; 8 using System.Text.Json.Serialization; 9 10 namespace Microsoft.PowerToys.Settings.UI.Library 11 { 12 public record MouseJumpThumbnailSize : INotifyPropertyChanged, ICmdLineRepresentable 13 { 14 private int _width; 15 private int _height; 16 17 [JsonPropertyName("width")] 18 public int Width 19 { 20 get 21 { 22 return _width; 23 } 24 25 set 26 { 27 var newWidth = Math.Max(0, value); 28 if (newWidth != _width) 29 { 30 _width = newWidth; 31 OnPropertyChanged(); 32 } 33 } 34 } 35 36 [JsonPropertyName("height")] 37 public int Height 38 { 39 get 40 { 41 return _height; 42 } 43 44 set 45 { 46 var newHeight = Math.Max(0, value); 47 if (newHeight != _height) 48 { 49 _height = newHeight; 50 OnPropertyChanged(); 51 } 52 } 53 } 54 55 public MouseJumpThumbnailSize() 56 { 57 Width = 1600; 58 Height = 1200; 59 } 60 61 public event PropertyChangedEventHandler PropertyChanged; 62 63 public void OnPropertyChanged([CallerMemberName] string propertyName = null) 64 { 65 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 66 } 67 68 public static bool TryParseFromCmd(string cmd, out object result) 69 { 70 result = null; 71 72 var parts = cmd.Split('x'); 73 if (parts.Length != 2) 74 { 75 return false; 76 } 77 78 if (int.TryParse(parts[0], out int width) && int.TryParse(parts[1], out int height)) 79 { 80 result = new MouseJumpThumbnailSize { Width = width, Height = height }; 81 return true; 82 } 83 84 return false; 85 } 86 87 public bool TryToCmdRepresentable(out string result) 88 { 89 result = $"{Width}x{Height}"; 90 return true; 91 } 92 } 93 }