diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2014-02-13 15:14:02 -0800 |
---|---|---|
committer | Michael Vrhel <michael.vrhel@artifex.com> | 2014-09-09 16:39:30 -0700 |
commit | a095083fc76bc78cfb1f6d8af495461278d66a27 (patch) | |
tree | cd62aec0e40e48a837e86217fd3ac0ff73ac7b53 | |
parent | 97fd142df917465017815f5bc40ef7c055d08bf3 (diff) | |
download | mupdf-a095083fc76bc78cfb1f6d8af495461278d66a27.tar.xz |
Fix zooming issues
The window resize was causing issues as this was triggering a scroll change and the
size we were rendering was tied to the window size.
-rw-r--r-- | platform/winrt/gsview/MainWindow.xaml | 13 | ||||
-rw-r--r-- | platform/winrt/gsview/MainWindow.xaml.cs | 74 |
2 files changed, 26 insertions, 61 deletions
diff --git a/platform/winrt/gsview/MainWindow.xaml b/platform/winrt/gsview/MainWindow.xaml index fba0c0ce..a7f0cce1 100644 --- a/platform/winrt/gsview/MainWindow.xaml +++ b/platform/winrt/gsview/MainWindow.xaml @@ -5,7 +5,7 @@ <Window.Resources> <DataTemplate x:Key="PageTemplate"> - <Image Width="{Binding Width}" Height="{Binding Height}" Stretch="Fill" HorizontalAlignment="Center" Source="{Binding BitMap}" Margin="24,24,0,0"> + <Image Width="{Binding Width}" Height="{Binding Height}" Stretch="Fill" HorizontalAlignment="Center" Source="{Binding BitMap}" Margin="24,24,0,0"> <Image.BitmapEffect> <DropShadowBitmapEffect Color="Black" Direction="-50" ShadowDepth="40" Softness=".7" /> @@ -398,7 +398,7 @@ Width="150" Orientation="Horizontal" HorizontalAlignment="Center" Value="100" Minimum="25" Maximum="400" SmallChange="1" LargeChange="1" - TickPlacement="None" TickFrequency="1" IsSnapToTickEnabled="True" MouseLeftButtonUp="ZoomReleased" PreviewMouseUp="Testing"/> + TickPlacement="None" TickFrequency="1" IsSnapToTickEnabled="True" MouseLeftButtonUp="ZoomReleased"/> <TextBox Grid.Row="0" Grid.Column="2" Width="30" Height="20" VerticalScrollBarVisibility="Hidden" IsReadOnly="True" HorizontalScrollBarVisibility="Hidden" TextAlignment="Center" Text="{Binding Mode=TwoWay, ElementName=xaml_ZoomSlider,Path=Value, UpdateSourceTrigger=PropertyChanged}" /> @@ -414,7 +414,7 @@ </ListView> </Grid> - <!-- Contents viewer/selector --> + <!-- Contents viewer/selector. --> <Grid x:Name="xaml_ContentGrid" Width="250" Background="DarkGray" DockPanel.Dock="Left" Visibility="Collapsed"> <ListView x:Name="xaml_ContentList" HorizontalAlignment="Stretch" ScrollViewer.CanContentScroll="False" PreviewMouseLeftButtonUp="ContentSelected" @@ -429,14 +429,15 @@ </ListView> </Grid> - <!-- Pages are last child fill. This goes in the center of our dock panel --> - <Grid x:Name="xaml_PageGrid" HorizontalAlignment="Stretch" Background="DarkGray" > - <ListView x:Name="xaml_PageList" HorizontalAlignment="Stretch" + <!-- Pages are last child fill. This goes in the center of our dock panel ScrollViewer.CanContentScroll False allows continuous scrolling--> + <Grid x:Name="xaml_PageGrid" HorizontalAlignment="Stretch" Background="DarkGray" DockPanel.Dock="Left"> + <ListView x:Name="xaml_PageList" HorizontalAlignment="Stretch" ItemTemplate="{StaticResource PageTemplate}" ScrollViewer.CanContentScroll="False" Background="DarkGray" ScrollViewer.PanningMode="Both" ScrollViewer.ScrollChanged="ListViewScrollChanged" PreviewMouseLeftButtonUp="PageSelected"> + <!-- This keeps the pages in the center of the panel --> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> diff --git a/platform/winrt/gsview/MainWindow.xaml.cs b/platform/winrt/gsview/MainWindow.xaml.cs index f1698f6b..ad408f30 100644 --- a/platform/winrt/gsview/MainWindow.xaml.cs +++ b/platform/winrt/gsview/MainWindow.xaml.cs @@ -306,22 +306,20 @@ namespace gsview { Point ras_size; status_t code; - double scale_factor; - spatial_info_t spatial_info = InitSpatial(1); + double scale_factor = Constants.SCALE_THUMB; BackgroundWorker worker = sender as BackgroundWorker; - spatial_info.scale_factor = Constants.SCALE_THUMB; Byte[] bitmap; for (int k = 0; k < m_num_pages; k++) { - if (ComputePageSize(spatial_info, k, out ras_size, out scale_factor) == status_t.S_ISOK) + if (ComputePageSize(k, scale_factor, out ras_size) == status_t.S_ISOK) { try { bitmap = new byte[(int)ras_size.X * (int)ras_size.Y * 4]; /* Synchronous call on our background thread */ - code = (status_t) mu_doc.RenderPage(k, bitmap, (int)ras_size.X, (int)ras_size.Y, scale_factor, false, false); + code = (status_t)mu_doc.RenderPage(k, bitmap, (int)ras_size.X, (int)ras_size.Y, scale_factor, false, false); } catch (OutOfMemoryException em) { @@ -366,7 +364,7 @@ namespace gsview this to be cancelled if we open a new doc while we are in loop rendering. Put the UI updates in the progress changed which will run on the main thread */ - try + try { BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; @@ -384,16 +382,6 @@ namespace gsview } } - private spatial_info_t InitSpatial(double scale) - { - spatial_info_t value = new spatial_info_t(); - - value.size.Y = this.ActualHeight; - value.size.X = this.ActualWidth; - value.scale_factor = scale; - return value; - } - private void OpenFile(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); @@ -445,30 +433,18 @@ namespace gsview } } - private status_t ComputePageSize(spatial_info_t spatial_info, int page_num, - out Point render_size, out double scale_factor) + private status_t ComputePageSize(int page_num, double scale_factor, + out Point render_size) { - Point screenSize = new Point(); Point renpageSize = new Point(); status_t code = (status_t)mu_doc.GetPageSize(page_num, out render_size); if (code != status_t.S_ISOK) - { - scale_factor = 1.0; return code; - } - - screenSize = spatial_info.size; - screenSize.Y *= Constants.SCREEN_SCALE; - screenSize.X *= Constants.SCREEN_SCALE; - double hscale = screenSize.X / render_size.X; - double vscale = screenSize.Y / render_size.Y; - double scale = Math.Min(hscale, vscale); - renpageSize.X = (render_size.X * scale * spatial_info.scale_factor); - renpageSize.Y = (render_size.Y * scale * spatial_info.scale_factor); + renpageSize.X = (render_size.X * scale_factor); + renpageSize.Y = (render_size.Y * scale_factor); - scale_factor = (scale * spatial_info.scale_factor); render_size = renpageSize; return status_t.S_ISOK; @@ -506,15 +482,14 @@ namespace gsview } /* Do the first few full res pages */ - spatial_info_t spatial_info = InitSpatial(1); for (int k = 0; k < Constants.LOOK_AHEAD + 2; k++) { if (m_num_pages > k) { Point ras_size; - double scale_factor; + double scale_factor = 1.0; - if (ComputePageSize(spatial_info, k, out ras_size, out scale_factor) == status_t.S_ISOK) + if (ComputePageSize(k, scale_factor, out ras_size) == status_t.S_ISOK) { try { @@ -590,7 +565,7 @@ namespace gsview if (m_num_pages < 0) return; - if (xaml_ContentList.Items.IsEmpty) + if (xaml_ContentList.Items.IsEmpty) { int size_content = mu_doc.ComputeContents(); if (size_content == 0) @@ -620,9 +595,10 @@ namespace gsview } } + /* We need to avoid rendering due to size changes */ private void ListViewScrollChanged(object sender, ScrollChangedEventArgs e) { - var lv = (System.Windows.Controls.ListView) sender; + var lv = (System.Windows.Controls.ListView)sender; foreach (var lvi in lv.Items) { var container = lv.ItemContainerGenerator.ContainerFromItem(lvi) as ListBoxItem; @@ -643,7 +619,6 @@ namespace gsview /* Render +/- the look ahead from where we are if blank page is present */ async private void RenderRange(int curr_page) { - spatial_info_t spatial_info = InitSpatial(m_doczoom); int range = Constants.LOOK_AHEAD; for (int k = curr_page - range; k <= curr_page + range; k++) @@ -656,9 +631,9 @@ namespace gsview doc.Zoom != m_doczoom) { Point ras_size; - double scale_factor; + double scale_factor = m_doczoom; - if (ComputePageSize(spatial_info, k, out ras_size, out scale_factor) == status_t.S_ISOK) + if (ComputePageSize(k, scale_factor, out ras_size) == status_t.S_ISOK) { try { @@ -696,7 +671,7 @@ namespace gsview Rect bounds = elem.TransformToAncestor(cont).TransformBounds(new Rect(0.0, 0.0, elem.ActualWidth, elem.ActualHeight)); Rect bounds2 = new Rect(new Point(bounds.TopLeft.X, bounds.TopLeft.Y), new Point(bounds.BottomRight.X, bounds.BottomRight.Y - 5)); return rect.Contains(bounds2.TopLeft) || rect.Contains(bounds2.BottomRight); - } + } private void ReleasePages(int old_page, int new_page) { @@ -843,7 +818,7 @@ namespace gsview { xaml_DistillGrid.Visibility = System.Windows.Visibility.Visible; } - + } PrintXPS(m_currfile); } @@ -879,7 +854,7 @@ namespace gsview } else { - xaml_PrintProgress.Value = 100 * (double) asyncInformation.Page / (double) m_num_pages; + xaml_PrintProgress.Value = 100 * (double)asyncInformation.Page / (double)m_num_pages; } } @@ -936,16 +911,5 @@ namespace gsview RenderRange(m_currpage); } } - - private void Testing(object sender, MouseButtonEventArgs e) - { - if (m_init_done) - { - m_doczoom = xaml_ZoomSlider.Value / 100.0; - RenderRange(m_currpage); - } - } - } -} - +}
\ No newline at end of file |