mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 19:58:54 +01:00
cmd/ebitenmobile: Refactoring
This commit is contained in:
parent
5040b3bcfc
commit
e3d1e7784e
@ -339,6 +339,7 @@ import android.os.Looper;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview;
|
import {{.JavaPkg}}.ebitenmobileview.Ebitenmobileview;
|
||||||
@ -393,6 +394,17 @@ public class EbitenView extends ViewGroup {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent e) {
|
||||||
|
for (int i = 0; i < e.getPointerCount(); i++) {
|
||||||
|
int id = e.getPointerId(i);
|
||||||
|
int x = (int)e.getX(i);
|
||||||
|
int y = (int)e.getY(i);
|
||||||
|
Ebitenmobileview.updateTouchesOnAndroid(e.getActionMasked(), id, (int)pxToDp(x), (int)pxToDp(y));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// suspendGame suspends the game.
|
// suspendGame suspends the game.
|
||||||
// It is recommended to call this when the application is being suspended e.g.,
|
// It is recommended to call this when the application is being suspended e.g.,
|
||||||
// Activity's onPause is called.
|
// Activity's onPause is called.
|
||||||
@ -428,7 +440,6 @@ import android.opengl.GLSurfaceView;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
@ -485,28 +496,6 @@ class EbitenSurfaceView extends GLSurfaceView {
|
|||||||
setRenderer(new EbitenRenderer());
|
setRenderer(new EbitenRenderer());
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getDeviceScale() {
|
|
||||||
if (deviceScale_ == 0.0) {
|
|
||||||
deviceScale_ = getResources().getDisplayMetrics().density;
|
|
||||||
}
|
|
||||||
return deviceScale_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double pxToDp(double x) {
|
|
||||||
return x / getDeviceScale();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onTouchEvent(MotionEvent e) {
|
|
||||||
for (int i = 0; i < e.getPointerCount(); i++) {
|
|
||||||
int id = e.getPointerId(i);
|
|
||||||
int x = (int)e.getX(i);
|
|
||||||
int y = (int)e.getY(i);
|
|
||||||
Ebitenmobileview.updateTouchesOnAndroid(e.getActionMasked(), id, (int)pxToDp(x), (int)pxToDp(y));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onErrorOnGameUpdate(Exception e) {
|
private void onErrorOnGameUpdate(Exception e) {
|
||||||
((EbitenView)getParent()).onErrorOnGameUpdate(e);
|
((EbitenView)getParent()).onErrorOnGameUpdate(e);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user