Option to pass touch events to both on-screen keyboard and application, used for Fire button in OpenArena

This commit is contained in:
pelya
2012-12-22 04:19:27 +02:00
parent 6d0e74e992
commit 5a68d9a803
7 changed files with 94 additions and 78 deletions

View File

@@ -37,8 +37,8 @@ HiddenMenuOptions='OptionalDownloadConfig DisplaySizeConfig'
FirstStartMenuOptions=''
MultiABI=y
AppMinimumRAM=300
AppVersionCode=08815
AppVersionName="0.8.8.15"
AppVersionCode=08816
AppVersionName="0.8.8.16"
ResetSdlConfigForThisVersion=y
DeleteFilesOnUpgrade="libsdl-DownloadFinished-10.flag .openarena/baseoa/q3config.cfg"
CompiledLibraries="sdl_mixer sdl_image freetype curl vorbis ogg"

View File

@@ -43,10 +43,7 @@ extern "C" {
#endif
/* Button IDs */
enum {
SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD = 0, /* Joystick/D-Pad button */
enum {
SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, /* Main (usually Fire) button */
SDL_ANDROID_SCREENKEYBOARD_BUTTON_1,
SDL_ANDROID_SCREENKEYBOARD_BUTTON_2,
@@ -56,6 +53,8 @@ enum {
SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, /* Button to show screen keyboard */
SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, /* Joystick/D-Pad button */
SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM
};
@@ -88,11 +87,15 @@ extern DECLSPEC
extern DECLSPEC int SDLCALL SDL_ANDROID_SetScreenKeyboardAutoFireButtonsAmount(int nbuttons);
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardAutoFireButtonsAmount(void);
/* Hide the whole screen keyboard */
extern DECLSPEC int SDLCALL SDL_ANDROID_SetScreenKeyboardShown(int shown);
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardShown(void);
/* Get the button size modifier, as configured by user with SDL startup menu */
extern DECLSPEC int SDLCALL SDL_ANDROID_GetScreenKeyboardSize(void);
/* Set a particular button to pass a mouse/multitouch events down to the application, by default all buttons block touch events */
extern DECLSPEC int SDLCALL SDL_ANDROID_SetScreenKeyboardButtonGenerateTouchEvents(int buttonId, int generateEvents);
/* Show Android on-screen keyboard, and pass entered text back to application as SDL keypress events,
previousText is UTF-8 encoded, it may be NULL, only 256 first bytes will be used, and this call will not block */
extern DECLSPEC int SDLCALL SDL_ANDROID_ToggleScreenKeyboardTextInput(const char * previousText);

View File

@@ -297,25 +297,28 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t
// even if the finger is not anymore above screen kb button it will not acr as mouse event, and if it's initially
// touches the screen outside of screen kb it won't trigger button keypress -
// I think it's more logical this way
if( SDL_ANDROID_isTouchscreenKeyboardUsed && ( action == MOUSE_DOWN || touchPointers[pointerId] == TOUCH_PTR_SCREENKB ) )
if( SDL_ANDROID_isTouchscreenKeyboardUsed && ( action == MOUSE_DOWN || touchPointers[pointerId] & TOUCH_PTR_SCREENKB ) )
{
if( SDL_ANDROID_processTouchscreenKeyboard(x, y, action, pointerId) && action == MOUSE_DOWN )
touchPointers[pointerId] = TOUCH_PTR_SCREENKB;
if( touchPointers[pointerId] == TOUCH_PTR_SCREENKB )
unsigned processed = SDL_ANDROID_processTouchscreenKeyboard(x, y, action, pointerId);
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_ANDROID_processTouchscreenKeyboard: ptr %d action %d ret 0x%08x", pointerId, action, processed);
if( processed && action == MOUSE_DOWN )
touchPointers[pointerId] |= TOUCH_PTR_SCREENKB;
if( touchPointers[pointerId] & TOUCH_PTR_SCREENKB )
{
if( action == MOUSE_UP )
touchPointers[pointerId] = TOUCH_PTR_UP;
return;
if( !(processed & TOUCHSCREEN_KEYBOARD_PASS_EVENT_DOWN_TO_SDL) )
return;
}
}
if( action == MOUSE_DOWN )
{
touchPointers[pointerId] = TOUCH_PTR_MOUSE;
touchPointers[pointerId] |= TOUCH_PTR_MOUSE;
firstMousePointerId = -1;
for( i = 0; i < MAX_MULTITOUCH_POINTERS; i++ )
{
if( touchPointers[i] == TOUCH_PTR_MOUSE )
if( touchPointers[i] & TOUCH_PTR_MOUSE )
{
firstMousePointerId = i;
break;
@@ -680,7 +683,7 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMotionEvent) ( JNIEnv* env, jobject t
firstMousePointerId = -1;
for( i = 0; i < MAX_MULTITOUCH_POINTERS; i++ )
{
if( touchPointers[i] == TOUCH_PTR_MOUSE )
if( touchPointers[i] |= TOUCH_PTR_MOUSE )
{
firstMousePointerId = i;
break;
@@ -2159,32 +2162,6 @@ JAVA_EXPORT_NAME(Settings_nativeSetTouchscreenCalibration) (JNIEnv* env, jobject
SDL_ANDROID_TouchscreenCalibrationHeight = y2 - y1;
}
static int ScreenKbRedefinedByUser = 0;
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyLayout) (JNIEnv* env, jobject thiz, jint keynum, jint x1, jint y1, jint x2, jint y2)
{
SDL_Rect rect = {x1, y1, x2-x1, y2-y1};
int key = -1;
if( keynum == 0 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD;
if( keynum == 1 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT;
if( keynum - 2 >= 0 && keynum - 2 <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 )
key = keynum - 2 + SDL_ANDROID_SCREENKEYBOARD_BUTTON_0;
if( key >= 0 )
{
ScreenKbRedefinedByUser = 1;
SDL_ANDROID_SetScreenKeyboardButtonPos(key, &rect);
}
}
int SDL_ANDROID_GetScreenKeyboardRedefinedByUser()
{
return ScreenKbRedefinedByUser;
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeInitKeymap) ( JNIEnv* env, jobject thiz )
{

View File

@@ -123,8 +123,8 @@ typedef SDLKey SDL_scancode;
#define SDL_KEY_VAL(X) X
enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP = 1, MOUSE_MOVE = 2, MOUSE_HOVER = 3 };
extern int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId);
enum { TOUCHSCREEN_KEYBOARD_PASS_EVENT_DOWN_TO_SDL = 0x40000000 };
extern unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId);
extern int SDL_ANDROID_isTouchscreenKeyboardUsed;
#ifndef SDL_ANDROID_KEYCODE_0

View File

@@ -48,15 +48,15 @@
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
enum { MAX_BUTTONS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM-1, MAX_BUTTONS_AUTOFIRE = 2, BUTTON_TEXT_INPUT = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT-1, BUTTON_ARROWS = MAX_BUTTONS } ; // Max amount of custom buttons
enum { MAX_BUTTONS = SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM-1, MAX_BUTTONS_AUTOFIRE = 2, BUTTON_TEXT_INPUT = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, BUTTON_ARROWS = MAX_BUTTONS } ; // Max amount of custom buttons
int SDL_ANDROID_isTouchscreenKeyboardUsed = 0;
static int touchscreenKeyboardTheme = 0;
static int touchscreenKeyboardShown = 1;
static int AutoFireButtonsNum = 0;
static int buttonsize = 1;
static int buttonDrawSize = 1;
static int transparency = 128;
static short touchscreenKeyboardTheme = 0;
static short touchscreenKeyboardShown = 1;
static short AutoFireButtonsNum = 0;
static short buttonsize = 1;
static short buttonDrawSize = 1;
static short transparency = 128;
static SDL_Rect arrows, arrowsExtended, buttons[MAX_BUTTONS], buttonsAutoFireRect[MAX_BUTTONS_AUTOFIRE];
static SDL_Rect arrowsDraw, buttonsDraw[MAX_BUTTONS];
@@ -71,13 +71,14 @@ SDL_KEY(SDL_KEY_VAL(SDL_ANDROID_SCREENKB_KEYCODE_5)),
};
enum { ARROW_LEFT = 1, ARROW_RIGHT = 2, ARROW_UP = 4, ARROW_DOWN = 8 };
static int oldArrows = 0;
static int ButtonAutoFire[MAX_BUTTONS_AUTOFIRE];
static int ButtonAutoFireX[MAX_BUTTONS_AUTOFIRE*2];
static int ButtonAutoFireRot[MAX_BUTTONS_AUTOFIRE];
static int ButtonAutoFireDecay[MAX_BUTTONS_AUTOFIRE];
static short oldArrows = 0;
static short ButtonAutoFire[MAX_BUTTONS_AUTOFIRE];
static short ButtonAutoFireX[MAX_BUTTONS_AUTOFIRE*2];
static short ButtonAutoFireRot[MAX_BUTTONS_AUTOFIRE];
static short ButtonAutoFireDecay[MAX_BUTTONS_AUTOFIRE];
static int pointerInButtonRect[MAX_BUTTONS + 1];
static short pointerInButtonRect[MAX_BUTTONS + 1];
static short buttonsGenerateSdlEvents[MAX_BUTTONS + 1];
typedef struct
{
@@ -416,22 +417,20 @@ static inline int ArrowKeysPressed(int x, int y)
return ret;
}
int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId)
unsigned SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointerId)
{
int i;
int processed = 0;
unsigned processed = 0;
if( !touchscreenKeyboardShown )
return 0;
if( action == MOUSE_DOWN )
{
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "touch %03dx%03d ptr %d action %d", x, y, pointerId, action);
if( InsideRect( &arrows, x, y ) )
{
processed = 1;
processed |= 1<<BUTTON_ARROWS;
if( pointerInButtonRect[BUTTON_ARROWS] == -1 )
{
pointerInButtonRect[BUTTON_ARROWS] = pointerId;
@@ -467,7 +466,7 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer
continue;
if( InsideRect( &buttons[i], x, y) )
{
processed = 1;
processed |= 1<<i;
if( pointerInButtonRect[i] == -1 )
{
pointerInButtonRect[i] = pointerId;
@@ -493,7 +492,7 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "touch %03dx%03d ptr %d action %d", x, y, pointerId, action);
if( pointerInButtonRect[BUTTON_ARROWS] == pointerId )
{
processed = 1;
processed |= 1<<BUTTON_ARROWS;
pointerInButtonRect[BUTTON_ARROWS] = -1;
if( SDL_ANDROID_isJoystickUsed )
{
@@ -515,7 +514,7 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer
continue;
if( pointerInButtonRect[i] == pointerId )
{
processed = 1;
processed |= 1<<i;
pointerInButtonRect[i] = -1;
if( i < AutoFireButtonsNum && ButtonAutoFire[i] )
{
@@ -538,13 +537,13 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer
if( action == MOUSE_MOVE )
{
// Process cases when pointer enters button area (it won't send keypress twice if button already pressed)
processed = SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId);
processed |= SDL_ANDROID_processTouchscreenKeyboard(x, y, MOUSE_DOWN, pointerId);
// Process cases when pointer leaves button area
// TODO: huge code size, split it or somehow make it more readable
if( pointerInButtonRect[BUTTON_ARROWS] == pointerId )
{
processed = 1;
processed |= 1<<BUTTON_ARROWS;
if( ! InsideRect( &arrowsExtended, x, y ) )
{
pointerInButtonRect[BUTTON_ARROWS] = -1;
@@ -601,7 +600,7 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer
{
if( pointerInButtonRect[i] == pointerId )
{
processed = 1;
processed |= 1<<i;
if( ! InsideRect( &buttonsAutoFireRect[i], x, y ) )
{
pointerInButtonRect[i] = -1;
@@ -652,8 +651,8 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer
continue;
if( pointerInButtonRect[i] == pointerId )
{
processed = 1;
if( ! InsideRect( &buttons[i], x, y ) )
processed |= 1<<i;
if( ! InsideRect( &buttons[i], x, y ) && ! buttonsGenerateSdlEvents[i] )
{
pointerInButtonRect[i] = -1;
if( i != BUTTON_TEXT_INPUT )
@@ -662,7 +661,10 @@ int SDL_ANDROID_processTouchscreenKeyboard(int x, int y, int action, int pointer
}
}
}
for( i = 0; i <= MAX_BUTTONS ; i++ )
if( ( processed & (1<<i) ) && buttonsGenerateSdlEvents[i] )
processed |= TOUCHSCREEN_KEYBOARD_PASS_EVENT_DOWN_TO_SDL;
return processed;
};
@@ -959,7 +961,7 @@ int SDL_ANDROID_SetScreenKeyboardButtonPos(int buttonId, SDL_Rect * pos)
}
else
{
int i = buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0;
int i = buttonId;
buttons[i] = *pos;
shrinkButtonRect(buttons[i], &buttonsDraw[i]);
if( i < AutoFireButtonsNum )
@@ -984,24 +986,24 @@ int SDL_ANDROID_GetScreenKeyboardButtonPos(int buttonId, SDL_Rect * pos)
}
else
{
*pos = buttons[buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0];
*pos = buttons[buttonId];
}
return 1;
};
int SDL_ANDROID_SetScreenKeyboardButtonKey(int buttonId, SDLKey key)
{
if( buttonId < SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 || buttonId > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 || ! key )
if( buttonId < 0 || buttonId > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 || ! key )
return 0;
buttonKeysyms[buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0] = key;
buttonKeysyms[buttonId] = key;
return 1;
};
SDLKey SDL_ANDROID_GetScreenKeyboardButtonKey(int buttonId)
{
if( buttonId < SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 || buttonId > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 )
if( buttonId < 0 || buttonId > SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 )
return SDLK_UNKNOWN;
return buttonKeysyms[buttonId - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0];
return buttonKeysyms[buttonId];
};
int SDL_ANDROID_SetScreenKeyboardAutoFireButtonsAmount(int nbuttons)
@@ -1100,3 +1102,37 @@ int SDLCALL SDL_ToggleScreenKeyboard(void *unused)
else
return SDL_ShowScreenKeyboard(NULL);
}
int SDLCALL SDL_ANDROID_SetScreenKeyboardButtonGenerateTouchEvents(int buttonId, int generateEvents)
{
if( buttonId < 0 || buttonId >= SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM )
return 0;
buttonsGenerateSdlEvents[buttonId] = generateEvents;
return 1;
}
static int ScreenKbRedefinedByUser = 0;
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(Settings_nativeSetScreenKbKeyLayout) (JNIEnv* env, jobject thiz, jint keynum, jint x1, jint y1, jint x2, jint y2)
{
SDL_Rect rect = {x1, y1, x2-x1, y2-y1};
int key = -1;
if( keynum == 0 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD;
if( keynum == 1 )
key = SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT;
if( keynum - 2 >= 0 && keynum - 2 <= SDL_ANDROID_SCREENKEYBOARD_BUTTON_5 - SDL_ANDROID_SCREENKEYBOARD_BUTTON_0 )
key = keynum - 2 + SDL_ANDROID_SCREENKEYBOARD_BUTTON_0;
if( key >= 0 )
{
ScreenKbRedefinedByUser = 1;
SDL_ANDROID_SetScreenKeyboardButtonPos(key, &rect);
}
}
int SDL_ANDROID_GetScreenKeyboardRedefinedByUser()
{
return ScreenKbRedefinedByUser;
}