OSDN Git Service

一覧の防空のリサイズとスケールがおかしいのを直す
[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         }\r
31 \r
32         public void Arrange(Control parent, Color color)\r
33         {\r
34             if (BackPanel != null)\r
35             {\r
36                 ArrangeBackPanel(parent, color);\r
37                 parent = BackPanel;\r
38             }\r
39             Arrange(parent);\r
40             SetBackColor(color);\r
41         }\r
42 \r
43         private void ArrangeBackPanel(Control parent, Color color)\r
44         {\r
45             parent.Controls.Add(BackPanel);\r
46             BackPanel.BackColor = color;\r
47         }\r
48 \r
49         private void SetParent(Control parent)\r
50         {\r
51             parent.Controls.AddRange(Controls);\r
52         }\r
53 \r
54         public void Scale()\r
55         {\r
56             if (BackPanel != null)\r
57             {\r
58                 Scaler.Scale(BackPanel);\r
59                 return;\r
60             }\r
61             foreach (var control in Controls)\r
62                 Scaler.Scale(control);\r
63         }\r
64 \r
65         private void SetBackColor(Color color)\r
66         {\r
67             foreach (var control in Controls)\r
68                 control.BackColor = color;\r
69         }\r
70 \r
71         public void SetClickHandler(EventHandler onClick)\r
72         {\r
73             foreach (var control in Controls)\r
74                 control.Click += onClick;\r
75         }\r
76 \r
77         public void SetTag(int index)\r
78         {\r
79             foreach (var control in Controls)\r
80                 control.Tag = index;\r
81         }\r
82 \r
83         public void Move(Point offset)\r
84         {\r
85             if (BackPanel == null)\r
86                 return;\r
87             var pos = BackPanel.Location;\r
88             pos.Offset(offset);\r
89             // 単にLocation.Offsetではだめで代入する必要がある\r
90             BackPanel.Location = pos;\r
91         }\r
92     }\r
93 }