-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat[touch_input]: Begin reimplementing touch input
- Loading branch information
Showing
6 changed files
with
312 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Touchpad.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...vlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/InGUIEventProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package net.kdt.pojavlaunch.customcontrols.mouse; | ||
|
||
import android.view.MotionEvent; | ||
|
||
import net.kdt.pojavlaunch.LwjglGlfwKeycode; | ||
import net.kdt.pojavlaunch.Tools; | ||
import net.kdt.pojavlaunch.prefs.LauncherPreferences; | ||
|
||
import org.lwjgl.glfw.CallbackBridge; | ||
|
||
public class InGUIEventProcessor implements TouchEventProcessor { | ||
private final PointerTracker mTracker = new PointerTracker(); | ||
private boolean mIsMouseDown = false; | ||
private final float mScaleFactor; | ||
public static final int FINGER_SCROLL_THRESHOLD = (int) Tools.dpToPx(6); | ||
public InGUIEventProcessor(float scaleFactor) { | ||
mScaleFactor = scaleFactor; | ||
} | ||
@Override | ||
public boolean processTouchEvent(MotionEvent motionEvent) { | ||
switch (motionEvent.getActionMasked()) { | ||
case MotionEvent.ACTION_DOWN: | ||
mTracker.startTracking(motionEvent); | ||
sendTouchCoords(motionEvent.getX(), motionEvent.getY()); | ||
enableMouse(); | ||
break; | ||
case MotionEvent.ACTION_MOVE: | ||
int pointerCount = motionEvent.getPointerCount(); | ||
int pointerIndex = mTracker.trackEvent(motionEvent); | ||
float mainPointerX = motionEvent.getX(pointerIndex); | ||
float mainPointerY = motionEvent.getY(pointerIndex); | ||
if(pointerCount == 1 || LauncherPreferences.PREF_DISABLE_GESTURES) { | ||
sendTouchCoords(mainPointerX, mainPointerY); | ||
if(!mIsMouseDown) enableMouse(); | ||
}else { | ||
float[] motionVector = mTracker.getMotionVector(); | ||
int hScroll = ((int) motionVector[0]) / FINGER_SCROLL_THRESHOLD; | ||
int vScroll = ((int) motionVector[1]) / FINGER_SCROLL_THRESHOLD; | ||
if(hScroll != 0 | vScroll != 0) CallbackBridge.sendScroll(hScroll, vScroll); | ||
} | ||
break; | ||
case MotionEvent.ACTION_UP: | ||
disableMouse(); | ||
} | ||
return true; | ||
} | ||
|
||
private void sendTouchCoords(float x, float y) { | ||
CallbackBridge.mouseX = x * mScaleFactor; | ||
CallbackBridge.mouseY = y * mScaleFactor; | ||
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY); | ||
} | ||
|
||
private void enableMouse() { | ||
CallbackBridge.sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT, true); | ||
mIsMouseDown = true; | ||
} | ||
|
||
private void disableMouse() { | ||
CallbackBridge.sendMouseButton(LwjglGlfwKeycode.GLFW_MOUSE_BUTTON_LEFT, false); | ||
mIsMouseDown = false; | ||
} | ||
|
||
@Override | ||
public void cancelPendingActions() { | ||
disableMouse(); | ||
} | ||
} |
Oops, something went wrong.