private void TruncateNameSub(Dictionary<string, string> dict, ShipNameWidth width)\r
{\r
var label = new ShipLabel {Parent = new Panel()};\r
- ShipLabel.ScaleFactor = new SizeF(1,1);\r
+ Scaler.Factor = new SizeF(1,1);\r
foreach (var entry in dict)\r
{\r
label.SetName(entry.Key, width);\r
public void SetName()\r
{\r
var label = new ShipLabel {Parent = new Panel()};\r
- ShipLabel.ScaleFactor = new SizeF(1, 1);\r
+ Scaler.Factor = new SizeF(1, 1);\r
label.SetName(new ShipStatus\r
{\r
Spec = new ShipSpec {Name = "綾波改二"},\r
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nyukyo/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pushbullet/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ryusei/@EntryIndexedValue">True</s:Boolean>
+ <s:Boolean x:Key="/Default/UserDictionary/Words/=Scaler/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scroller/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scrollify/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Seiran/@EntryIndexedValue">True</s:Boolean>
<SubType>Component</SubType>\r
</Compile>\r
<Compile Include="Model\ShipInfo.cs" />\r
+ <Compile Include="View\Scaler.cs" />\r
<Compile Include="View\ShipLabel.cs" />\r
<Compile Include="View\ShipListPanel.cs">\r
<SubType>Component</SubType>\r
using System.Linq;\r
using System.Windows.Forms;\r
using KancolleSniffer.View;\r
-using static System.Math;\r
\r
namespace KancolleSniffer\r
{\r
{\r
/* DPIではなくズームしたときにパネルは大きくなるがScrollBarはそのままなので隙間ができる。\r
そこでScrollBarの幅に合わせて全体の横幅を設定し直す。*/\r
- Width = (int)Round((PanelWidth + 12 /* PanelとFrameの内側 */) * ShipLabel.ScaleFactor.Width) +\r
+ Width = Scaler.ScaleWidth(PanelWidth + 12 /* PanelとFrameの内側 */) +\r
SystemInformation.VerticalScrollBarWidth + 2 /* 縁の幅 */ + Width - ClientSize.Width;\r
MinimumSize = new Size(Width, 0);\r
MaximumSize = new Size(Width, int.MaxValue);\r
private void SetScaleFactorOfDpiScaling()\r
{\r
var autoScaleDimensions = new SizeF(6f, 12f); // AutoScaleDimensionの初期値\r
- ShipLabel.ScaleFactor = new SizeF(CurrentAutoScaleDimensions.Width / autoScaleDimensions.Width,\r
+ Scaler.Factor = new SizeF(CurrentAutoScaleDimensions.Width / autoScaleDimensions.Width,\r
CurrentAutoScaleDimensions.Height / autoScaleDimensions.Height);\r
}\r
\r
}\r
ShipLabel.LatinFont = new Font("Tahoma", 8f * Config.Zoom / 100);\r
var cur = CurrentAutoScaleDimensions;\r
- ShipLabel.ScaleFactor = new SizeF(ShipLabel.ScaleFactor.Width * cur.Width / prev.Width,\r
- ShipLabel.ScaleFactor.Height * cur.Height / prev.Height);\r
+ Scaler.Factor = Scaler.Scale(cur.Width / prev.Width, cur.Height / prev.Height);\r
}\r
\r
private void RestoreLocation()\r
// See the License for the specific language governing permissions and\r
// limitations under the License.\r
\r
-using System;\r
using System.Collections.Generic;\r
using System.Drawing;\r
using System.Linq;\r
BackColor = ShipLabel.ColumnColors[(i + 1) % 2],\r
Visible = false\r
};\r
- lbp.Scale(ShipLabel.ScaleFactor);\r
+ Scaler.Scale(lbp);\r
lbp.Tag = lbp.Location.Y;\r
var labels = new[]\r
{\r
Controls.Add(lbp);\r
foreach (var label in labels)\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.PresetColor =\r
label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
}\r
var i = _table.FindIndex(e => e.Id == id);\r
if (i == -1)\r
return;\r
- var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);\r
+ var y = Scaler.ScaleHeight(LineHeight * i);\r
AutoScrollPosition = new Point(0, y);\r
}\r
}\r
var panel = _panelList[i];\r
if (panel.Visible)\r
continue;\r
- panel.Location = new Point(AutoScrollPosition.X,\r
- (int)Round((int)panel.Tag * ShipLabel.ScaleFactor.Height) + AutoScrollPosition.Y);\r
+ panel.Location = Scaler.Move(AutoScrollPosition.X, AutoScrollPosition.Y, 0, (int)panel.Tag);\r
panel.Visible = true;\r
}\r
for (var i = lines; i < _panelList.Count; i++)\r
_enemyLabels[0][1].Location.X + _enemyLabels.Max(labels => labels[1].Size.Width) - 1); // 敵の名前の右端\r
for (var i = 0; i < lines; i++)\r
_panelList[i].Width = panelWidth;\r
- _informationPanel.Location = new Point(\r
- (int)Round(0 * ShipLabel.ScaleFactor.Width) + AutoScrollPosition.X,\r
- (int)Round(20 * ShipLabel.ScaleFactor.Height) + AutoScrollPosition.Y);\r
+ _informationPanel.Location = Scaler.Move(AutoScrollPosition.X, AutoScrollPosition.Y, 0, 20);\r
_informationPanel.Visible = true;\r
UpdateCellInfo(_cellInfo);\r
}\r
BackColor = ShipLabel.ColumnColors[(i + 1) % 2],\r
Visible = false\r
};\r
- lbp.Scale(ShipLabel.ScaleFactor);\r
+ Scaler.Scale(lbp);\r
lbp.Tag = lbp.Location.Y;\r
var labels = new FleetLabels\r
{\r
Controls.Add(lbp);\r
foreach (var label in labels)\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.PresetColor =\r
label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
}\r
var i = Array.FindIndex(_table, e => e.Id == id);\r
if (i == -1)\r
return;\r
- var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);\r
+ var y = Scaler.ScaleHeight(LineHeight * i);\r
AutoScrollPosition = new Point(0, y);\r
}\r
\r
var i = Array.FindIndex(_table, e => e.Fleet.StartsWith(fn));\r
if (i == -1)\r
return;\r
- var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);\r
+ var y = Scaler.ScaleHeight(LineHeight * i);\r
AutoScrollPosition = new Point(0, y);\r
}\r
}\r
public void DrawMark()\r
{\r
var halfOfWidth = _panel.Width * 0.5f;\r
- var halfOfMark = MarkWidth * 0.5f * ShipLabel.ScaleFactor.Width;\r
+ var halfOfMark = Scaler.ScaleWidth(MarkWidth * 0.5f);\r
var left = halfOfWidth - halfOfMark;\r
var right = halfOfWidth + halfOfMark;\r
var center = halfOfWidth;\r
using System.Drawing;\r
using System.Windows.Forms;\r
using KancolleSniffer.Model;\r
-using static System.Math;\r
\r
namespace KancolleSniffer.View\r
{\r
});\r
foreach (var label in headings)\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.BackColor = ShipLabel.ColumnColors[1];\r
}\r
for (var i = 0; i < shipLabels.Length; i++)\r
});\r
foreach (var label in shipLabels[i])\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.PresetColor = label.BackColor = ShipLabel.ColumnColors[i % 2];\r
label.Tag = i;\r
label.Click += onClick;\r
});\r
foreach (var label in headings)\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.BackColor = ShipLabel.ColumnColors[1];\r
}\r
for (var i = 0; i < _combinedLabels.Length; i++)\r
});\r
foreach (var label in _combinedLabels[i])\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.PresetColor = label.BackColor = ShipLabel.ColumnColors[i % 2];\r
label.Tag = i;\r
label.Click += onClick;\r
label.BackColor = ShipLabel.ColumnColors[i % 2];\r
}\r
foreach (var label in timerLabels)\r
- label.Scale();\r
+ Scaler.Scale(label);\r
parent.ResumeLayout();\r
}\r
\r
\r
public void AdjustAkashiTimers(ShipLabel[] timers, int lineHeight)\r
{\r
- var scale = ShipLabel.ScaleFactor;\r
- if (scale.Height < 1.2)\r
+ if (Scaler.ScaleHeight(1f) < 1.2)\r
return;\r
for (var i = 0; i < timers.Length; i++)\r
{\r
const int x = 55;\r
var y = 3 + lineHeight * (i + 1);\r
- timers[i].Location = new Point((int)Round(x * scale.Width) - 3, (int)Round(y * scale.Height));\r
- timers[i].Size = new Size((int)Round(31 * scale.Width) + 1, (int)Round(12 * scale.Height));\r
+ timers[i].Location = Scaler.Move(-3, 0, x, y);\r
+ timers[i].Size = new Size(Scaler.ScaleWidth(31) + 1, Scaler.ScaleWidth(12));\r
}\r
}\r
\r
});\r
foreach (var label in _ndockLabels[i])\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.Click += onClick;\r
}\r
}\r
_lines = LimitLines(lines);\r
_labels = new QuestLabels[_lines];\r
SuspendLayout();\r
- Height = (int)Math.Round((TopMargin * 2 + LineHeight * lines) * ShipLabel.ScaleFactor.Height);\r
+ Height = Scaler.ScaleHeight(TopMargin * 2 + LineHeight * lines);\r
for (var i = 0; i < _lines; i++)\r
{\r
var y = TopMargin + i * LineHeight;\r
_labels[i].Name.DoubleClick += onDoubleClick;\r
Controls.AddRange(_labels[i].Labels);\r
foreach (var label in _labels[i].Labels)\r
- label.Scale();\r
+ Scaler.Scale(label);\r
}\r
ResumeLayout();\r
SetupListScroller();\r
Controls.AddRange(_repairLabels[i].Labels);\r
foreach (var label in _repairLabels[i].Labels)\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.PresetColor = label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
label.Click += onClick;\r
}\r
{\r
get\r
{\r
- var baseHeight = (Parent.ClientRectangle.Height - Location.Y) / ShipLabel.ScaleFactor.Height;\r
- return (int)Round((baseHeight - PanelPadding * 2) / LineHeight);\r
+ var baseHeight = Parent.ClientRectangle.Height - Location.Y;\r
+ return (int)Round((baseHeight - Scaler.ScaleHeight((float)PanelPadding) * 2) / Scaler.ScaleHeight((float)LineHeight));\r
}\r
}\r
\r
private void SetPanelHeight()\r
{\r
var lines = Min(Max(1, _repairList.Length), _repairLabels.Length);\r
- Size = new Size(Width,\r
- (int)Round(ShipLabel.ScaleFactor.Height * (lines * LineHeight + PanelPadding * 2)));\r
+ Size = new Size(Width, Scaler.ScaleHeight(lines * LineHeight + PanelPadding * 2));\r
}\r
\r
private void ShowRepairList()\r
--- /dev/null
+// Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+using System;\r
+using System.Drawing;\r
+using System.Windows.Forms;\r
+\r
+namespace KancolleSniffer.View\r
+{\r
+ public static class Scaler\r
+ {\r
+ public static SizeF Factor { private get; set; }\r
+\r
+ public static void Scale(Control control)\r
+ {\r
+ control.Scale(Factor);\r
+ }\r
+\r
+ public static float ScaleWidth(float width)\r
+ {\r
+ return width * Factor.Width;\r
+ }\r
+\r
+ public static float ScaleHeight(float height)\r
+ {\r
+ return height * Factor.Height;\r
+ }\r
+\r
+ public static int ScaleWidth(int width)\r
+ {\r
+ return (int)Math.Round(width * Factor.Width);\r
+ }\r
+\r
+ public static int ScaleHeight(int height)\r
+ {\r
+ return (int)Math.Round(height * Factor.Height);\r
+ }\r
+\r
+ public static Size Scale(Size size)\r
+ {\r
+ return new Size(ScaleWidth(size.Width), ScaleHeight(size.Height));\r
+ }\r
+\r
+ public static Size Scale(int width, int height)\r
+ {\r
+ return new Size(ScaleWidth(width), ScaleHeight(height));\r
+ }\r
+\r
+ public static SizeF Scale(float width, float height)\r
+ {\r
+ return new SizeF(ScaleWidth(width), ScaleHeight(height));\r
+ }\r
+\r
+ public static Point Move(int x, int y, int width, int height)\r
+ {\r
+ return new Point(x + ScaleWidth(width), y + ScaleHeight(height));\r
+ }\r
+ }\r
+}
\ No newline at end of file
public class ShipLabel : Label\r
{\r
public static Color[] ColumnColors = {SystemColors.Control, Color.White};\r
- public static SizeF ScaleFactor { get; set; }\r
public static Font LatinFont { get; set; } = new Font("Tahoma", 8f);\r
public Color PresetColor { get; set; }\r
public bool AnchorRight { get; set; }\r
name = "";\r
_slotStatus = slotStatus;\r
var lu = new Regex(@"^\p{Lu}").IsMatch(name);\r
- var shift = (int)Round(ScaleFactor.Height);\r
+ var shift = Scaler.ScaleHeight(1);\r
if (lu && Font.Equals(BaseFont))\r
{\r
Location += new Size(0, -shift);\r
foreach (var ch in name)\r
{\r
var tmp = truncated + ch;\r
- if (TextRenderer.MeasureText(tmp, Font).Width > (int)width * ScaleFactor.Width)\r
+ if (TextRenderer.MeasureText(tmp, Font).Width > Scaler.ScaleWidth((float)width))\r
break;\r
truncated = tmp;\r
}\r
{\r
Font = StrongFont,\r
BackColor = CUDColors.Red,\r
- Location = new Point(Left + (int)Round(4 * ScaleFactor.Width), Top),\r
+ Location = Scaler.Move(Left, Top, 4, 0),\r
AutoSize = true,\r
MinimumSize = new Size(0, Height),\r
AnchorRight = true,\r
base.OnPaint(e);\r
if ((_slotStatus & SlotStatus.NormalEmpty) != 0)\r
{\r
- e.Graphics.DrawRectangle(\r
- Pens.Black,\r
- ClientSize.Width - 3 * ScaleFactor.Width, 0,\r
- 2 * ScaleFactor.Width, 5 * ScaleFactor.Height);\r
+ e.Graphics.DrawRectangle(Pens.Black,\r
+ new Rectangle(Scaler.Move(ClientSize.Width, 0, -3, 0), Scaler.Scale(2, 5)));\r
}\r
else if ((_slotStatus & SlotStatus.SemiEquipped) != 0)\r
{\r
- e.Graphics.DrawLine(\r
- Pens.Black,\r
- ClientSize.Width - 1 * ScaleFactor.Width, 0,\r
- ClientSize.Width - 1 * ScaleFactor.Width, 5 * ScaleFactor.Height);\r
+ e.Graphics.DrawLine(Pens.Black,\r
+ Scaler.Move(ClientSize.Width, 0, -1, 0),\r
+ Scaler.Move(ClientSize.Width, 0, -1, 5));\r
}\r
if ((_slotStatus & SlotStatus.ExtraEmpty) != 0)\r
{\r
- e.Graphics.DrawRectangle(\r
- Pens.Black,\r
- ClientSize.Width - 3 * ScaleFactor.Width, 8 * ScaleFactor.Height,\r
- 2 * ScaleFactor.Width, 3 * ScaleFactor.Height);\r
+ e.Graphics.DrawRectangle(Pens.Black,\r
+ new Rectangle(Scaler.Move(ClientSize.Width, 0, -3, 8), Scaler.Scale(2, 3)));\r
}\r
}\r
-\r
- public void Scale()\r
- {\r
- Scale(ScaleFactor);\r
- }\r
}\r
}
\ No newline at end of file
\r
private void SetupScrollBar()\r
{\r
- var needBar = _shipList.Length * LineHeight * ShipLabel.ScaleFactor.Height > Height;\r
+ var needBar = Scaler.ScaleHeight((float)_shipList.Length * LineHeight) > Height;\r
if (!needBar)\r
{\r
ScrollBar.Visible = false;\r
}\r
ScrollBar.Visible = true;\r
ScrollBar.Minimum = 0;\r
- var lines = Max(1, Height / (int)Round(LineHeight * ShipLabel.ScaleFactor.Height));\r
+ var lines = Max(1, Height / Scaler.ScaleHeight(LineHeight));\r
var max = _shipList.Length - lines;\r
var largeChange = Min(lines, max);\r
ScrollBar.LargeChange = largeChange;\r
Size = new Size(ListForm.PanelWidth, LineHeight),\r
BackColor = ShipLabel.ColumnColors[(i + 1) % 2]\r
};\r
- panel.Scale(ShipLabel.ScaleFactor);\r
+ Scaler.Scale(panel);\r
panel.Tag = panel.Location.Y;\r
var labels = new[]\r
{\r
Size = new Size(12, 11),\r
Tag = i * 10 + j\r
};\r
- cb[j].Scale(ShipLabel.ScaleFactor);\r
+ Scaler.Scale(cb[j]);\r
cb[j].CheckedChanged += checkboxGroup_CheckedChanged;\r
}\r
_groupingLabelList.Add(labels);\r
var unused = panel.Handle; // create handle\r
foreach (var label in labels)\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.PresetColor =\r
label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
}\r
Size = new Size(ListForm.PanelWidth, LineHeight),\r
BackColor = ShipLabel.ColumnColors[(i + 1) % 2]\r
};\r
- panel.Scale(ShipLabel.ScaleFactor);\r
+ Scaler.Scale(panel);\r
panel.Tag = panel.Location.Y;\r
var labels = new[]\r
{\r
var unused = panel.Handle; // create handle\r
foreach (var label in labels)\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.PresetColor =\r
label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
}\r
Size = new Size(ListForm.PanelWidth, LineHeight),\r
BackColor = ShipLabel.ColumnColors[(i + 1) % 2]\r
};\r
- panel.Scale(ShipLabel.ScaleFactor);\r
+ Scaler.Scale(panel);\r
var labels = new[]\r
{\r
new ShipLabel\r
var unused = panel.Handle; // create handle\r
foreach (var label in labels)\r
{\r
- label.Scale();\r
+ Scaler.Scale(label);\r
label.PresetColor =\r
label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
}\r