Files
eveo/src/Eve-O-Preview/Configuration/Implementation/ThumbnailConfiguration.cs

535 lines
20 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace EveOPreview.Configuration.Implementation {
sealed class ThumbnailConfiguration : IThumbnailConfiguration {
#region Private fields
private bool _enablePerClientThumbnailLayouts;
private bool _enableClientLayoutTracking;
#endregion
public ThumbnailConfiguration() {
this.ConfigVersion = 1;
this.CycleGroup1ForwardHotkeys = new List<string> { "F14", "Control+F14" };
this.CycleGroup1BackwardHotkeys = new List<string> { "F13", "Control+F13" };
this.CycleGroup1ClientsOrder = new Dictionary<string, int> {
{ "EVE - Example DPS Toon 1", 1 }, { "EVE - Example DPS Toon 2", 2 }, { "EVE - Example DPS Toon 3", 3 }
};
this.CycleGroup2ForwardHotkeys = new List<string> { "F16", "Control+F16" };
this.CycleGroup2BackwardHotkeys = new List<string> { "F15", "Control+F15" };
this.CycleGroup2ClientsOrder = new Dictionary<string, int> { { "EVE - Example Logi Toon 1", 1 },
{ "EVE - Example Scout Toon 2", 2 },
{ "EVE - Example Tackle Toon 3", 3 } };
this.CycleGroup3ForwardHotkeys = new List<string> { "" };
this.CycleGroup3BackwardHotkeys = new List<string> { "" };
this.CycleGroup3ClientsOrder = new Dictionary<string, int> {
{ "EVE - cycle group 3", 1 },
};
this.CycleGroup4ForwardHotkeys = new List<string> { "" };
this.CycleGroup4BackwardHotkeys = new List<string> { "" };
this.CycleGroup4ClientsOrder = new Dictionary<string, int> {
{ "EVE - cycle group 4", 1 },
};
this.CycleGroup5ForwardHotkeys = new List<string> { "" };
this.CycleGroup5BackwardHotkeys = new List<string> { "" };
this.CycleGroup5ClientsOrder = new Dictionary<string, int> {
{ "EVE - cycle group 5", 1 },
};
this.PerClientActiveClientHighlightColor =
new Dictionary<string, Color> { { "EVE - Example Toon 1", Color.Red },
{ "EVE - Example Toon 2", Color.Green } };
this.PerClientThumbnailSize =
new Dictionary<string, Size> { { "EVE - Example Toon 1", new Size(200, 200) },
{ "EVE - Example Toon 2", new Size(200, 200) } };
this.PerClientThumbnailRegion = new Dictionary<string, Rectangle>();
this.PerClientZoomAnchor = new Dictionary<string, ZoomAnchor> { { "EVE - Example Toon 1", ZoomAnchor.N },
{ "EVE - Example Toon 2", ZoomAnchor.S } };
this.PerClientLayout = new Dictionary<string, Dictionary<string, Point>>();
this.FlatLayout = new Dictionary<string, Point>();
this.ClientLayout = new Dictionary<string, ClientLayout>();
this.ClientHotkey = new Dictionary<string, string>();
this.DisableThumbnail = new Dictionary<string, bool>();
this.PriorityClients = new List<string>();
this.ExecutablesToPreview = new List<string> { "exefile" };
this.MinimizeToTray = false;
this.ThumbnailRefreshPeriod = 500;
this.ThumbnailResizeTimeoutPeriod = 500;
#if LINUX
this.EnableWineCompatibilityMode = true;
#else
this.EnableWineCompatibilityMode = false;
#endif
this.ThumbnailOpacity = 0.5;
this.EnableClientLayoutTracking = false;
this.HideActiveClientThumbnail = false;
this.HideLoginClientThumbnail = false;
this.MinimizeInactiveClients = false;
this.WindowsAnimationStyle = AnimationStyle.NoAnimation;
this.ShowThumbnailsAlwaysOnTop = true;
this.EnablePerClientThumbnailLayouts = false;
this.HideThumbnailsOnLostFocus = false;
this.HideThumbnailsDelay = 2; // 2 thumbnails refresh cycles (1.0 sec)
this.ThumbnailSize = new Size(384, 216);
this.ThumbnailMinimumSize = new Size(192, 108);
this.ThumbnailMaximumSize = new Size(960, 540);
this.EnableThumbnailSnap = true;
this.ThumbnailSnapRange = 20;
this.ThumbnailZoomEnabled = false;
this.ThumbnailZoomFactor = 2;
this.ThumbnailZoomAnchor = ZoomAnchor.NW;
this.OverlayLabelAnchor = ZoomAnchor.NW;
this.ShowThumbnailOverlays = true;
this.ShowThumbnailFrames = false;
this.LockThumbnailLocation = false;
this.ThumbnailSnapToGrid = true;
this.ThumbnailSnapToGridSizeX = 100;
this.ThumbnailSnapToGridSizeY = 50;
this.EnableActiveClientHighlight = false;
this.ActiveClientHighlightColor = Color.GreenYellow;
this.ActiveClientHighlightThickness = 3;
this.OverlayLabelColor = Color.Orange;
this.OverlayLabelSize = 10;
this.EnableThumbnailRegionSnipping = false;
this.DefaultThumbnailRegion = new Rectangle(0, 0, 384, 216);
this.CurrentProfile = "Default";
this.AvailableProfiles = new List<string> { "Default" };
this.IconName = "";
this.LoginThumbnailLocation = new Point(5, 5);
this.ToggleTrackingHotkey = "Alt+F16";
this.ToggleSingleProcessHotkey = "Control+F16";
this.ToggleAllThumbnailsHotkey = "Alt+F12";
this.ThumbnailsManuallyHidden = false;
}
[JsonProperty("ConfigVersion")]
public int ConfigVersion { get; set; }
[JsonProperty("CycleGroup1ForwardHotkeys")]
public List<string> CycleGroup1ForwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup1BackwardHotkeys")]
public List<string> CycleGroup1BackwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup1ClientsOrder")]
public Dictionary<string, int> CycleGroup1ClientsOrder {
get; set;
}
[JsonProperty("CycleGroup2ForwardHotkeys")]
public List<string> CycleGroup2ForwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup2BackwardHotkeys")]
public List<string> CycleGroup2BackwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup2ClientsOrder")]
public Dictionary<string, int> CycleGroup2ClientsOrder {
get; set;
}
[JsonProperty("CycleGroup3ForwardHotkeys")]
public List<string> CycleGroup3ForwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup3BackwardHotkeys")]
public List<string> CycleGroup3BackwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup3ClientsOrder")]
public Dictionary<string, int> CycleGroup3ClientsOrder {
get; set;
}
[JsonProperty("CycleGroup4ForwardHotkeys")]
public List<string> CycleGroup4ForwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup4BackwardHotkeys")]
public List<string> CycleGroup4BackwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup4ClientsOrder")]
public Dictionary<string, int> CycleGroup4ClientsOrder {
get; set;
}
[JsonProperty("CycleGroup5ForwardHotkeys")]
public List<string> CycleGroup5ForwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup5BackwardHotkeys")]
public List<string> CycleGroup5BackwardHotkeys {
get; set;
}
[JsonProperty("CycleGroup5ClientsOrder")]
public Dictionary<string, int> CycleGroup5ClientsOrder {
get; set;
}
[JsonProperty("PerClientActiveClientHighlightColor")]
public Dictionary<string, Color> PerClientActiveClientHighlightColor {
get; set;
}
[JsonProperty("PerClientThumbnailSize")]
public Dictionary<string, Size> PerClientThumbnailSize {
get; set;
}
[JsonProperty("PerClientThumbnailRegion")]
public Dictionary<string, Rectangle> PerClientThumbnailRegion {
get; set;
}
[JsonProperty("PerClientZoomAnchor")]
public Dictionary<string, ZoomAnchor> PerClientZoomAnchor {
get; set;
}
public bool MinimizeToTray { get; set; }
public int ThumbnailRefreshPeriod { get; set; }
public int ThumbnailResizeTimeoutPeriod { get; set; }
[JsonProperty("WineCompatibilityMode")]
public bool EnableWineCompatibilityMode {
get; set;
}
[JsonProperty("ThumbnailsOpacity")]
public double ThumbnailOpacity {
get; set;
}
public bool EnableClientLayoutTracking {
get => this._enableClientLayoutTracking;
set {
if (!value) {
this.ClientLayout.Clear();
}
this._enableClientLayoutTracking = value;
}
}
public bool HideActiveClientThumbnail { get; set; }
public bool HideLoginClientThumbnail { get; set; }
public bool MinimizeInactiveClients { get; set; }
public AnimationStyle WindowsAnimationStyle { get; set; }
public bool ShowThumbnailsAlwaysOnTop { get; set; }
public bool EnablePerClientThumbnailLayouts {
get => this._enablePerClientThumbnailLayouts;
set {
if (!value) {
this.PerClientLayout.Clear();
}
this._enablePerClientThumbnailLayouts = value;
}
}
public bool HideThumbnailsOnLostFocus { get; set; }
public int HideThumbnailsDelay { get; set; }
public Size ThumbnailSize { get; set; }
public Size ThumbnailMaximumSize { get; set; }
public Size ThumbnailMinimumSize { get; set; }
public bool EnableThumbnailSnap { get; set; }
public int ThumbnailSnapRange { get; set; }
[JsonProperty("EnableThumbnailZoom")]
public bool ThumbnailZoomEnabled {
get; set;
}
public int ThumbnailZoomFactor { get; set; }
public ZoomAnchor ThumbnailZoomAnchor { get; set; }
public ZoomAnchor OverlayLabelAnchor { get; set; }
public bool ShowThumbnailOverlays { get; set; }
public bool ShowThumbnailFrames { get; set; }
public bool LockThumbnailLocation { get; set; }
public bool ThumbnailSnapToGrid { get; set; }
public int ThumbnailSnapToGridSizeX { get; set; }
public int ThumbnailSnapToGridSizeY { get; set; }
public bool EnableActiveClientHighlight { get; set; }
public Color ActiveClientHighlightColor { get; set; }
public Color OverlayLabelColor { get; set; }
public int OverlayLabelSize { get; set; }
public bool EnableThumbnailRegionSnipping { get; set; }
public Rectangle DefaultThumbnailRegion { get; set; }
public string CurrentProfile { get; set; }
public List<string> AvailableProfiles { get; set; }
[JsonProperty("IconName")]
public string IconName {
get; set;
}
public int ActiveClientHighlightThickness { get; set; }
[JsonProperty("LoginThumbnailLocation")]
public Point LoginThumbnailLocation {
get; set;
}
[JsonProperty("ToggleTrackingHotkey")]
public string ToggleTrackingHotkey {
get; set;
}
[JsonProperty("ToggleSingleProcessHotkey")]
public string ToggleSingleProcessHotkey {
get; set;
}
[JsonProperty("ToggleAllThumbnailsHotkey")]
public string ToggleAllThumbnailsHotkey {
get; set;
}
[JsonProperty("ThumbnailsManuallyHidden")]
public bool ThumbnailsManuallyHidden {
get; set;
}
[JsonProperty]
private Dictionary<string, Dictionary<string, Point>> PerClientLayout {
get; set;
}
[JsonProperty]
private Dictionary<string, Point> FlatLayout {
get; set;
}
[JsonProperty]
private Dictionary<string, ClientLayout> ClientLayout {
get; set;
}
[JsonProperty]
private Dictionary<string, string> ClientHotkey {
get; set;
}
[JsonProperty]
private Dictionary<string, bool> DisableThumbnail {
get; set;
}
[JsonProperty]
private List<string> PriorityClients {
get; set;
}
[JsonProperty]
public List<string> ExecutablesToPreview {
get; set;
}
public Point GetThumbnailLocation(string currentClient, string activeClient, Point defaultLocation) {
Point location;
// What this code does:
// If Per-Client layouts are enabled
// and client name is known
// and there is a separate thumbnails layout for this client
// and this layout contains an entry for the current client
// then return that entry
// otherwise try to get client layout from the flat all-clients layout
// If there is no layout too then use the default one
if (this.EnablePerClientThumbnailLayouts && !string.IsNullOrEmpty(activeClient)) {
Dictionary<string, Point> layoutSource;
if (this.PerClientLayout.TryGetValue(activeClient, out layoutSource) &&
layoutSource.TryGetValue(currentClient, out location)) {
return location;
}
}
return this.FlatLayout.TryGetValue(currentClient, out location) ? location : defaultLocation;
}
public Size GetThumbnailSize(string currentClient, string activeClient, Size defaultSize) {
Size sizeOfThumbnail;
return this.PerClientThumbnailSize.TryGetValue(currentClient, out sizeOfThumbnail) ? sizeOfThumbnail
: defaultSize;
}
public Rectangle GetThumbnailRegion(string currentClient, Rectangle defaultRegion) {
Rectangle region;
return this.PerClientThumbnailRegion.TryGetValue(currentClient, out region) ? region : defaultRegion;
}
public ZoomAnchor GetZoomAnchor(string currentClient, ZoomAnchor defaultZoomAnchor) {
ZoomAnchor zoomAnchor;
return this.PerClientZoomAnchor.TryGetValue(currentClient, out zoomAnchor) ? zoomAnchor : defaultZoomAnchor;
}
public void SetThumbnailLocation(string currentClient, string activeClient, Point location) {
Dictionary<string, Point> layoutSource;
if (this.EnablePerClientThumbnailLayouts) {
if (string.IsNullOrEmpty(activeClient)) {
return;
}
if (!this.PerClientLayout.TryGetValue(activeClient, out layoutSource)) {
layoutSource = new Dictionary<string, Point>();
this.PerClientLayout[activeClient] = layoutSource;
}
} else {
layoutSource = this.FlatLayout;
}
layoutSource[currentClient] = location;
}
public void SetThumbnailRegion(string currentClient, Rectangle region) {
this.PerClientThumbnailRegion[currentClient] = region;
}
public void SaveProfile(string profileName) {
if (!this.AvailableProfiles.Contains(profileName)) {
this.AvailableProfiles.Add(profileName);
}
this.CurrentProfile = profileName;
}
public void LoadProfile(string profileName) {
if (this.AvailableProfiles.Contains(profileName)) {
this.CurrentProfile = profileName;
}
}
public void DeleteProfile(string profileName) {
if (profileName != "Default" && this.AvailableProfiles.Contains(profileName)) {
this.AvailableProfiles.Remove(profileName);
if (this.CurrentProfile == profileName) {
this.CurrentProfile = "Default";
}
}
}
public ClientLayout GetClientLayout(string currentClient) {
ClientLayout layout;
this.ClientLayout.TryGetValue(currentClient, out layout);
return layout;
}
public void SetClientLayout(string currentClient, ClientLayout layout) {
this.ClientLayout[currentClient] = layout;
}
public Keys GetClientHotkey(string currentClient) {
string hotkey;
if (this.ClientHotkey.TryGetValue(currentClient, out hotkey)) {
// Protect from incorrect values
object rawValue = (new KeysConverter()).ConvertFromInvariantString(hotkey);
return rawValue != null ? (Keys)rawValue : Keys.None;
}
return Keys.None;
}
public void SetClientHotkey(string currentClient, Keys hotkey) {
this.ClientHotkey[currentClient] = (new KeysConverter()).ConvertToInvariantString(hotkey);
}
public Keys StringToKey(string hotkey) {
object rawValue = (new KeysConverter()).ConvertFromInvariantString(hotkey);
return rawValue != null ? (Keys)rawValue : Keys.None;
}
public bool IsPriorityClient(string currentClient) {
return this.PriorityClients.Contains(currentClient);
}
public bool IsExecutableToPreview(string processName) {
return this.ExecutablesToPreview.Any(s => s.Equals(processName, StringComparison.OrdinalIgnoreCase));
}
public bool IsThumbnailDisabled(string currentClient) {
return this.DisableThumbnail.TryGetValue(currentClient, out bool isDisabled) && isDisabled;
}
public void ToggleThumbnail(string currentClient, bool isDisabled) {
this.DisableThumbnail[currentClient] = isDisabled;
}
/// <summary>
/// Applies restrictions to different parameters of the config
/// </summary>
public void ApplyRestrictions() {
#if LINUX
this.ThumbnailRefreshPeriod =
ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailRefreshPeriod, 10, 1000);
#else
this.ThumbnailRefreshPeriod =
ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailRefreshPeriod, 300, 1000);
#endif
this.ThumbnailResizeTimeoutPeriod =
ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailResizeTimeoutPeriod, 200, 5000);
this.ThumbnailSize = new Size(
ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailSize.Width, this.ThumbnailMinimumSize.Width,
this.ThumbnailMaximumSize.Width),
ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailSize.Height, this.ThumbnailMinimumSize.Height,
this.ThumbnailMaximumSize.Height));
this.ThumbnailOpacity =
ThumbnailConfiguration.ApplyRestrictions((int)(this.ThumbnailOpacity * 100.00), 20, 100) / 100.00;
this.ThumbnailZoomFactor = ThumbnailConfiguration.ApplyRestrictions(this.ThumbnailZoomFactor, 2, 10);
this.ActiveClientHighlightThickness =
ThumbnailConfiguration.ApplyRestrictions(this.ActiveClientHighlightThickness, 1, 6);
}
private static int ApplyRestrictions(int value, int minimum, int maximum) {
if (value <= minimum) {
return minimum;
}
if (value >= maximum) {
return maximum;
}
return value;
}
}
}