• 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/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
            this.fadeTimer.Stop();
×
55
            this.fadeTimer.Start();
×
56
            this.Invalidate();
×
57
        });
×
58
    }
×
59

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

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

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

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

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

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