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,23 +350,10 @@ import android.view.WindowManager;
|
|||||||
import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview;
|
import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview;
|
||||||
|
|
||||||
public class EbitenView extends ViewGroup implements InputManager.InputDeviceListener {
|
public class EbitenView extends ViewGroup implements InputManager.InputDeviceListener {
|
||||||
private double getDeviceScale() {
|
private static double pxToDp(double x) {
|
||||||
if (this.deviceScale == 0.0) {
|
return x / Ebitenmobileview.deviceScale();
|
||||||
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 double pxToDp(double x) {
|
|
||||||
return x / getDeviceScale();
|
|
||||||
}
|
|
||||||
|
|
||||||
private double deviceScale = 0.0;
|
|
||||||
|
|
||||||
public EbitenView(Context context) {
|
public EbitenView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
initialize(context);
|
initialize(context);
|
||||||
|
File diff suppressed because one or more lines are too long
@ -30,6 +30,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"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/restorable"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/uidriver/mobile"
|
"github.com/hajimehoshi/ebiten/v2/internal/uidriver/mobile"
|
||||||
)
|
)
|
||||||
@ -85,3 +86,7 @@ func Resume() {
|
|||||||
func OnContextLost() {
|
func OnContextLost() {
|
||||||
restorable.OnContextLost()
|
restorable.OnContextLost()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeviceScale() float64 {
|
||||||
|
return devicescale.GetAt(0, 0)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user