X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=AcessNative%2Facesskernel_src%2Fui_sdl.c;h=a3e4d4b9cc681beb3671622c3845b082f6587ad6;hb=13078002b01ee4f63eb2001d2ef479a2a006ea32;hp=25f2964ea7ef1d1b18027fc15152613091b5f580;hpb=4e9f0fb47bf1be7303d95a243101880221c82ac1;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/ui_sdl.c b/AcessNative/acesskernel_src/ui_sdl.c index 25f2964e..a3e4d4b9 100644 --- a/AcessNative/acesskernel_src/ui_sdl.c +++ b/AcessNative/acesskernel_src/ui_sdl.c @@ -27,6 +27,7 @@ SDL_Thread *gInputThread; int giUI_Pitch = 0; tUI_KeybardCallback gUI_KeyboardCallback; Uint32 gUI_Keymap[2][SDLK_LAST]; // Upper/Lower case + int gbUpdateTriggered = 0; // === FUNCTIONS === int UI_Initialise(int MaxWidth, int MaxHeight) @@ -70,7 +71,6 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym) if( gUI_Keymap[shiftState][Sym] ) return gUI_Keymap[shiftState][Sym]; - // Enter key on acess returns \n, but SDL returns \r switch(Sym) { case SDLK_a ... SDLK_z: @@ -79,11 +79,13 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym) case SDLK_0 ... SDLK_9: ret = Sym - SDLK_0 + KEYSYM_0; break; + case SDLK_SLASH: ret = KEYSYM_SLASH; break; + case SDLK_CAPSLOCK: ret = KEYSYM_CAPS; break; + case SDLK_TAB: ret = KEYSYM_TAB; 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; @@ -97,9 +99,15 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym) 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_LALT: ret = KEYSYM_LEFTALT; break; + case SDLK_LCTRL: ret = KEYSYM_LEFTCTRL; break; + case SDLK_LSHIFT: ret = KEYSYM_LEFTSHIFT; break; case SDLK_LSUPER: ret = KEYSYM_LEFTGUI; break; + case SDLK_RALT: ret = KEYSYM_RIGHTALT; break; + case SDLK_RCTRL: ret = KEYSYM_RIGHTCTRL; break; + case SDLK_RSHIFT: ret = KEYSYM_RIGHTSHIFT; break; + case SDLK_RSUPER: ret = KEYSYM_RIGHTGUI; break; + case SDLK_BACKSPACE: ret = KEYSYM_BACKSP; break; default: printf("Unhandled key code %i\n", Sym); break; @@ -109,47 +117,73 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym) return ret; } +Uint32 UI_GetButtonBits(Uint8 sdlstate) +{ + Uint32 rv = 0; + rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_LEFT) ? (1 << 0) : 0; + rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_RIGHT) ? (1 << 1) : 0; + rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_MIDDLE) ? (1 << 2) : 0; + rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_X1) ? (1 << 3) : 0; + rv |= sdlstate & SDL_BUTTON(SDL_BUTTON_X2) ? (1 << 4) : 0; + return rv; +} + void UI_MainLoop(void) { SDL_Event event; Uint32 acess_sym; - for( ;; ) + while( SDL_WaitEvent(&event) ) { - while(SDL_PollEvent(&event)) + switch(event.type) { - switch(event.type) - { - case SDL_QUIT: - AcessNative_Exit(); - return ; - - case SDL_KEYDOWN: - acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym); - - if( gUI_KeyboardCallback ) { - gUI_KeyboardCallback(KEY_ACTION_RAWSYM|acess_sym); - gUI_KeyboardCallback(KEY_ACTION_PRESS|event.key.keysym.unicode); - } - break; + case SDL_QUIT: + AcessNative_Exit(); + return ; + + case SDL_KEYDOWN: + acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym); + // Enter key on acess returns \n, but SDL returns \r + if(event.key.keysym.sym == SDLK_RETURN) + event.key.keysym.unicode = '\n'; + + if( gUI_KeyboardCallback ) { + 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); - case SDL_KEYUP: - acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym); - - if( gUI_KeyboardCallback ) { - gUI_KeyboardCallback(KEY_ACTION_RAWSYM|acess_sym); - gUI_KeyboardCallback(KEY_ACTION_RELEASE|0); - } - break; - - case SDL_USEREVENT: + if( gUI_KeyboardCallback ) { + gUI_KeyboardCallback(KEY_ACTION_RAWSYM|acess_sym); + gUI_KeyboardCallback(KEY_ACTION_RELEASE|0); + } + break; + + case SDL_USEREVENT: + if( gbUpdateTriggered ) + { + gbUpdateTriggered = 0; SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height); SDL_Flip(gScreen); - break; - - default: - break; } + break; + + case SDL_MOUSEMOTION: { + int abs[] = {event.motion.x, event.motion.y}; + int delta[] = {event.motion.xrel, event.motion.yrel}; + Mouse_HandleEvent(UI_GetButtonBits(SDL_GetMouseState(NULL, NULL)), delta, abs); + break; } + case SDL_MOUSEBUTTONUP: + case SDL_MOUSEBUTTONDOWN: { + int abs[] = {event.button.x, event.button.y}; + Mouse_HandleEvent(UI_GetButtonBits(SDL_GetMouseState(NULL, NULL)), NULL, abs); + break; } + + default: + break; } } } @@ -203,12 +237,16 @@ void UI_Redraw(void) { // TODO: Keep track of changed rectangle // SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height); - SDL_Event e; + if( gbUpdateTriggered == 0 ) + { + gbUpdateTriggered = 1; + SDL_Event e; - e.type = SDL_USEREVENT; - e.user.code = 0; - e.user.data1 = 0; - e.user.data2 = 0; + e.type = SDL_USEREVENT; + e.user.code = 0; + e.user.data1 = 0; + e.user.data2 = 0; - SDL_PushEvent( &e ); + SDL_PushEvent( &e ); + } }