Skip to content
This repository has been archived by the owner on May 19, 2022. It is now read-only.

Independently sized thumbnails #77

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bin/
obj/
*.suo
*.user
packages
11 changes: 9 additions & 2 deletions Eve-O-Preview/Configuration/IThumbnailConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IThumbnailConfig
bool HideThumbnailsOnLostFocus { get; set; }
bool EnablePerClientThumbnailLayouts { get; set; }

Size ThumbnailSize { get; set; }
Size ThumbnailDefaultSize { get; set; }
Size ThumbnailMinimumSize { get; set; }
Size ThumbnailMaximumSize { get; set; }

Expand All @@ -34,10 +34,17 @@ public interface IThumbnailConfig
Color ActiveClientHighlightColor { get; set; }
int ActiveClientHighlightThickness { get; set; }

bool SyncThumbnailSizes { get; set; }

bool LockThumbnails { get; set; }

Point GetThumbnailLocation(string currentClient, string activeClient, Point defaultLocation);
void SetThumbnailLocation(string currentClient, string activeClient, Point location);

ClientLayout GetClientLayout(string currentClient);
Size GetThumbnailSize(string currentClient, string activeClient, Size defaultSize);
void SetThumbnailSize(string currentClient, string activeClient, Size size);

ClientLayout GetClientLayout(string currentClient);
void SetClientLayout(string currentClient, ClientLayout layout);

Keys GetClientHotkey(string currentClient);
Expand Down
77 changes: 72 additions & 5 deletions Eve-O-Preview/Configuration/ThumbnailConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ThumbnailConfig()
this.HideThumbnailsOnLostFocus = false;
this.EnablePerClientThumbnailLayouts = false;

this.ThumbnailSize = new Size(250, 150);
this.ThumbnailDefaultSize = new Size(250, 150);
this.ThumbnailMinimumSize = new Size(100, 80);
this.ThumbnailMaximumSize = new Size(640, 400);

Expand All @@ -35,6 +35,13 @@ public ThumbnailConfig()
this.ActiveClientHighlightColor = Color.GreenYellow;
this.ActiveClientHighlightThickness = 3;

this.SyncThumbnailSizes = false;

this.LockThumbnails = false;

this.PerClientSizes = new Dictionary<string, Dictionary<string, Size>>();
this.FlatSizes = new Dictionary<string, Size>();

this.PerClientLayout = new Dictionary<string, Dictionary<string, Point>>();
this.FlatLayout = new Dictionary<string, Point>();
this.ClientLayout = new Dictionary<string, ClientLayout>();
Expand All @@ -53,7 +60,8 @@ public ThumbnailConfig()
public bool HideThumbnailsOnLostFocus { get; set; }
public bool EnablePerClientThumbnailLayouts { get; set; }

public Size ThumbnailSize { get; set; }
[JsonProperty("ThumbnailSize")]
public Size ThumbnailDefaultSize { get; set; }
public Size ThumbnailMaximumSize { get; set; }
public Size ThumbnailMinimumSize { get; set; }

Expand All @@ -71,7 +79,17 @@ public ThumbnailConfig()

public int ActiveClientHighlightThickness { get; set; }

[JsonProperty("SyncSizesToDefault")]
public bool SyncThumbnailSizes { get; set; }

public bool LockThumbnails { get; set; }

[JsonProperty]
private Dictionary<string, Dictionary<string, Size>> PerClientSizes { get; set; }
[JsonProperty]
private Dictionary<string, Size> FlatSizes { get; set; }

[JsonProperty]
private Dictionary<string, Dictionary<string, Point>> PerClientLayout { get; set; }
[JsonProperty]
private Dictionary<string, Point> FlatLayout { get; set; }
Expand Down Expand Up @@ -129,7 +147,56 @@ public void SetThumbnailLocation(string currentClient, string activeClient, Poin
layoutSource[currentClient] = location;
}

public ClientLayout GetClientLayout(string currentClient)
public Size GetThumbnailSize(string currentClient, string activeClient, Size defaultSize)
{
Size size;

// 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, Size> layoutSource;
if (this.PerClientSizes.TryGetValue(activeClient, out layoutSource) && layoutSource.TryGetValue(currentClient, out size))
{
return size;
}
}

