| 182 | |
| 183 | |
| 184 | int PlatformAndroid::onInputEvent(struct android_app* app, AInputEvent* event) |
| 185 | { |
| 186 | static int activePointerIdx; |
| 187 | |
| 188 | if (AInputEvent_getSource(event) & AINPUT_SOURCE_TOUCHSCREEN) |
| 189 | { |
| 190 | int action = AKeyEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK; |
| 191 | int pointer = (AKeyEvent_getAction(event) & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; |
| 192 | |
| 193 | // Only need two pointers for now |
| 194 | //if(pointer > 1) |
| 195 | // break; |
| 196 | static int s_tumbLastFrameDown[2] = { 0,0 }; |
| 197 | |
| 198 | switch(action){ |
| 199 | case AMOTION_EVENT_ACTION_MOVE: |
| 200 | case AMOTION_EVENT_ACTION_DOWN: |
| 201 | case AMOTION_EVENT_ACTION_POINTER_DOWN: |
| 202 | { |
| 203 | int pointerCount = AMotionEvent_getPointerCount(event); |
| 204 | for(int i = 0; i < pointerCount; ++i) |
| 205 | { |
| 206 | int pointerIndex = i; |
| 207 | int x = AMotionEvent_getX(event, pointerIndex); |
| 208 | int y = AMotionEvent_getY(event, pointerIndex); |
| 209 | |
| 210 | const Math::float2 controlSize(getWindowWidth() / 16, getWindowHeight() / 16); |
| 211 | |
| 212 | mouseMoveEvent(x,y); |
| 213 | mouseButtonEvent(0, KEY_ACTION_PRESS, 0); |
| 214 | |
| 215 | // Movement |
| 216 | int movementX = 0; |
| 217 | int movementY = 0; |
| 218 | int thumb = 0; |
| 219 | |
| 220 | if(y > getWindowHeight() / 2) |
| 221 | { |
| 222 | if(x < getWindowWidth() / 2) |
| 223 | { |
| 224 | // Left stick |
| 225 | movementX = getWindowWidth() / 6; |
| 226 | movementY = getWindowHeight() - (getWindowHeight() / 6); |
| 227 | thumb = 0; |
| 228 | |
| 229 | Math::float2 dir = Math::float2(static_cast<float>(x - movementX), static_cast<float>(y - movementY)); |
| 230 | |
| 231 | //LogInfo() << "Thumb Source" << thumb << ": " << dir.toString(); |
| 232 | |
| 233 | // Set max thumbstick position |
| 234 | |
| 235 | dir.x = dir.x > 0 ? std::min(controlSize.x, dir.x) : std::max(-controlSize.x, dir.x); |
| 236 | dir.y = dir.y > 0 ? std::min(controlSize.y, dir.y) : std::max(-controlSize.y, dir.y); |
| 237 | |
| 238 | // Normalize // FIXME: Analogue input not working properly because the normalize drops all distance information |
| 239 | dir.normalize(); |
| 240 | |
| 241 | //LogInfo() << "Thumb " << thumb << ": " << dir.toString(); |