More efficient SDL_IsScreenKeyboardShown() implementation
This commit is contained in:
@@ -14,8 +14,9 @@
|
||||
#include <math.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_image.h"
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_image.h>
|
||||
#include <SDL/SDL_screenkeyboard.h>
|
||||
|
||||
#define fprintf(X, ...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__)
|
||||
#define printf(...) __android_log_print(ANDROID_LOG_INFO, "Ballfield", __VA_ARGS__)
|
||||
@@ -438,6 +439,7 @@ int main(int argc, char* argv[])
|
||||
struct TouchPointer_t { int x; int y; int pressure; int pressed; } touchPointers[MAX_POINTERS];
|
||||
int accel[2], screenjoy[2];
|
||||
SDL_Surface *mouse[4];
|
||||
int screenKeyboardShown = 0;
|
||||
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
|
||||
@@ -671,6 +673,11 @@ int main(int argc, char* argv[])
|
||||
touchPointers[evt.jball.ball].y = evt.jball.yrel;
|
||||
}
|
||||
}
|
||||
if( screenKeyboardShown != SDL_IsScreenKeyboardShown(NULL))
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "Ballfield", "Screen keyboard shown: %d -> %d", screenKeyboardShown, SDL_IsScreenKeyboardShown(NULL));
|
||||
screenKeyboardShown = SDL_IsScreenKeyboardShown(NULL);
|
||||
}
|
||||
|
||||
/* Animate */
|
||||
x_speed = 500.0 * sin(t * 0.37);
|
||||
|
||||
@@ -832,7 +832,7 @@ JNIEXPORT void JNICALL
|
||||
JAVA_EXPORT_NAME(DemoRenderer_nativeTextInputFinished) ( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
textInputBuffer = NULL;
|
||||
SDL_ANDROID_TextInputFinished();
|
||||
SDL_ANDROID_TextInputFinished = 1;
|
||||
}
|
||||
|
||||
static void updateOrientation ( float accX, float accY, float accZ );
|
||||
@@ -1943,6 +1943,14 @@ void SDL_ANDROID_DeferredTextInput()
|
||||
if( isMouseUsed )
|
||||
SDL_ANDROID_MainThreadPushMouseMotion(currentMouseX + (currentMouseX % 2 ? -1 : 1), currentMouseY); // Force screen redraw
|
||||
}
|
||||
else
|
||||
{
|
||||
if( SDL_ANDROID_TextInputFinished )
|
||||
{
|
||||
SDL_ANDROID_TextInputFinished = 0;
|
||||
SDL_ANDROID_IsScreenKeyboardShownFlag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_mutexV(deferredTextMutex);
|
||||
};
|
||||
|
||||
@@ -73,6 +73,8 @@ static int glContextLost = 0;
|
||||
static int showScreenKeyboardDeferred = 0;
|
||||
static const char * showScreenKeyboardOldText = "";
|
||||
static int showScreenKeyboardSendBackspace = 0;
|
||||
int SDL_ANDROID_IsScreenKeyboardShownFlag = 0;
|
||||
int SDL_ANDROID_TextInputFinished = 0;
|
||||
int SDL_ANDROID_VideoLinearFilter = 0;
|
||||
int SDL_ANDROID_VideoMultithreaded = 0;
|
||||
int SDL_ANDROID_VideoForceSoftwareMode = 0;
|
||||
@@ -240,12 +242,6 @@ int SDL_ANDROID_ToggleScreenKeyboardWithoutTextInput(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
volatile static textInputFinished = 0;
|
||||
void SDL_ANDROID_TextInputFinished()
|
||||
{
|
||||
textInputFinished = 1;
|
||||
};
|
||||
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
#else
|
||||
extern int SDL_Flip(SDL_Surface *screen);
|
||||
@@ -254,6 +250,8 @@ extern SDL_Surface *SDL_GetVideoSurface(void);
|
||||
|
||||
void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen)
|
||||
{
|
||||
SDL_ANDROID_TextInputFinished = 0;
|
||||
SDL_ANDROID_IsScreenKeyboardShownFlag = 1;
|
||||
if( !outBuf )
|
||||
{
|
||||
showScreenKeyboardDeferred = 1;
|
||||
@@ -266,7 +264,6 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf,
|
||||
}
|
||||
else
|
||||
{
|
||||
textInputFinished = 0;
|
||||
SDL_ANDROID_TextInputInit(outBuf, outBufLen);
|
||||
|
||||
if( SDL_ANDROID_VideoMultithreaded )
|
||||
@@ -283,9 +280,10 @@ void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf,
|
||||
else
|
||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaShowScreenKeyboard, (*JavaEnv)->NewStringUTF(JavaEnv, oldText), 0 );
|
||||
|
||||
while( !textInputFinished )
|
||||
while( !SDL_ANDROID_TextInputFinished )
|
||||
SDL_Delay(100);
|
||||
textInputFinished = 0;
|
||||
SDL_ANDROID_TextInputFinished = 0;
|
||||
SDL_ANDROID_IsScreenKeyboardShownFlag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,9 +292,9 @@ void SDL_ANDROID_CallJavaHideScreenKeyboard()
|
||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaHideScreenKeyboard );
|
||||
}
|
||||
|
||||
int SDL_ANDROID_CallJavaIsScreenKeyboardShown()
|
||||
int SDL_ANDROID_IsScreenKeyboardShown()
|
||||
{
|
||||
return (*JavaEnv)->CallIntMethod( JavaEnv, JavaRenderer, JavaIsScreenKeyboardShown );
|
||||
return SDL_ANDROID_IsScreenKeyboardShownFlag;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
|
||||
@@ -49,7 +49,7 @@ extern int SDL_ANDROID_UseGles2;
|
||||
extern int SDL_ANDROID_BYTESPERPIXEL;
|
||||
extern int SDL_ANDROID_BITSPERPIXEL;
|
||||
extern void SDL_ANDROID_TextInputInit(char * buffer, int len);
|
||||
extern void SDL_ANDROID_TextInputFinished();
|
||||
extern int SDL_ANDROID_TextInputFinished;
|
||||
extern SDL_Surface *SDL_CurrentVideoSurface;
|
||||
extern SDL_Rect SDL_ANDROID_ForceClearScreenRect;
|
||||
extern int SDL_ANDROID_ShowScreenUnderFinger;
|
||||
@@ -57,7 +57,8 @@ extern SDL_Rect SDL_ANDROID_ShowScreenUnderFingerRect, SDL_ANDROID_ShowScreenUnd
|
||||
extern int SDL_ANDROID_CallJavaSwapBuffers();
|
||||
extern void SDL_ANDROID_CallJavaShowScreenKeyboard(const char * oldText, char * outBuf, int outBufLen);
|
||||
extern void SDL_ANDROID_CallJavaHideScreenKeyboard();
|
||||
extern int SDL_ANDROID_CallJavaIsScreenKeyboardShown();
|
||||
extern int SDL_ANDROID_IsScreenKeyboardShown();
|
||||
extern int SDL_ANDROID_IsScreenKeyboardShownFlag;
|
||||
extern int SDL_ANDROID_drawTouchscreenKeyboard();
|
||||
extern void SDL_ANDROID_VideoContextLost();
|
||||
extern void SDL_ANDROID_VideoContextRecreated();
|
||||
|
||||
@@ -1090,7 +1090,7 @@ int SDLCALL SDL_HideScreenKeyboard(void *unused)
|
||||
|
||||
int SDLCALL SDL_IsScreenKeyboardShown(void *unused)
|
||||
{
|
||||
return SDL_ANDROID_CallJavaIsScreenKeyboardShown();
|
||||
return SDL_ANDROID_IsScreenKeyboardShown();
|
||||
}
|
||||
|
||||
int SDLCALL SDL_ToggleScreenKeyboard(void *unused)
|
||||
|
||||
Reference in New Issue
Block a user