Skip to content

Commit 0dc02fd

Browse files
author
Carl Chang
committed
replace thumbs panel to support virtualization;
add option to disable most effects that affect performance; fix decode pixel not being set correctly; remember last view window position; add opton for thumb change delay mutiplier; other minor tweaks;
1 parent d287fc1 commit 0dc02fd

18 files changed

+559
-284
lines changed

App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ResourceDictionary.MergedDictionaries>
1010
<ResourceDictionary Source="UserControls/AppleStyleScrollBar.xaml"/>
1111
<ResourceDictionary Source="UserControls/StylesAndAnimations.xaml"/>
12+
<ResourceDictionary Source="UserControls/BorderlessWindow.xaml"/>
1213
<ResourceDictionary Source="UserControls/Generic.xaml"/>
1314
<!--<ResourceDictionary>
1415
--><!--<FontFamily x:Key="FontAwesomeRegular">/ZipImageViewer;component/Resources/FontAwesome5FreeRegular400.otf#Font Awesome 5 Free Regular</FontFamily>

Helpers/Helpers.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,19 @@ public static BitmapSource GetImageSource(Stream stream, SizeInt decodeSize) {
219219
var bi = new BitmapImage();
220220
bi.BeginInit();
221221
bi.CacheOption = BitmapCacheOption.OnLoad;
222-
if (frameSize.Width > frameSize.Height)
223-
bi.DecodePixelHeight = decodeSize.Height;
224-
else
225-
bi.DecodePixelWidth = decodeSize.Width;
222+
if (frameSize.Width > 0 && frameSize.Height > 0) {
223+
var frameRatio = frameSize.Width / frameSize.Height;
224+
if (decodeSize.Width > 0 && decodeSize.Height > 0) {
225+
if (frameRatio > (double)decodeSize.Width / decodeSize.Height)
226+
bi.DecodePixelHeight = decodeSize.Height;
227+
else
228+
bi.DecodePixelWidth = decodeSize.Width;
229+
}
230+
else if (decodeSize.Width == 0 && decodeSize.Height > 0)
231+
bi.DecodePixelHeight = decodeSize.Height;
232+
else if (decodeSize.Height == 0 && decodeSize.Width > 0)
233+
bi.DecodePixelWidth = decodeSize.Width;
234+
}
226235
bi.StreamSource = stream;
227236
bi.EndInit();
228237
bi.Freeze();
@@ -427,5 +436,30 @@ public static string CustomCmdArgsReplace(string input, ObjectInfo objInfo) {
427436
return input.Replace(@"%FileSystemPath%", objInfo.FileSystemPath);
428437
}
429438

439+
440+
public static T GetVisualChild<T>(DependencyObject parent) where T : Visual {
441+
T child = default;
442+
443+
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
444+
for (int i = 0; i < numVisuals; i++) {
445+
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
446+
child = v as T;
447+
if (child == null) {
448+
child = GetVisualChild<T>(v);
449+
}
450+
if (child != null) {
451+
break;
452+
}
453+
}
454+
return child;
455+
}
456+
}
457+
458+
459+
public class VirtualizingWrapPanel : WpfToolkit.Controls.VirtualizingWrapPanel
460+
{
461+
public int TotalRowCount => rowCount;
462+
public int RowItemCount => itemsPerRowCount;
463+
public new int VisualChildrenCount => base.VisualChildrenCount;
430464
}
431465
}

Helpers/ObjectInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,6 @@ public ObjectInfo(string fsPath, FileFlags flag = FileFlags.Unknown, ImageSource
136136
imageSources = sources;
137137
}
138138
}
139+
140+
139141
}

Helpers/Setting.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ public static TransitionSpeed ViewerTransitionSpeed {
7474
}
7575
}
7676

77+
private static double thumbSwapDelayMultiplier = 1d;
78+
public static double ThumbSwapDelayMultiplier {
79+
get => thumbSwapDelayMultiplier;
80+
set {
81+
if (thumbSwapDelayMultiplier == value) return;
82+
thumbSwapDelayMultiplier = value;
83+
OnStaticPropertyChanged(nameof(ThumbSwapDelayMultiplier));
84+
}
85+
}
86+
7787
private static double thumbDbSize = 2d;
7888
public static double ThumbDbSize {
7989
get => thumbDbSize;
@@ -104,6 +114,17 @@ public static string LastPath {
104114
}
105115
}
106116

