Merge pull request #1110 from Mathias-Boulay/Installer_scaler

QoL UI updates
This commit is contained in:
LegacyGamerHD 2021-04-05 20:39:46 +02:00 committed by GitHub
commit bc7de9bacd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 104 additions and 48 deletions

View File

@ -10,6 +10,9 @@ import net.kdt.pojavlaunch.utils.*;
import org.lwjgl.glfw.*;
public class AWTCanvasView extends TextureView implements TextureView.SurfaceTextureListener, Runnable {
private int mScaleFactor;
private int[] mScales;
private int mWidth, mHeight;
private boolean mIsDestroyed = false;
@ -32,6 +35,22 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
}
return difference > 0 ? times.size() / difference : 0.0;
}
/** Computes the scale to better fit the screen */
int[] initScaleFactors(){
//Could be optimized
int minDimension = Math.min(CallbackBridge.physicalHeight,CallbackBridge.physicalWidth);
mScaleFactor = (3*minDimension)/1080;
int[] scales = new int[2]; //Left, Top
scales[0] = (CallbackBridge.physicalWidth/2);
scales[0] -= scales[0]/mScaleFactor;
scales[1] = (CallbackBridge.physicalHeight/2);
scales[1] -= scales[1]/mScaleFactor;
return scales;
}
public AWTCanvasView(Context ctx) {
this(ctx, null);
@ -46,6 +65,7 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
fpsPaint.setTextSize(20);
setSurfaceTextureListener(this);
mScales = initScaleFactors();
}
@Override
@ -91,7 +111,15 @@ public class AWTCanvasView extends TextureView implements TextureView.SurfaceTex
int[] rgbArray = JREUtils.renderAWTScreenFrame(/* canvas, mWidth, mHeight */);
mDrawing = rgbArray != null;
if (rgbArray != null) {
canvas.save();
canvas.scale(mScaleFactor, mScaleFactor);
canvas.translate(-mScales[0],-mScales[1]);
canvas.drawBitmap(rgbArray, 0, CallbackBridge.physicalWidth, 0, 0, CallbackBridge.physicalWidth, CallbackBridge.physicalHeight, true, null);
canvas.restore();
}
rgbArray = null;
// System.gc();

View File

