[AWT launcher] add PRI, SEC

This commit is contained in:
khanhduytran0 2021-02-03 21:31:14 +07:00
parent bbbd0b61e3
commit 93f49243c2
2 changed files with 61 additions and 12 deletions

View File

@ -16,7 +16,7 @@ import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.utils.*;
import org.lwjgl.glfw.*;
public class JavaGUILauncherActivity extends LoggableActivity {
public class JavaGUILauncherActivity extends LoggableActivity implements View.OnTouchListener {
private static final int MSG_LEFT_MOUSE_BUTTON_CHECK = 1028;
private AWTCanvasView mTextureView;
@ -74,6 +74,9 @@ public class JavaGUILauncherActivity extends LoggableActivity {
CallbackBridge.windowWidth = (int) ((float)displayMetrics.widthPixels * scaleFactor);
CallbackBridge.windowHeight = (int) ((float)displayMetrics.heightPixels * scaleFactor);
System.out.println("WidthHeight: " + CallbackBridge.windowWidth + ":" + CallbackBridge.windowHeight);
findViewById(R.id.installmod_mouse_pri).setOnTouchListener(this);
findViewById(R.id.installmod_mouse_sec).setOnTouchListener(this);
this.touchPad = findViewById(R.id.main_touchpad);
touchPad.setFocusable(false);
@ -228,6 +231,35 @@ public class JavaGUILauncherActivity extends LoggableActivity {
}
}
@Override
public boolean onTouch(View v, MotionEvent e) {
boolean isDown;
switch (e.getActionMasked()) {
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;
default:
return false;
}
switch (v.getId()) {
case R.id.installmod_mouse_pri:
AWTInputBridge.sendMousePress(AWTInputEvent.BUTTON1_DOWN_MASK, isDown);
break;
case R.id.installmod_mouse_sec:
AWTInputBridge.sendMousePress(AWTInputEvent.BUTTON3_DOWN_MASK, isDown);
break;
}
return true;
}
public void placeMouseAdd(float x, float y) {
this.mousePointer.setTranslationX(mousePointer.getTranslationX() + x);
this.mousePointer.setTranslationY(mousePointer.getTranslationY() + y);

View File

@ -13,19 +13,19 @@
android:layout_width="match_parent"
android:id="@+id/installmod_surfaceview"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:id="@+id/main_touchpad">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:id="@+id/main_touchpad">
<ImageView
android:layout_height="27dp"
android:layout_width="18dp"
android:src="@drawable/mouse_pointer"
android:id="@+id/main_mouse_pointer"/>
<ImageView
android:layout_height="27dp"
android:layout_width="18dp"
android:src="@drawable/mouse_pointer"
android:id="@+id/main_mouse_pointer"/>
</LinearLayout>
</LinearLayout>
<Button
android:layout_height="wrap_content"
@ -44,6 +44,23 @@
android:onClick="openLogOutput"
android:layout_toLeftOf="@id/installmod_btn2"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/control_button"
android:text="@string/control_primary"
android:id="@+id/installmod_mouse_pri"
android:layout_alignParentBottom="true"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/control_button"
android:text="@string/control_secondary"
android:id="@+id/installmod_mouse_sec"
android:layout_toRightOf="@id/installmod_mouse_pri"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<LinearLayout