Skip to content

Commit

Permalink
Issue #71 Zoom enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
d2phap committed May 2, 2016
1 parent 723221f commit 665c6f1
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 26 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -156,3 +156,5 @@ $RECYCLE.BIN/
.DS_Store
*.cache
*.cache
*.cache
Source/ImageGlass/obj/Debug/DesignTimeResolveAssemblyReferences.cache
8 changes: 4 additions & 4 deletions Source/Components/ImageGlass.Library/Language/Language.cs
Expand Up @@ -402,11 +402,11 @@ private void InitDefaultLanguageDictionary()
this.Items.Add("frmSetting.chkLoopSlideshow", "Loop back slideshow to the first image when reaching the end of the list"); //v2.0 final
this.Items.Add("frmSetting.chkImageBoosterBack", "Turn on Image Booster when navigate back (need more ~20% RAM)"); //v2.0 final
this.Items.Add("frmSetting.chkESCToQuit", "Allow to press ESC to quit application"); //v2.0 final
//this.Items.Add("frmSetting.lblGeneral_ZoomOptimization", "Zoom optimization:"); //removed 3.0
this.Items.Add("frmSetting.lblGeneral_ZoomOptimization", "Zoom optimization:"); //-3.0, +3.3
this.Items.Add("frmSetting.chkAllowMultiInstances", "Allow multiple instances of the program"); //v3.0
//this.Items.Add("frmSetting.cmbZoomOptimization._Auto", "Auto"); //removed 3.2
//this.Items.Add("frmSetting.cmbZoomOptimization._SmoothPixels", "Smooth pixels"); //removed 3.2
//this.Items.Add("frmSetting.cmbZoomOptimization._ClearPixels", "Clear pixels"); //removed 3.2
this.Items.Add("frmSetting.cmbZoomOptimization._Auto", "Auto"); //-3.2, +3.3
this.Items.Add("frmSetting.cmbZoomOptimization._SmoothPixels", "Smooth pixels"); //-3.2, +3.3
this.Items.Add("frmSetting.cmbZoomOptimization._ClearPixels", "Clear pixels"); //-3.2, +3.3
this.Items.Add("frmSetting.lblSlideshowInterval", "Slide show interval: {0} seconds");
this.Items.Add("frmSetting.lblGeneral_MaxFileSize", "Maximum thumbnail file size (MB):");
this.Items.Add("frmSetting.lblGeneral_ThumbnailSize", "Thumbnail dimension (pixel):"); // v3.0
Expand Down
Expand Up @@ -327,15 +327,15 @@ public static ZoomOptimizationValue ZoomOptimizationMethod

if (value == ZoomOptimizationValue.SmoothPixels)
{
GlobalSetting.SetConfig("ZoomOptimize", "1");
GlobalSetting.SetConfig("ZoomOptimization", "1");
}
else if (value == ZoomOptimizationValue.ClearPixels)
{
GlobalSetting.SetConfig("ZoomOptimize", "2");
GlobalSetting.SetConfig("ZoomOptimization", "2");
}
else
{
GlobalSetting.SetConfig("ZoomOptimize", "0");
GlobalSetting.SetConfig("ZoomOptimization", "0");
}
}
}
Expand Down
51 changes: 48 additions & 3 deletions Source/ImageGlass/frmMain.cs
Expand Up @@ -624,7 +624,33 @@ private void frmMain_KeyDown(object sender, KeyEventArgs e)


#region Private functions


/// <summary>
/// Start Zoom optimization
/// </summary>
private void ZoomOptimization()
{
if (GlobalSetting.ZoomOptimizationMethod == ZoomOptimizationValue.Auto)
{
if (picMain.Zoom > 100)
{
picMain.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
}
else if (picMain.Zoom < 100)
{
picMain.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
}
}
else if (GlobalSetting.ZoomOptimizationMethod == ZoomOptimizationValue.ClearPixels)
{
picMain.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
}
else if (GlobalSetting.ZoomOptimizationMethod == ZoomOptimizationValue.SmoothPixels)
{
picMain.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
}
}

/// <summary>
/// Rename image
/// </summary>
Expand Down Expand Up @@ -1119,6 +1145,21 @@ private void LoadConfig()
GlobalSetting.IsZoomToFit = bool.Parse(GlobalSetting.GetConfig("IsZoomToFit", "False"));
mnuMainZoomToFit.Checked = GlobalSetting.IsZoomToFit;

//Zoom optimization method-------------------------------------------------------
string z = GlobalSetting.GetConfig("ZoomOptimization", "0");
if (z == "1")
{
GlobalSetting.ZoomOptimizationMethod = ZoomOptimizationValue.SmoothPixels;
}
else if (z == "2")
{
GlobalSetting.ZoomOptimizationMethod = ZoomOptimizationValue.ClearPixels;
}
else //auto
{
GlobalSetting.ZoomOptimizationMethod = ZoomOptimizationValue.Auto;
}

