-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Image Resizer Settings (#2324)
* added image resizer settings * updated string resource and binding * added tests and removed sett advanced settings from image resizer * fixed string resource spacing * moved conbo box strings to string resource * updated name of contributor * Capitalized size names * updated fallback encoder and sizers configs * removed interence between settings | used static resource binding * fixed build error
- Loading branch information
Lavius Motileng
committed
Apr 27, 2020
1 parent
4946dae
commit 8f2a33d
Showing
38 changed files
with
1,429 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.Lib | ||
{ | ||
public class ImageResizerProperties | ||
{ | ||
public ImageResizerProperties() | ||
{ | ||
ImageresizerSelectedSizeIndex = new IntProperty(0); | ||
ImageresizerShrinkOnly = new BoolProperty(false); | ||
ImageresizerReplace = new BoolProperty(false); | ||
ImageresizerIgnoreOrientation = new BoolProperty(true); | ||
ImageresizerJpegQualityLevel = new IntProperty(90); | ||
ImageresizerPngInterlaceOption = new IntProperty(); | ||
ImageresizerTiffCompressOption = new IntProperty(); | ||
ImageresizerFileName = new StringProperty("%1 (%2)"); | ||
|
||
ImageresizerSizes = new ImageresizerSizes(new ObservableCollection<ImageSize>() | ||
{ | ||
new ImageSize(0, "Small", ResizeFit.Fit, 854, 480, ResizeUnit.Pixel), | ||
new ImageSize(1, "Medium", ResizeFit.Fit, 1366, 768, ResizeUnit.Pixel), | ||
new ImageSize(2, "Large", ResizeFit.Fit, 1920, 1080, ResizeUnit.Pixel), | ||
new ImageSize(3, "Phone", ResizeFit.Fit, 320, 568, ResizeUnit.Pixel), | ||
}); | ||
|
||
ImageresizerKeepDateModified = new BoolProperty(); | ||
ImageresizerFallbackEncoder = new StringProperty(new System.Guid("19e4a5aa-5662-4fc5-a0c0-1758028e1057").ToString()); | ||
ImageresizerCustomSize = new ImageresizerCustomSizeProperty(new ImageSize(4, "custom", ResizeFit.Fit, 1024, 640, ResizeUnit.Pixel)); | ||
} | ||
|
||
[JsonPropertyName("imageresizer_selectedSizeIndex")] | ||
public IntProperty ImageresizerSelectedSizeIndex { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_shrinkOnly")] | ||
public BoolProperty ImageresizerShrinkOnly { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_replace")] | ||
public BoolProperty ImageresizerReplace { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_ignoreOrientation")] | ||
public BoolProperty ImageresizerIgnoreOrientation { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_jpegQualityLevel")] | ||
public IntProperty ImageresizerJpegQualityLevel { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_pngInterlaceOption")] | ||
public IntProperty ImageresizerPngInterlaceOption { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_tiffCompressOption")] | ||
public IntProperty ImageresizerTiffCompressOption { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_fileName")] | ||
public StringProperty ImageresizerFileName { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_sizes")] | ||
public ImageresizerSizes ImageresizerSizes { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_keepDateModified")] | ||
public BoolProperty ImageresizerKeepDateModified { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_fallbackEncoder")] | ||
public StringProperty ImageresizerFallbackEncoder { get; set; } | ||
|
||
[JsonPropertyName("imageresizer_customSize")] | ||
public ImageresizerCustomSizeProperty ImageresizerCustomSize { get; set; } | ||
|
||
public string ToJsonString() | ||
{ | ||
return JsonSerializer.Serialize(this); | ||
} | ||
} | ||
|
||
public enum ResizeFit | ||
{ | ||
Fill = 0, | ||
Fit = 1, | ||
Stretch = 2, | ||
} | ||
|
||
public enum ResizeUnit | ||
{ | ||
Centimeter = 0, | ||
Inch = 1, | ||
Percent = 2, | ||
Pixel = 3, | ||
} | ||
|
||
public enum PngInterlaceOption | ||
{ | ||
Default = 0, | ||
On = 1, | ||
Off = 2, | ||
} | ||
|
||
public enum TiffCompressOption | ||
{ | ||
Default = 0, | ||
None = 1, | ||
Ccitt3 = 2, | ||
Ccitt4 = 3, | ||
Lzw = 4, | ||
Rle = 5, | ||
Zip = 6, | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageResizerSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.Lib | ||
{ | ||
public class ImageResizerSettings | ||
{ | ||
[JsonPropertyName("version")] | ||
public string Version { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonPropertyName("properties")] | ||
public ImageResizerProperties Properties { get; set; } | ||
|
||
public ImageResizerSettings() | ||
{ | ||
this.Version = "1"; | ||
this.Name = "Image Resizer"; | ||
this.Properties = new ImageResizerProperties(); | ||
} | ||
|
||
public string ToJsonString() | ||
{ | ||
var options = new JsonSerializerOptions | ||
{ | ||
WriteIndented = true, | ||
}; | ||
return JsonSerializer.Serialize(this, options); | ||
} | ||
} | ||
} |
187 changes: 187 additions & 0 deletions
187
src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageSize.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.Lib | ||
{ | ||
public class ImageSize : INotifyPropertyChanged | ||
{ | ||
public ImageSize(int id) | ||
{ | ||
Id = id; | ||
Name = string.Empty; | ||
Fit = (int)ResizeFit.Fit; | ||
Width = 0; | ||
Height = 0; | ||
Unit = (int)ResizeUnit.Pixel; | ||
} | ||
|
||
public ImageSize() | ||
{ | ||
Id = 0; | ||
Name = string.Empty; | ||
Fit = (int)ResizeFit.Fit; | ||
Width = 0; | ||
Height = 0; | ||
Unit = (int)ResizeUnit.Pixel; | ||
} | ||
|
||
public ImageSize(int id, string name, ResizeFit fit, double width, double height, ResizeUnit unit) | ||
{ | ||
Id = id; | ||
Name = name; | ||
Fit = (int)fit; | ||
Width = width; | ||
Height = height; | ||
Unit = (int)unit; | ||
} | ||
|
||
private int _id; | ||
private string _name; | ||
private int _fit; | ||
private double _height; | ||
private double _width; | ||
private int _unit; | ||
|
||
public int Id | ||
{ | ||
get | ||
{ | ||
return _id; | ||
} | ||
|
||
set | ||
{ | ||
if (_id != value) | ||
{ | ||
_id = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
[JsonPropertyName("name")] | ||
public string Name | ||
{ | ||
get | ||
{ | ||
return _name; | ||
} | ||
|
||
set | ||
{ | ||
if (_name != value) | ||
{ | ||
_name = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
[JsonPropertyName("fit")] | ||
public int Fit | ||
{ | ||
get | ||
{ | ||
return _fit; | ||
} | ||
|
||
set | ||
{ | ||
if (_fit != value) | ||
{ | ||
_fit = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
[JsonPropertyName("width")] | ||
public double Width | ||
{ | ||
get | ||
{ | ||
return _width; | ||
} | ||
|
||
set | ||
{ | ||
if (_width != value) | ||
{ | ||
_width = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
[JsonPropertyName("height")] | ||
public double Height | ||
{ | ||
get | ||
{ | ||
return _height; | ||
} | ||
|
||
set | ||
{ | ||
if (_height != value) | ||
{ | ||
_height = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
[JsonPropertyName("unit")] | ||
public int Unit | ||
{ | ||
get | ||
{ | ||
return _unit; | ||
} | ||
|
||
set | ||
{ | ||
if (_unit != value) | ||
{ | ||
_unit = value; | ||
OnPropertyChanged(); | ||
} | ||
} | ||
} | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public void OnPropertyChanged([CallerMemberName] string propertyName = null) | ||
{ | ||
var handler = PropertyChanged; | ||
if (handler != null) | ||
{ | ||
handler(this, new PropertyChangedEventArgs(propertyName)); | ||
} | ||
} | ||
|
||
public void Update(ImageSize modifiedSize) | ||
{ | ||
Id = modifiedSize.Id; | ||
Name = modifiedSize.Name; | ||
Fit = modifiedSize.Fit; | ||
Width = modifiedSize.Width; | ||
Height = modifiedSize.Height; | ||
Unit = modifiedSize.Unit; | ||
} | ||
|
||
public string ToJsonString() | ||
{ | ||
return JsonSerializer.Serialize(this); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/core/Microsoft.PowerToys.Settings.UI.Lib/ImageresizerCustomSizeProperty.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.PowerToys.Settings.UI.Lib | ||
{ | ||
|
||
public class ImageresizerCustomSizeProperty | ||
{ | ||
[JsonPropertyName("value")] | ||
public ImageSize Value { get; set; } | ||
|
||
public ImageresizerCustomSizeProperty() | ||
{ | ||
this.Value = new ImageSize(); | ||
} | ||
|
||
public ImageresizerCustomSizeProperty(ImageSize value) | ||
{ | ||
Value = value; | ||
} | ||
} | ||
} |
Oops, something went wrong.