Option to assign mouse click to any HW key

This commit is contained in:
pelya
2011-01-04 16:19:40 +00:00
parent 28b25e2224
commit 92fe366c81
12 changed files with 73 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ package net.sourceforge.clonekeenplus;
import android.app.Activity;
import android.content.Context;
import java.util.Vector;
import android.view.KeyEvent;
class Globals {
public static String ApplicationName = "CommanderGenius";
@@ -65,13 +66,15 @@ class Globals {
public static final int LEFT_CLICK_NEAR_CURSOR = 1;
public static final int LEFT_CLICK_WITH_MULTITOUCH = 2;
public static final int LEFT_CLICK_WITH_PRESSURE = 3;
public static final int LEFT_CLICK_WITH_DPAD = 4;
public static final int LEFT_CLICK_WITH_KEY = 4;
public static int LeftClickMethod = LEFT_CLICK_NORMAL;
public static int LeftClickKey = KeyEvent.KEYCODE_DPAD_CENTER;
public static final int RIGHT_CLICK_NONE = 0;
public static final int RIGHT_CLICK_WITH_MULTITOUCH = 1;
public static final int RIGHT_CLICK_WITH_PRESSURE = 2;
public static final int RIGHT_CLICK_WITH_MENU_BUTTON = 3;
public static final int RIGHT_CLICK_WITH_KEY = 3;
public static int RightClickMethod = RIGHT_CLICK_NONE;
public static int RightClickKey = KeyEvent.KEYCODE_MENU;
public static boolean MoveMouseWithJoystick = false;
public static int MoveMouseWithJoystickSpeed = 0;
public static int MoveMouseWithJoystickAccel = 0;

View File

@@ -108,6 +108,8 @@ class Settings
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
for( int ii = 0; ii < 4; ii++ )
out.writeInt(Globals.ScreenKbControlsLayout[i][ii]);
out.writeInt(Globals.LeftClickKey);
out.writeInt(Globals.RightClickKey);
out.close();
settingsLoaded = true;
@@ -230,6 +232,8 @@ class Settings
for( int i = 0; i < Globals.ScreenKbControlsLayout.length; i++ )
for( int ii = 0; ii < 4; ii++ )
Globals.ScreenKbControlsLayout[i][ii] = settingsFile.readInt();
Globals.LeftClickKey = settingsFile.readInt();
Globals.RightClickKey = settingsFile.readInt();
settingsLoaded = true;
@@ -876,7 +880,7 @@ class Settings
p.getResources().getString(R.string.leftclick_near_cursor),
p.getResources().getString(R.string.leftclick_multitouch),
p.getResources().getString(R.string.leftclick_pressure),
p.getResources().getString(R.string.leftclick_dpadcenter) };
p.getResources().getString(R.string.rightclick_key) };
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(R.string.leftclick_question);
@@ -886,7 +890,10 @@ class Settings
{
Globals.LeftClickMethod = item;
dialog.dismiss();
showMouseConfigMainMenu(p);
if( item == Globals.LEFT_CLICK_WITH_KEY )
p.keyListener = new KeyRemapToolMouseClick(p, true);
else
showMouseConfigMainMenu(p);
}
});
AlertDialog alert = builder.create();
@@ -905,7 +912,7 @@ class Settings
final CharSequence[] items = { p.getResources().getString(R.string.rightclick_none),
p.getResources().getString(R.string.rightclick_multitouch),
p.getResources().getString(R.string.rightclick_pressure),
p.getResources().getString(R.string.rightclick_menu) };
p.getResources().getString(R.string.rightclick_key) };
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(R.string.rightclick_question);
@@ -915,7 +922,10 @@ class Settings
{
Globals.RightClickMethod = item;
dialog.dismiss();
showMouseConfigMainMenu(p);
if( item == Globals.RIGHT_CLICK_WITH_KEY )
p.keyListener = new KeyRemapToolMouseClick(p, false);
else
showMouseConfigMainMenu(p);
}
});
AlertDialog alert = builder.create();
@@ -923,6 +933,35 @@ class Settings
alert.show();
}
public static class KeyRemapToolMouseClick implements KeyEventsListener
{
MainActivity p;
boolean leftClick;
public KeyRemapToolMouseClick(MainActivity _p, boolean leftClick)
{
p = _p;
p.setText(p.getResources().getString(R.string.remap_hwkeys_press));
this.leftClick = leftClick;
}
public void onKeyEvent(final int keyCode)
{
p.touchListener = null;
int keyIndex = keyCode;
if( keyIndex < 0 )
keyIndex = 0;
if( keyIndex > SDL_Keys.JAVA_KEYCODE_LAST )
keyIndex = 0;
if( leftClick )
Globals.LeftClickKey = keyIndex;
else
Globals.RightClickKey = keyIndex;
showMouseConfigMainMenu(p);
}
}
static void showAdditionalMouseConfig(final MainActivity p)
{
if( ! Globals.AppUsesMouse )
@@ -1597,7 +1636,9 @@ class Settings
Globals.ClickScreenPressure,
Globals.ClickScreenTouchspotSize,
Globals.MoveMouseWithJoystickSpeed,
Globals.MoveMouseWithJoystickAccel );
Globals.MoveMouseWithJoystickAccel,
Globals.LeftClickKey,
Globals.RightClickKey );
if( Globals.AppUsesJoystick && (Globals.UseAccelerometerAsArrowKeys || Globals.UseTouchscreenKeyboard) )
nativeSetJoystickUsed();
if( Globals.AppUsesMultitouch )
@@ -1678,7 +1719,8 @@ class Settings
private static native void nativeSetAccelerometerSettings(int sensitivity, int centerPos);
private static native void nativeSetMouseUsed(int RightClickMethod, int ShowScreenUnderFinger, int LeftClickMethod,
int MoveMouseWithJoystick, int ClickMouseWithDpad, int MaxForce, int MaxRadius,
int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel);
int MoveMouseWithJoystickSpeed, int MoveMouseWithJoystickAccel,
int leftClickKeycode, int rightClickKeycode);
private static native void nativeSetJoystickUsed();
private static native void nativeSetMultitouchUsed();
private static native void nativeSetTouchscreenKeyboardUsed();

