OSDN Git Service

TweenMain.currentScaleFactorをOTBaseFormに移動
authorKimura Youichi <kim.upsilon@bucyou.net>
Tue, 3 Feb 2015 00:19:31 +0000 (09:19 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Thu, 5 Feb 2015 16:18:31 +0000 (01:18 +0900)
OpenTween.Tests/OTBaseFormTest.cs [new file with mode: 0644]
OpenTween.Tests/OpenTween.Tests.csproj
OpenTween/OTBaseForm.cs
OpenTween/Tween.cs

diff --git a/OpenTween.Tests/OTBaseFormTest.cs b/OpenTween.Tests/OTBaseFormTest.cs
new file mode 100644 (file)
index 0000000..14519fe
--- /dev/null
@@ -0,0 +1,61 @@
+// OpenTween - Client of Twitter
+// Copyright (c) 2015 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Xunit;
+
+namespace OpenTween
+{
+    public class OTBaseFormTest
+    {
+        class TestForm : OTBaseForm
+        {
+            public SizeF fakeAutoScaleDimensions = new SizeF(96.0f, 96.0f);
+
+            public override SizeF CurrentAutoScaleDimensions
+            {
+                get { return this.fakeAutoScaleDimensions; }
+            }
+        }
+
+        [Fact]
+        public void CurrentScaleFactor_Test()
+        {
+            using (var form = new TestForm())
+            {
+                form.AutoScaleMode = AutoScaleMode.Dpi;
+                form.AutoScaleDimensions = new SizeF(96.0f, 96.0f);
+
+                // 96dpi -> 120dpi
+                form.fakeAutoScaleDimensions = new SizeF(120.0f, 120.0f);
+                form.Scale(new SizeF(1.25f, 1.25f));
+
+                Assert.Equal(new SizeF(1.25f, 1.25f), form.CurrentScaleFactor);
+            }
+        }
+    }
+}
index 40a86fd..9cb09f0 100644 (file)
@@ -68,6 +68,7 @@
     <Compile Include="HashtagManageTest.cs" />
     <Compile Include="HttpMessageHandlerMock.cs" />
     <Compile Include="MyApplicationTest.cs" />
+    <Compile Include="OTBaseFormTest.cs" />
     <Compile Include="OTPictureBoxTest.cs" />
     <Compile Include="OTSplitContainerTest.cs" />
     <Compile Include="PostFilterRuleTest.cs" />
index 710b4b3..35144a2 100644 (file)
@@ -21,6 +21,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Drawing;
 using System.Linq;
 using System.Text;
@@ -41,9 +42,19 @@ namespace OpenTween
         /// </remarks>
         public static Font GlobalFont { get; set; }
 
+        /// <summary>
+        /// デザイン時のスケールと現在のスケールの比
+        /// </summary>
+        /// <remarks>
+        /// 例えば、デザイン時が 96 dpi (96.0, 96.0) で実行時が 120dpi (120.0, 120.0) の場合は 1.25, 1.25 が返ります
+        /// </remarks>
+        public SizeF CurrentScaleFactor { get; private set; }
+
         protected OTBaseForm()
             : base()
         {
+            this.CurrentScaleFactor = new SizeF(1.0f, 1.0f);
+
             this.Load += (o, e) =>
             {
                 // デフォルトの UI フォントを変更
@@ -62,5 +73,22 @@ namespace OpenTween
 
             return new Font(OTBaseForm.GlobalFont.Name, source.Size, source.Style);
         }
+
+        protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
+        {
+            base.ScaleControl(factor, specified);
+
+            const float baseDpi = 96.0f;
+
+            this.CurrentScaleFactor = new SizeF(
+                this.CurrentAutoScaleDimensions.Width / baseDpi,
+                this.CurrentAutoScaleDimensions.Height / baseDpi);
+        }
+
+        // テスト時にスケールを偽装するために使用
+        public new virtual SizeF CurrentAutoScaleDimensions
+        {
+            get { return base.CurrentAutoScaleDimensions; }
+        }
     }
 }
index 1aaeb4f..6e56616 100644 (file)
@@ -218,11 +218,6 @@ namespace OpenTween
 
         private string recommendedStatusFooter;
 
-        /// <summary>
-        /// デザイン時の DPI (96dpi) と実際の表示時の DPI との比を表します
-        /// </summary>
-        protected SizeF currentScaleFactor = new SizeF();
-
         //URL短縮のUndo用
         private struct urlUndo
         {
@@ -4096,7 +4091,7 @@ namespace OpenTween
                 // ディスプレイの DPI 設定を考慮したサイズを設定する
                 _listViewImageList.ImageSize = new Size(
                     1,
-                    (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
+                    (int)Math.Ceiling(this._iconSz * this.CurrentScaleFactor.Height));
             }
             else
             {
@@ -5326,8 +5321,8 @@ namespace OpenTween
             }
 
             // ディスプレイの DPI 設定を考慮したアイコンサイズ
-            var realIconSize = new SizeF(this._iconSz * this.currentScaleFactor.Width, this._iconSz * this.currentScaleFactor.Height).ToSize();
-            var realStateSize = new SizeF(16 * this.currentScaleFactor.Width, 16 * this.currentScaleFactor.Height).ToSize();
+            var realIconSize = new SizeF(this._iconSz * this.CurrentScaleFactor.Width, this._iconSz * this.CurrentScaleFactor.Height).ToSize();
+            var realStateSize = new SizeF(16 * this.CurrentScaleFactor.Width, 16 * this.CurrentScaleFactor.Height).ToSize();
 
             Rectangle iconRect;
             var img = item.Image;
@@ -5370,18 +5365,6 @@ namespace OpenTween
             }
         }
 
-        protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
-        {
-            base.ScaleControl(factor, specified);
-
-            const int baseDpi = 96;
-
-            // デザイン時の DPI (96dpi) との比を更新する
-            this.currentScaleFactor = new SizeF(
-                this.CurrentAutoScaleDimensions.Width / baseDpi,
-                this.CurrentAutoScaleDimensions.Height / baseDpi);
-        }
-
         //private void DrawListViewItemStateIcon(DrawListViewSubItemEventArgs e, RectangleF rct)
         //{
         //    ImageListViewItem item = (ImageListViewItem)e.Item;