diff options
author | Michael Vrhel <michael.vrhel@artifex.com> | 2013-03-13 21:07:00 -0700 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-05-16 19:25:33 +0100 |
commit | 23575e94b917921484b824d4cbd920d386a8d971 (patch) | |
tree | 681307d72f89adff89fbf0663e652ae3ca7c2bf5 | |
parent | 6c91b8f63e12591596e24ac503f8915705f749b2 (diff) | |
download | mupdf-23575e94b917921484b824d4cbd920d386a8d971.tar.xz |
Fix issues with slow zoom as well as orientation changes while in zoom mode
-rw-r--r-- | winRT/winapp/MainPage.xaml | 4 | ||||
-rw-r--r-- | winRT/winapp/MainPage.xaml.cpp | 96 | ||||
-rw-r--r-- | winRT/winapp/MainPage.xaml.h | 5 |
3 files changed, 83 insertions, 22 deletions
diff --git a/winRT/winapp/MainPage.xaml b/winRT/winapp/MainPage.xaml index e8fac631..a25a4fe1 100644 --- a/winRT/winapp/MainPage.xaml +++ b/winRT/winapp/MainPage.xaml @@ -58,9 +58,9 @@ <ProgressBar x:Name="xaml_Progress" IsIndeterminate="False" Maximum="100" Value="0" Height="10" Width="400" IsEnabled="False" Opacity="0"/> <Grid x:Name="xaml_MainGrid" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SizeChanged="GridSizeChanged"> - <Canvas x:Name="xaml_zoomCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" DoubleTapped="Canvas_Double" + <Canvas x:Name="xaml_zoomCanvas" HorizontalAlignment="Center" VerticalAlignment="Center" DoubleTapped="Canvas_Double" ManipulationDelta="Canvas_ManipulationDelta" ManipulationStarted="Canvas_ManipulationStarted" - ManipulationStarting="Canvas_ManipulationStarting" ManipulationMode="All"> + ManipulationStarting="Canvas_ManipulationStarting" ManipulationCompleted="Canvas_ManipulationCompleted" ManipulationMode="All"> <FlipView x:Name="xaml_horiz_flipView" SelectionChanged="FlipView_SelectionChanged" DoubleTapped="FlipView_Double" VerticalAlignment="Center" HorizontalAlignment="Center"> <FlipView.ItemsPanel> diff --git a/winRT/winapp/MainPage.xaml.cpp b/winRT/winapp/MainPage.xaml.cpp index 054a3733..c9cbdbc5 100644 --- a/winRT/winapp/MainPage.xaml.cpp +++ b/winRT/winapp/MainPage.xaml.cpp @@ -315,6 +315,24 @@ void winapp::MainPage::PixToMemStream(fz_pixmap *pix, DataWriter ^dw, Platform:: } } +void winapp::MainPage::PageSize(fz_document *doc, fz_page *page, int *width, int *height, double scale_factor) +{ + RectSize pageSize; + RectSize scale; + RectSize screenSize; + + screenSize.height = this->ActualHeight; + screenSize.width = this->ActualWidth; + + screenSize.width *= screenScale; + screenSize.height *= screenScale; + + pageSize = measurePage(doc, page); + scale = fitPageToScreen(pageSize, screenSize); + *width = pageSize.width * scale.width * scale_factor; + *height = pageSize.height * scale.height * scale_factor; +} + void winapp::MainPage::RenderPage(fz_document *doc, fz_page *page, int *width, int *height, double scale_factor) { fz_matrix ctm, *pctm = &ctm; @@ -404,6 +422,7 @@ void winapp::MainPage::CleanUp() if (this->m_doc != NULL) fz_close_document(m_doc); + this->m_curr_flipView = nullptr; m_currpage = 0; m_file_open = false; m_doc = NULL; @@ -412,7 +431,7 @@ void winapp::MainPage::CleanUp() m_init_done = false; m_memory_use = 0; m_zoom_mode = false; - m_zoom_handled = false; + m_from_doubleflip = false; m_first_time = false; m_insearch = false; m_sliderchange = false; @@ -639,6 +658,23 @@ void winapp::MainPage::Canvas_ManipulationStarted(Object^ sender, ManipulationSt this->m_touchpoint = e->Position; } +void winapp::MainPage::Canvas_ManipulationCompleted(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationCompletedRoutedEventArgs^ e) +{ + if (m_scaling_occured) + { + int width, height; + int pos = this->m_curr_flipView->SelectedIndex; + fz_page *page = fz_load_page(m_doc, pos); + + RenderPage(m_doc, page, &width, &height, m_curr_zoom); + this->xaml_zoomCanvas->Background = this->m_renderedImage; + m_renderedImage->Stretch = Windows::UI::Xaml::Media::Stretch::None; + + this->xaml_zoomCanvas->Width = width; + this->xaml_zoomCanvas->Height = height; + } +} + void winapp::MainPage::Canvas_ManipulationDelta(Object^ sender, ManipulationDeltaRoutedEventArgs^ e) { int width, height; @@ -652,13 +688,23 @@ void winapp::MainPage::Canvas_ManipulationDelta(Object^ sender, ManipulationDelt m_curr_zoom = m_curr_zoom * e->Delta.Scale; if (m_curr_zoom < MIN_SCALE) m_curr_zoom = MIN_SCALE; if (m_curr_zoom > MAX_SCALE) m_curr_zoom = MAX_SCALE; - this->RenderPage(m_doc, page, &width, &height, m_curr_zoom); - this->xaml_zoomCanvas->Background = this->m_renderedImage; + if (m_first_time) + { + RenderPage(m_doc, page, &width, &height, m_curr_zoom); + this->xaml_zoomCanvas->Background = this->m_renderedImage; + m_renderedImage->Stretch = Windows::UI::Xaml::Media::Stretch::None; + } + else + { + PageSize(m_doc, page, &width, &height, m_curr_zoom); + m_renderedImage->Stretch = Windows::UI::Xaml::Media::Stretch::Fill; + } this->xaml_zoomCanvas->Width = width; this->xaml_zoomCanvas->Height = height; m_zoom_size.X = width; m_zoom_size.Y = height; m_first_time = false; + m_scaling_occured = true; } TranslateTransform ^trans_transform = ref new TranslateTransform(); @@ -690,18 +736,26 @@ void winapp::MainPage::Canvas_ManipulationDelta(Object^ sender, ManipulationDelt void winapp::MainPage::FlipView_Double(Object^ sender, DoubleTappedRoutedEventArgs^ e) { - if (!m_zoom_mode) + if (!m_zoom_mode && this->m_num_pages != -1) { m_zoom_mode = true; int pos = this->m_curr_flipView->SelectedIndex; - FlipViewItem ^flipview_temp = (FlipViewItem^) m_curr_flipView->Items->GetAt(pos); - Canvas^ Curr_Canvas = (Canvas^) (flipview_temp->Content); + int width, height; + fz_page *page = fz_load_page(m_doc, pos); + + RenderPage(m_doc, page, &width, &height, 1); + this->xaml_zoomCanvas->Background = this->m_renderedImage; + m_renderedImage->Stretch = Windows::UI::Xaml::Media::Stretch::None; + + this->xaml_zoomCanvas->Width = width; + this->xaml_zoomCanvas->Height = height; + m_curr_flipView->IsEnabled = false; - this->xaml_zoomCanvas->Background = Curr_Canvas->Background; this->xaml_zoomCanvas->Background->Opacity = 1; this->m_curr_flipView->Opacity = 0.0; - m_zoom_handled = true; m_first_time = true; + m_from_doubleflip = true; + m_curr_zoom = 1.0; } } @@ -709,7 +763,7 @@ void winapp::MainPage::Canvas_Double(Object^ sender, DoubleTappedRoutedEventArgs { TranslateTransform ^trans_transform = ref new TranslateTransform(); - if (m_zoom_mode && !m_zoom_handled) + if (m_zoom_mode && !m_from_doubleflip) { m_zoom_mode = false; int pos = this->m_curr_flipView->SelectedIndex; @@ -723,17 +777,15 @@ void winapp::MainPage::Canvas_Double(Object^ sender, DoubleTappedRoutedEventArgs this->xaml_zoomCanvas->Background = nullptr; this->m_curr_flipView->Opacity = 1; m_curr_flipView->IsEnabled = true; - m_first_time = true; + this->xaml_zoomCanvas->Height = this->ActualHeight; + this->xaml_zoomCanvas->Width = this->ActualWidth; + trans_transform->X = 0; + trans_transform->Y = 0; + m_canvas_translate.X = 0; + m_canvas_translate.Y = 0; + this->xaml_zoomCanvas->RenderTransform = trans_transform; } - m_zoom_handled = false; - m_curr_zoom = 1.0; - this->xaml_zoomCanvas->Height = this->ActualHeight; - this->xaml_zoomCanvas->Width = this->ActualWidth; - trans_transform->X = 0; - trans_transform->Y = 0; - m_canvas_translate.X = 0; - m_canvas_translate.Y = 0; - this->xaml_zoomCanvas->RenderTransform = trans_transform; + m_from_doubleflip = false; } /* Search Related Code */ @@ -987,6 +1039,10 @@ void winapp::MainPage::GridSizeChanged() int width = this->ActualWidth; FlipView^ old_flip = m_curr_flipView; + if (m_zoom_mode) + { + Canvas_Double(nullptr, nullptr); + } if (height > width) { m_curr_flipView = this->xaml_vert_flipView; @@ -1040,3 +1096,5 @@ void winapp::MainPage::UpDatePageSizes() this->RenderRange(this->m_currpage, &height, &width); } }; + + diff --git a/winRT/winapp/MainPage.xaml.h b/winRT/winapp/MainPage.xaml.h index 78d400aa..fb7d4a5c 100644 --- a/winRT/winapp/MainPage.xaml.h +++ b/winRT/winapp/MainPage.xaml.h @@ -78,7 +78,8 @@ namespace winapp SolidColorBrush^ m_color_brush; FlipView^ m_curr_flipView; bool m_zoom_mode; - bool m_zoom_handled; + bool m_from_doubleflip; + bool m_scaling_occured; bool m_insearch; bool m_sliderchange; bool m_update_flip; @@ -116,5 +117,7 @@ namespace winapp void GridSizeChanged(); void UpDatePageSizes(); void ShowThumbnail(); + void PageSize(fz_document *doc, fz_page *page, int *width, int *height, double scale_factor); + void Canvas_ManipulationCompleted(Platform::Object^ sender, Windows::UI::Xaml::Input::ManipulationCompletedRoutedEventArgs^ e); }; } |