@ -1,20 +1,20 @@
package net.kdt.pojavlaunch;
import android.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.util.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import androidx.appcompat.app.*;
import java.io.*;
import java.util.*;
import net.kdt.pojavlaunch.prefs.*;
import net.kdt.pojavlaunch.utils.*;
import org.lwjgl.glfw.*;
import static net.kdt.pojavlaunch.utils.MathUtils.map;
public class JavaGUILauncherActivity extends LoggableActivity implements View.OnTouchListener {
private static final int MSG_LEFT_MOUSE_BUTTON_CHECK = 1028;
@ -33,12 +33,11 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
private final Object mDialogLock = new Object();
private DisplayMetrics displayMetrics;
private boolean isLogAllow, mSkipDetectMod;
private boolean rightOverride = false;
private float scaleFactor = 1;
private int fingerStillThreshold = 8;
private int[] scaleFactor = initScaleFactors();
private final int fingerStillThreshold = 8;
private int initialX;
private int initialY;
private static boolean triggeredLeftMouseButton = false;
@ -68,11 +67,6 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
try {
gestureDetector = new GestureDetector(this, new SingleTapConfirm());
this.displayMetrics = Tools.getDisplayMetrics(this);
CallbackBridge.windowWidth = (int) ((float)displayMetrics.widthPixels * scaleFactor);
CallbackBridge.windowHeight = (int) ((float)displayMetrics.heightPixels * scaleFactor);
System.out.println("WidthHeight: " + CallbackBridge.windowWidth + ":" + CallbackBridge.windowHeight);
findViewById(R.id.installmod_mouse_pri).setOnTouchListener(this);
findViewById(R.id.installmod_mouse_sec).setOnTouchListener(this);
@ -81,24 +75,13 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
touchPad.setFocusable(false);
this.mousePointer = findViewById(R.id.main_mouse_pointer);
this.mousePointer.post(new Runnable(){
@Override
public void run() {
ViewGroup.LayoutParams params = mousePointer.getLayoutParams();
params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE);
params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE);
}
});
/*
touchPad.setOnHoverListener(new OnHoverListener() {
@Override
public boolean onHover(View v, MotionEvent event) {
AWTInputBridge.sendMousePos((int) event.getX(), (int) event.getY());
return false;
}
this.mousePointer.post(() -> {
ViewGroup.LayoutParams params = mousePointer.getLayoutParams();
params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE);
params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE);
});
*/
touchPad.setOnTouchListener(new OnTouchListener(){
private float prevX, prevY;
@Override
@ -124,7 +107,8 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
if (gestureDetector.onTouchEvent(event)) {
AWTInputBridge.sendMousePos((int) (mouseX * scaleFactor), (int) (mouseY *scaleFactor));
sendScaledMousePosition(mouseX,mouseY);
AWTInputBridge.sendMousePress(rightOverride ? AWTInputEvent.BUTTON3_DOWN_MASK : AWTInputEvent.BUTTON1_DOWN_MASK);
if (!rightOverride) {
CallbackBridge.mouseLeft = true;
@ -140,11 +124,11 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
}
break;
case MotionEvent.ACTION_MOVE: // 2
mouseX = Math.max(0, Math.min(displayMetrics.widthPixels, mouseX + x - prevX));
mouseY = Math.max(0, Math.min(displayMetrics.heightPixels, mouseY + y - prevY));
mouseX = Math.max(0, Math.min(CallbackBridge.physicalWidth, mouseX + x - prevX));
mouseY = Math.max(0, Math.min(CallbackBridge.physicalHeight, mouseY + y - prevY));
placeMouseAt(mouseX, mouseY);
AWTInputBridge.sendMousePos((int) (mouseX * scaleFactor), (int) (mouseY *scaleFactor));
sendScaledMousePosition(mouseX,mouseY);
/*
if (!CallbackBridge.isGrabbing()) {
CallbackBridge.sendMouseKeycode(LWJGLGLFWKeycode.GLFW_MOUSE_BUTTON_LEFT, 0, isLeftMouseDown);
@ -269,6 +253,11 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
this.mousePointer.setTranslationY(y);
}
void sendScaledMousePosition(float x, float y){
AWTInputBridge.sendMousePos((int) map(x,0,CallbackBridge.physicalWidth,scaleFactor[0],scaleFactor[2]),
(int) map(y,0,CallbackBridge.physicalHeight,scaleFactor[1],scaleFactor[3]));
}
public void forceClose(View v) {
BaseMainActivity.dialogForceClose(this);
}
@ -334,12 +323,31 @@ public class JavaGUILauncherActivity extends LoggableActivity implements View.On
public void appendToLog(final String text, boolean checkAllow) {
logStream.print(text);
if (checkAllow && !isLogAllow) return;
textLog.post(new Runnable(){
@Override
public void run() {
textLog.append(text);
contentScroll.fullScroll(ScrollView.FOCUS_DOWN);
}
});
textLog.post(() -> {
textLog.append(text);
contentScroll.fullScroll(ScrollView.FOCUS_DOWN);
});
}
int[] initScaleFactors(){
//Could be optimized
int minDimension = Math.min(CallbackBridge.physicalHeight,CallbackBridge.physicalWidth);
int scaleFactor = (3*minDimension)/1080;
int[] scales = new int[4]; //Left, Top, Right, Bottom
scales[0] = (CallbackBridge.physicalWidth/2);
scales[0] -= scales[0]/scaleFactor;
scales[1] = (CallbackBridge.physicalHeight/2);
scales[1] -= scales[1]/scaleFactor;
scales[2] = (CallbackBridge.physicalWidth/2);
scales[2] += scales[2]/scaleFactor;
scales[3] = (CallbackBridge.physicalHeight/2);
scales[3] += scales[3]/scaleFactor;
return scales;
}
}

View File

@ -32,6 +32,7 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
@ -651,15 +652,16 @@ public class PojavLoginActivity extends BaseActivity
View child = inflater.inflate(R.layout.simple_account_list_item, null);
TextView accountName = child.findViewById(R.id.accountitem_text_name);
ImageButton removeButton = child.findViewById(R.id.accountitem_button_remove);
ImageView imageView = child.findViewById(R.id.account_head);
String accNameStr = s.substring(0, s.length() - 5);
String skinFaceBase64 = MinecraftAccount.load(accNameStr).skinFaceBase64;
if (skinFaceBase64 != null) {
byte[] faceIconBytes = Base64.decode(skinFaceBase64, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(faceIconBytes, 0, faceIconBytes.length);
accountName.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(getResources(),
bitmap), null, null, null);
imageView.setImageDrawable(new BitmapDrawable(getResources(),
bitmap));
}
accountName.setText(accNameStr);

View File

@ -0,0 +1,10 @@
package net.kdt.pojavlaunch.utils;
public class MathUtils {
//Ported from https://www.arduino.cc/reference/en/language/functions/math/map/
public static float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
}

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -8,20 +7,19 @@
<TextView
android:id="@+id/accountitem_text_name"
android:layout_width="240dp"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:maxHeight="?android:attr/listPreferredItemHeightSmall"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:text="Name Placeholder"
android:text="Name Placeholder"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:drawablePadding="20dp"
app:layout_constraintEnd_toStartOf="@+id/accountitem_button_remove"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
@ -37,5 +35,15 @@
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_remove" />
<ImageView
android:id="@+id/account_head"
android:layout_width="48dp"
android:layout_height="48dp"
android:maxHeight="?android:attr/listPreferredItemHeightSmall"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
app:layout_constraintEnd_toStartOf="@+id/accountitem_text_name"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>