• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / Key2Joy / 6602636543

22 Oct 2023 08:16AM UTC coverage: 44.104% (-8.4%) from 52.519%
6602636543

Pull #50

github

web-flow
Merge cf342a7b3 into 14b7ce9a7
Pull Request #50: Add XInput in preparation for gamepad triggers + add xmldoc

764 of 2383 branches covered (0.0%)

Branch coverage included in aggregate %.

3060 of 3060 new or added lines in 106 files covered. (100.0%)

3896 of 8183 relevant lines covered (47.61%)

15812.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/Key2Joy.Gui/NotificationBannerControl.cs
1
using System;
2
using System.Drawing;
3
using System.Windows.Forms;
4

5
namespace Key2Joy.Gui;
6

7
public enum NotificationBannerStyle
8
{
9
    Information = 0,
10
    Warning = 1,
11
    Error = 2,
12
}
13

14
public partial class NotificationBannerControl : UserControl
15
{
16
    private const int BORDER_WIDTH = 2;
17
    private const int BORDER_MARGIN = 2;
18

19
    private readonly string message;
20
    private readonly NotificationBannerStyle style;
21
    private readonly Timer timeLeftTimer;
22

23
    public NotificationBannerControl(
×
24
        string message,
×
25
        NotificationBannerStyle style = NotificationBannerStyle.Information,
×
26
        TimeSpan? duration = null
×
27
    )
×
28
    {
29
        this.InitializeComponent();
×
30

31
        this.message = message;
×
32
        this.style = style;
×
33

34
        this.lblMessage.Text = message;
×
35

36
        duration ??= TimeSpan.FromSeconds(10);
×
37

38
        this.timeLeftTimer = new Timer
×
39
        {
×
40
            Interval = (int)Math.Min(1000, duration.Value.TotalMilliseconds)
×
41
        };
×
42
        this.timeLeftTimer.Tick += (s, e) =>
×
43
        {
×
44
            // Show the remaining time in the btnClose every second, close when times up
×
45
            duration -= TimeSpan.FromSeconds(1);
×
46
            this.btnClose.Text = $"✖ {duration.Value.TotalSeconds:0}s";
×
47

×
48
            if (duration.Value.TotalSeconds <= 0)
×
49
            {
×
50
                this.Close();
×
51
            }
×
52
        };
×
53
        this.timeLeftTimer.Start();
×
54

55
        switch (this.style)
×
56
        {
57
            case NotificationBannerStyle.Information:
58
                this.lblMessage.ForeColor = Color.White;
×
59
                this.BackColor = Color.DarkBlue;
×
60
                break;
×
61

62
            case NotificationBannerStyle.Warning:
63
                this.lblMessage.ForeColor = Color.Black;
×
64
                this.BackColor = Color.Gold;
×
65
                break;
×
66

67
            case NotificationBannerStyle.Error:
68
                this.lblMessage.ForeColor = Color.White;
×
69
                this.BackColor = Color.Crimson;
×
70
                break;
71
        }
72
    }
×
73

74
    private void Close()
75
    {
76
        this.timeLeftTimer.Stop();
×
77
        this.timeLeftTimer.Dispose();
×
78
        this.Parent?.Controls.Remove(this);
×
79
    }
×
80

81
    private void BtnClose_Click(object sender, System.EventArgs e)
82
        => this.Close();
×
83

84
    private void NotificationBannerControl_Paint(object sender, PaintEventArgs e)
85
    {
86
        const ButtonBorderStyle borderStyle = ButtonBorderStyle.Dashed;
87
        var borderColor = Color.WhiteSmoke;
×
88

89
        if (this.style == NotificationBannerStyle.Warning)
×
90
        {
91
            borderColor = Color.Black;
×
92
        }
93

94
        ControlPaint.DrawBorder(
×
95
            e.Graphics,
×
96
            new Rectangle(
×
97
                this.ClientRectangle.X + BORDER_MARGIN,
×
98
                this.ClientRectangle.Y + BORDER_MARGIN,
×
99
                this.ClientRectangle.Width - (BORDER_MARGIN * 2),
×
100
                this.ClientRectangle.Height - (BORDER_MARGIN * 2)
×
101
            ),
×
102
            borderColor,
×
103
            BORDER_WIDTH,
×
104
            borderStyle,
×
105
            borderColor,
×
106
            BORDER_WIDTH,
×
107
            borderStyle,
×
108
            borderColor,
×
109
            BORDER_WIDTH,
×
110
            borderStyle,
×
111
            borderColor,
×
112
            BORDER_WIDTH,
×
113
            borderStyle
×
114
        );
×
115
    }
×
116
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc