Code[mouse]: change internal function names and use default in AbstractTouchpad

This commit is contained in:
artdeell 2024-04-29 13:07:31 +03:00 committed by Maksim Belov
parent aab37d1fef
commit e302a467a2
2 changed files with 12 additions and 17 deletions

View File

@ -13,7 +13,9 @@ public interface AbstractTouchpad {
* on the screen and send the new cursor position to the game.
* @param vector the array that contains the vector
*/
void applyMotionVector(float[] vector);
default void applyMotionVector(float[] vector) {
applyMotionVector(vector[0], vector[1]);
}
/**
* Apply a motion vector to the mouse in form of the separate X/Y coordinates. This will move the mouse

View File

@ -41,13 +41,13 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
}
/** Enable the touchpad */
private void privateEnable(){
private void _enable(){
setVisibility(VISIBLE);
placeMouseAt(currentDisplayMetrics.widthPixels / 2f, currentDisplayMetrics.heightPixels / 2f);
}
/** Disable the touchpad and hides the mouse */
private void privateDisable(){
private void _disable(){
setVisibility(GONE);
}
@ -55,8 +55,8 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
public boolean switchState(){
mDisplayState = !mDisplayState;
if(!CallbackBridge.isGrabbing()) {
if(mDisplayState) privateEnable();
else privateDisable();
if(mDisplayState) _enable();
else _disable();
}
return mDisplayState;
}
@ -112,10 +112,10 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
}
private void updateGrabState(boolean isGrabbing) {
if(!isGrabbing) {
if(mDisplayState && getVisibility() != VISIBLE) privateEnable();
if(!mDisplayState && getVisibility() == VISIBLE) privateDisable();
if(mDisplayState && getVisibility() != VISIBLE) _enable();
if(!mDisplayState && getVisibility() == VISIBLE) _disable();
}else{
if(getVisibility() != View.GONE) privateDisable();
if(getVisibility() != View.GONE) _disable();
}
}
@ -124,11 +124,6 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
return mDisplayState;
}
@Override
public void applyMotionVector(float[] vector) {
applyMotionVector(vector[0], vector[1]);
}
@Override
public void applyMotionVector(float x, float y) {
mMouseX = Math.max(0, Math.min(currentDisplayMetrics.widthPixels, mMouseX + x * LauncherPreferences.PREF_MOUSESPEED));
@ -141,15 +136,13 @@ public class Touchpad extends View implements GrabListener, AbstractTouchpad {
if(mDisplayState) return;
mDisplayState = true;
if(supposed && CallbackBridge.isGrabbing()) return;
privateEnable();
_enable();
}
@Override
public void disable() {
if(!mDisplayState) return;
mDisplayState = false;
privateDisable();
_disable();
}
}