diff options
author | 2011-02-19 01:08:02 -0800 | |
---|---|---|
committer | 2011-02-19 05:23:10 -0800 | |
commit | 3ea4de826d95c580c28d854c677ded0d15d220a8 (patch) | |
tree | 1bdaeb75ab7922160f2f22b1e62af0ca1e6b759e /libs/ui/Input.cpp | |
parent | d647fdcb9cfa0ab2438d7e37a32c4d48357c9b64 (diff) |
Add new axes for joysticks and mouse wheels.
Added API on InputDevice to query the set of axes available.
Added API on KeyEvent and MotionEvent to convert keycodes and axes
to symbolic name strings for diagnostic purposes.
Added API on KeyEvent to query if a given key code is a gamepad button.
Added a new "axis" element to key layout files to specify the
mapping between raw absolute axis values and motion axis ids.
Expanded the axis bitfield to 64bits to allow for future growth.
Modified the Makefile for keyboard prebuilts to run the keymap
validation tool during the build.
Added layouts for two game controllers.
Added default actions for game pad button keys.
Added more tests.
Fixed a bunch of bugs.
Change-Id: I73f9166c3b3c5bcf4970845b58088ad467525525
Diffstat (limited to 'libs/ui/Input.cpp')
-rw-r--r-- | libs/ui/Input.cpp | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/libs/ui/Input.cpp b/libs/ui/Input.cpp index e3107d50fd..a80320e475 100644 --- a/libs/ui/Input.cpp +++ b/libs/ui/Input.cpp @@ -250,11 +250,59 @@ void KeyEvent::initialize(const KeyEvent& from) { // --- PointerCoords --- +float PointerCoords::getAxisValue(int32_t axis) const { + if (axis < 0 || axis > 63) { + return 0; + } + + uint64_t axisBit = 1LL << axis; + if (!(bits & axisBit)) { + return 0; + } + uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL)); + return values[index]; +} + +status_t PointerCoords::setAxisValue(int32_t axis, float value) { + if (axis < 0 || axis > 63) { + return NAME_NOT_FOUND; + } + + uint64_t axisBit = 1LL << axis; + uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL)); + if (!(bits & axisBit)) { + uint32_t count = __builtin_popcountll(bits); + if (count >= MAX_AXES) { + tooManyAxes(axis); + return NO_MEMORY; + } + bits |= axisBit; + for (uint32_t i = count; i > index; i--) { + values[i] = values[i - 1]; + } + } + values[index] = value; + return OK; +} + +float* PointerCoords::editAxisValue(int32_t axis) { + if (axis < 0 || axis > 63) { + return NULL; + } + + uint64_t axisBit = 1LL << axis; + if (!(bits & axisBit)) { + return NULL; + } + uint32_t index = __builtin_popcountll(bits & (axisBit - 1LL)); + return &values[index]; +} + #ifdef HAVE_ANDROID_OS status_t PointerCoords::readFromParcel(Parcel* parcel) { - bits = parcel->readInt32(); + bits = parcel->readInt64(); - uint32_t count = __builtin_popcount(bits); + uint32_t count = __builtin_popcountll(bits); if (count > MAX_AXES) { return BAD_VALUE; } @@ -266,9 +314,9 @@ status_t PointerCoords::readFromParcel(Parcel* parcel) { } status_t PointerCoords::writeToParcel(Parcel* parcel) const { - parcel->writeInt32(bits); + parcel->writeInt64(bits); - uint32_t count = __builtin_popcount(bits); + uint32_t count = __builtin_popcountll(bits); for (uint32_t i = 0; i < count; i++) { parcel->writeInt32(values[i]); } |