From 9b7641df07a082ff38f0e80200b7ec2f2d1761a2 Mon Sep 17 00:00:00 2001 From: Benlitz Date: Sat, 14 Sep 2013 16:09:44 +0000 Subject: [PATCH] input: added a GetAvailableDevices function to retrieve device names. --- src/input/input.cpp | 10 ++++++++++ src/input/input.h | 32 +++++++++++++++++--------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index b5498cf8..73485308 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -22,6 +22,16 @@ namespace lol Array InputDevice::devices; bool InputDevice::m_capturemouse; +Array InputDevice::GetAvailableDevices() +{ + Array result; + for (int i = 0; i < devices.Count(); ++i) + { + result.Push(devices[i]->m_name); + } + return result; +} + void InputDeviceInternal::AddKey(const char* name) { m_keynames.Push(name); diff --git a/src/input/input.h b/src/input/input.h index ea6d3391..d8516b7f 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -19,41 +19,43 @@ namespace lol class InputDevice { public: - /** Get the name of this input device */ + /** Gets the name of this input device */ const String& GetName(); - /** Get the index of the corresponding key, needed to call GetKey */ + /** Gets the index of the corresponding key, needed to call GetKey */ int GetKeyIndex(const char* name) const { return GetItemIndex(name, m_keynames); } - /** Get the index of the corresponding axis, needed to call GetAxis */ + /** Gets the index of the corresponding axis, needed to call GetAxis */ int GetAxisIndex(const char* name) const { return GetItemIndex(name, m_axisnames); } - /** Get the index of the corresponding cursor, needed to call GetCursor */ + /** Gets the index of the corresponding cursor, needed to call GetCursor */ int GetCursorIndex(const char* name) const { return GetItemIndex(name, m_cursornames); } - /** Get the current state of the given key, true being pressed and false being released */ + /** Gets the current state of the given key, true being pressed and false being released */ bool GetKey(int index) const { return m_keys[index]; } - /** Get the current value of the given axis. Devices should cap this value between -1 and 1 as much as possible, through it is not guaranteed */ + /** Gets the current value of the given axis. Devices should cap this value between -1 and 1 as much as possible, through it is not guaranteed */ float GetAxis(int index) const { return m_axis[index].m1 * m_axis[index].m2; } - /** Get the current value of the given cursor, 0,0 being the bottom-left corner and 1,1 being the top-right corner */ + /** Gets the current value of the given cursor, 0,0 being the bottom-left corner and 1,1 being the top-right corner */ vec2 GetCursor(int index) const { return m_cursors[index].m1; } - /** Get the coordinate of the pixel the cursor is currently over, 0,0 being the bottom-left corner. */ + /** Gets the coordinate of the pixel the cursor is currently over, 0,0 being the bottom-left corner. */ ivec2 GetCursorPixel(int index) const { return m_cursors[index].m2; } - /** Set a per-device-axis sensitivity factor. The value returned by the operating system will be multiplied by this value before being returned by GetAxis */ + /** Sets a per-device-axis sensitivity factor. The value returned by the operating system will be multiplied by this value before being returned by GetAxis */ void SetAxisSensitivity(int index, float sensitivity) { m_axis[index].m2 = sensitivity; } - /** Get the per-device-axis sensitivity factor. The value returned by the operating system will be multiplied by this value before being returned by GetAxis */ + /** Gets the per-device-axis sensitivity factor. The value returned by the operating system will be multiplied by this value before being returned by GetAxis */ float GetAxisSensitivity(int index) const { return m_axis[index].m2; } - /** Get a list of the name of all available keys in this device */ + /** Gets a list of the name of all available keys in this device */ const Array& GetAllKeys() const { return m_keynames; } - /** Get a list of the name of all available axis in this device */ + /** Gets a list of the name of all available axis in this device */ const Array& GetAllAxis() const { return m_axisnames; } - /** Get a list of the name of all available cursors in this device */ + /** Gets a list of the name of all available cursors in this device */ const Array& GetAllCursors() const { return m_cursornames; } - /** Get an input device by its name */ + /** Gets a list of the name of all available input devices */ + static Array GetAvailableDevices(); + /** Gets an input device by its name */ static InputDevice* Get(const char* name) { return GetDevice(name); } - /** Set whether the mouse cursor should be captured. */ + /** Sets whether the mouse cursor should be captured. */ static void CaptureMouse(bool activated) { m_capturemouse = activated; } protected: