From 78117eaed1ea691148e27c08eceeb37aaa01b03c Mon Sep 17 00:00:00 2001 From: Jarvis Niu Date: Thu, 3 Mar 2016 19:13:24 +0800 Subject: [PATCH] fullwindow -> fitWindow --- src/Controller.cs | 2 +- src/ImageInfo.cs | 4 ++-- src/Transformer.cs | 23 ++++++++------------ xaml/NivWindow.xaml.cs | 48 +++++++++++++++++------------------------- 4 files changed, 31 insertions(+), 46 deletions(-) diff --git a/src/Controller.cs b/src/Controller.cs index 60e78b5..80df8c9 100644 --- a/src/Controller.cs +++ b/src/Controller.cs @@ -81,7 +81,7 @@ public void onMouseLeftUp(int timestamp) public void onMouseDoubleClick() { - if (transformer.isFullwindow) + if (transformer.isFitWindow) transformer.zoomTo(1, mousePos).animate(); else transformer.fitWindow().animate(); diff --git a/src/ImageInfo.cs b/src/ImageInfo.cs index d739857..fd8b3a3 100644 --- a/src/ImageInfo.cs +++ b/src/ImageInfo.cs @@ -11,8 +11,8 @@ class ImageInfo // The filename of this image public string filename; - // If this image is in fullwindow mode, say, fixed to the window size. - public bool isFullwindow = true; + // If this image is in Fit-Window mode, say, its size following the window size. + public bool fitWindow = true; // If this image is smooth on rendering (anti-alias) public bool smooth = true; diff --git a/src/Transformer.cs b/src/Transformer.cs index 264d04d..cbaebad 100644 --- a/src/Transformer.cs +++ b/src/Transformer.cs @@ -15,11 +15,6 @@ namespace Niv { class Transformer { - // TODO remove this - // In this fullwindow mode: - // 1. Image size will follow the window size changing. - // 2. When the image is scaling, the scaling state will not saved to folder walker. - // 3. This mode will be breaking after the user zoom or pan the image proactively. /// Constants ---------------------------------------------------------- @@ -93,12 +88,12 @@ public double scale } } - public bool isFullwindow + public bool isFitWindow { get { if (walker.currentImageInfo != null) - return walker.currentImageInfo.isFullwindow; + return walker.currentImageInfo.fitWindow; else return true; } @@ -174,7 +169,7 @@ private Thickness getEasedMargin() // Set to initial state used when the image appears the first time public Transformer initOne() { - exitFullwindowMode(); + exitFitWindowMode(); screenCenter(); scale = 1; @@ -192,7 +187,7 @@ public Transformer fitWindow() fullsize(); screenCenter(); - walker.currentImageInfo.isFullwindow = true; + walker.currentImageInfo.fitWindow = true; calcMarginDesByKeys(); @@ -230,7 +225,7 @@ public Transformer zoomAtStand(double deltaScale) // Zoom-by the image at pivot which is the normalized position in the image. public Transformer zoomBy(double dS, Point pivot) { - exitFullwindowMode(); + exitFitWindowMode(); Size gridSize = container.RenderSize; @@ -293,7 +288,7 @@ public Transformer calcMarginDesByKeys() // Pan the `margin-destination` by a distance, in unit "px" public Transformer pan(double dX, double dY) { - exitFullwindowMode(); + exitFitWindowMode(); Thickness m = marginDestination; marginDestination = new Thickness(m.Left + dX, m.Top + dY, m.Right - dX, m.Bottom - dY); @@ -359,11 +354,11 @@ public Transformer setScaleCenterWithImage() return this; } - // Exit `fullwindow` mode - public Transformer exitFullwindowMode() + // Exit `fit-window` mode + public Transformer exitFitWindowMode() { if (walker.currentImageInfo != null) - walker.currentImageInfo.isFullwindow = false; + walker.currentImageInfo.fitWindow = false; return this; } diff --git a/xaml/NivWindow.xaml.cs b/xaml/NivWindow.xaml.cs index 187891f..6388e28 100644 --- a/xaml/NivWindow.xaml.cs +++ b/xaml/NivWindow.xaml.cs @@ -218,12 +218,8 @@ private void setTheme(string theme) imageDelete.Source = loadThemeBitmap("icon-delete.png", theme); imagePrev.Source = loadThemeBitmap("icon-prev.png", theme); imageNext.Source = loadThemeBitmap("icon-next.png", theme); - imageSmooth.Source = loadThemeBitmap( - walker.currentImageInfo != null && walker.currentImageInfo.smooth - ? "icon-smooth-off.png" : "icon-smooth-on.png", theme); - imageZoom.Source = loadThemeBitmap( - walker.currentImageInfo != null && walker.currentImageInfo.isFullwindow - ? "icon-one-to-one.png" : "icon-fit-window.png", theme); + refreshSmoothButton(); + refreshZoomButton(); imageMenu.Source = loadThemeBitmap("icon-menu.png", theme); imageCloseInfo.Source = imageExit.Source = loadThemeBitmap("icon-close.png", theme); // menu images @@ -277,6 +273,7 @@ private void bindToolbarButtonsEvents() btnSmooth.MouseUp += (object sender, MouseButtonEventArgs e) => { if (isSmoothButtonVisible) setSmoothTo(!walker.currentImageInfo.smooth); + refreshSmoothButton(); }; // Zoom button click @@ -341,7 +338,7 @@ private void bindContainerEvents() // Size-changed envent container.SizeChanged += (object sender, SizeChangedEventArgs e) => { - if (walker.count > 0 && walker.currentImageInfo.isFullwindow) + if (walker.count > 0 && walker.currentImageInfo.fitWindow) transformer.fitWindow().calcMarginDesByKeys().apply(); else transformer.calcMarginDesByKeys().apply(); @@ -515,19 +512,20 @@ private void loadFromWalker() } else { - if (info.isFullwindow) + if (info.fitWindow) { transformer.fullsize().calcMarginDesByKeys().apply(); transformer.screenCenter().calcMarginDesByKeys().animate(); } else { - transformer.exitFullwindowMode().setScale(info.scale).calcMarginDesByKeys().apply(); + transformer.exitFitWindowMode().setScale(info.scale).calcMarginDesByKeys().apply(); transformer.setCenter(info.center).calcMarginDesByKeys().animate(); } animatorJar.rotateToI(image, info.rotationAngle); } + refreshSmoothButton(); refreshZoomButton(); } @@ -781,7 +779,7 @@ private double getProgressLeft() private void toggleZoomIn121AndFit() { - if (transformer.isFullwindow) + if (transformer.isFitWindow) transformer.initOne().animate(); else transformer.fitWindow().animate(); @@ -810,27 +808,18 @@ private void setSmoothByImageResolution() setSmoothTo(!isImageSmall); } + private void refreshSmoothButton() + { + imageSmooth.Source = loadThemeBitmap( + walker.currentImageInfo != null && walker.currentImageInfo.smooth + ? "icon-smooth-off.png" : "icon-smooth-on.png", theme); + } private void refreshZoomButton() { - if (walker.count == 0) return; - - if (transformer.isFullwindow) - { - if (isZoomButtonInFitMode) - { - imageZoom.Source = loadThemeBitmap("icon-one-to-one.png", theme); - isZoomButtonInFitMode = false; - } - } - else - { - if (!isZoomButtonInFitMode) - { - imageZoom.Source = loadThemeBitmap("icon-fit-window.png", theme); - isZoomButtonInFitMode = true; - } - } + imageZoom.Source = loadThemeBitmap( + walker.currentImageInfo != null && walker.currentImageInfo.fitWindow + ? "icon-one-to-one.png" : "icon-fit-window.png", theme); } private bool isRotated() @@ -1135,11 +1124,12 @@ private void delete() // Press key "D" to show something for debugging. private void debug() { + MessageBox.Show(toolbar.Margin.Right.ToString()); } private void exit() { - //restoreRotation(); + setImageRotationBackToZero(); //recycleBin.clean(); aboutWindow.exit(); Application.Current.Shutdown();