Implemented clicking with tap and timeout

This commit is contained in:
pelya
2011-02-07 17:49:14 +00:00
parent d840a57e2c
commit 0cb701bb24
12 changed files with 173 additions and 79 deletions

View File

@@ -1208,6 +1208,36 @@ class Settings
alert.show();
}
static void showRelativeMouseMovementConfig(final MainActivity p)
{
final CharSequence[] items = { p.getResources().getString(R.string.accel_fast),
p.getResources().getString(R.string.accel_medium),
p.getResources().getString(R.string.accel_slow) };
AlertDialog.Builder builder = new AlertDialog.Builder(p);
builder.setTitle(R.string.pointandclick_relative_speed);
builder.setSingleChoiceItems(items, Globals.RelativeMouseMovementSpeed, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int item)
{
Globals.RelativeMouseMovementSpeed = item;
dialog.dismiss();
showRelativeMouseMovementConfig1(p);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener()
{
public void onCancel(DialogInterface dialog)
{
showConfigMainMenu(p);
}
});
AlertDialog alert = builder.create();
alert.setOwnerActivity(p);
alert.show();
}
static void showRelativeMouseMovementConfig1(final MainActivity p)
{
final CharSequence[] items = { p.getResources().getString(R.string.accel_fast),
@@ -1997,7 +2027,7 @@ class Settings
Globals.RightClickKey,
Globals.LeftClickTimeout,
Globals.RightClickTimeout,
Globals.RelativeMouseMovement,
Globals.RelativeMouseMovement ? 1 : 0,
Globals.RelativeMouseMovementSpeed,
Globals.RelativeMouseMovementAccel );
if( Globals.AppUsesJoystick && (Globals.UseAccelerometerAsArrowKeys || Globals.UseTouchscreenKeyboard) )

View File

@@ -219,7 +219,9 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
public int swapBuffers() // Called from native code
{
this.notify();
synchronized(this) {
this.notify();
}
if( ! super.SwapBuffers() && Globals.NonBlockingSwapBuffers )
return 0;
if(mGlContextLost) {
@@ -227,19 +229,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
Settings.SetupTouchscreenKeyboardGraphics(context); // Reload on-screen buttons graphics
}
/*
// Pass just one char per frame, many SDL games cannot handle multiple events in a single frame
synchronized(context.textInput) {
if( context.textInput.size() >= 2 )
{
if( context.textInput.getFirst() != 0 )
nativeTextInput( context.textInput.getFirst(), context.textInput.get(1) );
context.textInput.removeFirst();
context.textInput.removeFirst();
}
}
*/
return 1;
}
@@ -256,7 +245,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
Callback cb = new Callback();
cb.parent = context;
context.runOnUiThread(cb);
//context.showScreenKeyboard();
}
public void exitApp() {
@@ -300,9 +288,11 @@ class DemoGLSurfaceView extends GLSurfaceView_SDL {
touchInput.process(event);
// Wait a bit, and try to synchronize to app framerate, or event thread will eat all CPU and we'll lose FPS
if( event.getAction() == MotionEvent.ACTION_MOVE ) {
try {
mRenderer.wait(300L);
} catch (InterruptedException e) { }
synchronized(mRenderer) {
try {
mRenderer.wait(300L);
} catch (InterruptedException e) { }
}
}
return true;
};

View File

@@ -11,15 +11,15 @@ SdlVideoResizeKeepAspect=n
NeedDepthBuffer=n
AppUsesMouse=y
AppNeedsTwoButtonMouse=y
AppNeedsArrowKeys=y
AppNeedsTextInput=y
AppNeedsArrowKeys=n
AppNeedsTextInput=n
AppUsesJoystick=n
AppHandlesJoystickSensitivity=n
AppUsesMultitouch=n
NonBlockingSwapBuffers=n
RedefinedKeys="SPACE"
AppTouchscreenKeyboardKeysAmount=6
AppTouchscreenKeyboardKeysAmountAutoFire=2
AppTouchscreenKeyboardKeysAmount=0
AppTouchscreenKeyboardKeysAmountAutoFire=0
RedefinedKeysScreenKb="1 2 3 4 5 6 1 2 3 4"
MultiABI=n
AppVersionCode=101

View File

@@ -16,7 +16,6 @@
#include "SDL.h"
#include "SDL_image.h"
#include "test.h"
#include "ballfield.h"
@@ -361,8 +360,6 @@ int main(int argc, char* argv[])
int fps_start = 0;
float x_speed, y_speed, z_speed;
__android_log_print(ANDROID_LOG_INFO, "==TEST==", "SDL_Main: test::initCount %d test::initCount2", test::initCount, test::initCount2);
SDL_Init(SDL_INIT_VIDEO);
atexit(SDL_Quit);
@@ -384,7 +381,7 @@ int main(int argc, char* argv[])
bpp = atoi(&argv[i][1]);
}
screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, bpp, flags);
screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, bpp, 0 /*flags*/);
if(!screen)
{
fprintf(stderr, "Failed to open screen!\n");
@@ -494,6 +491,28 @@ int main(int argc, char* argv[])
print_num(screen, font, screen->w-37, screen->h-12, fps);
++fps_count;
int mouseX, mouseY;
int mouseB = SDL_GetMouseState(&mouseX, &mouseY);
r.x = mouseX;
r.y = mouseY;
r.w = 10;
r.h = 1;
SDL_FillRect(screen, &r, 0xeeeeeeee);
if( mouseB & SDL_BUTTON_LMASK )
{
r.w = 20;
r.h = 5;
SDL_FillRect(screen, &r, 0xabcdaabb);
}
if( mouseB & SDL_BUTTON_RMASK )
{
r.w = 5;
r.h = 20;
SDL_FillRect(screen, &r, 0x67895566);
}
SDL_Flip(screen);
/* Animate */

View File

@@ -1,18 +0,0 @@
#include <stdio.h>
#include "test.h"
int test::initCount = 0;
int test::initCount2 = 12345;
test::test()
{
initCount++;
__android_log_print(ANDROID_LOG_INFO, "==TEST==", "test::test(): initCount %d initCount2 %d", initCount, initCount2);
}
test::~test()
{
initCount--;
__android_log_print(ANDROID_LOG_INFO, "==TEST==", "test::~test(): initCount %d initCount2 %d", initCount, initCount2);
}

View File

@@ -1,15 +0,0 @@
#include <stdio.h>
#include <android/log.h>
class test
{
public:
test();
~test();
public:
static int initCount;
static int initCount2;
};

View File

@@ -1,7 +0,0 @@
#include <stdio.h>
#include "test.h"
test t;

View File

@@ -22,8 +22,8 @@ AppTouchscreenKeyboardKeysAmount=0
AppTouchscreenKeyboardKeysAmountAutoFire=0
RedefinedKeysScreenKb="LCTRL M T H E C SPACE C S L"
MultiABI=n
AppVersionCode=224411
AppVersionName="2244.11"
AppVersionCode=224812
AppVersionName="2248.12"
CompiledLibraries="sdl_net sdl_mixer sdl_image sdl_ttf png intl"
CustomBuildScript=n
AppCflags='-finline-functions -O2 -DWITH_ZLIB -DWITH_MIXER -DWITH_XML -DWITH_IMAGE -DWITH_TTF -DWITH_AI=simple'

View File

@@ -1 +1 @@
ufoai
ballfield

View File

@@ -101,6 +101,15 @@ int SDL_ANDROID_TouchscreenCalibrationWidth = 480;
int SDL_ANDROID_TouchscreenCalibrationHeight = 320;
int SDL_ANDROID_TouchscreenCalibrationX = 0;
int SDL_ANDROID_TouchscreenCalibrationY = 0;
int leftClickTimeout = 0;
int rightClickTimeout = 0;
int relativeMovement = 0;
int relativeMovementSpeed = 0;
int relativeMovementAccel = 0;
int mouseInitialX = -1;
int mouseInitialY = -1;
unsigned int mouseInitialTime = 0;
int deferredMouseTap = 0;
static inline int InsideRect(const SDL_Rect * r, int x, int y)
{
@@ -356,10 +365,26 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j
SDL_GetMouseState( &oldX, &oldY );
if( action == MOUSE_UP )
{
if( SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(SDL_BUTTON_LEFT) )
SDL_ANDROID_MainThreadPushMouseButton( SDL_RELEASED, SDL_BUTTON_LEFT );
if( SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(SDL_BUTTON_RIGHT) )
SDL_ANDROID_MainThreadPushMouseButton( SDL_RELEASED, SDL_BUTTON_RIGHT );
if( mouseInitialX >= 0 && mouseInitialY >= 0 && (
leftClickMethod == LEFT_CLICK_WITH_TAP || leftClickMethod == LEFT_CLICK_WITH_TAP_OR_TIMEOUT ) &&
abs(mouseInitialX - x) < SDL_ANDROID_sFakeWindowHeight / 6 &&
abs(mouseInitialY - y) < SDL_ANDROID_sFakeWindowHeight / 6 &&
SDL_GetTicks() - mouseInitialTime < 300 )
{
SDL_ANDROID_MainThreadPushMouseMotion(mouseInitialX, mouseInitialY);
SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_LEFT );
deferredMouseTap = 2;
mouseInitialX = -1;
mouseInitialY = -1;
}
else
{
if( SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(SDL_BUTTON_LEFT) )
SDL_ANDROID_MainThreadPushMouseButton( SDL_RELEASED, SDL_BUTTON_LEFT );
if( SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(SDL_BUTTON_RIGHT) )
SDL_ANDROID_MainThreadPushMouseButton( SDL_RELEASED, SDL_BUTTON_RIGHT );
}
SDL_ANDROID_ShowScreenUnderFingerRect.w = SDL_ANDROID_ShowScreenUnderFingerRect.h = 0;
SDL_ANDROID_ShowScreenUnderFingerRectSrc.w = SDL_ANDROID_ShowScreenUnderFingerRectSrc.h = 0;
if( SDL_ANDROID_ShowScreenUnderFinger )
@@ -395,6 +420,9 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j
{
SDL_ANDROID_MainThreadPushMouseMotion(x, y);
action == MOUSE_MOVE;
mouseInitialX = x;
mouseInitialY = y;
mouseInitialTime = SDL_GetTicks();
}
UpdateScreenUnderFingerRect(x, y);
}
@@ -438,6 +466,39 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j
if( ( (SDL_GetMouseState( NULL, NULL ) & SDL_BUTTON(button)) != 0 ) != buttonState )
SDL_ANDROID_MainThreadPushMouseButton( buttonState ? SDL_PRESSED : SDL_RELEASED, button );
}
if( mouseInitialX >= 0 && mouseInitialY >= 0 && (
leftClickMethod == LEFT_CLICK_WITH_TIMEOUT || leftClickMethod == LEFT_CLICK_WITH_TAP ||
leftClickMethod == LEFT_CLICK_WITH_TAP_OR_TIMEOUT || rightClickMethod == RIGHT_CLICK_WITH_TIMEOUT ) )
{
if( abs(mouseInitialX - x) >= SDL_ANDROID_sFakeWindowHeight / 6 || abs(mouseInitialY - y) >= SDL_ANDROID_sFakeWindowHeight / 6 )
{
mouseInitialX = -1;
mouseInitialY = -1;
}
else
{
if( leftClickMethod == LEFT_CLICK_WITH_TIMEOUT || leftClickMethod == LEFT_CLICK_WITH_TAP_OR_TIMEOUT )
{
if( SDL_GetTicks() - mouseInitialTime > leftClickTimeout )
{
SDL_ANDROID_MainThreadPushMouseMotion(mouseInitialX, mouseInitialY);
SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_LEFT );
mouseInitialX = -1;
mouseInitialY = -1;
}
}
if( rightClickMethod == RIGHT_CLICK_WITH_TIMEOUT )
{
if( SDL_GetTicks() - mouseInitialTime > rightClickTimeout )
{
SDL_ANDROID_MainThreadPushMouseMotion(mouseInitialX, mouseInitialY);
SDL_ANDROID_MainThreadPushMouseButton( SDL_PRESSED, SDL_BUTTON_RIGHT );
mouseInitialX = -1;
mouseInitialY = -1;
}
}
}
}
UpdateScreenUnderFingerRect(x, y);
}
}
@@ -470,6 +531,16 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, j
}
}
void ProcessDeferredMouseTap()
{
if( deferredMouseTap > 0 )
{
deferredMouseTap--;
if( !deferredMouseTap )
SDL_ANDROID_MainThreadPushMouseButton( SDL_RELEASED, SDL_BUTTON_LEFT );
}
}
static int processAndroidTrackball(int key, int action);
JNIEXPORT void JNICALL
@@ -544,14 +615,27 @@ JAVA_EXPORT_NAME(Settings_nativeSetTrackballUsed) ( JNIEnv* env, jobject thiz)
isTrackballUsed = 1;
}
JNIEXPORT void JNICALL
static int getClickTimeout(int v)
{
switch(v)
{
case 0: return 300;
case 1: return 500;
case 2: return 700;
case 3: return 1000;
case 4: return 1500;
}
return 1000;
}
JNIEXPORT void JNICALL
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 LeftClickKeycode, jint RightClickKeycode,
jint LeftClickTimeout, jint RghtClickTimeout,
jint LeftClickTimeout, jint RightClickTimeout,
jint RelativeMovement, jint RelativeMovementSpeed, jint RelativeMovementAccel)
{
isMouseUsed = 1;
@@ -566,6 +650,11 @@ JAVA_EXPORT_NAME(Settings_nativeSetMouseUsed) ( JNIEnv* env, jobject thiz,
moveMouseWithKbAccel = MoveMouseWithJoystickAccel;
leftClickKey = LeftClickKeycode;
rightClickKey = RightClickKeycode;
leftClickTimeout = getClickTimeout(LeftClickTimeout);
rightClickTimeout = getClickTimeout(RightClickTimeout);
relativeMovement = RelativeMovement;
relativeMovementSpeed = RelativeMovementSpeed;
relativeMovementAccel = RelativeMovementAccel;
}
JNIEXPORT void JNICALL
@@ -1272,7 +1361,7 @@ static int deferredTextIdx1 = 0;
static int deferredTextIdx2 = 0;
static SDL_mutex * deferredTextMutex = NULL;
extern void SDL_ANDROID_DeferredTextInput()
void SDL_ANDROID_DeferredTextInput()
{
int count = 2;
if( !deferredTextMutex )
@@ -1397,6 +1486,12 @@ void SDL_ANDROID_processMoveMouseWithKeyboard()
SDL_ANDROID_MainThreadPushMouseMotion(moveMouseWithKbX, moveMouseWithKbY);
};
extern void SDL_ANDROID_ProcessDeferredEvents()
{
SDL_ANDROID_DeferredTextInput();
ProcessDeferredMouseTap();
};
void ANDROID_InitOSKeymap()
{
#if (SDL_VERSION_ATLEAST(1,3,0))

View File

@@ -118,7 +118,7 @@ int SDL_ANDROID_CallJavaSwapBuffers()
showScreenKeyboardDeferred = 0;
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard );
}
SDL_ANDROID_DeferredTextInput();
SDL_ANDROID_ProcessDeferredEvents();
return 1;
}

View File

@@ -52,7 +52,7 @@ extern void SDL_ANDROID_processAndroidTrackballDampening();
extern void SDL_ANDROID_processMoveMouseWithKeyboard();
extern int SDL_ANDROID_InsideVideoThread();
extern SDL_VideoDevice *ANDROID_CreateDevice_1_3(int devindex);
extern void SDL_ANDROID_DeferredTextInput();
extern void SDL_ANDROID_ProcessDeferredEvents();
extern void SDL_ANDROID_initFakeStdout();
#if SDL_VERSION_ATLEAST(1,3,0)