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

luttje / Key2Joy / 9836432308

08 Jul 2024 08:46AM UTC coverage: 43.937% (-0.8%) from 44.758%
9836432308

Pull #66

github

web-flow
Merge aa8186077 into 3bfa3ba36
Pull Request #66: Bugfix recently discovered input bugs

793 of 2455 branches covered (32.3%)

Branch coverage included in aggregate %.

19 of 278 new or added lines in 20 files covered. (6.83%)

43 existing lines in 11 files now uncovered.

4012 of 8481 relevant lines covered (47.31%)

1567.5 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
        {
×
NEW
54
            try
×
NEW
55
            {
×
NEW
56
                this.fadeTimer.Stop();
×
NEW
57
                this.fadeTimer.Start();
×
NEW
58
                this.Invalidate();
×
NEW
59
            }
×
NEW
60
            catch (System.ComponentModel.Win32Exception)
×
NEW
61
            {
×
NEW
62
                // Ignore (happens if we spam the chkArmed in MainForm)
×
NEW
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