]> git.tdb.fi Git - libs/gui.git/commitdiff
Add a type enumeration for devices
authorMikko Rasa <tdb@tdb.fi>
Thu, 17 Nov 2022 09:54:28 +0000 (11:54 +0200)
committerMikko Rasa <tdb@tdb.fi>
Thu, 17 Nov 2022 22:41:43 +0000 (00:41 +0200)
This will help in storing control bindings in a way that isn't tied to
a particular instance of a device.

source/input/device.cpp
source/input/device.h
source/input/generic/gamecontroller.cpp
source/input/gesturedetector.cpp
source/input/hub.cpp
source/input/keyboard.cpp
source/input/linux/gamecontroller.cpp
source/input/mouse.cpp
source/input/touchscreen.cpp
source/input/windows/gamecontroller.cpp

index 228313616c62a92b0bb75d0c370f224944c4b883..7dbe8ea274812d4ecd047a16c4162a747b3b6fbb 100644 (file)
@@ -4,7 +4,8 @@
 namespace Msp {
 namespace Input {
 
-Device::Device()
+Device::Device(DeviceType t):
+       type(t)
 { }
 
 Device::~Device()
index b42ed3fde4991feb8d87b05258831585db57efec..be708e2636a2ae88010c5d9ba79a31b0abf2835b 100644 (file)
@@ -17,6 +17,16 @@ public:
 };
 
 
+enum DeviceType
+{
+       UNSPECIFIED,
+       KEYBOARD,
+       MOUSE,
+       TOUCH_SURFACE,
+       GAME_CONTROLLER
+};
+
+
 /**
 Base class for input devices.  Input devices have two types of controls:
 buttons and axes.  Buttons are either on or off.  Axes have a floating point
@@ -47,14 +57,16 @@ public:
        sigc::signal<bool, unsigned, float, float>::accumulated<EventAccumulator> signal_axis_motion;
 
 protected:
+       DeviceType type;
        std::string name;
        std::vector<char> buttons;
        std::vector<float> axes;
 
-       Device();
+       Device(DeviceType);
 public:
        virtual ~Device();
 
+       DeviceType get_type() const { return type; }
        const std::string &get_name() const { return name; }
        bool get_button_state(unsigned) const;
        float get_axis_value(unsigned) const;
index 9ab6738ab24ebc7b4a68de226bada7029a91a5a8..8f14e02d92d8ded287de3713e30b04d31d590652 100644 (file)
@@ -6,7 +6,8 @@ using namespace std;
 namespace Msp {
 namespace Input {
 
-GameController::GameController(unsigned)
+GameController::GameController(unsigned):
+       Device(GAME_CONTROLLER)
 {
        throw device_not_available("GameController");
 }
index 97e3d56f0fc53a3e4a7eb0e271a2a0c060303603..d53c07f7c47c827142513a0e148f776536dbd039 100644 (file)
@@ -10,6 +10,7 @@ namespace Msp {
 namespace Input {
 
 GestureDetector::GestureDetector(Touchscreen &ts):
+       Device(UNSPECIFIED),
        touchscreen(ts),
        current_gesture(GESTURE_NONE),
        pending_tap(GESTURE_NONE),
index 635ea8a6c935fe9485fee30c87dc55386a3f56ed..b83d10d22431b6b89b7126c9f5fb7a61f38c97fe 100644 (file)
@@ -10,7 +10,8 @@ using namespace std;
 namespace Msp {
 namespace Input {
 
-Hub::Hub()
+Hub::Hub():
+       Device(UNSPECIFIED)
 {
        name = "Hub";
 }
index 0a690d1b686a569a790d187224a3fb4e725e93ec..30a6145618090ea75801f8cceb994ad4bb3f9a9d 100644 (file)
@@ -6,6 +6,7 @@ namespace Msp {
 namespace Input {
 
 Keyboard::Keyboard(Graphics::Window &w):
+       Device(KEYBOARD),
        window(w)
 {
        name = "Keyboard";
index f0139e96baeb4b04f150bf463c5fa7f84701a83f..d0029e8fe3c4bbad1249bb4fdcea6b1baca1d7b6 100644 (file)
@@ -16,6 +16,7 @@ namespace Input {
 vector<string> GameController::Private::detected_controllers;
 
 GameController::GameController(unsigned index):
+       Device(GAME_CONTROLLER),
        event_disp(0)
 {
        if(!detect_done)
@@ -79,11 +80,11 @@ void GameController::tick()
                unsigned count = len/sizeof(js_event);
                for(unsigned i=0; i<count; ++i)
                {
-                       unsigned type = events[i].type&0x7F;
+                       unsigned etype = events[i].type&0x7F;
                        bool init = events[i].type&JS_EVENT_INIT;
-                       if(type==JS_EVENT_AXIS)
+                       if(etype==JS_EVENT_AXIS)
                                set_axis_value(events[i].number, events[i].value/32768.0f, !init);
-                       else if(type==JS_EVENT_BUTTON)
+                       else if(etype==JS_EVENT_BUTTON)
                                set_button_state(events[i].number, events[i].value, !init);
                }
 
index 1b41e3654517c2adb12d02e5cb10821df70a5764..48d0f6922338652763cea0c0b1578ee9d74ff04e 100644 (file)
@@ -5,6 +5,7 @@ namespace Msp {
 namespace Input {
 
 Mouse::Mouse(Graphics::Window &w):
+       Device(MOUSE),
        window(w)
 {
        name = "Mouse";
index c4de688a76d32efddcf3905f7a4bdeded22e204b..f2e06f6bd49f463b56ff0b37ac39e8b4a3762d73 100644 (file)
@@ -6,6 +6,7 @@ namespace Msp {
 namespace Input {
 
 Touchscreen::Touchscreen(Graphics::Window &w):
+       Device(TOUCH_SURFACE),
        window(w)
 {
        if(!is_available())
index 43a947b5e3fb214e3f8d37ec524ec9895fdee001..1d06bfea2fa3652474959682be793f987907b74e 100644 (file)
@@ -10,7 +10,8 @@ namespace Input {
 
 vector<unsigned> GameController::Private::detected_controllers;
 
-GameController::GameController(unsigned index)
+GameController::GameController(unsigned index):
+       Device(GAME_CONTROLLER)
 {
        if(!detect_done)
                detect();