117+
private static bool liteMode = false;
118+
public static bool LiteMode {
119+
get => liteMode;
120+
set {
121+
if (liteMode == value) return;
122+
liteMode = value;
123+
OnStaticPropertyChanged(nameof(LiteMode));
124+
}
125+
}
126+
127+
107128
private static ObservableCollection<ObservableObj> customCommands;
108129
public static ObservableCollection<ObservableObj> CustomCommands {
109130
get => customCommands;
@@ -147,14 +168,16 @@ public static void LoadConfigFromFile(string path = "config.ini") {
147168
//parse config file
148169
var iniData = new FileIniDataParser().ReadFile(path, System.Text.Encoding.UTF8);
149170

150-
SevenZipDllPath = ParseConfig(iniData, nameof(SevenZipDllPath), SevenZipDllPath);
151-
ThumbDbDir = ParseConfig(iniData, nameof(ThumbDbDir), ThumbDbDir);
152-
ThumbnailSize = ParseConfig(iniData, nameof(ThumbnailSize), ThumbnailSize);
153-
ThumbDbSize = ParseConfig(iniData, nameof(ThumbDbSize), ThumbDbSize);
154-
ViewerTransition = ParseConfig(iniData, nameof(ViewerTransition), ViewerTransition);
155-
ViewerTransitionSpeed = ParseConfig(iniData, nameof(ViewerTransitionSpeed), ViewerTransitionSpeed);
156-
LastWindowSize = ParseConfig(iniData, nameof(LastWindowSize), LastWindowSize);
157-
LastPath = ParseConfig(iniData, nameof(LastPath), LastPath);
171+
SevenZipDllPath = ParseConfig(iniData, nameof(SevenZipDllPath), SevenZipDllPath);
172+
ThumbDbDir = ParseConfig(iniData, nameof(ThumbDbDir), ThumbDbDir);
173+
ThumbnailSize = ParseConfig(iniData, nameof(ThumbnailSize), ThumbnailSize);
174+
ThumbSwapDelayMultiplier = ParseConfig(iniData, nameof(ThumbSwapDelayMultiplier), ThumbSwapDelayMultiplier);
175+
ThumbDbSize = ParseConfig(iniData, nameof(ThumbDbSize), ThumbDbSize);
176+
ViewerTransition = ParseConfig(iniData, nameof(ViewerTransition), ViewerTransition);
177+
ViewerTransitionSpeed = ParseConfig(iniData, nameof(ViewerTransitionSpeed), ViewerTransitionSpeed);
178+
LastWindowSize = ParseConfig(iniData, nameof(LastWindowSize), LastWindowSize);
179+
LastPath = ParseConfig(iniData, nameof(LastPath), LastPath);
180+
LiteMode = ParseConfig(iniData, nameof(LiteMode), LiteMode);
158181

159182
//parse custom commands
160183
CustomCommands = new ObservableCollection<ObservableObj>();
@@ -189,6 +212,9 @@ private static T ParseConfig<T>(IniData iniData, string key, T defaultVal) {
189212
case string _:
190213
result = value;
191214
break;
215+
case bool _:
216+
result = bool.Parse(value);
217+
break;
192218
case SizeInt _:
193219
case ObservablePair<int, int> _:
194220
int iW, iH;
@@ -250,11 +276,13 @@ [App Config]
250276
{nameof(SevenZipDllPath)}={SevenZipDllPath}
251277
{nameof(ThumbDbDir)}={ThumbDbDir}
252278
{nameof(ThumbnailSize)}={ThumbnailSize.Item1}x{ThumbnailSize.Item2}
279+
{nameof(ThumbSwapDelayMultiplier)}={ThumbSwapDelayMultiplier}
253280
{nameof(ThumbDbSize)}={ThumbDbSize}
254281
{nameof(ViewerTransition)}={ViewerTransition}
255282
{nameof(ViewerTransitionSpeed)}={ViewerTransitionSpeed}
256283
{nameof(LastWindowSize)}={LastWindowSize.Width}x{LastWindowSize.Height}
257284
{nameof(LastPath)}={LastPath}
285+
{nameof(LiteMode)}={LiteMode}
258286
259287
[Custom Commands]
260288
{(CustomCommands?.Count > 0 ?

0 commit comments

Comments
 (0)