Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2010 The Android Open Source Project |
| 3 | // |
| 4 | // Provides a pipe-based transport for native events in the NDK. |
| 5 | // |
| 6 | #define LOG_TAG "Input" |
| 7 | |
| 8 | //#define LOG_NDEBUG 0 |
| 9 | |
| 10 | #include <ui/Input.h> |
| 11 | |
| 12 | namespace android { |
| 13 | |
| 14 | // class InputEvent |
| 15 | |
| 16 | void InputEvent::initialize(int32_t deviceId, int32_t nature) { |
| 17 | mDeviceId = deviceId; |
| 18 | mNature = nature; |
| 19 | } |
| 20 | |
| 21 | // class KeyEvent |
| 22 | |
| 23 | void KeyEvent::initialize( |
| 24 | int32_t deviceId, |
| 25 | int32_t nature, |
| 26 | int32_t action, |
| 27 | int32_t flags, |
| 28 | int32_t keyCode, |
| 29 | int32_t scanCode, |
| 30 | int32_t metaState, |
| 31 | int32_t repeatCount, |
| 32 | nsecs_t downTime, |
| 33 | nsecs_t eventTime) { |
| 34 | InputEvent::initialize(deviceId, nature); |
| 35 | mAction = action; |
| 36 | mFlags = flags; |
| 37 | mKeyCode = keyCode; |
| 38 | mScanCode = scanCode; |
| 39 | mMetaState = metaState; |
| 40 | mRepeatCount = repeatCount; |
| 41 | mDownTime = downTime; |
| 42 | mEventTime = eventTime; |
| 43 | } |
| 44 | |
| 45 | // class MotionEvent |
| 46 | |
| 47 | void MotionEvent::initialize( |
| 48 | int32_t deviceId, |
| 49 | int32_t nature, |
| 50 | int32_t action, |
| 51 | int32_t edgeFlags, |
| 52 | int32_t metaState, |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 53 | float xOffset, |
| 54 | float yOffset, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 55 | float xPrecision, |
| 56 | float yPrecision, |
| 57 | nsecs_t downTime, |
| 58 | nsecs_t eventTime, |
| 59 | size_t pointerCount, |
| 60 | const int32_t* pointerIds, |
| 61 | const PointerCoords* pointerCoords) { |
| 62 | InputEvent::initialize(deviceId, nature); |
| 63 | mAction = action; |
| 64 | mEdgeFlags = edgeFlags; |
| 65 | mMetaState = metaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 66 | mXOffset = xOffset; |
| 67 | mYOffset = yOffset; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 68 | mXPrecision = xPrecision; |
| 69 | mYPrecision = yPrecision; |
| 70 | mDownTime = downTime; |
| 71 | mPointerIds.clear(); |
| 72 | mPointerIds.appendArray(pointerIds, pointerCount); |
| 73 | mSampleEventTimes.clear(); |
| 74 | mSamplePointerCoords.clear(); |
| 75 | addSample(eventTime, pointerCoords); |
| 76 | } |
| 77 | |
| 78 | void MotionEvent::addSample( |
| 79 | int64_t eventTime, |
| 80 | const PointerCoords* pointerCoords) { |
| 81 | mSampleEventTimes.push(eventTime); |
| 82 | mSamplePointerCoords.appendArray(pointerCoords, getPointerCount()); |
| 83 | } |
| 84 | |
| 85 | void MotionEvent::offsetLocation(float xOffset, float yOffset) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 86 | mXOffset += xOffset; |
| 87 | mYOffset += yOffset; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | } // namespace android |