@Override public boolean onTouch(View v, MotionEvent event) { // Determine the button state to apply based on the MotionEvent action flag. // TODO: This will not work when Axis support is added. Make sure to refactor this when that // time comes // The reason it won't work is that when moving an axis, you would get the event // MotionEvent.ACTION_MOVE. // // TODO: Refactor this so we detect either Axis movements or button presses so we don't run two // loops all the time. // int buttonState = (event.getAction() == MotionEvent.ACTION_DOWN) ? ButtonState.PRESSED : ButtonState.RELEASED; // Check if there was a touch within the bounds of a drawable. for (InputOverlayDrawableButton button : overlayButtons) { if (button.getBounds().contains((int) event.getX(), (int) event.getY())) NativeLibrary.onTouchEvent(0, button.getId(), buttonState); } for (InputOverlayDrawableJoystick joystick : overlayJoysticks) { joystick.TrackEvent(event); int[] axisIDs = joystick.getAxisIDs(); float[] axises = joystick.getAxisValues(); for (int i = 0; i < 4; i++) NativeLibrary.onTouchAxisEvent(0, axisIDs[i], axises[i]); } return true; }
@Override public void draw(Canvas canvas) { super.draw(canvas); for (InputOverlayDrawableButton button : overlayButtons) { button.draw(canvas); } for (InputOverlayDrawableJoystick joystick : overlayJoysticks) { joystick.draw(canvas); } }