Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9439 from Darwin-Rist/master
Added Opacity settings for touchscreen controls
  • Loading branch information
leoetlino committed Jan 27, 2021
2 parents 28cd6f6 + d1c3d4f commit b597b16
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 17 deletions.
Expand Up @@ -544,7 +544,7 @@ public void handleMenuAction(@MenuAction int menuAction)
toggleControls();
break;

// Adjust the scale of the overlay controls.
// Adjust the scale and opacity of the overlay controls.
case MENU_ACTION_ADJUST_SCALE:
adjustScale();
break;
Expand Down Expand Up @@ -828,15 +828,14 @@ public void chooseDoubleTapButton()
private void adjustScale()
{
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.dialog_seekbar, null);
View view = inflater.inflate(R.layout.dialog_input_adjust, null);

final SeekBar seekbar = view.findViewById(R.id.seekbar);
final TextView value = view.findViewById(R.id.text_value);
final TextView units = view.findViewById(R.id.text_units);
final SeekBar scaleSeekbar = view.findViewById(R.id.input_scale_seekbar);
final TextView scaleValue = view.findViewById(R.id.input_scale_value);

seekbar.setMax(150);
seekbar.setProgress(IntSetting.MAIN_CONTROL_SCALE.getInt(mSettings));
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
scaleSeekbar.setMax(150);
scaleSeekbar.setProgress(IntSetting.MAIN_CONTROL_SCALE.getInt(mSettings));
scaleSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
public void onStartTrackingTouch(SeekBar seekBar)
{
Expand All @@ -845,7 +844,7 @@ public void onStartTrackingTouch(SeekBar seekBar)

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
value.setText(String.valueOf(progress + 50));
scaleValue.setText((progress + 50) + "%");
}

public void onStopTrackingTouch(SeekBar seekBar)
Expand All @@ -854,20 +853,46 @@ public void onStopTrackingTouch(SeekBar seekBar)
}
});

value.setText(String.valueOf(seekbar.getProgress() + 50));
units.setText("%");
scaleValue.setText((scaleSeekbar.getProgress() + 50) + "%");

// alpha
final SeekBar seekbarOpacity = view.findViewById(R.id.input_opacity_seekbar);
final TextView valueOpacity = view.findViewById(R.id.input_opacity_value);

seekbarOpacity.setMax(100);
seekbarOpacity.setProgress(IntSetting.MAIN_CONTROL_OPACITY.getInt(mSettings));
seekbarOpacity.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener()
{
public void onStartTrackingTouch(SeekBar seekBar)
{
// Do nothing
}

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
valueOpacity.setText(progress + "%");
}

public void onStopTrackingTouch(SeekBar seekBar)
{
// Do nothing
}
});
valueOpacity.setText(seekbarOpacity.getProgress() + "%");

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DolphinDialogBase);
builder.setTitle(R.string.emulation_control_scale);
builder.setTitle(R.string.emulation_control_adjustments);
builder.setView(view);
builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
{
IntSetting.MAIN_CONTROL_SCALE.setInt(mSettings, seekbar.getProgress());
IntSetting.MAIN_CONTROL_SCALE.setInt(mSettings, scaleSeekbar.getProgress());
IntSetting.MAIN_CONTROL_OPACITY.setInt(mSettings, seekbarOpacity.getProgress());
mEmulationFragment.refreshInputOverlay();
});
builder.setNeutralButton(R.string.default_values, (dialogInterface, i) ->
{
IntSetting.MAIN_CONTROL_SCALE.delete(mSettings);
IntSetting.MAIN_CONTROL_OPACITY.delete(mSettings);
mEmulationFragment.refreshInputOverlay();
});

Expand Down
Expand Up @@ -22,6 +22,7 @@ public enum IntSetting implements AbstractIntSetting
MAIN_AUDIO_VOLUME(Settings.FILE_DOLPHIN, Settings.SECTION_INI_DSP, "Volume", 100),

MAIN_CONTROL_SCALE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "ControlScale", 50),
MAIN_CONTROL_OPACITY(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "ControlOpacity", 50),
MAIN_EMULATION_ORIENTATION(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
"EmulationOrientation", ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
MAIN_LAST_PLATFORM_TAB(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "LastPlatformTab", 0),
Expand Down
Expand Up @@ -955,6 +955,7 @@ private static InputOverlayDrawableButton initializeOverlayButton(Context contex

// Need to set the image's position
overlayDrawable.setPosition(drawableX, drawableY);
overlayDrawable.setOpacity(IntSetting.MAIN_CONTROL_OPACITY.getIntGlobal() * 255 / 100);

return overlayDrawable;
}
Expand Down Expand Up @@ -1039,6 +1040,7 @@ private static InputOverlayDrawableDpad initializeOverlayDpad(Context context,

// Need to set the image's position
overlayDrawable.setPosition(drawableX, drawableY);
overlayDrawable.setOpacity(IntSetting.MAIN_CONTROL_OPACITY.getIntGlobal() * 255 / 100);

return overlayDrawable;
}
Expand Down Expand Up @@ -1104,6 +1106,7 @@ private static InputOverlayDrawableJoystick initializeOverlayJoystick(Context co

// Need to set the image's position
overlayDrawable.setPosition(drawableX, drawableY);
overlayDrawable.setOpacity(IntSetting.MAIN_CONTROL_OPACITY.getIntGlobal() * 255 / 100);

return overlayDrawable;
}
Expand Down
Expand Up @@ -114,6 +114,11 @@ public void setBounds(int left, int top, int right, int bottom)
mPressedStateBitmap.setBounds(left, top, right, bottom);
}

public void setOpacity(int value)
{
mDefaultStateBitmap.setAlpha(value);
}

