Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #580 from SeannyM/smaller-b
[Android] User configurable input overlay scaling
  • Loading branch information
lioncash committed Jul 16, 2014
2 parents 9481af8 + cd9a0b6 commit 30e4366
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Source/Android/res/values-ja/strings.xml
Expand Up @@ -68,8 +68,11 @@

<!-- Input Config Fragment -->
<string name="input_settings">入力</string>
<string name="input_overlay">入力オーバーレイ</string>
<string name="input_overlay_desc">画面上の入力のオーバーレイを設定し。</string>
<string name="input_overlay_layout">入力オーバーレイレイアウト</string>
<string name="input_overlay_layout_desc">入力オーバーレイのためのボタンのレイアウト。</string>
<string name="controls_size">コントロールのサイズを調整し</string>
<string name="gamecube_bindings">ゲームキューブコントローラの入力バインディング</string>
<string name="controller_0">コントローラ1</string>
<string name="controller_1">コントローラ2</string>
Expand Down
3 changes: 3 additions & 0 deletions Source/Android/res/values/strings.xml
Expand Up @@ -69,8 +69,11 @@

<!-- Input Config Fragment -->
<string name="input_settings">Input</string>
<string name="input_overlay">Input Overlay</string>
<string name="input_overlay_desc">Configure the onscreen input overlay.</string>
<string name="input_overlay_layout">Input Overlay Layout</string>
<string name="input_overlay_layout_desc">Button layout for the input overlay.</string>
<string name="controls_size">Adjust the control size</string>
<string name="gamecube_bindings">GameCube Controller Bindings</string>
<string name="controller_0">Controller 1</string>
<string name="controller_1">Controller 2</string>
Expand Down
28 changes: 19 additions & 9 deletions Source/Android/res/xml/input_prefs.xml
@@ -1,15 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/input_settings">

<Preference
android:key="inputOverlayConfigPref"
android:summary="@string/input_overlay_layout_desc"
android:title="@string/input_overlay_layout">
<intent
android:targetPackage="org.dolphinemu.dolphinemu"
android:targetClass="org.dolphinemu.dolphinemu.settings.input.overlayconfig.OverlayConfigActivity"/>
</Preference>
<PreferenceScreen
android:key="input_overlay"
android:title="@string/input_overlay"
android:summary="@string/input_overlay_desc">
<Preference
android:key="inputOverlayConfigPref"
android:summary="@string/input_overlay_layout_desc"
android:title="@string/input_overlay_layout">
<intent
android:targetPackage="org.dolphinemu.dolphinemu"
android:targetClass="org.dolphinemu.dolphinemu.settings.input.overlayconfig.OverlayConfigActivity"/>
</Preference>
<SeekBarPreference
android:key="controls_size"
android:title="@string/controls_size"
android:defaultValue="25"
android:max="75">
</SeekBarPreference>
</PreferenceScreen>

<!-- GameCube controller bindings -->
<PreferenceScreen
Expand Down
Expand Up @@ -186,8 +186,31 @@ private static InputOverlayDrawableButton initializeOverlayButton(Context contex
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton.
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);

// Decide scale based on button ID
float scale;
float overlaySize = sPrefs.getInt("controls_size", 25);
overlaySize += 25;
overlaySize /= 50;

switch (resId)
{
case R.drawable.gcpad_b:
scale = 0.13f * overlaySize;
break;
case R.drawable.gcpad_x:
case R.drawable.gcpad_y:
scale = 0.18f * overlaySize;
break;
case R.drawable.gcpad_start:
scale = 0.12f * overlaySize;
break;
default:
scale = 0.20f * overlaySize;
break;
}

// Initialize the InputOverlayDrawableButton.
final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), 0.20f);
final Bitmap bitmap = resizeBitmap(context, BitmapFactory.decodeResource(res, resId), scale);
final InputOverlayDrawableButton overlayDrawable = new InputOverlayDrawableButton(res, bitmap, buttonId);

// String ID of the Drawable. This is what is passed into SharedPreferences
Expand Down Expand Up @@ -231,7 +254,10 @@ private static InputOverlayDrawableJoystick initializeOverlayJoystick(Context co
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);

// Initialize the InputOverlayDrawableJoystick.
final Bitmap bitmapOuter = resizeBitmap(context, BitmapFactory.decodeResource(res, resOuter), 0.30f);
float overlaySize = sPrefs.getInt("controls_size", 20);
overlaySize += 30;
overlaySize /= 50;
final Bitmap bitmapOuter = resizeBitmap(context, BitmapFactory.decodeResource(res, resOuter), 0.30f * overlaySize);
final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner);

// String ID of the Drawable. This is what is passed into SharedPreferences
Expand Down
Expand Up @@ -76,13 +76,43 @@ public OverlayConfigButton(Context context, String buttonId, int drawableId)
// Set the button as its own OnTouchListener.
setOnTouchListener(this);

// Set the button's icon that represents it.
setBackground(resizeDrawable(getResources().getDrawable(drawableId),
drawableId == R.drawable.gcpad_joystick_range ? 0.30f : 0.20f));

// Get the SharedPreferences instance.
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

// Decide scale based on button ID

// SeekBars are not able to set a minimum value, only a maximum value, which complicates
// things a bit. What happens here is after the SeekBar's value is retrieved, 25 is
// added so the value will never go below 25. It is then divided by 50 (25 + 25) so the
// default value will be 100%.
float scale;
float overlaySize = sharedPrefs.getInt("controls_size", 25);
overlaySize += 25;
overlaySize /= 50;

switch (drawableId)
{
case R.drawable.gcpad_b:
scale = 0.13f * overlaySize;
break;
case R.drawable.gcpad_x:
case R.drawable.gcpad_y:
scale = 0.18f * overlaySize;
break;
case R.drawable.gcpad_start:
scale = 0.12f * overlaySize;
break;
case R.drawable.gcpad_joystick_range:
scale = 0.30f * overlaySize;
break;
default:
scale = 0.20f * overlaySize;
break;
}

// Set the button's icon that represents it.
setBackground(resizeDrawable(getResources().getDrawable(drawableId), scale));

// Check if this button has previous values set that aren't the default.
final float x = sharedPrefs.getFloat(buttonId+"-X", -1f);
final float y = sharedPrefs.getFloat(buttonId+"-Y", -1f);
Expand Down

0 comments on commit 30e4366

Please sign in to comment.