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

luttje / Key2Joy / 6598306412

21 Oct 2023 03:54PM UTC coverage: 45.09% (-7.4%) from 52.519%
6598306412

Pull #50

github

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

751 of 2289 branches covered (0.0%)

Branch coverage included in aggregate %.

2384 of 2384 new or added lines in 80 files covered. (100.0%)

3845 of 7904 relevant lines covered (48.65%)

15964.61 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.Diagnostics;
3
using System.Drawing;
4
using System.Windows.Forms;
5
using Key2Joy.LowLevelInput;
6

7
namespace Key2Joy.Gui;
8

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

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

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

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

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

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

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

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

53
        this.Invoke((MethodInvoker)delegate
×
54
        {
×
55
            this.fadeTimer.Stop();
×
56
            this.fadeTimer.Start();
×
57
            this.Invalidate();
×
58
        });
×
59
    }
×
60

61
    private void FadeTimer_Tick(object sender, EventArgs e)
62
    {
63
        if ((DateTime.Now - this.lastActivityOccurred).TotalSeconds <= 2)
×
64
        {
65
            this.Invalidate();
×
66
        }
67
        else
68
        {
69
            this.fadeTimer.Stop();
×
70
        }
71
    }
×
72

73
    private void DeviceControl_Paint(object sender, PaintEventArgs e)
74
    {
75
        var owner = (Control)sender;
×
76
        var g = e.Graphics;
×
77

78
        var elapsed = (DateTime.Now - this.lastActivityOccurred).TotalSeconds;
×
79

80
        var currentColor = this.InterpolateColors(Color.White, Color.Gold, elapsed / FADE_DURATION);
×
81
        using var brush = new SolidBrush(currentColor);
×
82
        g.FillRectangle(brush, BORDER_WIDTH, BORDER_WIDTH, owner.Width - (BORDER_WIDTH * 2), owner.Height - (BORDER_WIDTH * 2));
×
83
    }
×
84

85
    private Color InterpolateColors(Color start, Color end, double ratio)
86
    {
87
        var r = (int)((start.R * (1 - ratio)) + (end.R * ratio));
×
88
        var g = (int)((start.G * (1 - ratio)) + (end.G * ratio));
×
89
        var b = (int)((start.B * (1 - ratio)) + (end.B * ratio));
×
90

91
        return Color.FromArgb(
×
92
            Math.Max(r, 0),
×
93
            Math.Max(g, 0),
×
94
            Math.Max(b, 0)
×
95
        );
×
96
    }
97
}
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