Skip to content

Commit

Permalink
Merge pull request #198 from Sonicadvance1/Android-onscreenconfigure
Browse files Browse the repository at this point in the history
Make configuring the onscreen controls less annoying.
  • Loading branch information
Sonicadvance1 committed Mar 23, 2014
2 parents 4c1cb65 + b76351e commit c7335dc
Showing 1 changed file with 15 additions and 2 deletions.
Expand Up @@ -41,6 +41,10 @@ public final class OverlayConfigButton extends Button implements OnTouchListener
// float buttonY = sPrefs.getFloat(buttonId+"-Y", -1f);
//
private final String buttonId;

// The offset of the press while moving the button
private float moveOffsetX, moveOffsetY;

private Drawable resizeDrawable(Drawable image, float scale)
{
// Retrieve screen dimensions.
Expand Down Expand Up @@ -97,11 +101,20 @@ public boolean onTouch(View v, MotionEvent event)
{
switch(event.getAction())
{
// Get the offset of the press within the button
// The event X and Y locations are the offset within the button, not the screen
case MotionEvent.ACTION_DOWN:
{
moveOffsetX = event.getX();
moveOffsetY = event.getY();
return true;
}

// Only change the X/Y coordinates when we move the button.
case MotionEvent.ACTION_MOVE:
{
setX(getX() + event.getX());
setY(getY() + event.getY());
setX(getX() + event.getX() - moveOffsetX);
setY(getY() + event.getY() - moveOffsetY);
return true;
}

Expand Down

0 comments on commit c7335dc

Please sign in to comment.