mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
mobile/ebitenmobileview: Add DeviceScale and use it at EbitenView
Closes #1482
This commit is contained in:
parent
8a8700b636
commit
2e6e1ed39d
@ -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
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user