mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2025-12-20 21:40:15 -07:00
Fix the real mouse and grabbing
This commit is contained in:
parent
c9f10317bb
commit
3b124c55ca
1 changed files with 58 additions and 115 deletions
|
|
@ -274,6 +274,7 @@ public class BaseMainActivity extends LoggableActivity {
|
||||||
// and other input controls. In this case, you are only
|
// and other input controls. In this case, you are only
|
||||||
// interested in events where the touch position changed.
|
// interested in events where the touch position changed.
|
||||||
// int index = event.getActionIndex();
|
// int index = event.getActionIndex();
|
||||||
|
|
||||||
int action = event.getActionMasked();
|
int action = event.getActionMasked();
|
||||||
|
|
||||||
float x = event.getX();
|
float x = event.getX();
|
||||||
|
|
@ -336,6 +337,21 @@ public class BaseMainActivity extends LoggableActivity {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View p1, MotionEvent e)
|
public boolean onTouch(View p1, MotionEvent e)
|
||||||
{
|
{
|
||||||
|
int mptrIndex = -1;
|
||||||
|
for(int i = 0; i < e.getPointerCount(); i++) {
|
||||||
|
if(e.getToolType(i) == MotionEvent.TOOL_TYPE_MOUSE) { //if there's at least one mouse...
|
||||||
|
mptrIndex = i; //index it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(mptrIndex != -1) {
|
||||||
|
//handle mouse events by just sending the coords of the new point in touch event
|
||||||
|
int x = ((int) e.getX(mptrIndex)) / scaleFactor;
|
||||||
|
int y = ((int) e.getY(mptrIndex)) / scaleFactor;
|
||||||
|
CallbackBridge.mouseX = x;
|
||||||
|
CallbackBridge.mouseY = y;
|
||||||
|
CallbackBridge.sendCursorPos(x,y);
|
||||||
|
return true; // event handled sucessfully
|
||||||
|
}//if index IS -1, continue handling as an usual touch event
|
||||||
// System.out.println("Pre touch, isTouchInHotbar=" + Boolean.toString(isTouchInHotbar) + ", action=" + MotionEvent.actionToString(e.getActionMasked()));
|
// System.out.println("Pre touch, isTouchInHotbar=" + Boolean.toString(isTouchInHotbar) + ", action=" + MotionEvent.actionToString(e.getActionMasked()));
|
||||||
int x = ((int) e.getX()) / scaleFactor;
|
int x = ((int) e.getX()) / scaleFactor;
|
||||||
int y = ((int) e.getY()) / scaleFactor;
|
int y = ((int) e.getY()) / scaleFactor;
|
||||||
|
|
@ -594,82 +610,25 @@ public class BaseMainActivity extends LoggableActivity {
|
||||||
builder.setLength(0);
|
builder.setLength(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isDown = false;
|
|
||||||
switch (e.getActionMasked()) {
|
|
||||||
/*
|
|
||||||
case MotionEvent.ACTION_DOWN: // 0
|
|
||||||
case MotionEvent.ACTION_POINTER_DOWN: // 5
|
|
||||||
CallbackBridge.sendPrepareGrabInitialPos();
|
|
||||||
|
|
||||||
CallbackBridge.sendMouseKeycode(CallbackBridge.mouseLeft ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, CallbackBridge.getCurrentMods(), true);
|
|
||||||
initialX = x;
|
|
||||||
initialY = y;
|
|
||||||
|
|
||||||
sendMouseButton(CallbackBridge.mouseLeft ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT, false);
|
|
||||||
|
|
||||||
// theHandler.sendEmptyMessageDelayed(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP: // 1
|
|
||||||
case MotionEvent.ACTION_CANCEL: // 3
|
|
||||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
|
||||||
// CallbackBridge.sendCursorPos(x, y);
|
|
||||||
// CallbackBridge.sendMouseKeycode(rightOverride ? LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT : LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, 0, true);
|
|
||||||
CallbackBridge.putMouseEventWithCoords(CallbackBridge.mouseLeft ? (byte) 0 : (byte) 1, (byte) 1, x, y);
|
|
||||||
|
|
||||||
// triggeredLeftMouseButton = false;
|
|
||||||
// theHandler.removeMessages(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK);
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_DOWN: // 0
|
|
||||||
case MotionEvent.ACTION_POINTER_DOWN: // 5
|
|
||||||
isDown = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP: // 1
|
|
||||||
case MotionEvent.ACTION_CANCEL: // 3
|
|
||||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
|
||||||
isDown = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
|
||||||
CallbackBridge.sendCursorPos(x, y);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_BUTTON_PRESS:
|
|
||||||
sendMouseButtonUnconverted(e.getActionButton(), isDown);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_SCROLL:
|
|
||||||
CallbackBridge.sendScroll(e.getAxisValue(MotionEvent.AXIS_HSCROLL), e.getAxisValue(MotionEvent.AXIS_VSCROLL));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
debugText.setText(CallbackBridge.DEBUG_STRING.toString());
|
debugText.setText(CallbackBridge.DEBUG_STRING.toString());
|
||||||
CallbackBridge.DEBUG_STRING.setLength(0);
|
CallbackBridge.DEBUG_STRING.setLength(0);
|
||||||
|
switch (e.getActionMasked()) {
|
||||||
return true;
|
case MotionEvent.ACTION_MOVE:
|
||||||
// If onClick fail with false, change back to true
|
CallbackBridge.sendCursorPos(x, y);
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_BUTTON_PRESS:
|
||||||
|
return sendMouseButtonUnconverted(e.getActionButton(), true);
|
||||||
|
case MotionEvent.ACTION_BUTTON_RELEASE:
|
||||||
|
return sendMouseButtonUnconverted(e.getActionButton(), false);
|
||||||
|
case MotionEvent.ACTION_SCROLL:
|
||||||
|
CallbackBridge.sendScroll(e.getAxisValue(MotionEvent.AXIS_HSCROLL), e.getAxisValue(MotionEvent.AXIS_VSCROLL));
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
minecraftGLView.setOnHoverListener(new View.OnHoverListener(){
|
|
||||||
@Override
|
|
||||||
public boolean onHover(View v, MotionEvent e) {
|
|
||||||
if (!CallbackBridge.isGrabbing() && mIsResuming) {
|
|
||||||
// return glTouchListener.onTouch(v, e);
|
|
||||||
int x = ((int) e.getX()) / scaleFactor;
|
|
||||||
int y = ((int) e.getY()) / scaleFactor;
|
|
||||||
CallbackBridge.mouseX = x;
|
|
||||||
CallbackBridge.mouseY = y;
|
|
||||||
CallbackBridge.sendCursorPos(x, y);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
minecraftGLView.setOnTouchListener(glTouchListener);
|
minecraftGLView.setOnTouchListener(glTouchListener);
|
||||||
minecraftGLView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener(){
|
minecraftGLView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener(){
|
||||||
|
|
||||||
|
|
@ -721,20 +680,6 @@ public class BaseMainActivity extends LoggableActivity {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
OnGenericMotionListener gmlistener = new OnGenericMotionListener(){
|
|
||||||
@Override
|
|
||||||
public boolean onGenericMotion(View v, MotionEvent event) {
|
|
||||||
switch (event.getActionMasked()) {
|
|
||||||
case MotionEvent.ACTION_SCROLL:
|
|
||||||
CallbackBridge.sendScroll((double) event.getAxisValue(MotionEvent.AXIS_VSCROLL), (double) event.getAxisValue(MotionEvent.AXIS_HSCROLL));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
minecraftGLView.setOnGenericMotionListener(gmlistener);
|
|
||||||
touchPad.setOnGenericMotionListener(gmlistener);
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Tools.showError(this, e, true);
|
Tools.showError(this, e, true);
|
||||||
}
|
}
|
||||||
|
|
@ -757,7 +702,7 @@ public class BaseMainActivity extends LoggableActivity {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
|
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
|
||||||
boolean isDown = false;
|
int mouseCursorIndex = -1;
|
||||||
if(ev.getSource() == InputDevice.SOURCE_CLASS_JOYSTICK) {
|
if(ev.getSource() == InputDevice.SOURCE_CLASS_JOYSTICK) {
|
||||||
CallbackBridge.nativePutControllerAxes((FloatBuffer)FloatBuffer.allocate(8)
|
CallbackBridge.nativePutControllerAxes((FloatBuffer)FloatBuffer.allocate(8)
|
||||||
.put(ev.getAxisValue(MotionEvent.AXIS_X))
|
.put(ev.getAxisValue(MotionEvent.AXIS_X))
|
||||||
|
|
@ -770,33 +715,30 @@ public class BaseMainActivity extends LoggableActivity {
|
||||||
.put(ev.getAxisValue(MotionEvent.AXIS_HAT_Y))
|
.put(ev.getAxisValue(MotionEvent.AXIS_HAT_Y))
|
||||||
.flip());
|
.flip());
|
||||||
return true;//consume the cum chalice
|
return true;//consume the cum chalice
|
||||||
}else if(ev.getSource() == InputDevice.SOURCE_MOUSE){
|
}else {
|
||||||
switch(ev.getActionMasked()) {
|
for(int i = 0; i < ev.getPointerCount(); i++) {
|
||||||
case MotionEvent.ACTION_DOWN: // 0
|
if(ev.getToolType(i) == MotionEvent.TOOL_TYPE_MOUSE) {
|
||||||
case MotionEvent.ACTION_POINTER_DOWN: // 5
|
mouseCursorIndex = i;
|
||||||
isDown = true;
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP: // 1
|
|
||||||
case MotionEvent.ACTION_CANCEL: // 3
|
|
||||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
|
||||||
isDown = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
|
||||||
CallbackBridge.sendCursorPos((int)ev.getX(), (int)ev.getY());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_BUTTON_PRESS:
|
|
||||||
sendMouseButtonUnconverted(ev.getActionButton(),isDown);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MotionEvent.ACTION_SCROLL:
|
|
||||||
CallbackBridge.sendScroll(ev.getAxisValue(MotionEvent.AXIS_HSCROLL), ev.getAxisValue(MotionEvent.AXIS_VSCROLL));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return true;
|
if(mouseCursorIndex == -1) return false; // we cant consoom that, theres no mice!
|
||||||
}else return false;
|
switch(ev.getActionMasked()) {
|
||||||
|
case MotionEvent.ACTION_HOVER_MOVE:
|
||||||
|
CallbackBridge.mouseX = (int) (ev.getX(mouseCursorIndex)/scaleFactor);
|
||||||
|
CallbackBridge.mouseY = (int) (ev.getY(mouseCursorIndex)/scaleFactor);
|
||||||
|
CallbackBridge.sendCursorPos((int) (ev.getX(mouseCursorIndex)/scaleFactor), (int) (ev.getY(mouseCursorIndex)/scaleFactor));
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_SCROLL:
|
||||||
|
CallbackBridge.sendScroll((double) ev.getAxisValue(MotionEvent.AXIS_VSCROLL), (double) ev.getAxisValue(MotionEvent.AXIS_HSCROLL));
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_BUTTON_PRESS:
|
||||||
|
return sendMouseButtonUnconverted(ev.getActionButton(),true);
|
||||||
|
case MotionEvent.ACTION_BUTTON_RELEASE:
|
||||||
|
return sendMouseButtonUnconverted(ev.getActionButton(),false);
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
byte[] kevArray = new byte[8];
|
byte[] kevArray = new byte[8];
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -1180,8 +1122,8 @@ public class BaseMainActivity extends LoggableActivity {
|
||||||
CallbackBridge.sendMouseKeycode(button, CallbackBridge.getCurrentMods(), status);
|
CallbackBridge.sendMouseKeycode(button, CallbackBridge.getCurrentMods(), status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMouseButtonUnconverted(int button, boolean status) {
|
public static boolean sendMouseButtonUnconverted(int button, boolean status) {
|
||||||
int glfwButton = 0;
|
int glfwButton = -256;
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case MotionEvent.BUTTON_PRIMARY:
|
case MotionEvent.BUTTON_PRIMARY:
|
||||||
glfwButton = LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT;
|
glfwButton = LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT;
|
||||||
|
|
@ -1193,8 +1135,9 @@ public class BaseMainActivity extends LoggableActivity {
|
||||||
glfwButton = LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT;
|
glfwButton = LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_RIGHT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if(glfwButton == -256) return false;
|
||||||
sendMouseButton(glfwButton, status);
|
sendMouseButton(glfwButton, status);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculateMcScale() {
|
public void calculateMcScale() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue