mirror of
https://github.com/stenzek/duckstation.git
synced 2024-11-23 05:49:43 +00:00
Android: Make touchscreen buttons larger when pushed
This commit is contained in:
parent
20ed6913a9
commit
f72cbfc653
@ -5,6 +5,7 @@ import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.View;
|
||||
|
||||
@ -67,18 +68,24 @@ public final class TouchscreenControllerButtonView extends View {
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
final int paddingLeft = getPaddingLeft();
|
||||
final int paddingTop = getPaddingTop();
|
||||
final int paddingRight = getPaddingRight();
|
||||
final int paddingBottom = getPaddingBottom();
|
||||
final int contentWidth = getWidth() - paddingLeft - paddingRight;
|
||||
final int contentHeight = getHeight() - paddingTop - paddingBottom;
|
||||
int leftBounds = 0;
|
||||
int rightBounds = leftBounds + getWidth();
|
||||
int topBounds = 0;
|
||||
int bottomBounds = topBounds + getHeight();
|
||||
|
||||
if (mPressed) {
|
||||
final int expandSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||
10.0f, getResources().getDisplayMetrics());
|
||||
leftBounds -= expandSize;
|
||||
rightBounds += expandSize;
|
||||
topBounds -= expandSize;
|
||||
bottomBounds += expandSize;
|
||||
}
|
||||
|
||||
// Draw the example drawable on top of the text.
|
||||
Drawable drawable = mPressed ? mPressedDrawable : mUnpressedDrawable;
|
||||
if (drawable != null) {
|
||||
drawable.setBounds(paddingLeft, paddingTop,
|
||||
paddingLeft + contentWidth, paddingTop + contentHeight);
|
||||
drawable.setBounds(leftBounds, topBounds, rightBounds, bottomBounds);
|
||||
drawable.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,11 @@ package com.github.stenzek.duckstation;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
||||
public final class TouchscreenControllerDPadView extends View {
|
||||
@ -122,10 +124,19 @@ public final class TouchscreenControllerDPadView extends View {
|
||||
}
|
||||
|
||||
private void drawDirection(int direction, int subX, int subY, Canvas canvas, int buttonWidth, int buttonHeight) {
|
||||
final int leftBounds = subX * buttonWidth;
|
||||
final int rightBounds = leftBounds + buttonWidth;
|
||||
final int topBounds = subY * buttonHeight;
|
||||
final int bottomBounds = topBounds + buttonHeight;
|
||||
int leftBounds = subX * buttonWidth;
|
||||
int rightBounds = leftBounds + buttonWidth;
|
||||
int topBounds = subY * buttonHeight;
|
||||
int bottomBounds = topBounds + buttonHeight;
|
||||
|
||||
if (mDirectionStates[direction]) {
|
||||
final int expandSize = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||
10.0f, getResources().getDisplayMetrics());
|
||||
leftBounds -= expandSize;
|
||||
rightBounds += expandSize;
|
||||
topBounds -= expandSize;
|
||||
bottomBounds += expandSize;
|
||||
}
|
||||
|
||||
final Drawable drawable = mDirectionStates[direction] ? mPressedDrawables[direction] : mUnpressedDrawables[direction];
|
||||
drawable.setBounds(leftBounds, topBounds, rightBounds, bottomBounds);
|
||||
|
@ -5,7 +5,8 @@
|
||||
android:id="@+id/constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:clipChildren="false">
|
||||
|
||||
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
|
||||
android:id="@+id/controller_button_r2"
|
||||
|
@ -5,7 +5,8 @@
|
||||
android:id="@+id/constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:clipChildren="false">
|
||||
|
||||
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
|
||||
android:id="@+id/controller_button_r2"
|
||||
|
@ -5,7 +5,8 @@
|
||||
android:id="@+id/constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:clipChildren="false">
|
||||
|
||||
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
|
||||
android:id="@+id/controller_button_r2"
|
||||
|
@ -5,7 +5,8 @@
|
||||
android:id="@+id/constraintLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:orientation="vertical"
|
||||
android:clipChildren="false">
|
||||
|
||||
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
|
||||
android:id="@+id/controller_button_a"
|
||||
|
Loading…
Reference in New Issue
Block a user