OSDN Git Service

Viewの下をMainWindowとListWindowに分ける
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / ControlsArranger.cs
1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\r
3 // Licensed under the Apache License, Version 2.0 (the "License");\r
4 // you may not use this file except in compliance with the License.\r
5 // You may obtain a copy of the License at\r
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\r
9 // Unless required by applicable law or agreed to in writing, software\r
10 // distributed under the License is distributed on an "AS IS" BASIS,\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 // See the License for the specific language governing permissions and\r
13 // limitations under the License.\r
14 \r
15 using System;\r
16 using System.Drawing;\r
17 using System.Windows.Forms;\r
18 \r
19 namespace KancolleSniffer.View\r
20 {\r
21     public abstract class ControlsArranger\r
22     {\r
23         public abstract Control[] Controls { get; }\r
24 \r
25         public Panel BackPanel;\r
26 \r
27         public void Arrange(Control parent)\r
28         {\r
29             SetParent(parent);\r
30             Scale();\r
31         }\r
32 \r
33         public void Arrange(Control parent, Color color)\r
34         {\r
35             if (BackPanel != null)\r
36             {\r
37                 ArrangeBackPanel(parent, color);\r
38                 parent = BackPanel;\r
39             }\r
40             Arrange(parent);\r
41             SetBackColor(color);\r
42         }\r
43 \r
44         private void ArrangeBackPanel(Control parent, Color color)\r
45         {\r
46             parent.Controls.Add(BackPanel);\r
47             BackPanel.BackColor = color;\r
48             Scaler.Scale(BackPanel);\r
49         }\r
50 \r
51         private void SetParent(Control parent)\r
52         {\r
53             parent.Controls.AddRange(Controls);\r
54         }\r
55 \r
56         private void Scale()\r
57         {\r
58             foreach (var control in Controls)\r
59                 Scaler.Scale(control);\r
60         }\r
61 \r
62         private void SetBackColor(Color color)\r
63         {\r
64             foreach (var control in Controls)\r
65                 control.BackColor = color;\r
66         }\r
67 \r
68         public void SetClickHandler(EventHandler onClick)\r
69         {\r
70             foreach (var control in Controls)\r
71                 control.Click += onClick;\r
72         }\r
73 \r
74         public void SetTag(int index)\r
75         {\r
76             foreach (var control in Controls)\r
77                 control.Tag = index;\r
78         }\r
79 \r
80         public void Move(Point offset)\r
81         {\r
82             if (BackPanel == null)\r
83                 return;\r
84             var pos = BackPanel.Location;\r
85             pos.Offset(offset);\r
86             // 単にLocation.Offsetではだめで代入する必要がある\r
87             BackPanel.Location = pos;\r
88         }\r
89     }\r
90 }