View File

@@ -107,4 +107,5 @@
<string name="calibrate_touchscreen_touch">Touch allen vier Rändern des Bildschirms, drücken Sie Menü, wenn Sie fertig</string>
<string name="screenkb_custom_layout">Passen Sie auf dem Bildschirm Tastatur-Layout</string>
<string name="screenkb_custom_layout_help">Slide-Bildschirm hinzufügen Taste, drücken Sie Menü zum letzten Knopf rückgängig machen</string>
<string name="rightclick_key">Physikalische Schlüssel</string>
</resources>

View File

@@ -107,4 +107,5 @@
<string name="calibrate_touchscreen_touch">Touch kaikki neljä reunaa näytön, paina Valikko, kun olet valmis</string>
<string name="screenkb_custom_layout">Mukauta-ruudun näppäimistö</string>
<string name="screenkb_custom_layout_help">Työnnä näytön lisätä painikkeen, paina Menu kumota viimeksi painike</string>
<string name="rightclick_key">Fyysinen avain</string>
</resources>

View File

@@ -110,4 +110,5 @@
<string name="calibrate_touchscreen_touch">Touchez les quatre bords de l\u0026#39;écran, appuyez sur MENU lorsque vous avez terminé</string>
<string name="screenkb_custom_layout">Personnalisation de la présentation du clavier à l\u0026#39;écran</string>
<string name="screenkb_custom_layout_help">Faites glisser l\u0026#39;écran pour ajouter le bouton, appuyez sur Menu pour annuler le dernier bouton</string>
<string name="rightclick_key">Physique clés</string>
</resources>

View File

@@ -100,4 +100,5 @@
<string name="calibrate_touchscreen_touch">Дотроньтесь до всех четырех краев экрана, потом нажмите MENU</string>
<string name="screenkb_custom_layout">Настройка расположения кнопок</string>
<string name="screenkb_custom_layout_help">Провезите по экрану, чтобы добавить кнопку, нажмите клавишу Меню, чтобы отменить последнюю кнопку</string>
<string name="rightclick_key">Физическая кнопка</string>
</resources>

View File

@@ -100,4 +100,5 @@
<string name="calibrate_touchscreen_touch">Доторкнiться до всіх чотирьох країв екрану, потiм натисніть MENU</string>
<string name="screenkb_custom_layout">Налаштування положення кнопок</string>
<string name="screenkb_custom_layout_help">Провезiть по екрану, щоб додати кнопку, натисніть клавішу Меню, щоб скасувати останню кнопку</string>
<string name="rightclick_key">Фізична кнопка</string>
</resources>

View File

@@ -71,6 +71,7 @@
<string name="mouse_emulation">Mouse emulation</string>
<string name="rightclick_question">Right mouse click</string>
<string name="rightclick_menu">Menu key</string>
<string name="rightclick_key">Physical key</string>
<string name="rightclick_multitouch">Touch screen with second finger</string>
<string name="rightclick_pressure">Touch screen with force</string>
<string name="rightclick_none">Disable right mouse click</string>

