X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fui_sdl.c;h=520ac0091dd23f74a654a8589d7a99889bb47a28;hb=74c10f8633b8d738b60ad3b6439b18bbe211ab86;hp=546021a6b505694beb9c0f97fcfc29769f941d27;hpb=9ed2477f5f7e5b01501368719e93259aa336932f;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/ui_sdl.c b/AcessNative/acesskernel_src/ui_sdl.c index 546021a6..520ac009 100644 --- a/AcessNative/acesskernel_src/ui_sdl.c +++ b/AcessNative/acesskernel_src/ui_sdl.c @@ -7,14 +7,13 @@ #define const #include "ui.h" #undef const -#include +#include // === IMPORTS === extern void AcessNative_Exit(void); // === PROTOTYPES === int UI_Initialise(int MaxWidth, int MaxHeight); - int UI_MainThread(void *Unused); void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap); void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H); void UI_FillBitmap(int X, int Y, int W, int H, Uint32 Value); @@ -36,9 +35,25 @@ int UI_Initialise(int MaxWidth, int MaxHeight) giUI_Width = MaxWidth; giUI_Height = MaxHeight; - // Start main thread - gInputThread = SDL_CreateThread(UI_MainThread, NULL); + // Set up video + SDL_Init(SDL_INIT_VIDEO); + printf("UI attempting %ix%i %ibpp\n", giUI_Width, giUI_Height, 32); + gScreen = SDL_SetVideoMode(giUI_Width, giUI_Height, 32, SDL_DOUBLEBUF); + if( !gScreen ) { + fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", giUI_Width, giUI_Height, SDL_GetError()); + SDL_Quit(); + exit(2); + } + SDL_WM_SetCaption("Acess2", "Acess2"); + + giUI_Width = gScreen->w; + giUI_Height = gScreen->h; + giUI_Pitch = gScreen->pitch; + + printf("UI window %ix%i %i bytes per line\n", giUI_Width, giUI_Height, giUI_Pitch); + SDL_EnableUNICODE(1); + return 0; } @@ -54,6 +69,10 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode) // Fast return if( gUI_Keymap[shiftState][Sym] ) 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 ) @@ -82,6 +101,7 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode) 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; default: printf("Unhandled key code %i\n", Sym); break; @@ -92,28 +112,11 @@ Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode) return ret; } -int UI_MainThread(void *Unused) +void UI_MainLoop(void) { SDL_Event event; Uint32 acess_sym; - - SDL_Init(SDL_INIT_VIDEO); - - // Set up video - gScreen = SDL_SetVideoMode(giUI_Width, giUI_Height, 32, 0); - if( !gScreen ) { - fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", giUI_Width, giUI_Height, SDL_GetError()); - SDL_Quit(); - exit(2); - } - SDL_WM_SetCaption("Acess2", "Acess2"); - - giUI_Width = gScreen->w; - giUI_Height = gScreen->h; - giUI_Pitch = gScreen->pitch; - - SDL_EnableUNICODE(1); - + for( ;; ) { while(SDL_PollEvent(&event)) @@ -122,24 +125,33 @@ int UI_MainThread(void *Unused) { case SDL_QUIT: AcessNative_Exit(); - return 0; + return ; case SDL_KEYDOWN: acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym, event.key.keysym.unicode); - if( gUI_KeyboardCallback ) - gUI_KeyboardCallback(acess_sym); + if( gUI_KeyboardCallback ) { + gUI_KeyboardCallback(KEY_ACTION_RAWSYM|event.key.keysym.sym); + gUI_KeyboardCallback(KEY_ACTION_PRESS|acess_sym); + } break; case SDL_KEYUP: acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym, event.key.keysym.unicode); - if( gUI_KeyboardCallback ) - gUI_KeyboardCallback(0x80000000|acess_sym); + if( gUI_KeyboardCallback ) { + gUI_KeyboardCallback(KEY_ACTION_RAWSYM|event.key.keysym.sym); + gUI_KeyboardCallback(KEY_ACTION_RELEASE|acess_sym); + } break; - + + case SDL_USEREVENT: + SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height); + SDL_Flip(gScreen); + break; + default: break; } @@ -152,15 +164,21 @@ void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap) SDL_Surface *tmp; SDL_Rect dstRect; +// printf("UI_BlitBitmap: Blit to (%i,%i) from %p (%ix%i 32bpp bitmap)\n", +// DstX, DstY, Bitmap, SrcW, SrcH); + tmp = SDL_CreateRGBSurfaceFrom(Bitmap, SrcW, SrcH, 32, SrcW*4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000); SDL_SetAlpha(tmp, 0, SDL_ALPHA_OPAQUE); dstRect.x = DstX; dstRect.y = DstY; + dstRect.w = -1; dstRect.h = -1; SDL_BlitSurface(tmp, NULL, gScreen, &dstRect); + //SDL_BlitSurface(tmp, NULL, gScreen, NULL); SDL_FreeSurface(tmp); +// SDL_Flip(gScreen); } void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H) @@ -182,10 +200,20 @@ void UI_FillBitmap(int X, int Y, int W, int H, Uint32 Value) dstRect.x = X; dstRect.y = Y; dstRect.w = W; dstRect.h = H; +// printf("UI_FillBitmap: gScreen = %p\n", gScreen); SDL_FillRect(gScreen, &dstRect, Value); } void UI_Redraw(void) { - // No-Op, we're not using double buffering + // TODO: Keep track of changed rectangle +// SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height); + SDL_Event e; + + e.type = SDL_USEREVENT; + e.user.code = 0; + e.user.data1 = 0; + e.user.data2 = 0; + + SDL_PushEvent( &e ); }