return this.FlatSizes.TryGetValue(currentClient, out size) ? size : defaultSize;
}

public void SetThumbnailSize(string currentClient, string activeClient, Size size)
{
Dictionary<string, Size> layoutSource;

if (this.EnablePerClientThumbnailLayouts)
{
if (string.IsNullOrEmpty(activeClient))
{
return;
}

if (!this.PerClientSizes.TryGetValue(activeClient, out layoutSource))
{
layoutSource = new Dictionary<string, Size>();
this.PerClientSizes[activeClient] = layoutSource;
}
}
else
{
layoutSource = this.FlatSizes;
}

layoutSource[currentClient] = size;
}

public ClientLayout GetClientLayout(string currentClient)
{
ClientLayout layout;
this.ClientLayout.TryGetValue(currentClient, out layout);
Expand Down Expand Up @@ -166,8 +233,8 @@ public void SetClientHotkey(string currentClient, Keys hotkey)
public void ApplyRestrictions()
{
this.ThumbnailRefreshPeriod = ThumbnailConfig.ApplyRestrictions(this.ThumbnailRefreshPeriod, 300, 1000);
this.ThumbnailSize = new Size(ThumbnailConfig.ApplyRestrictions(this.ThumbnailSize.Width, this.ThumbnailMinimumSize.Width, this.ThumbnailMaximumSize.Width),
ThumbnailConfig.ApplyRestrictions(this.ThumbnailSize.Height, this.ThumbnailMinimumSize.Height, this.ThumbnailMaximumSize.Height));
this.ThumbnailDefaultSize = new Size(ThumbnailConfig.ApplyRestrictions(this.ThumbnailDefaultSize.Width, this.ThumbnailMinimumSize.Width, this.ThumbnailMaximumSize.Width),
ThumbnailConfig.ApplyRestrictions(this.ThumbnailDefaultSize.Height, this.ThumbnailMinimumSize.Height, this.ThumbnailMaximumSize.Height));
this.ThumbnailOpacity = ThumbnailConfig.ApplyRestrictions((int)(this.ThumbnailOpacity * 100.00), 20, 100) / 100.00;
this.ThumbnailZoomFactor = ThumbnailConfig.ApplyRestrictions(this.ThumbnailZoomFactor, 2, 10);
this.ActiveClientHighlightThickness = ThumbnailConfig.ApplyRestrictions(this.ActiveClientHighlightThickness, 1, 6);
Expand Down
5 changes: 4 additions & 1 deletion Eve-O-Preview/Presentation/IThumbnailManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ public interface IThumbnailManager
void Deactivate();

void SetThumbnailState(IntPtr thumbnailId, bool hideAlways);
void SetThumbnailsSize(Size size);
void SetThumbnailsSize(IntPtr id, Size size);
void SetupThumbnailFrames();

void SetThumbnailResizeLock(bool locked);
void SetThumbnailPositionLock(bool locked);

Action<IList<IThumbnailView>> ThumbnailsAdded { get; set; }
Action<IList<IThumbnailView>> ThumbnailsUpdated { get; set; }
Action<IList<IThumbnailView>> ThumbnailsRemoved { get; set; }
Expand Down
41 changes: 37 additions & 4 deletions Eve-O-Preview/Presentation/MainPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public MainPresenter(IApplicationController controller, IMainView view, IThumbna
this.View.ThumbnailStateChanged = this.UpdateThumbnailState;
this.View.ForumUrlLinkActivated = this.OpenForumUrlLink;
this.View.ApplicationExitRequested = this.ExitApplication;
this.View.SyncChanged = this.SyncChanged;
this.View.LockChanged = this.LockChanged;

this._thumbnailManager.ThumbnailsAdded = this.ThumbnailsAdded;
this._thumbnailManager.ThumbnailsUpdated = this.ThumbnailsUpdated;
Expand All @@ -54,12 +56,16 @@ private void Activate()
{
this.LoadApplicationSettings();
this.View.SetForumUrl(MainPresenter.ForumUrl);

if (this._configuration.MinimizeToTray)
{
this.View.Minimize();
}

this._thumbnailManager.Activate();

this.SyncChanged();
this.LockChanged();
}

private void Minimize()
Expand Down Expand Up @@ -88,8 +94,25 @@ private void Close(ViewCloseRequest request)

private void UpdateThumbnailsSize()
{
this._thumbnailManager.SetThumbnailsSize(this.View.ThumbnailSize);

this.SaveApplicationSettings();

if (this.View.SyncThumbnailSizes)
{
this._thumbnailManager.Activate();
}
}

private void SyncChanged()
{
this._thumbnailManager.SetThumbnailResizeLock(this.View.SyncThumbnailSizes || this.View.LockThumbnails); //if either is true, lock resize
this._thumbnailManager.Activate();
}

private void LockChanged()
{
this._thumbnailManager.SetThumbnailPositionLock(this.View.LockThumbnails);
this._thumbnailManager.SetThumbnailResizeLock(this.View.SyncThumbnailSizes || this.View.LockThumbnails);
}

private void LoadApplicationSettings()
Expand All @@ -107,7 +130,7 @@ private void LoadApplicationSettings()
this.View.EnablePerClientThumbnailLayouts = this._configuration.EnablePerClientThumbnailLayouts;

this.View.SetThumbnailSizeLimitations(this._configuration.ThumbnailMinimumSize, this._configuration.ThumbnailMaximumSize);
this.View.ThumbnailSize = this._configuration.ThumbnailSize;
this.View.ThumbnailSize = this._configuration.ThumbnailDefaultSize;

this.View.EnableThumbnailZoom = this._configuration.ThumbnailZoomEnabled;
this.View.ThumbnailZoomFactor = this._configuration.ThumbnailZoomFactor;
Expand All @@ -117,6 +140,10 @@ private void LoadApplicationSettings()
this.View.ShowThumbnailFrames = this._configuration.ShowThumbnailFrames;
this.View.EnableActiveClientHighlight = this._configuration.EnableActiveClientHighlight;
this.View.ActiveClientHighlightColor = this._configuration.ActiveClientHighlightColor;

this.View.SyncThumbnailSizes = this._configuration.SyncThumbnailSizes;

this.View.LockThumbnails = this._configuration.LockThumbnails;
}

private void SaveApplicationSettings()
Expand All @@ -131,7 +158,7 @@ private void SaveApplicationSettings()
this._configuration.HideThumbnailsOnLostFocus = this.View.HideThumbnailsOnLostFocus;
this._configuration.EnablePerClientThumbnailLayouts = this.View.EnablePerClientThumbnailLayouts;

this._configuration.ThumbnailSize = this.View.ThumbnailSize;
this._configuration.ThumbnailDefaultSize = this.View.ThumbnailSize;

this._configuration.ThumbnailZoomEnabled = this.View.EnableThumbnailZoom;
this._configuration.ThumbnailZoomFactor = this.View.ThumbnailZoomFactor;
Expand All @@ -142,6 +169,10 @@ private void SaveApplicationSettings()
this._configuration.EnableActiveClientHighlight = this.View.EnableActiveClientHighlight;
this._configuration.ActiveClientHighlightColor = this.View.ActiveClientHighlightColor;

this._configuration.SyncThumbnailSizes = this.View.SyncThumbnailSizes;

this._configuration.LockThumbnails = this.View.LockThumbnails;

this._configurationStorage.Save();

this.View.RefreshZoomSettings();
Expand All @@ -152,6 +183,8 @@ private void SaveApplicationSettings()
private void ThumbnailsAdded(IList<IThumbnailView> thumbnails)
{
this.View.AddThumbnails(this.GetThumbnailViews(thumbnails, false));
this.LockChanged();
this.SyncChanged();
}

private void ThumbnailsUpdated(IList<IThumbnailView> thumbnails)
Expand Down Expand Up @@ -208,7 +241,7 @@ private IList<IThumbnailDescriptionView> GetThumbnailViews(IList<IThumbnailView>

private void ThumbnailSizeChanged(Size size)
{
this.View.ThumbnailSize = size;
//don't need to change anything here
}

private void UpdateThumbnailState(IntPtr thumbnailId)
Expand Down
44 changes: 35 additions & 9 deletions Eve-O-Preview/Presentation/ThumbnailManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,39 @@ public void SetThumbnailState(IntPtr thumbnailId, bool hideAlways)
thumbnail.IsEnabled = !hideAlways;
}

public void SetThumbnailsSize(Size size)
public void SetThumbnailsSize(IntPtr id, Size size)
{
this.DisableViewEvents();

foreach (KeyValuePair<IntPtr, IThumbnailView> entry in this._thumbnailViews)
{
entry.Value.ThumbnailSize = size;
entry.Value.Refresh(false);
}
IThumbnailView view;

if(this._thumbnailViews.TryGetValue(id, out view))
{
view.ThumbnailSize = size;
view.Refresh(false);
}

this.ThumbnailSizeChanged?.Invoke(size);

this.EnableViewEvents();
}

public void SetThumbnailResizeLock(bool locked)
{
foreach(IThumbnailView view in this._thumbnailViews.Values)
{
view.SetResizeLocked(locked);
}
}

public void SetThumbnailPositionLock(bool locked)
{
foreach (IThumbnailView view in this._thumbnailViews.Values)
{
view.SetPositionLocked(locked);
}
}

private void RefreshThumbnails()
{
IntPtr foregroundWindowHandle = WindowManagerNativeMethods.GetForegroundWindow();
Expand Down Expand Up @@ -129,6 +147,7 @@ private void RefreshThumbnails()
if (view.Title != ThumbnailManager.DefaultClientTitle)
{
view.ThumbnailLocation = this._configuration.GetThumbnailLocation(view.Title, this._activeClientTitle, view.ThumbnailLocation);
view.ThumbnailSize = this._configuration.SyncThumbnailSizes ? this._configuration.ThumbnailDefaultSize : this._configuration.GetThumbnailSize(view.Title, this._activeClientTitle, view.ThumbnailSize);
}

view.SetOpacity(this._configuration.ThumbnailOpacity);
Expand Down Expand Up @@ -208,15 +227,17 @@ private void UpdateThumbnailsList()

if ((view == null) && (processTitle != ""))
{
view = this._thumbnailViewFactory.Create(processHandle, processTitle, this._configuration.ThumbnailSize);
view = this._thumbnailViewFactory.Create(processHandle, processTitle, this._configuration.ThumbnailDefaultSize);
view.IsEnabled = true;
view.IsOverlayEnabled = this._configuration.ShowThumbnailOverlays;
view.SetFrames(this._configuration.ShowThumbnailFrames);
// Max/Min size limitations should be set AFTER the frames are disabled
// Otherwise thumbnail window will be unnecessary resized
view.SetSizeLimitations(this._configuration.ThumbnailMinimumSize, this._configuration.ThumbnailMaximumSize);
view.SetTopMost(this._configuration.ShowThumbnailsAlwaysOnTop);
view.ThumbnailLocation = this._configuration.GetThumbnailLocation(processTitle, this._activeClientTitle, view.ThumbnailLocation);

view.ThumbnailLocation = this._configuration.GetThumbnailLocation(processTitle, this._activeClientTitle, view.ThumbnailLocation);
view.ThumbnailSize = this._configuration.SyncThumbnailSizes ? this._configuration.ThumbnailDefaultSize : this._configuration.GetThumbnailSize(processTitle, this._activeClientTitle, view.ThumbnailSize);

this._thumbnailViews.Add(processHandle, view);

Expand Down Expand Up @@ -360,7 +381,12 @@ private void ThumbnailViewResized(IntPtr id)

IThumbnailView view = this._thumbnailViews[id];

this.SetThumbnailsSize(view.ThumbnailSize);
this.SetThumbnailsSize(id, view.ThumbnailSize);

if (!this._configuration.SyncThumbnailSizes)
{
this._configuration.SetThumbnailSize(view.Title, this._activeClientTitle, view.ThumbnailSize);
}

view.Refresh(false);
}
Expand Down
Loading