//Load theme--------------------------------------------------------------------
thumbnailBar.SetRenderer(new ImageListView.ImageListViewRenderers.ThemeRenderer()); //ThumbnailBar Renderer must be done BEFORE loading theme
LoadTheme();
Expand Down Expand Up @@ -1157,7 +1198,7 @@ private void LoadConfig()
mnuMainThumbnailBar_Click(null, EventArgs.Empty);

//Load background---------------------------------------------------------------
string z = GlobalSetting.GetConfig("BackgroundColor", "-1");
z = GlobalSetting.GetConfig("BackgroundColor", "-1");
GlobalSetting.BackgroundColor = Color.FromArgb(int.Parse(z));
picMain.BackColor = GlobalSetting.BackgroundColor;

Expand Down Expand Up @@ -1191,7 +1232,7 @@ private void SaveConfig()

//Window always on top
GlobalSetting.SetConfig("IsWindowAlwaysOnTop", GlobalSetting.IsWindowAlwaysOnTop.ToString());

//Zoom to fit
GlobalSetting.SetConfig("IsZoomToFit", GlobalSetting.IsZoomToFit.ToString());

Expand Down Expand Up @@ -1509,6 +1550,10 @@ private void sysWatch_Changed(object sender, FileSystemEventArgs e)
private void picMain_Zoomed(object sender, ImageBoxZoomEventArgs e)
{
this._isZoomed = true;

//Zoom optimization
ZoomOptimization();

this.UpdateStatusBar(true);
}

Expand Down
54 changes: 41 additions & 13 deletions Source/ImageGlass/frmSetting.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 38 additions & 3 deletions Source/ImageGlass/frmSetting.cs
Expand Up @@ -330,8 +330,28 @@ private void LoadTabGeneralConfig()
//Get value of IsPressESCToQuit
chkAllowMultiInstances.Checked = bool.Parse(GlobalSetting.GetConfig("IsAllowMultiInstances", "true"));

//Load items of cmbZoomOptimization
cmbZoomOptimization.Items.Clear();
cmbZoomOptimization.Items.Add(GlobalSetting.LangPack.Items["frmSetting.cmbZoomOptimization._Auto"]);
cmbZoomOptimization.Items.Add(GlobalSetting.LangPack.Items["frmSetting.cmbZoomOptimization._SmoothPixels"]);
cmbZoomOptimization.Items.Add(GlobalSetting.LangPack.Items["frmSetting.cmbZoomOptimization._ClearPixels"]);

//Get value of cmbZoomOptimization
s = GlobalSetting.GetConfig("ZoomOptimization", "0");
int i = 0;
if (int.TryParse(s, out i))
{
if (-1 < i && i < cmbZoomOptimization.Items.Count)
{ }
else
{
i = 0;
}
}
cmbZoomOptimization.SelectedIndex = i;

//Get value of barInterval
int i = int.Parse(GlobalSetting.GetConfig("Interval", "5"));
i = int.Parse(GlobalSetting.GetConfig("Interval", "5"));
if (0 < i && i < 61)
{
barInterval.Value = i;
Expand All @@ -341,8 +361,7 @@ private void LoadTabGeneralConfig()
barInterval.Value = 5;
}

lblSlideshowInterval.Text = string.Format(GlobalSetting.LangPack.Items["frmSetting.lblSlideshowInterval"],
barInterval.Value);
lblSlideshowInterval.Text = string.Format(GlobalSetting.LangPack.Items["frmSetting.lblSlideshowInterval"], barInterval.Value);

//load thumbnail dimension
i = int.Parse(GlobalSetting.GetConfig("ThumbnailDimension", "48"));
Expand Down Expand Up @@ -438,6 +457,22 @@ private void barInterval_Scroll(object sender, EventArgs e)
barInterval.Value);
}

private void cmbZoomOptimization_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbZoomOptimization.SelectedIndex == 1)
{
GlobalSetting.ZoomOptimizationMethod = ZoomOptimizationValue.SmoothPixels;
}
else if (cmbZoomOptimization.SelectedIndex == 2)
{
GlobalSetting.ZoomOptimizationMethod = ZoomOptimizationValue.ClearPixels;
}
else
{
GlobalSetting.ZoomOptimizationMethod = ZoomOptimizationValue.Auto;
}
}

private void numMaxThumbSize_ValueChanged(object sender, EventArgs e)
{
GlobalSetting.SetConfig("MaxThumbnailFileSize", numMaxThumbSize.Value.ToString());
Expand Down
Binary file not shown.

0 comments on commit 665c6f1

Please sign in to comment.