Working hiver jitter filter

This commit is contained in:
pelya
2014-02-23 14:47:55 +02:00
parent 4bc6687d1a
commit 0b4b82b969
6 changed files with 70 additions and 26 deletions

View File

@@ -121,8 +121,6 @@ abstract class DifferentTouchInput
Log.i("SDL", "Device board: " + android.os.Build.BOARD);
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH )
{
if ( Globals.GenerateSubframeTouchEvents )
return IcsTouchInputWithHistory.Holder.sInstance;
if( DetectCrappyDragonRiseDatexGamepad() )
return CrappyDragonRiseDatexGamepadInputWhichNeedsItsOwnHandlerBecauseImTooCheapAndStupidToBuyProperGamepad.Holder.sInstance;
//return IcsTouchInput.Holder.sInstance;
@@ -331,8 +329,9 @@ abstract class DifferentTouchInput
}
public void process(final MotionEvent event)
{
int hwMouseEvent = (event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE ? Mouse.MOUSE_HW_INPUT_MOUSE :
(event.getSource() & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS ? Mouse.MOUSE_HW_INPUT_STYLUS : Mouse.MOUSE_HW_INPUT_FINGER;
int hwMouseEvent = ((event.getSource() & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS) ? Mouse.MOUSE_HW_INPUT_STYLUS :
((event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) ? Mouse.MOUSE_HW_INPUT_MOUSE :
Mouse.MOUSE_HW_INPUT_FINGER;
if( ExternalMouseDetected != hwMouseEvent )
{
ExternalMouseDetected = hwMouseEvent;
@@ -561,7 +560,10 @@ abstract class DifferentTouchInput
}
Settings.applyMouseEmulationOptions();
}
touchInput = IcsTouchInput.Holder.sInstance;
if ( Globals.GenerateSubframeTouchEvents )
touchInput = IcsTouchInputWithHistory.Holder.sInstance;
else
touchInput = IcsTouchInput.Holder.sInstance;
}
}
super.process(event);
@@ -577,7 +579,7 @@ abstract class DifferentTouchInput
hoverX = event.getX();
hoverY = event.getY();
hoverTime = System.currentTimeMillis();
if( ExternalMouseDetected != 0 && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_MOVE )
if( ExternalMouseDetected == 0 && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_MOVE )
fingerHover = true;
if( tap && System.currentTimeMillis() < tapTime + 1000 )
{

View File

@@ -158,7 +158,7 @@ void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, i
int x, y, i, ii;
SDL_Event event;
int res = -1, dpi = -1;
char native[32] = "0x0", native78[32], native68[32], native58[32], native48[32];
char native[32] = "0x0", native56[32], native46[32], native36[32], native26[32];
int vertical = SDL_ListModes(NULL, 0)[0]->w < SDL_ListModes(NULL, 0)[0]->h;
char cfgpath[PATH_MAX];
FILE * cfgfile;
@@ -174,16 +174,16 @@ void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, i
}
const char * resStr[] = {
native, native78, native68, native58,
native48, "1280x1024", "1280x960", "1280x720",
native, native56, native46, native36,
native26, "1280x1024", "1280x960", "1280x720",
"1024x768", "800x600", "800x480", "640x480"
};
const int resVal[][2] = {
{*resolutionW, *resolutionH},
{*resolutionW * 7 / 8, *resolutionH * 7 / 8},
{*resolutionW * 6 / 8, *resolutionH * 6 / 8},
{*resolutionW * 5 / 8, *resolutionH * 5 / 8},
{*resolutionW * 4 / 8, *resolutionH * 4 / 8},
{*resolutionW * 5 / 6, *resolutionH * 5 / 6},
{*resolutionW * 4 / 6, *resolutionH * 4 / 6},
{*resolutionW * 3 / 6, *resolutionH * 3 / 6},
{*resolutionW * 2 / 6, *resolutionH * 2 / 6},
{1280,1024}, {1280,960}, {1280,720},
{1024,768}, {800,600}, {800,480}, {640,480}
};
@@ -202,10 +202,10 @@ void XSDL_showConfigMenu(int * resolutionW, int * displayW, int * resolutionH, i
};
sprintf(native, "%dx%d", resVal[0][0], resVal[0][1]);
sprintf(native78, "%dx%d", resVal[1][0], resVal[1][1]);
sprintf(native68, "%dx%d", resVal[2][0], resVal[2][1]);
sprintf(native58, "%dx%d", resVal[3][0], resVal[3][1]);
sprintf(native48, "%dx%d", resVal[4][0], resVal[4][1]);
sprintf(native56, "%dx%d", resVal[1][0], resVal[1][1]);
sprintf(native46, "%dx%d", resVal[2][0], resVal[2][1]);
sprintf(native36, "%dx%d", resVal[3][0], resVal[3][1]);
sprintf(native26, "%dx%d", resVal[4][0], resVal[4][1]);
int savedRes = 0;
int savedDpi = 8;

View File

@@ -127,7 +127,7 @@ int SDL_ANDROID_currentMouseButtons = 0;
static int hardwareMouseDetected = 0;
enum { MOUSE_HW_BUTTON_LEFT = 1, MOUSE_HW_BUTTON_RIGHT = 2, MOUSE_HW_BUTTON_MIDDLE = 4, MOUSE_HW_BUTTON_BACK = 8, MOUSE_HW_BUTTON_FORWARD = 16, MOUSE_HW_BUTTON_MAX = MOUSE_HW_BUTTON_FORWARD };
enum { MOUSE_HW_INPUT_FINGER = 0, MOUSE_HW_INPUT_STYLUS = 1, MOUSE_HW_INPUT_MOUSE = 2 };
enum { DEADZONE_HOVER_FINGER = 16, DEADZONE_HOVER_STYLUS = 32, HOVER_FREEZE_TIME = 300 };
enum { DEADZONE_HOVER_FINGER = 32, DEADZONE_HOVER_STYLUS = 64, HOVER_FREEZE_TIME = 300 };
static int hoverJitterFilter = 1;
static int hoverX, hoverY, hoverTime = 0, hoverMouseFreeze = 0, hoverDeadzone = 0;
@@ -676,6 +676,16 @@ static void ProcessMouseHover( jint *xx, jint *yy, int action )
*xx = hoverX;
*yy = hoverY;
}
#ifdef VIDEO_DEBUG
SDL_ANDROID_VideoDebugRect.x = hoverX - hoverDeadzone;
SDL_ANDROID_VideoDebugRect.y = hoverY - hoverDeadzone;
SDL_ANDROID_VideoDebugRect.w = hoverDeadzone * 2;
SDL_ANDROID_VideoDebugRect.h = hoverDeadzone * 2;
memset(&SDL_ANDROID_VideoDebugRectColor, 0, sizeof(SDL_ANDROID_VideoDebugRectColor));
SDL_ANDROID_VideoDebugRectColor.g = hoverMouseFreeze * 255;
SDL_ANDROID_VideoDebugRectColor.r = SDL_ANDROID_VideoDebugRectColor.b = (SDL_GetTicks() - hoverTime) * 255 / HOVER_FREEZE_TIME;
#endif
}
JNIEXPORT void JNICALL
@@ -971,12 +981,16 @@ JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeHardwareMouseDetected) (JNIEnv* env, jo
relativeMovement = cfg.relativeMovement;
SDL_ANDROID_ShowMouseCursor = cfg.ShowMouseCursor;
}
int hoverDeadzone = (hardwareMouseDetected == MOUSE_HW_INPUT_STYLUS) ?
SDL_ANDROID_sFakeWindowHeight / DEADZONE_HOVER_STYLUS :
(hardwareMouseDetected == MOUSE_HW_INPUT_FINGER) ?
SDL_ANDROID_sFakeWindowHeight / DEADZONE_HOVER_FINGER : 0;
}
SDL_ANDROID_SetHoverDeadzone();
}
void SDL_ANDROID_SetHoverDeadzone()
{
hoverDeadzone = (hardwareMouseDetected == MOUSE_HW_INPUT_STYLUS) ?
SDL_ANDROID_sFakeWindowHeight / DEADZONE_HOVER_STYLUS :
(hardwareMouseDetected == MOUSE_HW_INPUT_FINGER) ?
SDL_ANDROID_sFakeWindowHeight / DEADZONE_HOVER_FINGER : 0;
}
JNIEXPORT void JNICALL

