]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
SDL2: combine SDL_KEYDOWN events directly with following SDL_TEXTINPUT events when...
[xonotic/darkplaces.git] / vid_sdl.c
index 21b3876b9c5e1fba765ec010f16827ce1a6897d5..98d6567ee19bee9ac97f9dcc6ce119727dcbc11a 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -84,7 +84,7 @@ static int win_half_height = 50;
 static int video_bpp;
 
 #if SDL_MAJOR_VERSION == 1
-static SDL_Surface *screen;
+static SDL_Surface *video_screen;
 static int video_flags;
 #else
 static SDL_GLContext context;
@@ -1154,7 +1154,7 @@ void Sys_SendKeyEvents( void )
                                        vid.width = event.resize.w;
                                        vid.height = event.resize.h;
                                        if (!vid_isfullscreen)
-                                               screen = SDL_SetVideoMode(vid.width, vid.height, video_bpp, video_flags);
+                                               video_screen = SDL_SetVideoMode(vid.width, vid.height, video_bpp, video_flags);
                                        if (vid_softsurface)
                                        {
                                                SDL_FreeSurface(vid_softsurface);
@@ -1218,12 +1218,14 @@ void Sys_SendKeyEvents( void )
        static qboolean sound_active = true;
        int keycode;
        int i;
+       qboolean isdown;
        Uchar unicode;
        SDL_Event event;
 
        VID_EnableJoystick(true);
 
        while( SDL_PollEvent( &event ) )
+               loop_start:
                switch( event.type ) {
                        case SDL_QUIT:
 #ifdef DEBUGSDLEVENTS
@@ -1240,8 +1242,31 @@ void Sys_SendKeyEvents( void )
                                        Con_DPrintf("SDL_Event: SDL_KEYUP %i\n", event.key.keysym.sym);
 #endif
                                keycode = MapKey(event.key.keysym.sym);
+                               isdown = (event.key.state == SDL_PRESSED);
+                               unicode = 0;
+                               if(isdown)
+                               {
+                                       if(SDL_PollEvent(&event))
+                                       {
+                                               if(event.type == SDL_TEXTINPUT)
+                                               {
+                                                       // combine key code from SDL_KEYDOWN event and character
+                                                       // from SDL_TEXTINPUT event in a single Key_Event call
+#ifdef DEBUGSDLEVENTS
+                                                       Con_DPrintf("SDL_Event: SDL_TEXTINPUT - text: %s\n", event.text.text);
+#endif
+                                                       unicode = u8_getchar_utf8_enabled(event.text.text + (int)u8_bytelen(event.text.text, 0), NULL);
+                                               }
+                                               else
+                                               {
+                                                       if (!VID_JoyBlockEmulatedKeys(keycode))
+                                                               Key_Event(keycode, 0, isdown);
+                                                       goto loop_start;
+                                               }
+                                       }
+                               }
                                if (!VID_JoyBlockEmulatedKeys(keycode))
-                                       Key_Event(keycode, 0, (event.key.state == SDL_PRESSED));
+                                       Key_Event(keycode, unicode, isdown);
                                break;
                        case SDL_MOUSEBUTTONDOWN:
                        case SDL_MOUSEBUTTONUP:
@@ -1961,6 +1986,9 @@ void GLES_Init(void)
        vid.support.ext_texture_edge_clamp = true; // GLES2 core
        vid.support.ext_texture_filter_anisotropic = false; // probably don't want to use it...
        vid.support.ext_texture_srgb = false;
+       vid.support.arb_texture_float = SDL_GL_ExtensionSupported("GL_OES_texture_float") != 0;
+       vid.support.arb_half_float_pixel = SDL_GL_ExtensionSupported("GL_OES_texture_half_float") != 0;
+       vid.support.arb_half_float_vertex = SDL_GL_ExtensionSupported("GL_OES_vertex_half_float") != 0;
 
        // NOTE: On some devices, a value of 512 gives better FPS than the maximum.
        qglGetIntegerv(GL_MAX_TEXTURE_SIZE, (GLint*)&vid.maxtexturesize_2d);
@@ -2619,15 +2647,15 @@ static qboolean VID_InitModeGL(viddef_mode_t *mode)
        video_bpp = mode->bitsperpixel;
 #if SDL_MAJOR_VERSION == 1
        video_flags = flags;
-       screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
-       if (screen == NULL)
+       video_screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
+       if (video_screen == NULL)
        {
                Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
                VID_Shutdown();
                return false;
        }
-       mode->width = screen->w;
-       mode->height = screen->h;
+       mode->width = video_screen->w;
+       mode->height = video_screen->h;
 #else
        window_flags = windowflags;
        window = SDL_CreateWindow(gamename, xPos, yPos, mode->width, mode->height, windowflags);
@@ -2731,15 +2759,15 @@ static qboolean VID_InitModeSoft(viddef_mode_t *mode)
        video_bpp = mode->bitsperpixel;
 #if SDL_MAJOR_VERSION == 1
        video_flags = flags;
-       screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
-       if (screen == NULL)
+       video_screen = VID_WrapSDL_SetVideoMode(mode->width, mode->height, mode->bitsperpixel, flags);
+       if (video_screen == NULL)
        {
                Con_Printf("Failed to set video mode to %ix%i: %s\n", mode->width, mode->height, SDL_GetError());
                VID_Shutdown();
                return false;
        }
-       mode->width = screen->w;
-       mode->height = screen->h;
+       mode->width = video_screen->w;
+       mode->height = video_screen->h;
 #else
        window_flags = windowflags;
        window = SDL_CreateWindow(gamename, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, mode->width, mode->height, windowflags);
@@ -2924,8 +2952,8 @@ void VID_Finish (void)
 #if SDL_MAJOR_VERSION == 1
 //             if (!r_test.integer)
                {
-                       SDL_BlitSurface(vid_softsurface, NULL, screen, NULL);
-                       SDL_Flip(screen);
+                       SDL_BlitSurface(vid_softsurface, NULL, video_screen, NULL);
+                       SDL_Flip(video_screen);
                }
 #else
                        {