Skip to content

Commit

Permalink
Fix conflicts between window resizing and image zooming
Browse files Browse the repository at this point in the history
- Prevent resizing zoomed image on window resizing / locked ratio
- Add new helper class to clone ToolStripMenuItem
  • Loading branch information
Dương Diệu Pháp committed Aug 15, 2015
1 parent 9df1187 commit f57c77c
Show file tree
Hide file tree
Showing 23 changed files with 156 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Menu.cs" />
<Compile Include="Comparer\DictionaryEntryComparer.cs" />
<Compile Include="Comparer\FileLogicalComparer.cs" />
<Compile Include="Comparer\NumericComparer.cs" />
Expand Down
2 changes: 1 addition & 1 deletion Source/Components/ImageGlass.Library/Language/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void InitDefaultLanguageDictionary()
this.Items.Add("frmMain.mnuExitSlideshow", "Exit slideshow");
this.Items.Add("frmMain.mnuShowToolBar._Hide", "Hide toolbar");
this.Items.Add("frmMain.mnuShowToolBar._Show", "Show toolbar");
this.Items.Add("frmMain.mnuEditWithPaint", "Edit with Paint"); //remove 2.1
//this.Items.Add("frmMain.mnuEditWithPaint", "Edit with Paint"); //remove 2.1
this.Items.Add("frmMain.mnuEditImage", "Edit image"); //v2.1
this.Items.Add("frmMain.mnuExtractFrames", "Extract image frames ({0})");
this.Items.Add("frmMain.mnuStartStopAnimating", "Start / Stop animating image"); //v2.1
Expand Down
73 changes: 73 additions & 0 deletions Source/Components/ImageGlass.Library/Menu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;

namespace ImageGlass.Library
{
public static class Menu
{
/// <summary>
/// Clone ToolStripMenu item
/// </summary>
/// <param name="mnu">ToolStripMenuItem</param>
/// <returns></returns>
public static ToolStripMenuItem Clone(ToolStripMenuItem mnu)
{
ToolStripMenuItem m = new ToolStripMenuItem();

//clone all events
var eventsField = typeof(Component).GetField("events", BindingFlags.NonPublic | BindingFlags.Instance);
var eventHandlerList = eventsField.GetValue(mnu);
eventsField.SetValue(m, eventHandlerList);

//clone all properties
m.AccessibleName = mnu.AccessibleName;
m.AccessibleRole = mnu.AccessibleRole;
m.Alignment = mnu.Alignment;
m.AllowDrop = mnu.AllowDrop;
m.Anchor = mnu.Anchor;
m.AutoSize = mnu.AutoSize;
m.AutoToolTip = mnu.AutoToolTip;
m.BackColor = mnu.BackColor;
m.BackgroundImage = mnu.BackgroundImage;
m.BackgroundImageLayout = mnu.BackgroundImageLayout;
m.Checked = mnu.Checked;
m.CheckOnClick = mnu.CheckOnClick;
m.CheckState = mnu.CheckState;
m.DisplayStyle = mnu.DisplayStyle;
m.Dock = mnu.Dock;
m.DoubleClickEnabled = mnu.DoubleClickEnabled;
m.Enabled = mnu.Enabled;
m.Font = mnu.Font;
m.ForeColor = mnu.ForeColor;
m.Image = mnu.Image;
m.ImageAlign = mnu.ImageAlign;
m.ImageScaling = mnu.ImageScaling;
m.ImageTransparentColor = mnu.ImageTransparentColor;
m.Margin = mnu.Margin;
m.MergeAction = mnu.MergeAction;
m.MergeIndex = mnu.MergeIndex;
m.Name = mnu.Name;
m.Overflow = mnu.Overflow;
m.Padding = mnu.Padding;
m.RightToLeft = mnu.RightToLeft;

m.ShortcutKeys = mnu.ShortcutKeys;
m.ShowShortcutKeys = mnu.ShowShortcutKeys;
m.Tag = mnu.Tag;
m.Text = mnu.Text;
m.TextAlign = mnu.TextAlign;
m.TextDirection = mnu.TextDirection;
m.TextImageRelation = mnu.TextImageRelation;
m.ToolTipText = mnu.ToolTipText;

m.Available = mnu.Available;

if (!mnu.AutoSize)
{
m.Size = mnu.Size;
}
return m;
}
}
}
Binary file modified Source/ImageGlass/bin/Debug/ImageGlass.Library.dll
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/ImageGlass.Library.pdb
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/ImageGlass.Services.dll
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/ImageGlass.Services.pdb
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/ImageGlass.Theme.dll
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/ImageGlass.Theme.pdb
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/ImageGlass.exe
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/ImageGlass.pdb
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/igcmd.exe
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/igcmd.pdb
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/igtasks.exe
Binary file not shown.
Binary file modified Source/ImageGlass/bin/Debug/igtasks.pdb
Binary file not shown.
17 changes: 15 additions & 2 deletions Source/ImageGlass/frmMain.Designer.cs

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

82 changes: 55 additions & 27 deletions Source/ImageGlass/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public frmMain()


#region Local variables
private string imageInfo = "";
private string _imageInfo = "";

// window size value before resizing
private Size _windowSize = new Size();

// determine if the image is zoomed
private bool _isZoomed = false;
#endregion


