AcessNative - Fixed buggy SDL key mappings
authorJohn Hodge <[email protected]>
Sun, 7 Oct 2012 09:42:00 +0000 (17:42 +0800)
committerJohn Hodge <[email protected]>
Sun, 7 Oct 2012 09:42:00 +0000 (17:42 +0800)
AcessNative/acesskernel_src/ui_sdl.c
AcessNative/acesskernel_src/video.c

index ae1d811..25f2964 100644 (file)
@@ -57,7 +57,7 @@ int UI_Initialise(int MaxWidth, int MaxHeight)
        return 0;
 }
 
-Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode)
+Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym)
 {
        Uint8   *keystate = SDL_GetKeyState(NULL);
         int    shiftState = 0;
@@ -71,43 +71,38 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode)
                return gUI_Keymap[shiftState][Sym];
 
        // Enter key on acess returns \n, but SDL returns \r
-       if( Sym == SDLK_RETURN )
-               Unicode = '\n';
-       
-       // How nice of you, a unicode value
-       if( Unicode )
-       {
-               ret = Unicode;
-       }
-       // Ok, we need to do work :(
-       else
+       switch(Sym)
        {
-               switch(Sym)
-               {
-               case SDLK_UP:   ret = KEY_UP;   break;
-               case SDLK_DOWN: ret = KEY_DOWN; break;
-               case SDLK_LEFT: ret = KEY_LEFT; break;
-               case SDLK_RIGHT:ret = KEY_RIGHT;break;
-               case SDLK_CAPSLOCK:     ret = KEY_CAPSLOCK;     break;
-               case SDLK_F1:   ret = KEY_F1;   break;
-               case SDLK_F2:   ret = KEY_F2;   break;
-               case SDLK_F3:   ret = KEY_F3;   break;
-               case SDLK_F4:   ret = KEY_F4;   break;
-               case SDLK_F5:   ret = KEY_F5;   break;
-               case SDLK_F6:   ret = KEY_F6;   break;
-               case SDLK_F7:   ret = KEY_F7;   break;
-               case SDLK_F8:   ret = KEY_F8;   break;
-               case SDLK_F9:   ret = KEY_F9;   break;
-               case SDLK_F10:  ret = KEY_F10;  break;
-               case SDLK_F11:  ret = KEY_F11;  break;
-               case SDLK_F12:  ret = KEY_F12;  break;
-               case SDLK_RETURN:       ret = '\n';     break;
-               case SDLK_LALT: ret = KEY_LALT; break;
-               case SDLK_RALT: ret = KEY_RALT; break;
-               default:
-                       printf("Unhandled key code %i\n", Sym);
-                       break;
-               }
+       case SDLK_a ... SDLK_z:
+               ret = Sym - SDLK_a + KEYSYM_a;
+               break;
+       case SDLK_0 ... SDLK_9:
+               ret = Sym - SDLK_0 + KEYSYM_0;
+               break;
+       case SDLK_UP:   ret = KEYSYM_UPARROW;   break;
+       case SDLK_DOWN: ret = KEYSYM_DOWNARROW; break;
+       case SDLK_LEFT: ret = KEYSYM_LEFTARROW; break;
+       case SDLK_RIGHT:ret = KEYSYM_RIGHTARROW;break;
+       case SDLK_CAPSLOCK:     ret = KEYSYM_CAPS;      break;
+       case SDLK_F1:   ret = KEYSYM_F1;        break;
+       case SDLK_F2:   ret = KEYSYM_F2;        break;
+       case SDLK_F3:   ret = KEYSYM_F3;        break;
+       case SDLK_F4:   ret = KEYSYM_F4;        break;
+       case SDLK_F5:   ret = KEYSYM_F5;        break;
+       case SDLK_F6:   ret = KEYSYM_F6;        break;
+       case SDLK_F7:   ret = KEYSYM_F7;        break;
+       case SDLK_F8:   ret = KEYSYM_F8;        break;
+       case SDLK_F9:   ret = KEYSYM_F9;        break;
+       case SDLK_F10:  ret = KEYSYM_F10;       break;
+       case SDLK_F11:  ret = KEYSYM_F11;       break;
+       case SDLK_F12:  ret = KEYSYM_F12;       break;
+       case SDLK_RETURN:       ret = KEYSYM_RETURN;    break;
+       case SDLK_LALT: ret = KEYSYM_LEFTALT;   break;
+       case SDLK_RALT: ret = KEYSYM_RIGHTALT;  break;
+       case SDLK_LSUPER:       ret = KEYSYM_LEFTGUI;   break;
+       default:
+               printf("Unhandled key code %i\n", Sym);
+               break;
        }
        
        gUI_Keymap[shiftState][Sym] = ret;
@@ -130,22 +125,20 @@ void UI_MainLoop(void)
                                return ;
                                
                        case SDL_KEYDOWN:
-                               acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
-                                       event.key.keysym.unicode);
+                               acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym);
                                
                                if( gUI_KeyboardCallback ) {
-                                       gUI_KeyboardCallback(KEY_ACTION_RAWSYM|event.key.keysym.sym);
-                                       gUI_KeyboardCallback(KEY_ACTION_PRESS|acess_sym);
+                                       gUI_KeyboardCallback(KEY_ACTION_RAWSYM|acess_sym);
+                                       gUI_KeyboardCallback(KEY_ACTION_PRESS|event.key.keysym.unicode);
                                }
                                break;
                        
                        case SDL_KEYUP:
-                               acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
-                                       event.key.keysym.unicode);
+                               acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym);
                                
                                if( gUI_KeyboardCallback ) {
-                                       gUI_KeyboardCallback(KEY_ACTION_RAWSYM|event.key.keysym.sym);
-                                       gUI_KeyboardCallback(KEY_ACTION_RELEASE|acess_sym);
+                                       gUI_KeyboardCallback(KEY_ACTION_RAWSYM|acess_sym);
+                                       gUI_KeyboardCallback(KEY_ACTION_RELEASE|0);
                                }
                                break;
 
index 5408b56..da18f48 100644 (file)
@@ -166,10 +166,12 @@ Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Bu
                
                LOG("buffer = %p", Buffer);
                
+               Offset /= 4;
                startX = Offset % giUI_Width;
                startY = Offset / giUI_Width;
-               
-               if( Length + startX < giUI_Width )
+               Length /= 4;
+
+               if( startX + Length < giUI_Width )
                {
                        // Single line
                        UI_BlitBitmap(
@@ -177,6 +179,15 @@ Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Bu
                                Length, 1,
                                Buffer);
                }
+               else if( startX == 0 )
+               {
+                       int     lines = Length / giUI_Width;
+                       int     rem = Length % giUI_Width;
+                       UI_BlitBitmap(0, startY, giUI_Width, lines, Buffer);
+                       if( rem ) {
+                               UI_BlitBitmap(0, startY + lines, rem, 1, (Uint32*)Buffer + lines*giUI_Width);
+                       }
+               }
                else
                {
                        // First scanline (partial or full)

UCC git Repository :: git.ucc.asn.au