aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Input/HLE/TouchScreenManager.cs
blob: ffa8eeacc50c1bb6af4a8c47b960e3c74e76daf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Ryujinx.HLE;
using Ryujinx.HLE.HOS.Services.Hid;
using System;

namespace Ryujinx.Input.HLE
{
    public class TouchScreenManager : IDisposable
    {
        private readonly IMouse _mouse;
        private Switch _device;

        public TouchScreenManager(IMouse mouse)
        {
            _mouse = mouse;
        }

        public void Initialize(Switch device)
        {
            _device = device;
        }

        public bool Update(bool isFocused, float aspectRatio = 0)
        {
            if (!isFocused)
            {
                _device.Hid.Touchscreen.Update();

                return false;
            }

            if (aspectRatio > 0)
            {
                var snapshot = IMouse.GetMouseStateSnapshot(_mouse);
                var touchPosition = IMouse.GetTouchPosition(snapshot.Position, _mouse.ClientSize, aspectRatio);

                TouchPoint currentPoint = new TouchPoint
                {
                    X = (uint)touchPosition.X,
                    Y = (uint)touchPosition.Y,

                    // Placeholder values till more data is acquired
                    DiameterX = 10,
                    DiameterY = 10,
                    Angle = 90
                };

                _device.Hid.Touchscreen.Update(currentPoint);

                return true;
            }

            return false;
        }

        public void Dispose() { }
    }
}