Fixed mouse events ignoring screen resizing

This commit is contained in:
pelya
2010-07-23 13:05:31 +03:00
parent 8876c75849
commit e97befb3e4
5 changed files with 29 additions and 1 deletions

View File

@@ -101,6 +101,8 @@ struct SDL_PrivateVideoData {
// Pointer to in-memory video surface
static int memX = 0;
static int memY = 0;
int SDL_ANDROID_sFakeWindowWidth = 640;
int SDL_ANDROID_sFakeWindowHeight = 480;
// In-memory surfaces
static void * memBuffer1 = NULL;
static void * memBuffer2 = NULL;
@@ -235,6 +237,8 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
memX = width;
memY = height;
SDL_ANDROID_sFakeWindowWidth = width;
SDL_ANDROID_sFakeWindowHeight = height;
if( ! sdl_opengl )
{
@@ -355,7 +359,11 @@ static int ANDROID_FlipHWSurface(_THIS, SDL_Surface *surface)
if( ! sdl_opengl )
{
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, memX, memY, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, memBuffer);
#if SDL_VIDEO_RENDER_RESIZE
glDrawTexiOES(0, 0, 1, SDL_ANDROID_sWindowWidth, SDL_ANDROID_sWindowHeight); // Stretch to screen
#else
glDrawTexiOES(0, SDL_ANDROID_sWindowHeight - SDL_ANDROID_sFakeWindowHeight, 1, SDL_ANDROID_sFakeWindowWidth, SDL_ANDROID_sFakeWindowHeight); // Do not stretch
#endif
if( surface->flags & SDL_DOUBLEBUF )
{

View File

@@ -198,6 +198,7 @@ static int ANDROIDAUD_OpenAudio (_THIS, SDL_AudioSpec *spec)
audioFormat->samples = audioBufferSize / bytesPerSample / audioFormat->channels;
audioFormat->size = audioBufferSize;
__android_log_print(ANDROID_LOG_INFO, "libSDL", "ANDROIDAUD_OpenAudio(): app opened audio bytespersample %d freq %d channels %d bufsize %d", bytesPerSample, audioFormat->freq, (jint)audioFormat->channels, audioBufferSize);
SDL_CalculateAudioSpec(&this->spec);

View File

@@ -69,6 +69,23 @@ enum MOUSE_ACTION { MOUSE_DOWN = 0, MOUSE_UP=1, MOUSE_MOVE=2 };
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(DemoGLSurfaceView_nativeMouse) ( JNIEnv* env, jobject thiz, jint x, jint y, jint action )
{
#if SDL_VIDEO_RENDER_RESIZE
// Translate mouse coordinates
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_Renderer *renderer;
renderer = SDL_GetCurrentRenderer(SDL_TRUE);
if( renderer && renderer->window ) {
x = x * renderer->window->w / renderer->window->display->desktop_mode.w;
y = y * renderer->window->h / renderer->window->display->desktop_mode.h;
}
#else
x = x * SDL_ANDROID_sFakeWindowWidth / SDL_ANDROID_sWindowWidth;
y = y * SDL_ANDROID_sFakeWindowHeight / SDL_ANDROID_sWindowHeight;
#endif
#endif
if( action == MOUSE_DOWN || action == MOUSE_UP )
{
#if SDL_VERSION_ATLEAST(1,3,0)

View File

@@ -45,7 +45,7 @@
// The device screen dimensions to draw on
int SDL_ANDROID_sWindowWidth = 320;
int SDL_ANDROID_sWindowWidth = 640;
int SDL_ANDROID_sWindowHeight = 480;
// Extremely wicked JNI environment to call Java functions from C code

View File

@@ -30,6 +30,8 @@ extern void ANDROID_InitOSKeymap();
extern int SDL_ANDROID_sWindowWidth;
extern int SDL_ANDROID_sWindowHeight;
extern int SDL_ANDROID_sFakeWindowWidth; // SDL 1.2 only
extern int SDL_ANDROID_sFakeWindowHeight; // SDL 1.2 only
extern int SDL_ANDROID_CallJavaSwapBuffers();