View File

@@ -22,8 +22,8 @@ AppTouchscreenKeyboardKeysAmount=0
AppTouchscreenKeyboardKeysAmountAutoFire=0
RedefinedKeysScreenKb="LALT RETURN KP_PLUS KP_MINUS SPACE DELETE KP_PLUS KP_MINUS 1 2"
MultiABI=n
AppVersionCode=10510
AppVersionName="1.0.5.10"
AppVersionCode=10511
AppVersionName="1.0.5.11"
CompiledLibraries="jpeg png freetype timidity lzma lzo2"
CustomBuildScript=y
AppCflags=''

View File

@@ -1 +1 @@
fheroes2
openttd

View File

@@ -57,10 +57,12 @@ static inline SDL_scancode TranslateKey(int scancode)
static int isTrackballUsed = 0;
static int isMouseUsed = 0;
enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2, RIGHT_CLICK_WITH_MENU_BUTTON = 3 };
enum { LEFT_CLICK_NORMAL = 0, LEFT_CLICK_NEAR_CURSOR = 1, LEFT_CLICK_WITH_MULTITOUCH = 2, LEFT_CLICK_WITH_PRESSURE = 3, LEFT_CLICK_WITH_DPAD = 4 };
enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2, RIGHT_CLICK_WITH_KEY = 3 };
enum { LEFT_CLICK_NORMAL = 0, LEFT_CLICK_NEAR_CURSOR = 1, LEFT_CLICK_WITH_MULTITOUCH = 2, LEFT_CLICK_WITH_PRESSURE = 3, LEFT_CLICK_WITH_KEY = 4 };
static int leftClickMethod = LEFT_CLICK_NORMAL;
static int rightClickMethod = RIGHT_CLICK_NONE;
static int leftClickKey = KEYCODE_DPAD_CENTER;
static int rightClickKey = KEYCODE_MENU;
int SDL_ANDROID_ShowScreenUnderFinger = 0;
SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect = {0, 0, 0, 0}, SDL_ANDROID_ShowScreenUnderFingerRectSrc = {0, 0, 0, 0};
static int moveMouseWithArrowKeys = 0;
@@ -480,12 +482,12 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeKey) ( JNIEnv* env, jobject thiz, jint
if( isTrackballUsed )
if( processAndroidTrackball(key, action) )
return;
if( key == KEYCODE_MENU && rightClickMethod == RIGHT_CLICK_WITH_MENU_BUTTON )
if( key == rightClickKey && rightClickMethod == RIGHT_CLICK_WITH_KEY )
{
SDL_ANDROID_MainThreadPushMouseButton( action ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_RIGHT );
return;
}
if( key == KEYCODE_DPAD_CENTER && ( clickMouseWithDpadCenter || leftClickMethod == LEFT_CLICK_WITH_DPAD ) )
if( (key == leftClickKey && leftClickMethod == LEFT_CLICK_WITH_KEY) || (clickMouseWithDpadCenter && key == KEYCODE_DPAD_CENTER) )
{
SDL_ANDROID_MainThreadPushMouseButton( action ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT );
return;
@@ -546,7 +548,8 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz,
jint RightClickMethod, jint ShowScreenUnderFinger, jint LeftClickMethod,
jint MoveMouseWithJoystick, jint ClickMouseWithDpad,
jint MaxForce, jint MaxRadius,
jint MoveMouseWithJoystickSpeed, jint MoveMouseWithJoystickAccel)
jint MoveMouseWithJoystickSpeed, jint MoveMouseWithJoystickAccel,
jint LeftClickKeycode, jint RightClickKeycode)
{
isMouseUsed = 1;
rightClickMethod = RightClickMethod;
@@ -558,6 +561,8 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz,
maxRadius = MaxRadius;
moveMouseWithKbSpeed = MoveMouseWithJoystickSpeed + 1;
moveMouseWithKbAccel = MoveMouseWithJoystickAccel;
leftClickKey = LeftClickKeycode;
rightClickKey = RightClickKeycode;
}
JNIEXPORT void JNICALL

View File

@@ -11,7 +11,7 @@ Bugs to fix
- Show/hide screen controls with longpress on Text Edit button.
- Right click by longpress, assign any HW key to do left/right click.
- Right click by longpress.
- Calling SDL_SetVideoMode() with SDL 1.3 several times makes it crash.