mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
mobile/ebitenmobileview: Add DeviceScale and use it at EbitenView
Closes #1482
This commit is contained in:
parent
8a8700b636
commit
2e6e1ed39d
@ -350,23 +350,10 @@ 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;
|
||||
}
|
||||
return this.deviceScale;
|
||||
private static double pxToDp(double x) {
|
||||
return x / Ebitenmobileview.deviceScale();
|
||||
}
|
||||
|
||||
private double pxToDp(double x) {
|
||||
return x / getDeviceScale();
|
||||
}
|
||||
|
||||
private double deviceScale = 0.0;
|
||||
|
||||
public EbitenView(Context context) {
|
||||
super(context);
|
||||
initialize(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