2020-12-21 22:55:50 +08:00
|
|
|
// Copyright (c) Microsoft Corporation
|
2020-04-27 08:34:03 +08:00
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
2020-10-20 04:32:05 +08:00
|
|
|
using System;
|
2020-04-27 08:34:03 +08:00
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Text.Json;
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
2020-10-23 00:45:48 +08:00
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library
|
2020-04-27 08:34:03 +08:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-20 04:18:37 +08:00
|
|
|
public int ExtraBoxOpacity
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-12-21 22:55:50 +08:00
|
|
|
if (Unit == 2 && Fit != 2)
|
2020-06-20 04:18:37 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool EnableEtraBoxes
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-12-21 22:55:50 +08:00
|
|
|
if (Unit == 2 && Fit != 2)
|
2020-06-20 04:18:37 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 08:34:03 +08:00
|
|
|
[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();
|
2020-12-21 22:55:50 +08:00
|
|
|
OnPropertyChanged(nameof(ExtraBoxOpacity));
|
|
|
|
OnPropertyChanged(nameof(EnableEtraBoxes));
|
2020-04-27 08:34:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[JsonPropertyName("width")]
|
|
|
|
public double Width
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _width;
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-09-04 04:43:55 +08:00
|
|
|
double newWidth = -1;
|
2020-07-04 06:40:53 +08:00
|
|
|
|
2020-09-04 04:43:55 +08:00
|
|
|
if (value < 0 || double.IsNaN(value))
|
2020-07-04 06:40:53 +08:00
|
|
|
{
|
|
|
|
newWidth = 0;
|
|
|
|
}
|
2020-09-04 04:43:55 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
newWidth = value;
|
|
|
|
}
|
2020-07-04 06:40:53 +08:00
|
|
|
|
2020-09-04 04:43:55 +08:00
|
|
|
if (_width != newWidth)
|
2020-04-27 08:34:03 +08:00
|
|
|
{
|
2020-07-04 06:40:53 +08:00
|
|
|
_width = newWidth;
|
2020-04-27 08:34:03 +08:00
|
|
|
OnPropertyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[JsonPropertyName("height")]
|
|
|
|
public double Height
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-09-04 04:43:55 +08:00
|
|
|
double newHeight = -1;
|
2020-07-04 06:40:53 +08:00
|
|
|
|
2020-09-04 04:43:55 +08:00
|
|
|
if (value < 0 || double.IsNaN(value))
|
2020-07-04 06:40:53 +08:00
|
|
|
{
|
|
|
|
newHeight = 0;
|
|
|
|
}
|
2020-09-04 04:43:55 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
newHeight = value;
|
|
|
|
}
|
2020-07-04 06:40:53 +08:00
|
|
|
|
2020-09-04 04:43:55 +08:00
|
|
|
if (_height != newHeight)
|
2020-04-27 08:34:03 +08:00
|
|
|
{
|
2020-07-04 06:40:53 +08:00
|
|
|
_height = newHeight;
|
2020-04-27 08:34:03 +08:00
|
|
|
OnPropertyChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[JsonPropertyName("unit")]
|
|
|
|
public int Unit
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (_unit != value)
|
|
|
|
{
|
|
|
|
_unit = value;
|
|
|
|
OnPropertyChanged();
|
2020-10-10 08:58:52 +08:00
|
|
|
OnPropertyChanged(nameof(ExtraBoxOpacity));
|
|
|
|
OnPropertyChanged(nameof(EnableEtraBoxes));
|
2020-04-27 08:34:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2020-10-20 04:32:05 +08:00
|
|
|
if (modifiedSize == null)
|
|
|
|
{
|
|
|
|
throw new ArgumentNullException(nameof(modifiedSize));
|
|
|
|
}
|
|
|
|
|
2020-04-27 08:34:03 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|