summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Abandoned Cart2023-06-11 20:45:50 -0400
committerGravatar Abandoned Cart2023-06-14 16:34:19 -0400
commiteb4026e3dbe38612e659bb66fcfe07ddcfea176e (patch)
tree090f446cdb607143a7aa6d87e3197153620cb304 /src
parentandroid: Enable automated portrait controls (diff)
downloadyuzu-eb4026e3dbe38612e659bb66fcfe07ddcfea176e.tar.gz
yuzu-eb4026e3dbe38612e659bb66fcfe07ddcfea176e.tar.xz
yuzu-eb4026e3dbe38612e659bb66fcfe07ddcfea176e.zip
android: Actually implement portrait controls
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt20
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt95
2 files changed, 82 insertions, 33 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
index 097820952..4da54c28f 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt
@@ -195,7 +195,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
195 195
196 override fun onConfigurationChanged(newConfig: Configuration) { 196 override fun onConfigurationChanged(newConfig: Configuration) {
197 super.onConfigurationChanged(newConfig) 197 super.onConfigurationChanged(newConfig)
198 if (!binding.surfaceInputOverlay.isInEditMode()) refreshInputOverlay() 198 if (!binding.surfaceInputOverlay.isInEditMode) refreshInputOverlay()
199 } 199 }
200 200
201 override fun onResume() { 201 override fun onResume() {
@@ -475,7 +475,19 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
475 popup.show() 475 popup.show()
476 } 476 }
477 477
478 @SuppressLint("SourceLockedOrientationActivity")
478 private fun startConfiguringControls() { 479 private fun startConfiguringControls() {
480 // Lock the current orientation to prevent editing inconsistencies
481 if (IntSetting.RENDERER_SCREEN_LAYOUT.int == Settings.LayoutOption_Default) {
482 emulationActivity?.let {
483 it.requestedOrientation =
484 if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
485 ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
486 } else {
487 ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
488 }
489 }
490 }
479 binding.doneControlConfig.visibility = View.VISIBLE 491 binding.doneControlConfig.visibility = View.VISIBLE
480 binding.surfaceInputOverlay.setIsInEditMode(true) 492 binding.surfaceInputOverlay.setIsInEditMode(true)
481 } 493 }
@@ -483,6 +495,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
483 private fun stopConfiguringControls() { 495 private fun stopConfiguringControls() {
484 binding.doneControlConfig.visibility = View.GONE 496 binding.doneControlConfig.visibility = View.GONE
485 binding.surfaceInputOverlay.setIsInEditMode(false) 497 binding.surfaceInputOverlay.setIsInEditMode(false)
498 // Unlock the orientation if it was locked for editing
499 if (IntSetting.RENDERER_SCREEN_LAYOUT.int == Settings.LayoutOption_Default) {
500 emulationActivity?.let {
501 it.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
502 }
503 }
486 } 504 }
487 505
488 @SuppressLint("SetTextI18n") 506 @SuppressLint("SetTextI18n")
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt
index 45dbf9dfa..ed84ba5f0 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt
@@ -7,6 +7,7 @@ import android.annotation.SuppressLint
7import android.app.Activity 7import android.app.Activity
8import android.content.Context 8import android.content.Context
9import android.content.SharedPreferences 9import android.content.SharedPreferences
10import android.content.res.Configuration
10import android.graphics.Bitmap 11import android.graphics.Bitmap
11import android.graphics.Canvas 12import android.graphics.Canvas
12import android.graphics.Point 13import android.graphics.Point
@@ -236,6 +237,11 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
236 val fingerPositionX = event.getX(pointerIndex).toInt() 237 val fingerPositionX = event.getX(pointerIndex).toInt()
237 val fingerPositionY = event.getY(pointerIndex).toInt() 238 val fingerPositionY = event.getY(pointerIndex).toInt()
238 239
240 val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)
241 "-Portrait"
242 else
243 ""
244
239 for (button in overlayButtons) { 245 for (button in overlayButtons) {
240 // Determine the button state to apply based on the MotionEvent action flag. 246 // Determine the button state to apply based on the MotionEvent action flag.
241 when (event.action and MotionEvent.ACTION_MASK) { 247 when (event.action and MotionEvent.ACTION_MASK) {
@@ -264,7 +270,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
264 saveControlPosition( 270 saveControlPosition(
265 buttonBeingConfigured!!.buttonId, 271 buttonBeingConfigured!!.buttonId,
266 buttonBeingConfigured!!.bounds.centerX(), 272 buttonBeingConfigured!!.bounds.centerX(),
267 buttonBeingConfigured!!.bounds.centerY() 273 buttonBeingConfigured!!.bounds.centerY(),
274 orientation
268 ) 275 )
269 buttonBeingConfigured = null 276 buttonBeingConfigured = null
270 } 277 }
@@ -296,7 +303,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
296 saveControlPosition( 303 saveControlPosition(
297 dpadBeingConfigured!!.upId, 304 dpadBeingConfigured!!.upId,
298 dpadBeingConfigured!!.bounds.centerX(), 305 dpadBeingConfigured!!.bounds.centerX(),
299 dpadBeingConfigured!!.bounds.centerY() 306 dpadBeingConfigured!!.bounds.centerY(),
307 orientation
300 ) 308 )
301 dpadBeingConfigured = null 309 dpadBeingConfigured = null
302 } 310 }
@@ -326,7 +334,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
326 saveControlPosition( 334 saveControlPosition(
327 joystickBeingConfigured!!.buttonId, 335 joystickBeingConfigured!!.buttonId,
328 joystickBeingConfigured!!.bounds.centerX(), 336 joystickBeingConfigured!!.bounds.centerX(),
329 joystickBeingConfigured!!.bounds.centerY() 337 joystickBeingConfigured!!.bounds.centerY(),
338 orientation
330 ) 339 )
331 joystickBeingConfigured = null 340 joystickBeingConfigured = null
332 } 341 }
@@ -336,7 +345,7 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
336 return true 345 return true
337 } 346 }
338 347
339 private fun addOverlayControls() { 348 private fun addOverlayControls(orientation: String) {
340 val windowSize = getSafeScreenSize(context) 349 val windowSize = getSafeScreenSize(context)
341 if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_0, true)) { 350 if (preferences.getBoolean(Settings.PREF_BUTTON_TOGGLE_0, true)) {
342 overlayButtons.add( 351 overlayButtons.add(
@@ -345,7 +354,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
345 windowSize, 354 windowSize,
346 R.drawable.facebutton_a, 355 R.drawable.facebutton_a,
347 R.drawable.facebutton_a_depressed, 356 R.drawable.facebutton_a_depressed,
348 ButtonType.BUTTON_A 357 ButtonType.BUTTON_A,
358 orientation
349 ) 359 )
350 ) 360 )
351 } 361 }
@@ -356,7 +366,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
356 windowSize, 366 windowSize,
357 R.drawable.facebutton_b, 367 R.drawable.facebutton_b,
358 R.drawable.facebutton_b_depressed, 368 R.drawable.facebutton_b_depressed,
359 ButtonType.BUTTON_B 369 ButtonType.BUTTON_B,
370 orientation
360 ) 371 )
361 ) 372 )
362 } 373 }
@@ -367,7 +378,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
367 windowSize, 378 windowSize,
368 R.drawable.facebutton_x, 379 R.drawable.facebutton_x,
369 R.drawable.facebutton_x_depressed, 380 R.drawable.facebutton_x_depressed,
370 ButtonType.BUTTON_X 381 ButtonType.BUTTON_X,
382 orientation
371 ) 383 )
372 ) 384 )
373 } 385 }
@@ -378,7 +390,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
378 windowSize, 390 windowSize,
379 R.drawable.facebutton_y, 391 R.drawable.facebutton_y,
380 R.drawable.facebutton_y_depressed, 392 R.drawable.facebutton_y_depressed,
381 ButtonType.BUTTON_Y 393 ButtonType.BUTTON_Y,
394 orientation
382 ) 395 )
383 ) 396 )
384 } 397 }
@@ -389,7 +402,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
389 windowSize, 402 windowSize,
390 R.drawable.l_shoulder, 403 R.drawable.l_shoulder,
391 R.drawable.l_shoulder_depressed, 404 R.drawable.l_shoulder_depressed,
392 ButtonType.TRIGGER_L 405 ButtonType.TRIGGER_L,
406 orientation
393 ) 407 )
394 ) 408 )
395 } 409 }
@@ -400,7 +414,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
400 windowSize, 414 windowSize,
401 R.drawable.r_shoulder, 415 R.drawable.r_shoulder,
402 R.drawable.r_shoulder_depressed, 416 R.drawable.r_shoulder_depressed,
403 ButtonType.TRIGGER_R 417 ButtonType.TRIGGER_R,
418 orientation
404 ) 419 )
405 ) 420 )
406 } 421 }
@@ -411,7 +426,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
411 windowSize, 426 windowSize,
412 R.drawable.zl_trigger, 427 R.drawable.zl_trigger,
413 R.drawable.zl_trigger_depressed, 428 R.drawable.zl_trigger_depressed,
414 ButtonType.TRIGGER_ZL 429 ButtonType.TRIGGER_ZL,
430 orientation
415 ) 431 )
416 ) 432 )
417 } 433 }
@@ -422,7 +438,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
422 windowSize, 438 windowSize,
423 R.drawable.zr_trigger, 439 R.drawable.zr_trigger,
424 R.drawable.zr_trigger_depressed, 440 R.drawable.zr_trigger_depressed,
425 ButtonType.TRIGGER_ZR 441 ButtonType.TRIGGER_ZR,
442 orientation
426 ) 443 )
427 ) 444 )
428 } 445 }
@@ -433,7 +450,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
433 windowSize, 450 windowSize,
434 R.drawable.facebutton_plus, 451 R.drawable.facebutton_plus,
435 R.drawable.facebutton_plus_depressed, 452 R.drawable.facebutton_plus_depressed,
436 ButtonType.BUTTON_PLUS 453 ButtonType.BUTTON_PLUS,
454 orientation
437 ) 455 )
438 ) 456 )
439 } 457 }
@@ -444,7 +462,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
444 windowSize, 462 windowSize,
445 R.drawable.facebutton_minus, 463 R.drawable.facebutton_minus,
446 R.drawable.facebutton_minus_depressed, 464 R.drawable.facebutton_minus_depressed,
447 ButtonType.BUTTON_MINUS 465 ButtonType.BUTTON_MINUS,
466 orientation
448 ) 467 )
449 ) 468 )
450 } 469 }
@@ -455,7 +474,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
455 windowSize, 474 windowSize,
456 R.drawable.dpad_standard, 475 R.drawable.dpad_standard,
457 R.drawable.dpad_standard_cardinal_depressed, 476 R.drawable.dpad_standard_cardinal_depressed,
458 R.drawable.dpad_standard_diagonal_depressed 477 R.drawable.dpad_standard_diagonal_depressed,
478 orientation
459 ) 479 )
460 ) 480 )
461 } 481 }
@@ -468,7 +488,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
468 R.drawable.joystick, 488 R.drawable.joystick,
469 R.drawable.joystick_depressed, 489 R.drawable.joystick_depressed,
470 StickType.STICK_L, 490 StickType.STICK_L,
471 ButtonType.STICK_L 491 ButtonType.STICK_L,
492 orientation
472 ) 493 )
473 ) 494 )
474 } 495 }
@@ -481,7 +502,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
481 R.drawable.joystick, 502 R.drawable.joystick,
482 R.drawable.joystick_depressed, 503 R.drawable.joystick_depressed,
483 StickType.STICK_R, 504 StickType.STICK_R,
484 ButtonType.STICK_R 505 ButtonType.STICK_R,
506 orientation
485 ) 507 )
486 ) 508 )
487 } 509 }
@@ -492,7 +514,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
492 windowSize, 514 windowSize,
493 R.drawable.facebutton_home, 515 R.drawable.facebutton_home,
494 R.drawable.facebutton_home_depressed, 516 R.drawable.facebutton_home_depressed,
495 ButtonType.BUTTON_HOME 517 ButtonType.BUTTON_HOME,
518 orientation
496 ) 519 )
497 ) 520 )
498 } 521 }
@@ -503,7 +526,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
503 windowSize, 526 windowSize,
504 R.drawable.facebutton_screenshot, 527 R.drawable.facebutton_screenshot,
505 R.drawable.facebutton_screenshot_depressed, 528 R.drawable.facebutton_screenshot_depressed,
506 ButtonType.BUTTON_CAPTURE 529 ButtonType.BUTTON_CAPTURE,
530 orientation
507 ) 531 )
508 ) 532 )
509 } 533 }
@@ -514,21 +538,25 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
514 overlayButtons.clear() 538 overlayButtons.clear()
515 overlayDpads.clear() 539 overlayDpads.clear()
516 overlayJoysticks.clear() 540 overlayJoysticks.clear()
541 val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)
542 "-Portrait"
543 else
544 ""
517 545
518 // Add all the enabled overlay items back to the HashSet. 546 // Add all the enabled overlay items back to the HashSet.
519 if (EmulationMenuSettings.showOverlay) { 547 if (EmulationMenuSettings.showOverlay) {
520 addOverlayControls() 548 addOverlayControls(orientation)
521 } 549 }
522 invalidate() 550 invalidate()
523 } 551 }
524 552
525 private fun saveControlPosition(sharedPrefsId: Int, x: Int, y: Int) { 553 private fun saveControlPosition(sharedPrefsId: Int, x: Int, y: Int, orientation: String) {
526 val windowSize = getSafeScreenSize(context) 554 val windowSize = getSafeScreenSize(context)
527 val min = windowSize.first 555 val min = windowSize.first
528 val max = windowSize.second 556 val max = windowSize.second
529 PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext).edit() 557 PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext).edit()
530 .putFloat("$sharedPrefsId-X", (x - min.x).toFloat() / max.x) 558 .putFloat("$sharedPrefsId$orientation-X", (x - min.x).toFloat() / max.x)
531 .putFloat("$sharedPrefsId-Y", (y - min.y).toFloat() / max.y) 559 .putFloat("$sharedPrefsId$orientation-Y", (y - min.y).toFloat() / max.y)
532 .apply() 560 .apply()
533 } 561 }
534 562
@@ -818,7 +846,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
818 windowSize: Pair<Point, Point>, 846 windowSize: Pair<Point, Point>,
819 defaultResId: Int, 847 defaultResId: Int,
820 pressedResId: Int, 848 pressedResId: Int,
821 buttonId: Int 849 buttonId: Int,
850 orientation: String
822 ): InputOverlayDrawableButton { 851 ): InputOverlayDrawableButton {
823 // Resources handle for fetching the initial Drawable resource. 852 // Resources handle for fetching the initial Drawable resource.
824 val res = context.resources 853 val res = context.resources
@@ -855,8 +884,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
855 884
856 // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay. 885 // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
857 // These were set in the input overlay configuration menu. 886 // These were set in the input overlay configuration menu.
858 val xKey = "$buttonId-X" 887 val xKey = "$buttonId$orientation-X"
859 val yKey = "$buttonId-Y" 888 val yKey = "$buttonId$orientation-Y"
860 val drawableXPercent = sPrefs.getFloat(xKey, 0f) 889 val drawableXPercent = sPrefs.getFloat(xKey, 0f)
861 val drawableYPercent = sPrefs.getFloat(yKey, 0f) 890 val drawableYPercent = sPrefs.getFloat(yKey, 0f)
862 val drawableX = (drawableXPercent * max.x + min.x).toInt() 891 val drawableX = (drawableXPercent * max.x + min.x).toInt()
@@ -898,7 +927,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
898 windowSize: Pair<Point, Point>, 927 windowSize: Pair<Point, Point>,
899 defaultResId: Int, 928 defaultResId: Int,
900 pressedOneDirectionResId: Int, 929 pressedOneDirectionResId: Int,
901 pressedTwoDirectionsResId: Int 930 pressedTwoDirectionsResId: Int,
931 orientation: String
902 ): InputOverlayDrawableDpad { 932 ): InputOverlayDrawableDpad {
903 // Resources handle for fetching the initial Drawable resource. 933 // Resources handle for fetching the initial Drawable resource.
904 val res = context.resources 934 val res = context.resources
@@ -935,8 +965,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
935 965
936 // The X and Y coordinates of the InputOverlayDrawableDpad on the InputOverlay. 966 // The X and Y coordinates of the InputOverlayDrawableDpad on the InputOverlay.
937 // These were set in the input overlay configuration menu. 967 // These were set in the input overlay configuration menu.
938 val drawableXPercent = sPrefs.getFloat("${ButtonType.DPAD_UP}-X", 0f) 968 val drawableXPercent = sPrefs.getFloat("${ButtonType.DPAD_UP}$orientation-X", 0f)
939 val drawableYPercent = sPrefs.getFloat("${ButtonType.DPAD_UP}-Y", 0f) 969 val drawableYPercent = sPrefs.getFloat("${ButtonType.DPAD_UP}$orientation-Y", 0f)
940 val drawableX = (drawableXPercent * max.x + min.x).toInt() 970 val drawableX = (drawableXPercent * max.x + min.x).toInt()
941 val drawableY = (drawableYPercent * max.y + min.y).toInt() 971 val drawableY = (drawableYPercent * max.y + min.y).toInt()
942 val width = overlayDrawable.width 972 val width = overlayDrawable.width
@@ -977,7 +1007,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
977 defaultResInner: Int, 1007 defaultResInner: Int,
978 pressedResInner: Int, 1008 pressedResInner: Int,
979 joystick: Int, 1009 joystick: Int,
980 button: Int 1010 button: Int,
1011 orientation: String
981 ): InputOverlayDrawableJoystick { 1012 ): InputOverlayDrawableJoystick {
982 // Resources handle for fetching the initial Drawable resource. 1013 // Resources handle for fetching the initial Drawable resource.
983 val res = context.resources 1014 val res = context.resources
@@ -1001,8 +1032,8 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
1001 1032
1002 // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay. 1033 // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
1003 // These were set in the input overlay configuration menu. 1034 // These were set in the input overlay configuration menu.
1004 val drawableXPercent = sPrefs.getFloat("$button-X", 0f) 1035 val drawableXPercent = sPrefs.getFloat("$button$orientation-X", 0f)
1005 val drawableYPercent = sPrefs.getFloat("$button-Y", 0f) 1036 val drawableYPercent = sPrefs.getFloat("$button$orientation-Y", 0f)
1006 val drawableX = (drawableXPercent * max.x + min.x).toInt() 1037 val drawableX = (drawableXPercent * max.x + min.x).toInt()
1007 val drawableY = (drawableYPercent * max.y + min.y).toInt() 1038 val drawableY = (drawableYPercent * max.y + min.y).toInt()
1008 val outerScale = 1.66f 1039 val outerScale = 1.66f