Commits

Ruxo Zheng  committed aee8bf1

Change size calculation of getNiceSize, making it more fitting to the screen.

  • Participants
  • Parent commits ec0af29

Comments (0)

Files changed (10)

File RZScreenSaver.suo

Binary file modified.

File RZWScreenSaver/MainApp.cs

 using System;
 using System.Configuration;
 using System.Diagnostics;
+using System.Globalization;
 using System.Text.RegularExpressions;
 using System.Windows;
 using RZWScreenSaver.Properties;
 
             Debug.WriteLine("arg count = " + arg.Length);
             for(int i=0; i < arg.Length; ++i)
-                Debug.WriteLine(String.Format("arg #{0} = {1}", i.ToString(), arg[i]));
+                Debug.WriteLine(String.Format("arg #{0} = {1}", i.ToString(CultureInfo.InvariantCulture), arg[i]));
 
             foreach (var provider in Settings.Default.Providers){
                 Debug.WriteLine("Provider = " + provider.ToString());

File RZWScreenSaver/Properties/Settings.Designer.cs

 //------------------------------------------------------------------------------
 // <auto-generated>
 //     This code was generated by a tool.
-//     Runtime Version:4.0.30319.488
+//     Runtime Version:4.0.30319.530
 //
 //     Changes to this file may cause incorrect behavior and will be lost if
 //     the code is regenerated.
         
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
-        [global::System.Configuration.DefaultSettingValueAttribute("0.5")]
+        [global::System.Configuration.DefaultSettingValueAttribute("0.75")]
         public double MaxSquareCardSize {
             get {
                 return ((double)(this["MaxSquareCardSize"]));
                 this["LastShownIndex"] = value;
             }
         }
+        
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("2")]
+        public double MaxImageScale {
+            get {
+                return ((double)(this["MaxImageScale"]));
+            }
+            set {
+                this["MaxImageScale"] = value;
+            }
+        }
     }
 }

File RZWScreenSaver/Properties/Settings.settings

       <Value Profile="(Default)">0.25</Value>
     </Setting>
     <Setting Name="MaxSquareCardSize" Type="System.Double" Scope="User">
-      <Value Profile="(Default)">0.5</Value>
+      <Value Profile="(Default)">0.75</Value>
     </Setting>
     <Setting Name="BackgroundPicturePath" Type="System.String" Scope="User">
       <Value Profile="(Default)" />
     <Setting Name="LastShownIndex" Type="System.Int32" Scope="User">
       <Value Profile="(Default)">0</Value>
     </Setting>
+    <Setting Name="MaxImageScale" Type="System.Double" Scope="User">
+      <Value Profile="(Default)">2</Value>
+    </Setting>
   </Settings>
 </SettingsFile>

File RZWScreenSaver/RZWScreenSaver.csproj

     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>RZWScreenSaver</RootNamespace>
     <AssemblyName>RZWScreenSaver</AssemblyName>
-    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <WarningLevel>4</WarningLevel>
     <IsWebBootstrapper>false</IsWebBootstrapper>
     <UseApplicationTrust>false</UseApplicationTrust>
     <BootstrapperEnabled>true</BootstrapperEnabled>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
     </Reference>
     <Reference Include="System.Drawing" />
     <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xaml" />
     <Reference Include="System.Xml" />
     <Reference Include="UIAutomationProvider">
       <RequiredTargetFramework>3.0</RequiredTargetFramework>

File RZWScreenSaver/SizeScaleExtension.cs

 using System;
 using System.Windows;
