aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Input/HLE/InputManager.cs
blob: bc38cf5a2c7c1560a79b9e2251be962716181ddf (plain) (blame)
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
using System;

namespace Ryujinx.Input.HLE
{
    public class InputManager : IDisposable
    {
        public IGamepadDriver KeyboardDriver { get; private set; }
        public IGamepadDriver GamepadDriver { get; private set; }
        public IGamepadDriver MouseDriver { get; private set; }

        public InputManager(IGamepadDriver keyboardDriver, IGamepadDriver gamepadDriver)
        {
            KeyboardDriver = keyboardDriver;
            GamepadDriver = gamepadDriver;
        }

        public void SetMouseDriver(IGamepadDriver mouseDriver)
        {
            MouseDriver?.Dispose();

            MouseDriver = mouseDriver;
        }

        public NpadManager CreateNpadManager()
        {
            return new NpadManager(KeyboardDriver, GamepadDriver, MouseDriver);
        }
        
        public TouchScreenManager CreateTouchScreenManager()
        {
            if (MouseDriver == null)
            {
                throw new InvalidOperationException("Mouse Driver has not been initialized.");
            }

            return new TouchScreenManager(MouseDriver.GetGamepad("0") as IMouse);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                KeyboardDriver?.Dispose();
                GamepadDriver?.Dispose();
                MouseDriver?.Dispose();
            }
        }

        public void Dispose()
        {
            Dispose(true);
        }
    }
}