mobile/ebitenmobileview: Add DeviceScale and use it at EbitenView

Closes #1482
This commit is contained in:
Hajime Hoshi 2021-04-11 02:30:35 +09:00
parent 8a8700b636
commit 2e6e1ed39d
3 changed files with 8 additions and 16 deletions

View File

@ -350,22 +350,9 @@ import android.view.WindowManager;
import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview;
public class EbitenView extends ViewGroup implements InputManager.InputDeviceListener {
private double getDeviceScale() {
if (this.deviceScale == 0.0) {
WindowManager windowManager = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getRealMetrics(displayMetrics);
this.deviceScale = displayMetrics.density;
private static double pxToDp(double x) {
return x / Ebitenmobileview.deviceScale();
}
return this.deviceScale;
}
private double pxToDp(double x) {
return x / getDeviceScale();
}
private double deviceScale = 0.0;
public EbitenView(Context context) {
super(context);

File diff suppressed because one or more lines are too long

View File

@ -30,6 +30,7 @@ import (
"sync/atomic"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/internal/devicescale"
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
"github.com/hajimehoshi/ebiten/v2/internal/uidriver/mobile"
)
@ -85,3 +86,7 @@ func Resume() {
func OnContextLost() {
restorable.OnContextLost()
}
func DeviceScale() float64 {
return devicescale.GetAt(0, 0)
}