From d79d856394ea51d48f6a9f135650b3ad138f8402 Mon Sep 17 00:00:00 2001 From: Matteo Hausner Date: Mon, 13 Jan 2014 18:00:45 +0100 Subject: [PATCH 1/8] First test-implementation for moveable touch controls --- .../src/com/reicast/emulator/GL2JNIView.java | 152 ++++++++++++++---- 1 file changed, 123 insertions(+), 29 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/GL2JNIView.java b/shell/android/src/com/reicast/emulator/GL2JNIView.java index 697482274..4204f7ffc 100644 --- a/shell/android/src/com/reicast/emulator/GL2JNIView.java +++ b/shell/android/src/com/reicast/emulator/GL2JNIView.java @@ -58,31 +58,50 @@ class GL2JNIView extends GLSurfaceView private static final int key_CONT_X = 0x0400; Vibrator vib; + + private boolean editVjoyMode = true; + private int selectedVjoyElement = -1; - - private static final float[][] vjoy_d = new float[][] - { - new float[] { 20+0, 288+64, 64,64, key_CONT_DPAD_LEFT}, - new float[] { 20+64, 288+0, 64,64, key_CONT_DPAD_UP}, - new float[] { 20+128, 288+64, 64,64, key_CONT_DPAD_RIGHT}, - new float[] { 20+64, 288+128, 64,64, key_CONT_DPAD_DOWN}, + private static final float[][] vjoy_d_custom = new float[][] + { + // x-shift, y-shift, sizing-factor + new float[] { 0, 0, 1 }, // DPAD - new float[] { 448+0, 288+64, 64,64, key_CONT_X}, - new float[] { 448+64, 288+0, 64,64, key_CONT_Y}, - new float[] { 448+128, 288+64, 64,64, key_CONT_B}, - new float[] { 448+64, 288+128, 64,64, key_CONT_A}, + new float[] { 0, 0, 1 }, // X, Y, B, A Buttons - new float[] { 320-32, 288+128, 64,64, key_CONT_START}, - - new float[] { 440, 200, 90,64, -1}, - new float[] { 542, 200, 90,64, -2}, - - new float[] { 16, 24+32, 128,128, -3}, - new float[] { 96, 320, 32,32, -4}, + new float[] { 0, 0, 1 }, // Start + new float[] { 0, 0, 1 }, // Left Trigger + new float[] { 0, 0, 1 }, // Right Trigger + new float[] { 0, 0, 1 }, // Analog Stick }; - + + private float[][] vjoy_d = getVjoy_d(); + + private static float[][] getVjoy_d() { + return new float[][] + { + new float[] { 20+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_LEFT}, + new float[] { 20+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_UP}, + new float[] { 20+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_RIGHT}, + new float[] { 20+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+128*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_DOWN}, + + new float[] { 448+0*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][1], 64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_X}, + new float[] { 448+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+0*vjoy_d_custom[1][2]+vjoy_d_custom[1][1], 64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_Y}, + new float[] { 448+128*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][1], 64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_B}, + new float[] { 448+64*vjoy_d_custom[1][2]+vjoy_d_custom[1][0], 288+128*vjoy_d_custom[1][2]+vjoy_d_custom[1][1], 64*vjoy_d_custom[1][2],64*vjoy_d_custom[1][2], key_CONT_A}, + + new float[] { 320-32+vjoy_d_custom[2][0], 288+128+vjoy_d_custom[2][1], 64*vjoy_d_custom[2][2],64*vjoy_d_custom[2][2], key_CONT_START}, + + new float[] { 440+vjoy_d_custom[3][0], 200+vjoy_d_custom[3][1], 90*vjoy_d_custom[3][2],64*vjoy_d_custom[3][2], -1}, + new float[] { 542+vjoy_d_custom[4][0], 200+vjoy_d_custom[4][1], 90*vjoy_d_custom[4][2],64*vjoy_d_custom[4][2], -2}, + + new float[] { 16+vjoy_d_custom[5][0], 24+32+vjoy_d_custom[5][1], 128*vjoy_d_custom[5][2],128*vjoy_d_custom[5][2], -3}, + new float[] { 96+vjoy_d_custom[5][0], 320+vjoy_d_custom[5][1], 32*vjoy_d_custom[5][2],32*vjoy_d_custom[5][2], -4}, + }; + } + private static final float[][] vjoy = new float[][] { new float[] { 24+0, 24+64, 64,64, key_CONT_DPAD_LEFT, 0}, @@ -206,6 +225,16 @@ class GL2JNIView extends GLSurfaceView { return (int) (p*scl ); } + + float invertVbase(float p, float m, float scl) + { + return m + (m + p) / scl; + } + + float invertVbase(float p, float scl) + { + return p / scl; + } public boolean isTablet() { return (getContext().getResources().getConfiguration().screenLayout @@ -273,6 +302,17 @@ class GL2JNIView extends GLSurfaceView } */ + private static int getElementIdFromButtonId(int buttonId) { + if (buttonId <= 3) + return 0; // DPAD + else if (buttonId <= 7) + return 1; // // X, Y, B, A Buttons + else if (buttonId == 8) + return 2; // Start + else + return -1; + } + static int[] kcode_raw = { 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF }; static int[] lt = new int[4], rt = new int[4], jx = new int[4], jy = new int[4]; @@ -288,6 +328,42 @@ class GL2JNIView extends GLSurfaceView int aid = event.getActionMasked(); int pid = event.getActionIndex(); + + if (editVjoyMode && selectedVjoyElement != -1 && aid == MotionEvent.ACTION_MOVE) { + float magic = isTablet() ? 0.8f : 0.7f; + float scl_i=480.0f/getHeight() * getContext().getResources().getDisplayMetrics().density * magic; + float scl_dc_i=getHeight()/480.0f; + float tx_i = ((getWidth()-640.0f*scl_dc_i)/2)/scl_dc_i; + float a_x = -tx_i+ 24*scl_i; + float a_y =- 24*scl_i; + + float x = (event.getX()-tx)/scl; + float y = (event.getY()-ty)/scl; + + /*if (x==invertVbase(288,scl_i)) + Log.w("type", "1"); + else if (x Date: Mon, 13 Jan 2014 21:10:53 +0100 Subject: [PATCH 2/8] First working sample implementation of edit mode --- .../src/com/reicast/emulator/GL2JNIView.java | 206 ++++++++++++------ 1 file changed, 134 insertions(+), 72 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/GL2JNIView.java b/shell/android/src/com/reicast/emulator/GL2JNIView.java index 4204f7ffc..0662aa570 100644 --- a/shell/android/src/com/reicast/emulator/GL2JNIView.java +++ b/shell/android/src/com/reicast/emulator/GL2JNIView.java @@ -19,6 +19,8 @@ import android.os.Vibrator; import android.preference.PreferenceManager; import android.util.Log; import android.view.MotionEvent; +import android.view.ScaleGestureDetector; +import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener; /** @@ -61,25 +63,20 @@ class GL2JNIView extends GLSurfaceView private boolean editVjoyMode = true; private int selectedVjoyElement = -1; + private ScaleGestureDetector scaleGestureDetector; - private static final float[][] vjoy_d_custom = new float[][] + private static float[][] vjoy_d_custom;/* = new float[][] { // x-shift, y-shift, sizing-factor new float[] { 0, 0, 1 }, // DPAD - new float[] { 0, 0, 1 }, // X, Y, B, A Buttons - new float[] { 0, 0, 1 }, // Start - new float[] { 0, 0, 1 }, // Left Trigger new float[] { 0, 0, 1 }, // Right Trigger - - new float[] { 0, 0, 1 }, // Analog Stick - }; + new float[] { 0, 0, 1 } // Analog Stick + };*/ - private float[][] vjoy_d = getVjoy_d(); - - private static float[][] getVjoy_d() { + private static float[][] getVjoy_d(float[][] vjoy_d_custom) { return new float[][] { new float[] { 20+0*vjoy_d_custom[0][2]+vjoy_d_custom[0][0], 288+64*vjoy_d_custom[0][2]+vjoy_d_custom[0][1], 64*vjoy_d_custom[0][2],64*vjoy_d_custom[0][2], key_CONT_DPAD_LEFT}, @@ -102,6 +99,49 @@ class GL2JNIView extends GLSurfaceView }; } + private static void writeCustomVjoyValues(float[][] vjoy_d_custom, Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + prefs.edit().putFloat("touch_x_shift_dpad", vjoy_d_custom[0][0]).commit(); + prefs.edit().putFloat("touch_y_shift_dpad", vjoy_d_custom[0][1]).commit(); + prefs.edit().putFloat("touch_scale_dpad", vjoy_d_custom[0][2]).commit(); + + prefs.edit().putFloat("touch_x_shift_buttons", vjoy_d_custom[1][0]).commit(); + prefs.edit().putFloat("touch_y_shift_buttons", vjoy_d_custom[1][1]).commit(); + prefs.edit().putFloat("touch_scale_buttons", vjoy_d_custom[1][2]).commit(); + + prefs.edit().putFloat("touch_x_shift_start", vjoy_d_custom[2][0]).commit(); + prefs.edit().putFloat("touch_y_shift_start", vjoy_d_custom[2][1]).commit(); + prefs.edit().putFloat("touch_scale_start", vjoy_d_custom[2][2]).commit(); + + prefs.edit().putFloat("touch_x_shift_left_trigger", vjoy_d_custom[3][0]).commit(); + prefs.edit().putFloat("touch_y_shift_left_trigger", vjoy_d_custom[3][1]).commit(); + prefs.edit().putFloat("touch_scale_left_trigger", vjoy_d_custom[3][2]).commit(); + + prefs.edit().putFloat("touch_x_shift_right_trigger", vjoy_d_custom[4][0]).commit(); + prefs.edit().putFloat("touch_y_shift_right_trigger", vjoy_d_custom[4][1]).commit(); + prefs.edit().putFloat("touch_scale_right_trigger", vjoy_d_custom[4][2]).commit(); + + prefs.edit().putFloat("touch_x_shift_analog", vjoy_d_custom[5][0]).commit(); + prefs.edit().putFloat("touch_y_shift_analog", vjoy_d_custom[5][1]).commit(); + prefs.edit().putFloat("touch_scale_analog", vjoy_d_custom[5][2]).commit(); + } + + private static float[][] readCustomVjoyValues(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + return new float[][] + { + // x-shift, y-shift, sizing-factor + new float[] { prefs.getFloat("touch_x_shift_dpad", 0), prefs.getFloat("touch_y_shift_dpad", 0), prefs.getFloat("touch_scale_dpad", 1) }, // DPAD + new float[] { prefs.getFloat("touch_x_shift_buttons", 0), prefs.getFloat("touch_y_shift_buttons", 0), prefs.getFloat("touch_scale_buttons", 1) }, // X, Y, B, A Buttons + new float[] { prefs.getFloat("touch_x_shift_start", 0), prefs.getFloat("touch_y_shift_start", 0), prefs.getFloat("touch_scale_start", 1) }, // Start + new float[] { prefs.getFloat("touch_x_shift_left_trigger", 0), prefs.getFloat("touch_y_shift_left_trigger", 0), prefs.getFloat("touch_scale_left_trigger", 1) }, // Left Trigger + new float[] { prefs.getFloat("touch_x_shift_right_trigger", 0), prefs.getFloat("touch_y_shift_right_trigger", 0), prefs.getFloat("touch_scale_right_trigger", 1) }, // Right Trigger + new float[] { prefs.getFloat("touch_x_shift_analog", 0), prefs.getFloat("touch_y_shift_analog", 0), prefs.getFloat("touch_scale_analog", 1) } // Analog Stick + }; + } + private static final float[][] vjoy = new float[][] { new float[] { 24+0, 24+64, 64,64, key_CONT_DPAD_LEFT, 0}, @@ -128,17 +168,22 @@ class GL2JNIView extends GLSurfaceView Renderer rend; private boolean touchVibrationEnabled; - + Context context; public GL2JNIView(Context context,String newFileName,boolean translucent,int depth,int stencil) { super(context); + this.context = context; setKeepScreenOn(true); vib=(Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); touchVibrationEnabled = prefs.getBoolean("touch_vibration_enabled", true); + vjoy_d_custom = readCustomVjoyValues(context); + + scaleGestureDetector = new ScaleGestureDetector(context, new OscOnScaleGestureListener()); + // This is the game we are going to run fileName = newFileName; @@ -225,16 +270,6 @@ class GL2JNIView extends GLSurfaceView { return (int) (p*scl ); } - - float invertVbase(float p, float m, float scl) - { - return m + (m + p) / scl; - } - - float invertVbase(float p, float scl) - { - return p / scl; - } public boolean isTablet() { return (getContext().getResources().getConfiguration().screenLayout @@ -243,11 +278,11 @@ class GL2JNIView extends GLSurfaceView } @Override - protected void onLayout(boolean changed, int left, int top, int right, int bottom) + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); //dcpx/cm = dcpx/px * px/cm - float magic = isTablet() ? 0.8f : 0.7f; + float magic = isTablet() ? 0.8f : 0.7f; float scl=480.0f/getHeight() * getContext().getResources().getDisplayMetrics().density * magic; float scl_dc=getHeight()/480.0f; float tx = ((getWidth()-640.0f*scl_dc)/2)/scl_dc; @@ -255,25 +290,28 @@ class GL2JNIView extends GLSurfaceView float a_x = -tx+ 24*scl; float a_y=- 24*scl; + float[][] vjoy_d = getVjoy_d(vjoy_d_custom); + for(int i=0;i=-2) { - if (vjoy[j][5]==0 && touchVibrationEnabled) + if (vjoy[j][5]==0) + if (!editVjoyMode && touchVibrationEnabled) vib.vibrate(50); vjoy[j][5]=2; } @@ -401,7 +439,8 @@ class GL2JNIView extends GLSurfaceView { if (editVjoyMode) { selectedVjoyElement = 5;Log.w("selcted", "anal"); // Analog - }else { + resetEditMode(); + } else { vjoy[j+1][0]=x-vjoy[j+1][2]/2; vjoy[j+1][1]=y-vjoy[j+1][3]/2; @@ -411,21 +450,24 @@ class GL2JNIView extends GLSurfaceView } else if (vjoy[j][4]==-4); else if(vjoy[j][4]==-1) { - if (editVjoyMode) + if (editVjoyMode) { selectedVjoyElement = 3; // Left Trigger - else + resetEditMode(); + } else lt[0]=pre; } else if(vjoy[j][4]==-2) { - if (editVjoyMode) + if (editVjoyMode) { selectedVjoyElement = 4; // Right Trigger - else + resetEditMode(); + } else rt[0]=pre; } else { - if (editVjoyMode) + if (editVjoyMode) { selectedVjoyElement = getElementIdFromButtonId(j); - else + resetEditMode(); + } else rv&=~(int)vjoy[j][4]; } } @@ -499,7 +541,27 @@ class GL2JNIView extends GLSurfaceView jy[0] = get_anal(11, 1); return(true); } - + +private class OscOnScaleGestureListener extends + SimpleOnScaleGestureListener { + + @Override + public boolean onScale(ScaleGestureDetector detector) { + if (editVjoyMode && selectedVjoyElement != -1) { + vjoy_d_custom[selectedVjoyElement][2] *= detector.getScaleFactor(); + requestLayout(); + + return true; + } + + return false; + } + + @Override + public void onScaleEnd(ScaleGestureDetector detector) { + selectedVjoyElement = -1; + } +} private static class ContextFactory implements GLSurfaceView.EGLContextFactory { From 95eca8fe4e80fbfaf7b63b2dccd0c396dd54bcd9 Mon Sep 17 00:00:00 2001 From: Matteo Hausner Date: Tue, 14 Jan 2014 21:45:37 +0100 Subject: [PATCH 3/8] Further integration of customizable OSC --- shell/android/AndroidManifest.xml | 5 +- .../res/layout/controllers_fragment.xml | 28 +++- .../reicast/emulator/ControllersFragment.java | 11 +- .../reicast/emulator/EditVJoyActivity.java | 122 ++++++++++++++++++ .../com/reicast/emulator/GL2JNIActivity.java | 2 +- .../src/com/reicast/emulator/GL2JNIView.java | 44 ++++++- 6 files changed, 202 insertions(+), 10 deletions(-) create mode 100644 shell/android/src/com/reicast/emulator/EditVJoyActivity.java diff --git a/shell/android/AndroidManifest.xml b/shell/android/AndroidManifest.xml index 4d4e9f6dd..b61af24da 100644 --- a/shell/android/AndroidManifest.xml +++ b/shell/android/AndroidManifest.xml @@ -43,7 +43,10 @@ + + + - \ No newline at end of file + diff --git a/shell/android/res/layout/controllers_fragment.xml b/shell/android/res/layout/controllers_fragment.xml index cefdc5c24..c13e0ffd7 100644 --- a/shell/android/res/layout/controllers_fragment.xml +++ b/shell/android/res/layout/controllers_fragment.xml @@ -9,6 +9,32 @@ android:layout_height="wrap_content" android:stretchColumns="*" > + + + + + + +