Expand Down Expand Up @@ -381,7 +387,7 @@ private void UpdateStatusBar(bool @zoomOnly = false)
fileinfo = ImageInfo.GetFileSize(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)) + "\t | ";
fileinfo += Path.GetExtension(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)).Replace(".", "").ToUpper() + " | ";
fileinfo += File.GetCreationTime(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)).ToString("yyyy/M/d HH:m:s");
this.imageInfo = fileinfo;
this._imageInfo = fileinfo;
}
catch { fileinfo = ""; }
}
Expand All @@ -391,15 +397,15 @@ private void UpdateStatusBar(bool @zoomOnly = false)

if (zoomOnly)
{
fileinfo = picMain.Zoom.ToString() + "% | " + imageInfo;
fileinfo = picMain.Zoom.ToString() + "% | " + _imageInfo;
}
else
{
fileinfo += ImageInfo.GetFileSize(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)) + "\t | ";
//fileinfo += Path.GetExtension(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)).Replace(".", "").ToUpper() + " | ";
fileinfo += File.GetCreationTime(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)).ToString("yyyy/M/d HH:m:s");

this.imageInfo = fileinfo;
this._imageInfo = fileinfo;

fileinfo = picMain.Zoom.ToString() + "% | " + fileinfo;
}
Expand Down Expand Up @@ -1257,11 +1263,20 @@ private void frmMain_Activated(object sender, EventArgs e)
GlobalSetting.IsForcedActive = false;
}

private void frmMain_ResizeBegin(object sender, EventArgs e)
{
this._windowSize = this.Size;
}

private void frmMain_ResizeEnd(object sender, EventArgs e)
{
mnuMainRefresh_Click(null, null);
if (this.Size != this._windowSize && !this._isZoomed)
{
mnuMainRefresh_Click(null, null);

SaveConfig();
SaveConfig();
}

}

private void thumbnailBar_ItemClick(object sender, ImageListView.ItemClickEventArgs e)
Expand Down Expand Up @@ -1343,6 +1358,7 @@ private void sysWatch_Changed(object sender, FileSystemEventArgs e)

private void picMain_Zoomed(object sender, ImageBoxZoomEventArgs e)
{
this._isZoomed = true;
this.UpdateStatusBar(true);
}

Expand Down Expand Up @@ -1503,6 +1519,13 @@ private void btnReport_Click(object sender, EventArgs e)
#region Popup Menu
private void mnuPopup_Opening(object sender, CancelEventArgs e)
{
//clear current items
mnuPopup.Items.Clear();

mnuPopup.Items.Add(Library.Menu.Clone(mnuMainReportIssue));



try
{
if (!File.Exists(GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex)) ||
Expand Down Expand Up @@ -1558,26 +1581,7 @@ private void mnuShowToolBar_Click(object sender, EventArgs e)

private void mnuEditImage_Click(object sender, EventArgs e)
{
if (GlobalSetting.IsImageError)
{
return;
}

string filename = GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex);

Process p = new Process();
p.StartInfo.FileName = filename;
p.StartInfo.Verb = "edit";

//show error dialog
p.StartInfo.ErrorDialog = true;

try
{
p.Start();
}
catch (Exception)
{ }
mnuMainEditImage_Click(null, null);
}

private void mnuProperties_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -1781,15 +1785,36 @@ private void mnuMainRefresh_Click(object sender, EventArgs e)
{
//Reset zoom
picMain.ZoomToFit();

this._isZoomed = false;
}

//Get image file information
this.UpdateStatusBar();
}

private void mnuMainOpenWith_Click(object sender, EventArgs e)
private void mnuMainEditImage_Click(object sender, EventArgs e)
{
if (GlobalSetting.IsImageError)
{
return;
}

string filename = GlobalSetting.ImageList.GetFileName(GlobalSetting.CurrentIndex);

Process p = new Process();
p.StartInfo.FileName = filename;
p.StartInfo.Verb = "edit";

//show error dialog
p.StartInfo.ErrorDialog = true;

try
{
p.Start();
}
catch (Exception)
{ }
}

private void mnuMainViewNext_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -2449,7 +2474,10 @@ private void mnuMain_Opening(object sender, CancelEventArgs e)




#endregion



}
}
11 changes: 11 additions & 0 deletions Source/ImageGlass/frmMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@
<metadata name="mnuMain.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>475, 4</value>
</metadata>
<data name="mnuMainEditImage.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAD
UgAAA1IBEAAkSgAAARJJREFUOE+10s9KAlEYhvEh+4fRVqhtW70GwQvoAlq2aN3GqEAXQbg0FCMqojYt
c6fgqlVBdVE9j2fOMErGBPnCjzlzzpnjN9+YLCPrqIXh39NBDycYYB+Fc4gj7OEZZ7hGoVTwEIbJJm7w
gmNUEdNA/j6LJe+G4TQesoUyrKYFq7HCU9zBtSz99FpKr/mspPJx33kYhniAk++YOLEgfqFbeOBMf+y8
B7xi6MSCPOIDHnDlRIwd34aHxJLny3Z9De6xR/Yiyw787sbX+cLl9C7Ehn0ivp57fWYmdvgAbh7DX/PT
jmA1T9iA8+79MRdoI5b/BqtZhXOuuefX1HEPX6UJH+rCrrtWOJbqP0/zDf2vJMk3JuombYnZDgYAAAAA
SUVORK5CYII=
</value>
</data>
<data name="btnMenu.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified Source/ImageGlass/obj/Debug/ImageGlass.exe
Binary file not shown.
Binary file modified Source/ImageGlass/obj/Debug/ImageGlass.frmMain.resources
Binary file not shown.
Binary file modified Source/ImageGlass/obj/Debug/ImageGlass.pdb
Binary file not shown.

0 comments on commit f57c77c

Please sign in to comment.