1 // Copyright (C) 2019 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
17 using System.Windows.Forms;
\r
19 namespace KancolleSniffer.View
\r
21 public class ListScroller
\r
23 private readonly Panel _panel;
\r
25 public int Padding { get; set; }
\r
27 public int Position { get; set; }
\r
29 public int Lines { get; set; }
\r
31 public int DataCount { get; set; }
\r
33 public event Action Update;
\r
35 public ListScroller(Panel panel, Label[] topLabels, Label[] bottomLabels)
\r
38 panel.Paint += (obj, ev) => DrawMark();
\r
39 SetTopEventHandler(topLabels);
\r
40 SetBottomEventHandler(bottomLabels);
\r
43 public void SetTopEventHandler(Label[] top)
\r
45 foreach (var label in top)
\r
47 label.MouseEnter += TopLineOnMouseEnter;
\r
48 label.MouseLeave += TopLineOnMouseLeave;
\r
50 _topScrollRepeatTimer.Tick += TopLineOnMouseEnter;
\r
53 public void SetBottomEventHandler(Label[] bottom)
\r
55 foreach (var label in bottom)
\r
57 label.MouseEnter += BottomLineOnMouseEnter;
\r
58 label.MouseLeave += BottomLineOnMouseLeave;
\r
60 _bottomScrollRepeatTimer.Tick += BottomLineOnMouseEnter;
\r
63 private readonly Timer _topScrollRepeatTimer = new Timer {Interval = 100};
\r
64 private readonly Timer _bottomScrollRepeatTimer = new Timer {Interval = 100};
\r
66 private void TopLineOnMouseEnter(object sender, EventArgs e)
\r
72 _topScrollRepeatTimer.Start();
\r
75 private void TopLineOnMouseLeave(object sender, EventArgs e)
\r
77 _topScrollRepeatTimer.Stop();
\r
80 private void BottomLineOnMouseEnter(object sender, EventArgs e)
\r
82 if (Position + Lines >= DataCount)
\r
86 _bottomScrollRepeatTimer.Start();
\r
89 private void BottomLineOnMouseLeave(object sender, EventArgs e)
\r
91 _bottomScrollRepeatTimer.Stop();
\r
94 public void DrawMark()
\r
96 using (var g = _panel.CreateGraphics())
\r
98 var topBrush = Position > 0 ? Brushes.Black : new SolidBrush(_panel.BackColor);
\r
99 g.FillPolygon(topBrush,
\r
102 new PointF(_panel.Width * 0.45f, Padding), new PointF(_panel.Width * 0.55f, Padding),
\r
103 new PointF(_panel.Width * 0.5f, 0), new PointF(_panel.Width * 0.45f, Padding)
\r
105 var bottomBrush = Position + Lines < DataCount
\r
107 : new SolidBrush(_panel.BackColor);
\r
108 g.FillPolygon(bottomBrush,
\r
111 new PointF(_panel.Width * 0.45f, _panel.Height - Padding - 2),
\r
112 new PointF(_panel.Width * 0.55f, _panel.Height - Padding - 2),
\r
113 new PointF(_panel.Width * 0.5f, _panel.Height - 2),
\r
114 new PointF(_panel.Width * 0.45f, _panel.Height - Padding - 2)
\r