Added some support for multitouch events, it's still not working

This commit is contained in:
pelya
2010-07-29 16:12:58 +03:00
parent 0950723da0
commit 90b098c2c3
7 changed files with 70 additions and 22 deletions

View File

@@ -13,4 +13,4 @@ AppVersionCode=110003
AppVersionName="1.1.0.p3"
CompiledLibraries="sdl_mixer sdl_image"
AppCflags='-finline-functions -O2'
ReadmeText='^You can press "Home" now - the data will be downloaded in background^In game press "Menu" for secondary fire, press "Volume Up/Down" to cycle through weapons'
ReadmeText='^You can press "Home" now - the data will be downloaded in background^In game press "Menu" for secondary fire, "Volume Up/Down" to cycle weapons^If your phone doesnt have joystick or trackball the accelerometer will be used'

View File

@@ -3,5 +3,5 @@
# Set here your own NDK path if needed
# export PATH=$PATH:~/src/endless_space/android-ndk-r4
cd project && nice -n5 ndk-build V=1 && ant debug && cd bin && adb install -r DemoActivity-debug.apk
cd project && nice -n5 ndk-build V=1 -j2 && ant debug && cd bin && adb install -r DemoActivity-debug.apk

View File

@@ -90,12 +90,12 @@ SdlCompat_AcceleratedSurface *SurfaceDB::loadSurface( string fn, bool alpha ) {
newSurface = hwSurface;
}
SDL_SetColorKey( newSurface, SDL_SRCCOLORKEY,
SDL_MapRGB(newSurface->format, transR, transG, transB) );
surfaceDB[ fn ] = SdlCompat_CreateAcceleratedSurface( newSurface );
SDL_FreeSurface(newSurface);
SDL_SetColorKey( surfaceDB[ fn ], SDL_SRCCOLORKEY,
SDL_MapRGB(surfaceDB[ fn ]->format, transR, transG, transB) );
if ( alpha ) {
SDL_SetAlpha( surfaceDB[ fn ], SDL_SRCALPHA, 128 );
}

View File

@@ -158,7 +158,7 @@ static SDL_Joystick *CurrentJoystick = NULL;
enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 };
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action )
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action, jint pointerId )
{
if( !isMouseUsed )
{
@@ -277,9 +277,9 @@ void ANDROID_InitOSKeymap()
// TODO: make this configurable
keymap[KEYCODE_MENU] = SDL_KEY(RETURN);
if( !isMouseUsed )
keymap[KEYCODE_MENU] = SDL_KEY(RCTRL);
keymap[KEYCODE_MENU] = SDL_KEY(LCTRL);
keymap[KEYCODE_CALL] = SDL_KEY(LCTRL);
keymap[KEYCODE_CALL] = SDL_KEY(RCTRL);
keymap[KEYCODE_ENDCALL] = SDL_KEY(LSHIFT);
keymap[KEYCODE_CAMERA] = SDL_KEY(RSHIFT);
keymap[KEYCODE_POWER] = SDL_KEY(RALT);

View File

@@ -23,7 +23,7 @@ class Globals {
public static boolean HorizontalOrientation = true;
// Readme text to be shown on download page
public static String ReadmeText = "^You can press \"Home\" now - the data will be downloaded in background^In game press \"Menu\" for secondary fire, press \"Volume Up/Down\" to cycle through weapons".replace("^","\n");
public static String ReadmeText = "^You can press \"Home\" now - the data will be downloaded in background^In game press \"Menu\" for secondary fire, \"Volume Up/Down\" to cycle weapons^If your phone doesnt have joystick or trackball the accelerometer will be used".replace("^","\n");
public static boolean AppUsesMouse = false;

View File

@@ -120,7 +120,7 @@ public class MainActivity extends Activity {
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
public boolean dispatchTouchEvent(final MotionEvent ev) {
if(mGLView != null)
mGLView.onTouchEvent(ev);
return true;

View File

@@ -21,6 +21,60 @@ import android.view.WindowManager;
import android.widget.TextView;
import java.lang.Thread;
import java.util.concurrent.locks.ReentrantLock;
import android.os.Build;
abstract class DifferentTouchInput
{
public static DifferentTouchInput getInstance()
{
if (Integer.parseInt(Build.VERSION.SDK) <= 4)
return SingleTouchInput.Holder.sInstance;
else
return MultiTouchInput.Holder.sInstance;
}
public abstract void process(final MotionEvent event);
private static class SingleTouchInput extends DifferentTouchInput
{
private static class Holder
{
private static final SingleTouchInput sInstance = new SingleTouchInput();
}
public void process(final MotionEvent event)
{
int action = -1;
if( event.getAction() == MotionEvent.ACTION_DOWN )
action = 0;
if( event.getAction() == MotionEvent.ACTION_UP )
action = 1;
if( event.getAction() == MotionEvent.ACTION_MOVE )
action = 2;
if ( action >= 0 )
DemoGLSurfaceView.nativeMouse( (int)event.getX(), (int)event.getY(), action, 0 );
}
}
private static class MultiTouchInput extends DifferentTouchInput
{
private static class Holder
{
private static final MultiTouchInput sInstance = new MultiTouchInput();
}
public void process(final MotionEvent event)
{
for( int i = 0; i < event.getPointerCount(); i++ )
{
int action = -1;
if( event.getAction() == MotionEvent.ACTION_DOWN )
action = 0;
if( event.getAction() == MotionEvent.ACTION_UP )
action = 1;
if( event.getAction() == MotionEvent.ACTION_MOVE )
action = 2;
if ( action >= 0 )
DemoGLSurfaceView.nativeMouse( (int)event.getX(event.getPointerId(i)), (int)event.getY(event.getPointerId(i)), action, event.getPointerId(i) );
}
}
}
}
class DemoRenderer extends GLSurfaceView_SDL.Renderer {
@@ -84,26 +138,19 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
public DemoGLSurfaceView(Activity context) {
super(context);
mParent = context;
touchInput = DifferentTouchInput.getInstance();
setEGLConfigChooser(Globals.NeedDepthBuffer);
accelerometer = new AccelerometerReader(context);
mRenderer = new DemoRenderer(context);
setRenderer(mRenderer);
}
@Override
public boolean onTouchEvent(final MotionEvent event)
{
touchInput.process(event);
// TODO: add multitouch support (added in Android 2.0 SDK)
int action = -1;
if( event.getAction() == MotionEvent.ACTION_DOWN )
action = 0;
if( event.getAction() == MotionEvent.ACTION_UP )
action = 1;
if( event.getAction() == MotionEvent.ACTION_MOVE )
action = 2;
if ( action >= 0 ) {
nativeMouse( (int)event.getX(), (int)event.getY(), action );
}
// Wait a bit, and try to synchronize to app framerate, or event thread will eat all CPU and we'll lose FPS
synchronized (mRenderer) {
try {
@@ -134,9 +181,10 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
DemoRenderer mRenderer;
Activity mParent;
AccelerometerReader accelerometer = null;
DifferentTouchInput touchInput = null;
public native void nativeMouse( int x, int y, int action );
public native void nativeKey( int keyCode, int down );
public static native void nativeMouse( int x, int y, int action, int pointerId );
public static native void nativeKey( int keyCode, int down );
}