diff --git a/Niv.csproj b/Niv.csproj index a449736..a947af5 100644 --- a/Niv.csproj +++ b/Niv.csproj @@ -130,6 +130,7 @@ Settings.settings True + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/exe/Niv.exe b/exe/Niv.exe index 807fea9..e217ee2 100644 Binary files a/exe/Niv.exe and b/exe/Niv.exe differ diff --git a/prop/AssemblyInfo.cs b/prop/AssemblyInfo.cs index af4be59..e9267bc 100644 --- a/prop/AssemblyInfo.cs +++ b/prop/AssemblyInfo.cs @@ -20,5 +20,5 @@ ResourceDictionaryLocation.SourceAssembly )] -[assembly: AssemblyVersion("0.3.1.0")] -[assembly: AssemblyFileVersion("0.3.1.0")] +[assembly: AssemblyVersion("0.3.2.0")] +[assembly: AssemblyFileVersion("0.3.2.0")] diff --git a/prop/Settings.Designer.cs b/prop/Settings.Designer.cs index 5e4df67..f9f1ff7 100644 --- a/prop/Settings.Designer.cs +++ b/prop/Settings.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Niv.prop { +namespace Niv { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] @@ -22,5 +22,29 @@ public static Settings Default { return defaultInstance; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("light")] + public string theme { + get { + return ((string)(this["theme"])); + } + set { + this["theme"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool fullscreen { + get { + return ((bool)(this["fullscreen"])); + } + set { + this["fullscreen"] = value; + } + } } } diff --git a/prop/Settings.settings b/prop/Settings.settings index 033d7a5..4e2283b 100644 --- a/prop/Settings.settings +++ b/prop/Settings.settings @@ -1,7 +1,12 @@  - - - - - + + + + + light + + + False + + \ No newline at end of file diff --git a/prop/app.config b/prop/app.config new file mode 100644 index 0000000..664a3e8 --- /dev/null +++ b/prop/app.config @@ -0,0 +1,18 @@ + + + + +
+ + + + + + light + + + False + + + + \ No newline at end of file diff --git a/src/Controller.cs b/src/Controller.cs index 80df8c9..b813a15 100644 --- a/src/Controller.cs +++ b/src/Controller.cs @@ -25,7 +25,7 @@ class Controller // but the distance is within this threshold. Then we also think it's a valid click. private static int CLICK_MOVE_THRESHOLD = 16; - private static int DOUBLE_CLICK_TIME_THRESHOLD = 750; + private static int DOUBLE_CLICK_TIME_THRESHOLD = 400; // The mouse moved distance during the click. private double movedDistanceOfClick = 0; diff --git a/src/com.jarvisniu/AnimationJar.cs b/src/com.jarvisniu/AnimationJar.cs index 7d247ae..8958627 100644 --- a/src/com.jarvisniu/AnimationJar.cs +++ b/src/com.jarvisniu/AnimationJar.cs @@ -99,7 +99,11 @@ public AnimatorJar() boardHeight.Children.Add(heightAnimation); } + /// -------------------------------------------------------------------- /// All transition animation effects ----------------------------------- + /// -------------------------------------------------------------------- + + /// Fade & Margin ------------------------------------------------------ public AnimatorJar fadeIn(FrameworkElement target) { @@ -126,25 +130,7 @@ public AnimatorJar marginTo(FrameworkElement target, Thickness m) return this; } - public AnimatorJar marginTopTo(FrameworkElement target, double des) - { - Thickness m = target.Margin; - translateAnimation.To = new Thickness(m.Left, des, m.Right, m.Bottom); - Storyboard.SetTarget(translateAnimation, target); - boardTranslate.Begin(); - - return this; - } - - public AnimatorJar marginBottomTo(FrameworkElement target, double des) - { - Thickness m = target.Margin; - translateAnimation.To = new Thickness(m.Left, m.Top, m.Right, des); - Storyboard.SetTarget(translateAnimation, target); - boardTranslate.Begin(); - - return this; - } + /// Translate ---------------------------------------------------------- public AnimatorJar translateTopTo(FrameworkElement target, double desTop) { @@ -222,18 +208,56 @@ public AnimatorJar translateLeftByI(FrameworkElement target, double delta) return this; } + public AnimatorJar translateBottomTo(FrameworkElement target, double des) + { + Thickness m = target.Margin; + translateAnimation.To = new Thickness(m.Left, m.Top, m.Right, des); + Storyboard.SetTarget(translateAnimation, target); + boardTranslate.Begin(); + + return this; + } + + public AnimatorJar translateBottomToI(FrameworkElement target, double des) + { + translateAnimation.Duration = DURITION_ZERO; + translateBottomTo(target, des); + translateAnimation.Duration = DURITION_DOT2; + + return this; + } + + public AnimatorJar translateLeftBottomTo(FrameworkElement target, double desLeft, double desBottom) + { + Thickness m = target.Margin; + translateAnimation.To = new Thickness(desLeft, m.Top, m.Right, desBottom); + Storyboard.SetTarget(translateAnimation, target); + boardTranslate.Begin(); + + return this; + } + + public AnimatorJar translateLeftBottomToI(FrameworkElement target, double desLeft, double desBottom) + { + translateAnimation.Duration = DURITION_ZERO; + translateLeftBottomTo(target, desLeft, desBottom); + translateAnimation.Duration = DURITION_DOT2; + + return this; + } + + /// Rotate ------------------------------------------------------------- + public AnimatorJar rotateTo(FrameworkElement target, double angle) { if (!(target.RenderTransform is RotateTransform)) target.RenderTransform = new RotateTransform(0); double currDegree = (double)target.RenderTransform.GetValue(RotateTransform.AngleProperty); - Console.WriteLine(currDegree + " => " + angle); while (Math.Abs(angle - currDegree) > 180) { if (angle > currDegree) angle -= 360; else angle += 360; } - Console.WriteLine(currDegree + " -> " + angle); rotateAnimation.To = angle; Storyboard.SetTarget(rotateAnimation, target); boardRotate.Begin(); diff --git a/xaml/NivWindow.xaml b/xaml/NivWindow.xaml index f6a4a8d..0aff07c 100644 --- a/xaml/NivWindow.xaml +++ b/xaml/NivWindow.xaml @@ -43,7 +43,7 @@ - + diff --git a/xaml/NivWindow.xaml.cs b/xaml/NivWindow.xaml.cs index c8c805b..2822255 100644 --- a/xaml/NivWindow.xaml.cs +++ b/xaml/NivWindow.xaml.cs @@ -37,9 +37,8 @@ public partial class NivWindow : Window static double WINDOW_MIN_WIDTH = 680; static double WINDOW_MIN_HEIGHT = 462; public static int SEPARATOR_HEIGHT = 2; - //public static int MESSAGE_BOX_HEIGHT = 48; + public static int TOOLBAR_HEIGHT = 48; public static int MARGIN_SIZE = 50; - // static int DB_CLICK_THRESH = 300; // TODO double click detect give to InputHandler static int AA_SCALE_THRESHHOLD = 2; static double PROGRESS_CAP = 2; static double INFO_WIDTH = 260; @@ -50,7 +49,6 @@ public partial class NivWindow : Window 6 * 4; // gap private BitmapImage ERROR_IMAGE = loadResourceBitmap("res/Niv.ico"); - private string theme = "light"; private Dictionary visibleStates = new Dictionary(); private bool isMarginBottomExist = true; private bool isSmoothButtonVisible = false; @@ -66,14 +64,13 @@ public partial class NivWindow : Window public NivWindow() { - this.Opacity = 0; InitializeComponent(); loadLanguage(); - setTheme(theme); + setTheme(); initLayout(); initComponents(); loadCommandLineFile(); - this.Opacity = 1; + if (Settings.Default.fullscreen) enterFullscreen(); bindContainerEvents(); bindMenuEvents(); @@ -183,11 +180,11 @@ private void setButtonSmoothVisibility() } } - private void setTheme(string theme) + private void setTheme() { - buttonAnimator.setTheme(theme); + buttonAnimator.setTheme(Settings.Default.theme); - if (theme == "light") + if (Settings.Default.theme == "light") { container.Background = grayBrush(250); toolbar.Background = menu.Background = iImageInfoTitle.Background = grayBrush(220); @@ -204,7 +201,7 @@ private void setTheme(string theme) page.BorderBrush = grayBrush(128, 0.75); btnExit.BorderBrush = grayBrush(128); } - else if (theme == "dark") + else if (Settings.Default.theme == "dark") { container.Background = grayBrush(32); toolbar.Background = grayBrush(32, 0.75); @@ -222,23 +219,23 @@ private void setTheme(string theme) page.BorderBrush = grayBrush(128, 0.75); btnExit.BorderBrush = grayBrush(0, 0); } - else MessageBox.Show("Not supported theme: " + theme); + else MessageBox.Show("Not supported theme: " + Settings.Default.theme); // button images - imageRotateLeft.Source = loadThemeBitmap("icon-rotate-left.png", theme); - imageRotateRight.Source = loadThemeBitmap("icon-rotate-right.png", theme); - imageDelete.Source = loadThemeBitmap("icon-delete.png", theme); - imagePrev.Source = loadThemeBitmap("icon-prev.png", theme); - imageNext.Source = loadThemeBitmap("icon-next.png", theme); + imageRotateLeft.Source = loadThemeBitmap("icon-rotate-left.png"); + imageRotateRight.Source = loadThemeBitmap("icon-rotate-right.png"); + imageDelete.Source = loadThemeBitmap("icon-delete.png"); + imagePrev.Source = loadThemeBitmap("icon-prev.png"); + imageNext.Source = loadThemeBitmap("icon-next.png"); refreshSmoothButton(); refreshZoomButton(); - imageMenu.Source = loadThemeBitmap("icon-menu.png", theme); - imageCloseInfo.Source = imageExit.Source = loadThemeBitmap("icon-close.png", theme); + imageMenu.Source = loadThemeBitmap("icon-menu.png"); + imageCloseInfo.Source = imageExit.Source = loadThemeBitmap("icon-close.png"); // menu images - imageHelp.Source = loadThemeBitmap("icon-help.png", theme); - imageAbout.Source = loadThemeBitmap("icon-info.png", theme); - imageSetting.Source = loadThemeBitmap("icon-setting.png", theme); - imageInfo.Source = loadThemeBitmap("icon-list.png", theme); + imageHelp.Source = loadThemeBitmap("icon-help.png"); + imageAbout.Source = loadThemeBitmap("icon-info.png"); + imageSetting.Source = loadThemeBitmap("icon-setting.png"); + imageInfo.Source = loadThemeBitmap("icon-list.png"); } #endregion @@ -503,6 +500,7 @@ private void loadFromWalker() labelInfoDate.Content = dateTimeToString(fi.LastWriteTime); this.Title = Path.GetFileName(info.filename) + " - " + I18n._("appName"); refreshProgress(); + refreshPageText(); showPage(); if (!isFileGif(info.filename)) @@ -687,10 +685,10 @@ private void showMessage(string message) MessageBox.Show(message); } - private static BitmapImage loadThemeBitmap(string filename, string theme) + private static BitmapImage loadThemeBitmap(string filename) { string namespaceName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name; - return new BitmapImage(new Uri("pack://application:,,,/" + namespaceName + ";component/res/theme-" + theme + "/" + filename)); + return new BitmapImage(new Uri("pack://application:,,,/" + namespaceName + ";component/res/theme-" + Settings.Default.theme + "/" + filename)); } private static BitmapImage loadResourceBitmap(string filepath) @@ -751,23 +749,33 @@ public void saveRotationToFile() walker.currentImageInfo.savedRotationAngle = walker.currentImageInfo.rotationAngle; } + private void refreshPageText() + { + iPage.Content = (walker.currentIndex + 1) + "/" + walker.count; + } + private void refreshProgress() { setProgressWidth(); double left = getProgressLeft(); + double bottom = TOOLBAR_HEIGHT - 1; + if (isFullscreen && !visibleStates[toolbar]) bottom = -4; + if (walker.isJumpBetweenEnds() || !visibleStates[toolbar]) - animatorJar.translateLeftToI(progress, left); + animatorJar.translateLeftBottomToI(progress, left, bottom); else - animatorJar.translateLeftTo(progress, left); - - iPage.Content = (walker.currentIndex + 1) + "/" + walker.count; + animatorJar.translateLeftBottomTo(progress, left, bottom); } private void refreshProgressI() { setProgressWidth(); - animatorJar.translateLeftToI(progress, getProgressLeft()); + + double left = getProgressLeft(); + double bottom = isFullscreen && !visibleStates[toolbar] ? -4 : TOOLBAR_HEIGHT - 1; + + animatorJar.translateLeftBottomToI(progress, left, bottom); } private void setProgressWidth() @@ -825,7 +833,7 @@ private void refreshSmoothButton() { if (walker.currentImageInfo != null) { - imageSmooth.Source = loadThemeBitmap(walker.currentImageInfo.smooth ? "icon-smooth-off.png" : "icon-smooth-on.png", theme); + imageSmooth.Source = loadThemeBitmap(walker.currentImageInfo.smooth ? "icon-smooth-off.png" : "icon-smooth-on.png"); btnSmooth.ToolTip = I18n._(walker.currentImageInfo.smooth ? "tooltip.disable-smooth" : "tooltip.enable-smooth"); } } @@ -834,7 +842,7 @@ private void refreshZoomButton() { if (walker.currentImageInfo != null) { - imageZoom.Source = loadThemeBitmap(walker.currentImageInfo.fitWindow ? "icon-one-to-one.png" : "icon-fit-window.png", theme); + imageZoom.Source = loadThemeBitmap(walker.currentImageInfo.fitWindow ? "icon-one-to-one.png" : "icon-fit-window.png"); btnZoom.ToolTip = I18n._(walker.currentImageInfo.fitWindow ? "tooltip.one-to-one" : "tooltip.fit-window"); } } @@ -971,21 +979,21 @@ private void toggleToolbar() private void showToolbar() { visibleStates[toolbar] = true; - animatorJar.marginBottomTo(toolbar, 0) - .marginBottomTo(page, MARGIN_SIZE * (isFullscreen ? 1 : 0) + 8) - .marginBottomTo(separator, 48) - .marginBottomTo(progress, 48 - 1) - .fadeIn(separator).fadeIn(progress); + animatorJar.translateBottomTo(toolbar, 0) + .translateBottomTo(page, MARGIN_SIZE + 8) + .translateBottomTo(separator, TOOLBAR_HEIGHT) + .fadeIn(separator); + refreshProgress(); } private void hideToolbar() { visibleStates[toolbar] = false; - animatorJar.marginBottomTo(toolbar, -48) - .marginBottomTo(page, 8) - .marginBottomTo(separator, 0) - .marginBottomTo(progress, -1) - .fadeOut(separator).fadeOut(progress); + animatorJar.translateBottomTo(toolbar, -TOOLBAR_HEIGHT) + .translateBottomTo(page, 8) + .translateBottomTo(separator, 0) + .fadeOut(separator); + refreshProgress(); } private void tryHideToolbar() @@ -1024,8 +1032,9 @@ public void hideMarginBottom() private void toggleTheme() { - theme = theme == "dark" ? "light" : "dark"; - setTheme(theme); + Settings.Default.theme = Settings.Default.theme == "dark" ? "light" : "dark"; + Settings.Default.Save(); + setTheme(); } // fullscreen @@ -1035,17 +1044,18 @@ public void toggleFullscreen() exitFullscreen(); else enterFullscreen(); + + Settings.Default.fullscreen = isFullscreen; + Settings.Default.Save(); } private void enterFullscreen() { lastWindowState = this.WindowState; - //this.Opacity = 0; this.WindowStyle = System.Windows.WindowStyle.None; if (this.WindowState != System.Windows.WindowState.Normal) this.WindowState = System.Windows.WindowState.Normal; this.WindowState = System.Windows.WindowState.Maximized; - //this.Opacity = 1; btnExit.Visibility = System.Windows.Visibility.Visible; @@ -1058,16 +1068,16 @@ private void enterFullscreen() } private void exitFullscreen() { - if (!visibleStates[toolbar]) showToolbar(); - showMarginBottom(); + isFullscreen = false; + isAutoHideToolbar = false; this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow; this.WindowState = lastWindowState; btnExit.Visibility = System.Windows.Visibility.Hidden; - isFullscreen = false; - isAutoHideToolbar = false; + showMarginBottom(); + if (!visibleStates[toolbar]) showToolbar(); } // menu @@ -1091,10 +1101,7 @@ private void hideMainMenu() animatorJar.heightTo(menu, 0); animatorJar.fadeOut(menu); } - - - - + #endregion private void closeMenu(object sender, MouseButtonEventArgs e) @@ -1141,7 +1148,7 @@ private void delete() // Press key "D" to show something for debugging. private void debug() { - MessageBox.Show(toolbar.Margin.Right.ToString()); + MessageBox.Show(progress.Margin.Bottom.ToString()); } private void exit()