summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Abandoned Cart2023-06-12 08:49:11 -0400
committerGravatar Abandoned Cart2023-06-14 16:34:22 -0400
commitfb28f9fd96e8a3370463263753daae778c99d381 (patch)
tree1332d66096b2eda87ba1a4d950ed49fb548de744 /src
parentandroid: Actually implement portrait controls (diff)
downloadyuzu-fb28f9fd96e8a3370463263753daae778c99d381.tar.gz
yuzu-fb28f9fd96e8a3370463263753daae778c99d381.tar.xz
yuzu-fb28f9fd96e8a3370463263753daae778c99d381.zip
android: Set portrait default control params
Diffstat (limited to 'src')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt4
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/overlay/InputOverlay.kt163
-rw-r--r--src/android/app/src/main/res/layout/fragment_emulation.xml4
-rw-r--r--src/android/app/src/main/res/values/integers.xml32
4 files changed, 186 insertions, 17 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 4da54c28f..c65db59f8 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
@@ -334,6 +334,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
334 // Prevent touch regions from being displayed in the hinge 334 // Prevent touch regions from being displayed in the hinge
335 binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx 335 binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx
336 binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx) 336 binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx)
337 binding.inGameMenu.layoutParams.height = it.bounds.bottom
338 refreshInputOverlay()
337 } 339 }
338 } 340 }
339 it.isSeparating 341 it.isSeparating
@@ -342,10 +344,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
342 binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT 344 binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
343 binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT 345 binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
344 binding.overlayContainer.updatePadding(0, 0, 0, 0) 346 binding.overlayContainer.updatePadding(0, 0, 0, 0)
347 binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
345 updateScreenLayout() 348 updateScreenLayout()
346 } 349 }
347 binding.emulationContainer.requestLayout() 350 binding.emulationContainer.requestLayout()
348 binding.overlayContainer.requestLayout() 351 binding.overlayContainer.requestLayout()
352 binding.inGameMenu.requestLayout()
349 } 353 }
350 354
351 override fun surfaceCreated(holder: SurfaceHolder) { 355 override fun surfaceCreated(holder: SurfaceHolder) {
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 ed84ba5f0..ae5d935d0 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
@@ -3,7 +3,6 @@
3 3
4package org.yuzu.yuzu_emu.overlay 4package org.yuzu.yuzu_emu.overlay
5 5
6import android.annotation.SuppressLint
7import android.app.Activity 6import android.app.Activity
8import android.content.Context 7import android.content.Context
9import android.content.SharedPreferences 8import android.content.SharedPreferences
@@ -16,14 +15,12 @@ import android.graphics.drawable.Drawable
16import android.graphics.drawable.VectorDrawable 15import android.graphics.drawable.VectorDrawable
17import android.os.Build 16import android.os.Build
18import android.util.AttributeSet 17import android.util.AttributeSet
19import android.util.Rational
20import android.view.HapticFeedbackConstants 18import android.view.HapticFeedbackConstants
21import android.view.MotionEvent 19import android.view.MotionEvent
22import android.view.SurfaceView 20import android.view.SurfaceView
23import android.view.View 21import android.view.View
24import android.view.View.OnTouchListener 22import android.view.View.OnTouchListener
25import android.view.WindowInsets 23import android.view.WindowInsets
26import android.view.WindowManager
27import androidx.core.content.ContextCompat 24import androidx.core.content.ContextCompat
28import androidx.preference.PreferenceManager 25import androidx.preference.PreferenceManager
29import androidx.window.layout.WindowMetricsCalculator 26import androidx.window.layout.WindowMetricsCalculator
@@ -36,7 +33,6 @@ import org.yuzu.yuzu_emu.features.settings.model.Settings
36import org.yuzu.yuzu_emu.utils.EmulationMenuSettings 33import org.yuzu.yuzu_emu.utils.EmulationMenuSettings
37import kotlin.math.max 34import kotlin.math.max
38import kotlin.math.min 35import kotlin.math.min
39import kotlin.math.roundToInt
40 36
41/** 37/**
42 * Draws the interactive input overlay on top of the 38 * Draws the interactive input overlay on top of the
@@ -237,11 +233,6 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
237 val fingerPositionX = event.getX(pointerIndex).toInt() 233 val fingerPositionX = event.getX(pointerIndex).toInt()
238 val fingerPositionY = event.getY(pointerIndex).toInt() 234 val fingerPositionY = event.getY(pointerIndex).toInt()
239 235
240 val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)
241 "-Portrait"
242 else
243 ""
244
245 for (button in overlayButtons) { 236 for (button in overlayButtons) {
246 // Determine the button state to apply based on the MotionEvent action flag. 237 // Determine the button state to apply based on the MotionEvent action flag.
247 when (event.action and MotionEvent.ACTION_MASK) { 238 when (event.action and MotionEvent.ACTION_MASK) {
@@ -538,10 +529,6 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
538 overlayButtons.clear() 529 overlayButtons.clear()
539 overlayDpads.clear() 530 overlayDpads.clear()
540 overlayJoysticks.clear() 531 overlayJoysticks.clear()
541 val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)
542 "-Portrait"
543 else
544 ""
545 532
546 // Add all the enabled overlay items back to the HashSet. 533 // Add all the enabled overlay items back to the HashSet.
547 if (EmulationMenuSettings.showOverlay) { 534 if (EmulationMenuSettings.showOverlay) {
@@ -566,7 +553,10 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
566 553
567 private fun defaultOverlay() { 554 private fun defaultOverlay() {
568 if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) { 555 if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) {
569 defaultOverlayLandscape() 556 if (orientation == portrait)
557 defaultOverlayPortrait()
558 else
559 defaultOverlayLandscape()
570 } 560 }
571 561
572 resetButtonPlacement() 562 resetButtonPlacement()
@@ -576,10 +566,141 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
576 } 566 }
577 567
578 fun resetButtonPlacement() { 568 fun resetButtonPlacement() {
579 defaultOverlayLandscape() 569 if (orientation == portrait)
570 defaultOverlayPortrait()
571 else
572 defaultOverlayLandscape()
580 refreshControls() 573 refreshControls()
581 } 574 }
582 575
576 private fun defaultOverlayPortrait() {
577 // Each value represents the position of the button in relation to the screen size without insets.
578 preferences.edit()
579 .putFloat(
580 ButtonType.BUTTON_A.toString() + "$portrait-X",
581 resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_X).toFloat() / 1000
582 )
583 .putFloat(
584 ButtonType.BUTTON_A.toString() + "$portrait-Y",
585 resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_Y).toFloat() / 1000
586 )
587 .putFloat(
588 ButtonType.BUTTON_B.toString() + "$portrait-X",
589 resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_X).toFloat() / 1000
590 )
591 .putFloat(
592 ButtonType.BUTTON_B.toString() + "$portrait-Y",
593 resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_Y).toFloat() / 1000
594 )
595 .putFloat(
596 ButtonType.BUTTON_X.toString() + "$portrait-X",
597 resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_X).toFloat() / 1000
598 )
599 .putFloat(
600 ButtonType.BUTTON_X.toString() + "$portrait-Y",
601 resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_Y).toFloat() / 1000
602 )
603 .putFloat(
604 ButtonType.BUTTON_Y.toString() + "$portrait-X",
605 resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_X).toFloat() / 1000
606 )
607 .putFloat(
608 ButtonType.BUTTON_Y.toString() + "$portrait-Y",
609 resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_Y).toFloat() / 1000
610 )
611 .putFloat(
612 ButtonType.TRIGGER_ZL.toString() + "$portrait-X",
613 resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_X).toFloat() / 1000
614 )
615 .putFloat(
616 ButtonType.TRIGGER_ZL.toString() + "$portrait-Y",
617 resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_Y).toFloat() / 1000
618 )
619 .putFloat(
620 ButtonType.TRIGGER_ZR.toString() + "$portrait-X",
621 resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_X).toFloat() / 1000
622 )
623 .putFloat(
624 ButtonType.TRIGGER_ZR.toString() + "$portrait-Y",
625 resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_Y).toFloat() / 1000
626 )
627 .putFloat(
628 ButtonType.DPAD_UP.toString() + "$portrait-X",
629 resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_X).toFloat() / 1000
630 )
631 .putFloat(
632 ButtonType.DPAD_UP.toString() + "$portrait-Y",
633 resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_Y).toFloat() / 1000
634 )
635 .putFloat(
636 ButtonType.TRIGGER_L.toString() + "$portrait-X",
637 resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_X).toFloat() / 1000
638 )
639 .putFloat(
640 ButtonType.TRIGGER_L.toString() + "$portrait-Y",
641 resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_Y).toFloat() / 1000
642 )
643 .putFloat(
644 ButtonType.TRIGGER_R.toString() + "$portrait-X",
645 resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_X).toFloat() / 1000
646 )
647 .putFloat(
648 ButtonType.TRIGGER_R.toString() + "$portrait-Y",
649 resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_Y).toFloat() / 1000
650 )
651 .putFloat(
652 ButtonType.BUTTON_PLUS.toString() + "$portrait-X",
653 resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_X).toFloat() / 1000
654 )
655 .putFloat(
656 ButtonType.BUTTON_PLUS.toString() + "$portrait-Y",
657 resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_Y).toFloat() / 1000
658 )
659 .putFloat(
660 ButtonType.BUTTON_MINUS.toString() + "$portrait-X",
661 resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_X).toFloat() / 1000
662 )
663 .putFloat(
664 ButtonType.BUTTON_MINUS.toString() + "$portrait-Y",
665 resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_Y).toFloat() / 1000
666 )
667 .putFloat(
668 ButtonType.BUTTON_HOME.toString() + "$portrait-X",
669 resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_X).toFloat() / 1000
670 )
671 .putFloat(
672 ButtonType.BUTTON_HOME.toString() + "$portrait-Y",
673 resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_Y).toFloat() / 1000
674 )
675 .putFloat(
676 ButtonType.BUTTON_CAPTURE.toString() + "$portrait-X",
677 resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_X)
678 .toFloat() / 1000
679 )
680 .putFloat(
681 ButtonType.BUTTON_CAPTURE.toString() + "$portrait-Y",
682 resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_Y)
683 .toFloat() / 1000
684 )
685 .putFloat(
686 ButtonType.STICK_R.toString() + "$portrait-X",
687 resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_X).toFloat() / 1000
688 )
689 .putFloat(
690 ButtonType.STICK_R.toString() + "$portrait-Y",
691 resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_Y).toFloat() / 1000
692 )
693 .putFloat(
694 ButtonType.STICK_L.toString() + "$portrait-X",
695 resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_X).toFloat() / 1000
696 )
697 .putFloat(
698 ButtonType.STICK_L.toString() + "$portrait-Y",
699 resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_Y).toFloat() / 1000
700 )
701 .apply()
702 }
703
583 private fun defaultOverlayLandscape() { 704 private fun defaultOverlayLandscape() {
584 // Each value represents the position of the button in relation to the screen size without insets. 705 // Each value represents the position of the button in relation to the screen size without insets.
585 preferences.edit() 706 preferences.edit()
@@ -712,10 +833,22 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
712 return inEditMode 833 return inEditMode
713 } 834 }
714 835
836 override fun onConfigurationChanged(newConfig: Configuration?) {
837 super.onConfigurationChanged(newConfig)
838 orientation =
839 if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT)
840 portrait
841 else
842 ""
843 }
844
715 companion object { 845 companion object {
716 private val preferences: SharedPreferences = 846 private val preferences: SharedPreferences =
717 PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) 847 PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
718 848
849 private const val portrait = "-Portrait"
850 private var orientation = ""
851
719 /** 852 /**
720 * Resizes a [Bitmap] by a given scale factor 853 * Resizes a [Bitmap] by a given scale factor
721 * 854 *
diff --git a/src/android/app/src/main/res/layout/fragment_emulation.xml b/src/android/app/src/main/res/layout/fragment_emulation.xml
index ccd0f4c50..01f6b9fe4 100644
--- a/src/android/app/src/main/res/layout/fragment_emulation.xml
+++ b/src/android/app/src/main/res/layout/fragment_emulation.xml
@@ -39,7 +39,7 @@
39 android:id="@+id/surface_input_overlay" 39 android:id="@+id/surface_input_overlay"
40 android:layout_width="match_parent" 40 android:layout_width="match_parent"
41 android:layout_height="match_parent" 41 android:layout_height="match_parent"
42 android:layout_gravity="bottom" 42 android:layout_gravity="center"
43 android:focusable="true" 43 android:focusable="true"
44 android:focusableInTouchMode="true" /> 44 android:focusableInTouchMode="true" />
45 45
@@ -72,7 +72,7 @@
72 android:id="@+id/in_game_menu" 72 android:id="@+id/in_game_menu"
73 android:layout_width="wrap_content" 73 android:layout_width="wrap_content"
74 android:layout_height="match_parent" 74 android:layout_height="match_parent"
75 android:layout_gravity="start" 75 android:layout_gravity="start|bottom"
76 app:headerLayout="@layout/header_in_game" 76 app:headerLayout="@layout/header_in_game"
77 app:menu="@menu/menu_in_game" /> 77 app:menu="@menu/menu_in_game" />
78 78
diff --git a/src/android/app/src/main/res/values/integers.xml b/src/android/app/src/main/res/values/integers.xml
index bc614b81d..326867664 100644
--- a/src/android/app/src/main/res/values/integers.xml
+++ b/src/android/app/src/main/res/values/integers.xml
@@ -2,6 +2,38 @@
2<resources> 2<resources>
3 <integer name="game_title_lines">2</integer> 3 <integer name="game_title_lines">2</integer>
4 4
5 <!-- Default SWITCH portrait layout -->
6 <integer name="SWITCH_BUTTON_A_PORTRAIT_X">830</integer>
7 <integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer>
8 <integer name="SWITCH_BUTTON_B_PORTRAIT_X">730</integer>
9 <integer name="SWITCH_BUTTON_B_PORTRAIT_Y">870</integer>
10 <integer name="SWITCH_BUTTON_X_PORTRAIT_X">730</integer>
11 <integer name="SWITCH_BUTTON_X_PORTRAIT_Y">770</integer>
12 <integer name="SWITCH_BUTTON_Y_PORTRAIT_X">630</integer>
13 <integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer>
14 <integer name="SWITCH_STICK_L_PORTRAIT_X">170</integer>
15 <integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer>
16 <integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer>
17 <integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer>
18 <integer name="SWITCH_TRIGGER_L_PORTRAIT_X">140</integer>
19 <integer name="SWITCH_TRIGGER_L_PORTRAIT_Y">240</integer>
20 <integer name="SWITCH_TRIGGER_R_PORTRAIT_X">860</integer>
21 <integer name="SWITCH_TRIGGER_R_PORTRAIT_Y">240</integer>
22 <integer name="SWITCH_TRIGGER_ZL_PORTRAIT_X">140</integer>
23 <integer name="SWITCH_TRIGGER_ZL_PORTRAIT_Y">180</integer>
24 <integer name="SWITCH_TRIGGER_ZR_PORTRAIT_X">860</integer>
25 <integer name="SWITCH_TRIGGER_ZR_PORTRAIT_Y">180</integer>
26 <integer name="SWITCH_BUTTON_MINUS_PORTRAIT_X">440</integer>
27 <integer name="SWITCH_BUTTON_MINUS_PORTRAIT_Y">950</integer>
28 <integer name="SWITCH_BUTTON_PLUS_PORTRAIT_X">560</integer>
29 <integer name="SWITCH_BUTTON_PLUS_PORTRAIT_Y">950</integer>
30 <integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">600</integer>
31 <integer name="SWITCH_BUTTON_HOME_PORTRAIT_Y">950</integer>
32 <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">400</integer>
33 <integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_Y">950</integer>
34 <integer name="SWITCH_BUTTON_DPAD_PORTRAIT_X">240</integer>
35 <integer name="SWITCH_BUTTON_DPAD_PORTRAIT_Y">820</integer>
36
5 <!-- Default SWITCH landscape layout --> 37 <!-- Default SWITCH landscape layout -->
6 <integer name="SWITCH_BUTTON_A_X">760</integer> 38 <integer name="SWITCH_BUTTON_A_X">760</integer>
7 <integer name="SWITCH_BUTTON_A_Y">790</integer> 39 <integer name="SWITCH_BUTTON_A_Y">790</integer>