OSDN Git Service

複数のラベルをまとめて処理するのをControlsArrangerに委譲する
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Fri, 17 May 2019 16:07:35 +0000 (01:07 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Tue, 21 May 2019 08:22:17 +0000 (17:22 +0900)
KancolleSniffer/KancolleSniffer.csproj
KancolleSniffer/View/ControlsArranger.cs [new file with mode: 0644]
KancolleSniffer/View/FleetPanel.cs
KancolleSniffer/View/ListScroller.cs
KancolleSniffer/View/QuestPanel.cs
KancolleSniffer/View/RepairListForMain.cs

index c32ed88..5ea1d23 100644 (file)
@@ -94,6 +94,7 @@
     <Compile Include="ConfirmDialog.Designer.cs">\r
       <DependentUpon>ConfirmDialog.cs</DependentUpon>\r
     </Compile>\r
+    <Compile Include="View\ControlsArranger.cs" />\r
     <Compile Include="View\CUDColors.cs" />\r
     <Compile Include="Model\DockInfo.cs" />\r
     <Compile Include="Model\Fleet.cs" />\r
diff --git a/KancolleSniffer/View/ControlsArranger.cs b/KancolleSniffer/View/ControlsArranger.cs
new file mode 100644 (file)
index 0000000..68b611a
--- /dev/null
@@ -0,0 +1,60 @@
+// 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 abstract class ControlsArranger\r
+    {\r
+        public abstract Control[] Controls { get; }\r
+\r
+        public void Arrange(Control parent)\r
+        {\r
+            SetParent(parent);\r
+            Scale();\r
+        }\r
+\r
+        public void Arrange(Control parent, Color color)\r
+        {\r
+            Arrange(parent);\r
+            SetBackColor(color);\r
+        }\r
+\r
+        private void SetParent(Control parent)\r
+        {\r
+            parent.Controls.AddRange(Controls);\r
+        }\r
+\r
+        private void SetBackColor(Color color)\r
+        {\r
+            foreach (var control in Controls)\r
+                control.BackColor = color;\r
+        }\r
+\r
+        private void Scale()\r
+        {\r
+            foreach (var control in Controls)\r
+                Scaler.Scale(control);\r
+        }\r
+\r
+        public void SetClickHandler(EventHandler onClick)\r
+        {\r
+            foreach (var control in Controls)\r
+                control.Click += onClick;\r
+        }\r
+    }\r
+}
\ No newline at end of file
index 062f32b..5dab5a1 100644 (file)
@@ -13,7 +13,6 @@
 // limitations under the License.\r
 \r
 using System;\r
-using System.Collections;\r
 using System.Collections.Generic;\r
 using System.Drawing;\r
 using System.Linq;\r
@@ -279,7 +278,7 @@ namespace KancolleSniffer.View
                 CreateLabels(i);\r
         }\r
 \r
-        private class FleetLabels : IEnumerable<ShipLabel>\r
+        private class FleetLabels : ControlsArranger\r
         {\r
             public ShipLabel Fleet { get; set; }\r
             public ShipLabel Name { get; set; }\r
@@ -287,10 +286,7 @@ namespace KancolleSniffer.View
             public ShipLabel EquipColor { get; set; }\r
             public ShipLabel Spec { get; set; }\r
 \r
-            public IEnumerator<ShipLabel> GetEnumerator() =>\r
-                ((IEnumerable<ShipLabel>)new[] {Fleet, Name, Equip, EquipColor, Spec}).GetEnumerator();\r
-\r
-            IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();\r
+            public override Control[] Controls => new Control[] {Fleet, Name, Equip, EquipColor, Spec};\r
         }\r
 \r
         private void CreateLabels(int i)\r
@@ -315,13 +311,8 @@ namespace KancolleSniffer.View
             };\r
             _labelList.Add(labels);\r
             _panelList.Add(lbp);\r
-            lbp.Controls.AddRange(labels.Cast<Control>().ToArray());\r
+            labels.Arrange(lbp, CustomColors.ColumnColors.BrightFirst(i));\r
             Controls.Add(lbp);\r
-            foreach (var label in labels)\r
-            {\r
-                Scaler.Scale(label);\r
-                label.BackColor = CustomColors.ColumnColors.BrightFirst(i);\r
-            }\r
         }\r
 \r
         private void SetRecords()\r
index 72f3a77..b749748 100644 (file)
@@ -37,7 +37,7 @@ namespace KancolleSniffer.View
 \r
         public event Action EndScroll;\r
 \r
-        public ListScroller(Panel panel, Label[] topLabels, Label[] bottomLabels)\r
+        public ListScroller(Panel panel, Control[] topLabels, Control[] bottomLabels)\r
         {\r
             _panel = panel;\r
             panel.Paint += (obj, ev) => DrawMark();\r
@@ -45,7 +45,7 @@ namespace KancolleSniffer.View
             SetBottomEventHandler(bottomLabels);\r
         }\r
 \r
