mirror of
https://github.com/amwatson/CitraVR.git
synced 2024-09-20 03:11:40 +02:00
add button handling for UI Ribbon
This commit is contained in:
parent
686550c6c4
commit
09cdf9cfdb
2 changed files with 44 additions and 4 deletions
|
@ -1,13 +1,43 @@
|
||||||
package org.citra.citra_emu.vr.ui
|
package org.citra.citra_emu.vr.ui
|
||||||
|
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.widget.Button
|
||||||
|
import android.widget.ImageButton
|
||||||
|
import org.citra.citra_emu.NativeLibrary
|
||||||
import org.citra.citra_emu.R
|
import org.citra.citra_emu.R
|
||||||
import org.citra.citra_emu.vr.VrActivity
|
import org.citra.citra_emu.vr.VrActivity
|
||||||
|
|
||||||
class VrRibbonLayer(activity: VrActivity) : VrUILayer(activity, R.layout.vr_ribbon) {
|
class VrRibbonLayer(activity: VrActivity) : VrUILayer(activity, R.layout.vr_ribbon) {
|
||||||
override fun onSurfaceCreated() {
|
override fun onSurfaceCreated() {
|
||||||
super.onSurfaceCreated()
|
super.onSurfaceCreated()
|
||||||
|
window?.findViewById<Button>(R.id.buttonSelect)?.setOnTouchListener { _, motionEvent ->
|
||||||
|
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
|
||||||
|
NativeLibrary.ButtonType.BUTTON_SELECT,
|
||||||
|
if (motionEvent.action == MotionEvent.ACTION_DOWN)
|
||||||
|
NativeLibrary.ButtonState.PRESSED
|
||||||
|
else NativeLibrary.ButtonState.RELEASED)
|
||||||
|
false
|
||||||
|
}
|
||||||
|
window?.findViewById<ImageButton>(R.id.buttonHome)?.setOnTouchListener { view, motionEvent ->
|
||||||
|
if (motionEvent.action == MotionEvent.ACTION_DOWN) {
|
||||||
|
(view as ImageButton).setImageResource(R.drawable.button_home_pressed)
|
||||||
|
} else {
|
||||||
|
(view as ImageButton).setImageResource(R.drawable.button_home)
|
||||||
|
}
|
||||||
|
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
|
||||||
|
NativeLibrary.ButtonType.BUTTON_HOME,
|
||||||
|
if (motionEvent.action == MotionEvent.ACTION_DOWN)
|
||||||
|
NativeLibrary.ButtonState.PRESSED
|
||||||
|
else NativeLibrary.ButtonState.RELEASED)
|
||||||
|
false
|
||||||
|
}
|
||||||
|
window?.findViewById<Button>(R.id.buttonStart)?.setOnTouchListener { _, motionEvent ->
|
||||||
|
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice,
|
||||||
|
NativeLibrary.ButtonType.BUTTON_START,
|
||||||
|
if (motionEvent.action == MotionEvent.ACTION_DOWN)
|
||||||
|
NativeLibrary.ButtonState.PRESSED
|
||||||
|
else NativeLibrary.ButtonState.RELEASED)
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -697,9 +697,10 @@ private:
|
||||||
mKeyboardLayer->SendClickToUI(cursorPos2d, triggerState.currentState);
|
mKeyboardLayer->SendClickToUI(cursorPos2d, triggerState.currentState);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// No dialogs/popups that should impede normal cursor interaction with
|
||||||
|
// applicable panels
|
||||||
shouldRenderCursor = mGameSurfaceLayer->GetRayIntersectionWithPanel(
|
shouldRenderCursor = mGameSurfaceLayer->GetRayIntersectionWithPanel(
|
||||||
start, end, cursorPos2d, cursorPose3d);
|
start, end, cursorPos2d, cursorPose3d);
|
||||||
ALOG_INPUT_VERBOSE("Cursor 2D coords: {} {}", cursorPos2d.x, cursorPos2d.y);
|
|
||||||
if (triggerState.currentState == 0 && triggerState.changedSinceLastSync) {
|
if (triggerState.currentState == 0 && triggerState.changedSinceLastSync) {
|
||||||
jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID,
|
jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID,
|
||||||
cursorPos2d.x, cursorPos2d.y, 0);
|
cursorPos2d.x, cursorPos2d.y, 0);
|
||||||
|
@ -713,6 +714,14 @@ private:
|
||||||
jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID,
|
jni->CallVoidMethod(mActivityObject, mSendClickToWindowMethodID,
|
||||||
cursorPos2d.x, cursorPos2d.y, 2);
|
cursorPos2d.x, cursorPos2d.y, 2);
|
||||||
}
|
}
|
||||||
|
if (!shouldRenderCursor) {
|
||||||
|
shouldRenderCursor = mRibbonLayer->GetRayIntersectionWithPanel(
|
||||||
|
start, end, cursorPos2d, cursorPose3d);
|
||||||
|
if (triggerState.changedSinceLastSync) {
|
||||||
|
mRibbonLayer->SendClickToUI(cursorPos2d, triggerState.currentState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!shouldRenderCursor) {
|
if (!shouldRenderCursor) {
|
||||||
// Handling this here means L2/R2 are liable to
|
// Handling this here means L2/R2 are liable to
|
||||||
// be slightly out of sync with the other
|
// be slightly out of sync with the other
|
||||||
|
@ -774,6 +783,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldRenderCursor) {
|
if (shouldRenderCursor) {
|
||||||
|
ALOG_INPUT_VERBOSE("Cursor 2D coords: {} {}", cursorPos2d.x, cursorPos2d.y);
|
||||||
XrCompositionLayerQuad quadLayer = {};
|
XrCompositionLayerQuad quadLayer = {};
|
||||||
mCursorLayer->Frame(gOpenXr->mLocalSpace, quadLayer, cursorPose3d, scaleFactor,
|
mCursorLayer->Frame(gOpenXr->mLocalSpace, quadLayer, cursorPose3d, scaleFactor,
|
||||||
cursorType);
|
cursorType);
|
||||||
|
|
Loading…
Reference in a new issue