Skip to content

Commit

Permalink
front: fix sticky touch buttons
Browse files Browse the repository at this point in the history
Need to test more thoroughly to make sure this doesn't break anything
  • Loading branch information
paulscode committed Jan 15, 2013
1 parent f67f2f2 commit 02952a4
Showing 1 changed file with 47 additions and 29 deletions.
76 changes: 47 additions & 29 deletions src/paulscode/android/mupen64plusae/input/TouchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,40 +242,58 @@ private void processButtonTouch( boolean touched, int xLocation, int yLocation,
{
// Update the pointer map
if( touched )
{
// Check if this pointer was already mapped to a button
int prevIndex = mPointerMap.get( pid );
if( prevIndex > 0 && prevIndex != index ) {
// Release the previous button
setTouchState( prevIndex, false );
}
mPointerMap.put( pid, index );
}
else
mPointerMap.delete( pid );

// Set the button state
if( index < AbstractController.NUM_N64_BUTTONS )
{
// A single button was pressed
mState.buttons[index] = touched;
}
else
setTouchState( index, touched );
}
}
/**
* Sets the state of a button, and handles the D-Pad diagonals.
*
* @param index Which button is affected.
* @param touched Whether the button is pressed.
*/
private void setTouchState( int index, boolean touched )
{
// Set the button state
if( index < AbstractController.NUM_N64_BUTTONS )
{
// A single button was pressed
mState.buttons[index] = touched;
}
else
{
// Two d-pad buttons pressed simultaneously
switch( index )
{
// Two d-pad buttons pressed simultaneously
switch( index )
{
case TouchMap.DPD_RU:
mState.buttons[DPD_R] = touched;
mState.buttons[DPD_U] = touched;
break;
case TouchMap.DPD_RD:
mState.buttons[DPD_R] = touched;
mState.buttons[DPD_D] = touched;
break;
case TouchMap.DPD_LD:
mState.buttons[DPD_L] = touched;
mState.buttons[DPD_D] = touched;
break;
case TouchMap.DPD_LU:
mState.buttons[DPD_L] = touched;
mState.buttons[DPD_U] = touched;
break;
default:
break;
}
case TouchMap.DPD_RU:
mState.buttons[DPD_R] = touched;
mState.buttons[DPD_U] = touched;
break;
case TouchMap.DPD_RD:
mState.buttons[DPD_R] = touched;
mState.buttons[DPD_D] = touched;
break;
case TouchMap.DPD_LD:
mState.buttons[DPD_L] = touched;
mState.buttons[DPD_D] = touched;
break;
case TouchMap.DPD_LU:
mState.buttons[DPD_L] = touched;
mState.buttons[DPD_U] = touched;
break;
default:
break;
}
}
}
Expand Down

0 comments on commit 02952a4

Please sign in to comment.