-        public void SetTopEventHandler(Label[] top)\r
+        public void SetTopEventHandler(Control[] top)\r
         {\r
             foreach (var label in top)\r
             {\r
@@ -55,7 +55,7 @@ namespace KancolleSniffer.View
             _topScrollRepeatTimer.Tick += (obj, e) => ScrollUp();\r
         }\r
 \r
-        public void SetBottomEventHandler(Label[] bottom)\r
+        public void SetBottomEventHandler(Control[] bottom)\r
         {\r
             foreach (var label in bottom)\r
             {\r
index 0a37708..0959ff8 100644 (file)
@@ -18,18 +18,16 @@ using System.Linq;
 using System.Windows.Forms;\r
 using KancolleSniffer.Model;\r
 \r
-// ReSharper disable CoVariantArrayConversion\r
-\r
 namespace KancolleSniffer.View\r
 {\r
-    public class QuestLabels\r
+    public class QuestLabels : ControlsArranger\r
     {\r
         public ShipLabel Color { get; set; }\r
         public ShipLabel Name { get; set; }\r
         public ShipLabel Count { get; set; }\r
         public ShipLabel Progress { get; set; }\r
 \r
-        public ShipLabel[] Labels => new[] {Color, Count, Progress, Name};\r
+        public override Control[] Controls => new Control[] {Color, Count, Progress, Name};\r
     }\r
 \r
     public class QuestPanel : PanelWithToolTip\r
@@ -79,9 +77,7 @@ namespace KancolleSniffer.View
                     }\r
                 };\r
                 _labels[i].Name.DoubleClick += onDoubleClick;\r
-                Controls.AddRange(_labels[i].Labels);\r
-                foreach (var label in _labels[i].Labels)\r
-                    Scaler.Scale(label);\r
+                _labels[i].Arrange(this);\r
             }\r
             ResumeLayout();\r
             SetupListScroller();\r
@@ -96,7 +92,7 @@ namespace KancolleSniffer.View
 \r
         private void SetupListScroller()\r
         {\r
-            _listScroller = new ListScroller(this, _labels[0].Labels, _labels[_lines - 1].Labels)\r
+            _listScroller = new ListScroller(this, _labels[0].Controls, _labels[_lines - 1].Controls)\r
             {\r
                 Lines = _lines,\r
                 Padding = TopMargin\r
index c93557a..a3129ce 100644 (file)
@@ -26,11 +26,11 @@ namespace KancolleSniffer.View
     {\r
         private const int PanelPadding = 5;\r
         private const int LineHeight = 15;\r
-        private RepairListLabels[] _repairLabels;\r
+        private RepairLabels[] _repairLabels;\r
         private ShipStatus[] _repairList = new ShipStatus[0];\r
         private ListScroller _listScroller;\r
 \r
-        private class RepairListLabels\r
+        private class RepairLabels : ControlsArranger\r
         {\r
             public ShipLabel Fleet { get; set; }\r
             public ShipLabel Name { get; set; }\r
@@ -38,18 +38,18 @@ namespace KancolleSniffer.View
             public ShipLabel Damage { get; set; }\r
             public ShipLabel BackGround { private get; set; }\r
 \r
-            public ShipLabel[] Labels => new[] {Fleet, Damage, Time, Name, BackGround};\r
+            public override Control[] Controls => new[] {Fleet, Damage, Time, Name, BackGround};\r
         }\r
 \r
         public void CreateLabels(EventHandler onClick)\r
         {\r
-            _repairLabels = new RepairListLabels[Lines];\r
+            _repairLabels = new RepairLabels[Lines];\r
             SuspendLayout();\r
             for (var i = 0; i < _repairLabels.Length; i++)\r
             {\r
                 var y = PanelPadding + 1 + i * LineHeight;\r
                 const int height = 12;\r
-                _repairLabels[i] = new RepairListLabels\r
+                _repairLabels[i] = new RepairLabels\r
                 {\r
                     Fleet = new ShipLabel {Location = new Point(0, y), Size = new Size(11, height)},\r
                     Damage = new ShipLabel {Location = new Point(119, y), Size = new Size(5, height - 1)},\r
@@ -61,13 +61,8 @@ namespace KancolleSniffer.View
                         Size = new Size(Width, height + 2)\r
                     }\r
                 };\r
-                Controls.AddRange(_repairLabels[i].Labels);\r
-                foreach (var label in _repairLabels[i].Labels)\r
-                {\r
-                    Scaler.Scale(label);\r
-                    label.BackColor = CustomColors.ColumnColors.BrightFirst(i);\r
-                    label.Click += onClick;\r
-                }\r
+                _repairLabels[i].Arrange(this, CustomColors.ColumnColors.BrightFirst(i));\r
+                _repairLabels[i].SetClickHandler(onClick);\r
             }\r
             ResumeLayout();\r
             SetupListScroller();\r
@@ -84,7 +79,7 @@ namespace KancolleSniffer.View
 \r
         private void SetupListScroller()\r
         {\r
-            _listScroller = new ListScroller(this, _repairLabels[0].Labels, _repairLabels.Last().Labels)\r
+            _listScroller = new ListScroller(this, _repairLabels[0].Controls, _repairLabels.Last().Controls)\r
             {\r
                 Lines = _repairLabels.Length,\r
                 Padding = PanelPadding\r