1 // Copyright (C) 2020 Kazuhiro Fujieda <fujieda@users.osdn.me>
\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
7 // http://www.apache.org/licenses/LICENSE-2.0
\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
16 using System.Drawing;
\r
18 using System.Windows.Forms;
\r
19 using KancolleSniffer.Model;
\r
21 namespace KancolleSniffer.View
\r
23 public class KDockPanel : Panel
\r
25 private const int TopMargin = 3;
\r
26 private const int LeftMargin = 2;
\r
27 private const int LabelHeight = 12;
\r
28 private const int LineHeight = 15;
\r
29 private readonly KDockLabels[] _labels = new KDockLabels[DockInfo.DockCount];
\r
31 private class KDockLabels
\r
33 public Label Number { get; set; }
\r
34 public Label Timer { get; set; }
\r
39 BorderStyle = BorderStyle.FixedSingle;
\r
40 for (var i = 0; i < _labels.Length; i++)
\r
42 var y = TopMargin + i * LineHeight;
\r
43 _labels[i] = new KDockLabels
\r
47 Location = new Point(LeftMargin, y),
\r
49 Text = "第" + new[] {"一", "二", "三", "四"}[i]
\r
53 Location = new Point(LeftMargin + 26, y),
\r
54 Size = new Size(47, LabelHeight),
\r
55 TextAlign = ContentAlignment.MiddleRight
\r
59 Controls.AddRange(_labels.SelectMany(l => new Control[] {l.Number, l.Timer}).ToArray());
\r
62 public void UpdateTimers(Sniffer sniffer, DateTime now)
\r
64 foreach (var entry in _labels.Zip(sniffer.KDock,
\r
65 (label, kdock) => new {label = label.Timer, timer = kdock}))
\r
67 SetTimerColor(entry.label, entry.timer, now);
\r
68 entry.label.Text = entry.timer.ToString(now);
\r
72 private void SetTimerColor(Label label, AlarmTimer timer, DateTime now)
\r
74 label.ForeColor = timer.IsFinished(now) ? CUDColors.Red : Color.Black;
\r