-using System.Windows.Media;
 
 namespace RZWScreenSaver{
     static class SizeScaleExtension{

File RZWScreenSaver/SlidePages/PhotoCollagePage.xaml.cs

         static PhotoCollagePage(){
             // TODO: Decouple this class from Settings!
             ViewAngle = Settings.Default.PhotoCollageAngle;
+            MaxImageScale = Settings.Default.MaxImageScale;
             SquareCardSize = new Range
                              {Min = Settings.Default.MinSquareCardSize, Max = Settings.Default.MaxSquareCardSize};
         }
         #endregion
 
         static readonly int ViewAngle;
+        static readonly double MaxImageScale;
         const int AnglePrecision = 100;
         static readonly Range SquareCardSize;
 
             // there may be better place for this code... (changing child in this method cause this method to be called again :(
             pageWidth = (int)result.Width;
             pageHeight = (int) result.Height;
-            if (viewBitmap == null || viewBitmap.Width != pageWidth || viewBitmap.Height != pageHeight){
+            if (viewBitmap == null || Math.Abs(viewBitmap.Width - pageWidth) > 1e-6 || Math.Abs(viewBitmap.Height - pageHeight) > 1e-6){
                 resetViewBitmaps(result);
             }
             return result;
             return raw.CloneWithData(Rgba32.FromHsl(hsl));
         }
         Size getNiceSize(ImageSource image, double sizeScale, int? orientation){
-            Size imageSize;
-            GetImageSizeByOrientation(image, orientation, out imageSize);
-            
-            var expectedArea = minCardArea + (maxCardArea - minCardArea)*sizeScale;
-            return imageSize.ScaleToArea(expectedArea);
+            var imageSize = GetImageSizeByOrientation(image, orientation);
+
+            var validHeight = Math.Min(imageSize.Height * MaxImageScale, pageHeight);
+            var validWidth = Math.Min(imageSize.Width * MaxImageScale, pageWidth);
+
+            var scaleFactor = SquareCardSize.Size * sizeScale + SquareCardSize.Min;
+            var ratio = imageSize.Height/imageSize.Width;
+            if (validHeight < validWidth){
+                var newHeight = validHeight*scaleFactor;
+                return new Size(newHeight/ratio, newHeight);
+            } else{
+                var newWidth = validWidth*scaleFactor;
+                return new Size(newWidth, newWidth*ratio);
+            }
         }
         void rebuildSurfaceBackground(){
             if (background != null){
         }
         struct Range{
             public double Min, Max;
+            public double Size{
+                get { return Max - Min; }
+            }
         }
         int pageWidth, pageHeight;
         double minCardArea, maxCardArea;

File RZWScreenSaver/SlidePages/SimpleSlide.xaml.cs

             }
         }
         bool canImageFitScreen(ImageSource image, int? orientation){
-            Size imageSize;
-            GetImageSizeByOrientation(image, orientation, out imageSize);
-
+            var imageSize = GetImageSizeByOrientation(image, orientation);
             var parentWindow = Parent as FrameworkElement;
             return parentWindow != null && imageSize.Width <= parentWindow.Width && imageSize.Height <= parentWindow.Height;
         }

File RZWScreenSaver/SlidePages/SlidePage.cs

 using System;
 using System.Diagnostics;
+using System.Globalization;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media;
             case 6:
                 return 270 /* degree clockwise */;
             default:
-                Trace.WriteLine("Unrecognized EXIF orientation: " + orientation.ToString());
+                Trace.WriteLine("Unrecognized EXIF orientation: " + orientation.ToString(CultureInfo.InvariantCulture));
                 return null;
             }
         }
-        static protected void GetImageSizeByOrientation(ImageSource image, int? orientation, out Size imageSize){
-            imageSize = IsLandscape(orientation) ? new Size(image.Width, image.Height) : new Size(image.Height, image.Width);
+        static protected Size GetImageSizeByOrientation(ImageSource image, int? orientation) {
+            return IsLandscape(orientation) ? new Size(image.Width, image.Height) : new Size(image.Height, image.Width);
         }
         static protected bool IsLandscape(int? orientation){
             return orientation == null || orientation.Value == 0 || orientation.Value == 180;

File RZWScreenSaver/app.config

-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0"?>
 <configuration>
     <configSections>
-        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
-            <section name="RZWScreenSaver.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
+        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+            <section name="RZWScreenSaver.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
         </sectionGroup>
     </configSections>
     <userSettings>
                 <value>0.25</value>
             </setting>
             <setting name="MaxSquareCardSize" serializeAs="String">
-                <value>0.5</value>
+                <value>0.75</value>
             </setting>
             <setting name="BackgroundPicturePath" serializeAs="String">
                 <value />
             <setting name="LastShownIndex" serializeAs="String">
                 <value>0</value>
             </setting>
+            <setting name="MaxImageScale" serializeAs="String">
+                <value>2</value>
+            </setting>
         </RZWScreenSaver.Properties.Settings>
     </userSettings>
-</configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>