Skip to content

Commit

Permalink
Make texture scale changeable by display DPI
Browse files Browse the repository at this point in the history
Resolves #1078

Signed-off-by: Songlin Jiang <[email protected]>
  • Loading branch information
HollowMan6 committed Oct 23, 2023
1 parent 6298da5 commit c1701ff
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,11 @@ void handleMotionEvent(final int aHandle, final int aDevice, final boolean aFocu
widget = null; // Fallback to mRootWidget in order to allow world clicks to dismiss UI.
}

float scale = widget != null ? widget.getPlacement().textureScale : 1.0f;
float scale = widget != null ? widget.getPlacement().textureScale : SettingsStore.getInstance(this).getDisplayDpi() / 100.0f;
// WindowWidget is an exception to handle coordinates correctly.
if (widget instanceof WindowWidget) {
scale = 1.0f;
}
final float x = aX / scale;
final float y = aY / scale;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ SettingsStore getInstance(final @NonNull Context aContext) {
public final static int WINDOW_WIDTH_DEFAULT = 800;
public final static int WINDOW_HEIGHT_DEFAULT = 450;
public final static int DISPLAY_DPI_DEFAULT = 96;
public final static int DISPLAY_DPI_MIN = 70;
public final static int DISPLAY_DPI_MAX = 400;
public final static int MAX_WINDOW_WIDTH_DEFAULT = 1200;
public final static int MAX_WINDOW_HEIGHT_DEFAULT = 1200;
public final static int POINTER_COLOR_DEFAULT_DEFAULT = Color.parseColor("#FFFFFF");
Expand Down Expand Up @@ -416,11 +418,15 @@ public float getWindowAspect() {
}

public int getDisplayDpi() {
return mPrefs.getInt(
mContext.getString(R.string.settings_key_display_dpi), DISPLAY_DPI_DEFAULT);
return Math.max(Math.min(mPrefs.getInt(
mContext.getString(R.string.settings_key_display_dpi), DISPLAY_DPI_DEFAULT), DISPLAY_DPI_MAX), DISPLAY_DPI_MIN);
}

public void setDisplayDpi(int aDpi) {
// Reject non-valid value
if (aDpi > DISPLAY_DPI_MAX || aDpi < DISPLAY_DPI_MIN) {
return;
}
SharedPreferences.Editor editor = mPrefs.edit();
editor.putInt(mContext.getString(R.string.settings_key_display_dpi), aDpi);
editor.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.rotationAxisX = 1.0f;
aPlacement.rotation = (float)Math.toRadians(-45);
aPlacement.cylinder = false;
aPlacement.textureScale = 1.0f;
aPlacement.textureScale *= aPlacement.worldWidth;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public WidgetPlacement(Context aContext) {
density = aContext.getResources().getDisplayMetrics().density;
// Default value
cylinderMapRadius = Math.abs(WidgetPlacement.floatDimension(aContext, R.dimen.window_world_z));
if (DeviceType.isHVRBuild()) {
textureScale = 1.0f;
}
textureScale = SettingsStore.getInstance(aContext).getDisplayDpi() / 100.0f;
}

public float density;
Expand All @@ -60,7 +58,7 @@ public WidgetPlacement(Context aContext) {
public boolean layer = true;
public int layerPriority = 0; // Used for depth sorting
public boolean proxifyLayer = false;
public float textureScale = 0.7f;
public float textureScale = SettingsStore.DISPLAY_DPI_DEFAULT / 100.0f;
// Widget will be curved if enabled.
public boolean cylinder = true;
public int tintColor = 0xFFFFFFFF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
aPlacement.density = getBrowserDensity();
aPlacement.visible = true;
aPlacement.cylinder = true;
aPlacement.textureScale = 1.0f;
aPlacement.name = "Window";
// Check Windows.placeWindow method for remaining placement set-up
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private boolean setDisplayDpi(int newDpi) {
mBinding.dpiEdit.setOnClickListener(null);
boolean restart = false;
int prevDensity = SettingsStore.getInstance(getContext()).getDisplayDpi();
if (newDpi <= 0) {
if (newDpi < SettingsStore.DISPLAY_DPI_MIN || newDpi > SettingsStore.DISPLAY_DPI_MAX) {
newDpi = prevDensity;

} else if (prevDensity != newDpi) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/tray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/status_bar"
android:layout_marginTop="-2px"
android:background="@drawable/tray_background_bottom"
android:orientation="horizontal">

Expand Down

0 comments on commit c1701ff

Please sign in to comment.