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

luttje / Key2Joy / 6738508468

02 Nov 2023 09:38PM UTC coverage: 43.012% (-0.8%) from 43.795%
6738508468

Pull #66

github

web-flow
Merge b13824648 into 6a3d02880
Pull Request #66: Bugfix recently discovered input bugs

754 of 2413 branches covered (0.0%)

Branch coverage included in aggregate %.

203 of 203 new or added lines in 9 files covered. (100.0%)

3859 of 8312 relevant lines covered (46.43%)

11968.52 hits per line

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

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

6
namespace Key2Joy.Gui;
7

8
public partial class DeviceControl : UserControl
9
{
10
    private const int FADE_DURATION = 2;
11
    private const int BORDER_WIDTH = 2;
12
    private DateTime lastActivityOccurred = DateTime.Now;
×
13
    private readonly Timer fadeTimer = new();
×
14
    private readonly IGamePadInfo device;
15

16
    private DeviceControl()
×
17
    {
18
        this.InitializeComponent();
×
19

20
        this.fadeTimer.Interval = 50;
×
21
        this.fadeTimer.Tick += this.FadeTimer_Tick;
×
22
        this.fadeTimer.Start();
×
23

24
        this.pnlDevice.Paint += this.DeviceControl_Paint;
×
25
        this.Layout += this.DeviceControl_Layout;
×
26
    }
×
27

28
    public DeviceControl(IGamePadInfo device)
29
        : this()
×
30
    {
31
        this.device = device;
×
32
        this.lblIndex.Text = $"#{device.Index}";
×
33
        this.lblDevice.Text = device.Name;
×
34
        //this.picImage.Image = null;
35
        device.ActivityOccurred += this.Device_ActivityOccurred;
×
36
    }
×
37

38
    private void DeviceControl_Layout(object sender, LayoutEventArgs e)
39
    {
40
        if (this.Height == this.Width)
×
41
        {
42
            return;
×
43
        }
44

45
        this.Height = this.Width;
×
46
    }
×
47

48
    private void Device_ActivityOccurred(object sender, GamePadActivityOccurredEventArgs e)
49
    {
50
        this.lastActivityOccurred = DateTime.Now;
×
51

52
        this.Invoke((MethodInvoker)delegate
×
53
        {
×
54
            try
×
55
            {
×
56
                this.fadeTimer.Stop();
×
57
                this.fadeTimer.Start();
×
58
                this.Invalidate();
×
59
            }
×
60
            catch (System.ComponentModel.Win32Exception)
×
61
            {
×
62
                // Ignore (happens if we spam the chkArmed in MainForm)
×
63
            }
×
64
        });
×
65
    }
×
66

67
    private void FadeTimer_Tick(object sender, EventArgs e)
68
    {
69
        if ((DateTime.Now - this.lastActivityOccurred).TotalSeconds <= 2)
×
70
        {
71
            this.Invalidate();
×
72
        }
73
        else
74
        {
75
            this.fadeTimer.Stop();
×
76
        }
77
    }
×
78

79
    private void DeviceControl_Paint(object sender, PaintEventArgs e)
80
    {
81
        var owner = (Control)sender;
×
82
        var g = e.Graphics;
×
83

84
        var elapsed = (DateTime.Now - this.lastActivityOccurred).TotalSeconds;
×
85

86
        var currentColor = this.InterpolateColors(Color.White, Color.Gold, elapsed / FADE_DURATION);
×
87
        using var brush = new SolidBrush(currentColor);
×
88
        g.FillRectangle(brush, BORDER_WIDTH, BORDER_WIDTH, owner.Width - (BORDER_WIDTH * 2), owner.Height - (BORDER_WIDTH * 2));
×
89
    }
×
90

91
    private Color InterpolateColors(Color start, Color end, double ratio)
92
    {
93
        var r = (int)((start.R * (1 - ratio)) + (end.R * ratio));
×
94
        var g = (int)((start.G * (1 - ratio)) + (end.G * ratio));
×
95
        var b = (int)((start.B * (1 - ratio)) + (end.B * ratio));
×
96

97
        return Color.FromArgb(
×
98
            Math.Max(r, 0),
×
99
            Math.Max(g, 0),
×
100
            Math.Max(b, 0)
×
101
        );
×
102
    }
103
}
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

© 2026 Coveralls, Inc