View File

@@ -48,8 +48,11 @@
#define _THIS SDL_VideoDevice *this
#ifdef VIDEO_DEBUG
#define DEBUGOUT(...) __android_log_print(ANDROID_LOG_INFO, "libSDL", __VA_ARGS__)
#else
#define DEBUGOUT(...)
//#define DEBUGOUT(...) __android_log_print(ANDROID_LOG_INFO, "libSDL", __VA_ARGS__)
#endif
static int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **ANDROID_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
@@ -501,6 +504,7 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
UpdateScreenUnderFingerRect(0,0);
SDL_ANDROID_ShowScreenUnderFingerRect.w = SDL_ANDROID_ShowScreenUnderFingerRect.h = 0;
SDL_ANDROID_SetHoverDeadzone();
/* We're done */
return(current);
@@ -1018,7 +1022,25 @@ static void ANDROID_FlipHWSurfaceInternal(int numrects, SDL_Rect *rects)
glPopMatrix();
//glFlush();
}
#ifdef VIDEO_DEBUG
if( SDL_ANDROID_VideoDebugRect.w > 0 )
{
SDL_Rect frame = SDL_ANDROID_VideoDebugRect;
glPushMatrix();
glLoadIdentity();
glOrthof( 0.0f, SDL_ANDROID_sFakeWindowWidth, SDL_ANDROID_sFakeWindowHeight, 0.0f, 0.0f, 1.0f );
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(SDL_ANDROID_VideoDebugRectColor.r / 255.0f, SDL_ANDROID_VideoDebugRectColor.g / 255.0f, SDL_ANDROID_VideoDebugRectColor.b / 255.0f, 1.0f);
GLshort vertices[] = { frame.x, frame.y,
frame.x + frame.w, frame.y,
frame.x + frame.w, frame.y + frame.h,
frame.x, frame.y + frame.h };
glVertexPointer(2, GL_SHORT, 0, vertices);
glDrawArrays(GL_LINE_LOOP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
}
#endif
if(SDL_ANDROID_ShowMouseCursor)
{
if( SDL_ANDROID_ShowScreenUnderFinger == ZOOM_NONE || SDL_ANDROID_ShowScreenUnderFinger == ZOOM_MAGNIFIER )

View File

@@ -88,6 +88,8 @@ int SDL_ANDROID_BYTESPERPIXEL = 2;
int SDL_ANDROID_BITSPERPIXEL = 16;
int SDL_ANDROID_UseGles2 = 0;
int SDL_ANDROID_ShowMouseCursor = 0;
SDL_Rect SDL_ANDROID_VideoDebugRect;
SDL_Color SDL_ANDROID_VideoDebugRectColor;
static void appPutToBackgroundCallbackDefault(void)
{

View File

@@ -28,6 +28,8 @@
#include "SDL_joystick.h"
#include "SDL_events.h"
//#define VIDEO_DEBUG 1
enum ScreenZoom { ZOOM_NONE = 0, ZOOM_MAGNIFIER = 1 };
extern int SDL_ANDROID_sWindowWidth;
@@ -76,6 +78,8 @@ extern void SDL_ANDROID_DrawMouseCursor(int x, int y, int size, float alpha);
extern void SDL_ANDROID_DrawMouseCursorIfNeeded();
extern void SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput();
extern void SDL_ANDROID_CallJavaStartAccelerometerGyroscope(int start);
extern SDL_Rect SDL_ANDROID_VideoDebugRect;
extern SDL_Color SDL_ANDROID_VideoDebugRectColor;
#if SDL_VERSION_ATLEAST(1,3,0)
extern SDL_Window * ANDROID_CurrentWindow;
@@ -88,6 +92,6 @@ extern int SDL_ANDROID_isJoystickUsed;
extern int SDL_ANDROID_isSecondJoystickUsed;
// Events have to be sent only from main thread from PumpEvents(), so we'll buffer them here
extern void SDL_ANDROID_PumpEvents();
extern void SDL_ANDROID_SetHoverDeadzone();
#endif /* _SDL_androidvideo_h */