Skip to content

Commit 4a02984

Browse files
committed
changing aspect ratio cutoff (+updating) works! done!
1 parent e5f96d0 commit 4a02984

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

MangaPrinter.Core/FileImporter.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public MangaPage getMangaPageFromPath(FileInfo fiImage, float cutoff)
3636
jpeg.PhysicalDimension.Height > 0 ?
3737
jpeg.PhysicalDimension.Width / jpeg.PhysicalDimension.Height :
3838
0;
39-
if (page.AspectRatio > cutoff)
40-
page.IsDouble = true;
39+
page.IsDouble = page.AspectRatio >= cutoff;
4140
}
4241
}
4342
catch (OutOfMemoryException ex) {

MangaPrinter.WpfGUI/Dialogs/dlgChooseCutoffRatio.xaml

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<Grid.RowDefinitions>
1313
<RowDefinition/>
1414
<RowDefinition Height="auto"></RowDefinition>
15+
<RowDefinition Height="auto"></RowDefinition>
1516
</Grid.RowDefinitions>
1617
<d3:Chart BottomTitle="Ratio (Page Width/Height)" LeftTitle="Count" Grid.Row="0" Margin="5,5">
1718
<Grid>
@@ -25,5 +26,11 @@
2526
<Slider Name="sldCutoff" Minimum="0" Maximum="99" SmallChange="1" LargeChange="1"
2627
Value="{Binding BucketIndex}" ValueChanged="Slider_ValueChanged"/>
2728
</StackPanel>
29+
<DockPanel Grid.Row="2" LastChildFill="False">
30+
<Button DockPanel.Dock="Right" Margin="5" Padding="5"
31+
Name="btnAccept" Click="BtnAccept_Click">Accept</Button>
32+
<Button DockPanel.Dock="Right" Margin="5" Padding="5" Background="LightPink"
33+
Name="btnCancel" Click="BtnCancel_Click">Cancel</Button>
34+
</DockPanel>
2835
</Grid>
2936
</Window>

MangaPrinter.WpfGUI/Dialogs/dlgChooseCutoffRatio.xaml.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,18 @@ private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<d
5858

5959
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
6060
{
61+
if (!(DialogResult ?? false)) // Make sure not left null
62+
DialogResult = false;
63+
}
6164

65+
private void BtnAccept_Click(object sender, RoutedEventArgs e)
66+
{
67+
DialogResult = true;
6268
}
6369

64-
70+
private void BtnCancel_Click(object sender, RoutedEventArgs e)
71+
{
72+
DialogResult = false;
73+
}
6574
}
6675
}

MangaPrinter.WpfGUI/MainWindow.xaml.cs

+24
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,30 @@ private void BtnNewCutoffRatio_Click(object sender, RoutedEventArgs e)
279279
},
280280
isProgressKnwon: false);
281281
dlg.ShowDialog();
282+
if ((dlg.DialogResult ?? false) && (dlg.InputBuckets != null) && (dlg.InputBuckets.Count > 0))
283+
{
284+
double newAspectCutoff = Math.Round(dlg.InputBuckets[dlg.BucketIndex].value, 2);
285+
txtPageMaxWidth.Text = newAspectCutoff.ToString();
286+
// Update all pages:
287+
winWorking.waitForTask((updateFunc) =>
288+
{
289+
if (mangaChapters.Count < 1)
290+
return 0;
291+
292+
List<MangaPage> allPages = mangaChapters.SelectMany((ch) => ch.Pages).ToList();
293+
if (allPages.Count < 1)
294+
return 0;
295+
296+
int counter = 0;
297+
foreach (MangaPage page in allPages)
298+
{
299+
updateFunc(page.Name, (int)(counter * 100.0f / allPages.Count));
300+
page.IsDouble = page.AspectRatio >= newAspectCutoff;
301+
}
302+
return 1;
303+
},
304+
isProgressKnwon: false);
305+
}
282306
}
283307

284308
#endregion

MangaPrinter.WpfGUI/winWorking.xaml.cs

+7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ private void MyWorker_DoWork(object sender, DoWorkEventArgs e)
7676
});
7777
}
7878

79+
/// <summary>
80+
/// Async computation with dialog showing moving progress
81+
/// </summary>
82+
/// <typeparam name="T">Type of returned result, when used correctly should't be important</typeparam>
83+
/// <param name="Task">The task to do, return result and get void update(description,percent)</param>
84+
/// <param name="isProgressKnwon">are you going to update the progress? or should we show general cycling progress bar</param>
85+
/// <returns>The result of the task</returns>
7986
public static T waitForTask<T>(Func<Action<string, int>, T> Task, bool isProgressKnwon) {
8087
winWorking taskWindow = new winWorking((update)=> { return Task(update); }, isProgressKnwon);
8188
taskWindow.ShowDialog();

0 commit comments

Comments
 (0)