public Rect getBounds()
{
return mDefaultStateBitmap.getBounds();
Expand Down
Expand Up @@ -183,6 +183,11 @@ public void setBounds(int left, int top, int right, int bottom)
mPressedTwoDirectionsStateBitmap.setBounds(left, top, right, bottom);
}

public void setOpacity(int value)
{
mDefaultStateBitmap.setAlpha(value);
}

public Rect getBounds()
{
return mDefaultStateBitmap.getBounds();
Expand Down
Expand Up @@ -32,6 +32,7 @@
private final int mHeight;
private Rect mVirtBounds;
private Rect mOrigBounds;
private int mOpacity;
private final BitmapDrawable mOuterBitmap;
private final BitmapDrawable mDefaultStateInnerBitmap;
private final BitmapDrawable mPressedStateInnerBitmap;
Expand Down Expand Up @@ -106,7 +107,7 @@ public boolean TrackEvent(MotionEvent event)
{
mPressedState = pressed = true;
mOuterBitmap.setAlpha(0);
mBoundsBoxBitmap.setAlpha(255);
mBoundsBoxBitmap.setAlpha(mOpacity);
if (reCenter)
{
getVirtBounds().offset((int) event.getX(pointerIndex) - getVirtBounds().centerX(),
Expand All @@ -123,7 +124,7 @@ public boolean TrackEvent(MotionEvent event)
pressed = true;
mPressedState = false;
axises[0] = axises[1] = 0.0f;
mOuterBitmap.setAlpha(255);
mOuterBitmap.setAlpha(mOpacity);
mBoundsBoxBitmap.setAlpha(0);
setVirtBounds(new Rect(mOrigBounds.left, mOrigBounds.top, mOrigBounds.right,
mOrigBounds.bottom));
Expand Down Expand Up @@ -251,6 +252,13 @@ public void setBounds(Rect bounds)
mOuterBitmap.setBounds(bounds);
}

public void setOpacity(int value)
{
mOpacity = value;
mDefaultStateInnerBitmap.setAlpha(value);
mOuterBitmap.setAlpha(value);
}

public Rect getBounds()
{
return mOuterBitmap.getBounds();
Expand Down
102 changes: 102 additions & 0 deletions Source/Android/app/src/main/res/layout/dialog_input_adjust.xml
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RelativeLayout
android:id="@+id/input_scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="false">

<TextView
android:id="@+id/input_scale_name"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_large"
android:layout_marginEnd="@dimen/spacing_large"
android:text="@string/emulation_control_scale"
android:textSize="16sp"
tools:text="@string/overclock_enable" />

<TextView
android:id="@+id/input_scale_value"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_below="@+id/input_scale_name"
android:layout_alignParentEnd="true"
android:layout_marginStart="@dimen/spacing_small"
android:layout_marginTop="@dimen/spacing_medlarge"
android:layout_marginEnd="@dimen/spacing_large"
android:layout_marginBottom="@dimen/spacing_large"
tools:text="99%"
android:textAlignment="textEnd"/>

<SeekBar
android:id="@+id/input_scale_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_scale_name"
android:layout_alignParentStart="true"
android:layout_marginTop="@dimen/spacing_medlarge"
android:layout_marginBottom="@dimen/spacing_large"
android:layout_toStartOf="@id/input_scale_value" />

</RelativeLayout>

<RelativeLayout
android:id="@+id/input_opacity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/input_scale"
android:layout_alignParentStart="true"
android:clickable="false">

<TextView
android:id="@+id/input_opacity_name"
style="@style/TextAppearance.AppCompat.Headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_large"
android:layout_marginEnd="@dimen/spacing_large"
android:text="@string/emulation_control_opacity"
android:textSize="16sp"
tools:text="@string/overclock_enable" />

<TextView
android:id="@+id/input_opacity_value"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_below="@+id/input_opacity_name"
android:layout_alignParentEnd="true"
android:layout_marginStart="@dimen/spacing_small"
android:layout_marginTop="@dimen/spacing_medlarge"
android:layout_marginEnd="@dimen/spacing_large"
android:layout_marginBottom="@dimen/spacing_large"
tools:text="99%"
android:textAlignment="textEnd"/>

<SeekBar
android:id="@+id/input_opacity_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_opacity_name"
android:layout_alignParentStart="true"
android:layout_marginTop="@dimen/spacing_medlarge"
android:layout_marginBottom="@dimen/spacing_large"
android:layout_toStartOf="@id/input_opacity_value" />

</RelativeLayout>

</RelativeLayout>
Expand Up @@ -12,7 +12,7 @@

<item
android:id="@+id/menu_emulation_adjust_scale"
android:title="@string/emulation_control_scale"/>
android:title="@string/emulation_control_adjustments"/>

<item
android:id="@+id/menu_emulation_joystick_rel_center"
Expand Down
Expand Up @@ -12,7 +12,7 @@

<item
android:id="@+id/menu_emulation_adjust_scale"
android:title="@string/emulation_control_scale"/>
android:title="@string/emulation_control_adjustments"/>

<group android:checkableBehavior="all">
<item
Expand Down
2 changes: 2 additions & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -396,6 +396,8 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="emulation_toggle_controls">Toggle Controls</string>
<string name="emulation_toggle_all">Toggle All</string>
<string name="emulation_control_scale">Adjust Scale</string>
<string name="emulation_control_opacity">Adjust Opacity</string>
<string name="emulation_control_adjustments">Adjust Controls</string>
<string name="emulation_control_joystick_rel_center">Relative Stick Center</string>
<string name="emulation_control_rumble">Rumble</string>
<string name="emulation_choose_controller">Choose Controller</string>
Expand Down

0 comments on commit b597b16

Please sign in to comment.