--- /dev/null
+// 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);
+ }
+ }
+ }
+}
<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" />
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
/// </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 フォントを変更
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; }
+ }
}
}
private string recommendedStatusFooter;
- /// <summary>
- /// デザイン時の DPI (96dpi) と実際の表示時の DPI との比を表します
- /// </summary>
- protected SizeF currentScaleFactor = new SizeF();
-
//URL短縮のUndo用
private struct urlUndo
{
// ディスプレイの DPI 設定を考慮したサイズを設定する
_listViewImageList.ImageSize = new Size(
1,
- (int)Math.Ceiling(this._iconSz * this.currentScaleFactor.Height));
+ (int)Math.Ceiling(this._iconSz * this.CurrentScaleFactor.Height));
}
else
{
}
// ディスプレイの 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;
}
}
- 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;