10 #include <tpl_drv_keyboard.h>
13 extern void AcessNative_Exit(void);
16 int UI_Initialise(int MaxWidth, int MaxHeight);
17 int UI_MainThread(void *Unused);
18 void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap);
19 void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H);
20 void UI_FillBitmap(int X, int Y, int W, int H, Uint32 Value);
25 SDL_Thread *gInputThread;
29 tUI_KeybardCallback gUI_KeyboardCallback;
30 Uint32 gUI_Keymap[2][SDLK_LAST]; // Upper/Lower case
33 int UI_Initialise(int MaxWidth, int MaxHeight)
35 // Changed when the video mode is set
36 giUI_Width = MaxWidth;
37 giUI_Height = MaxHeight;
40 gInputThread = SDL_CreateThread(UI_MainThread, NULL);
45 Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode)
47 Uint8 *keystate = SDL_GetKeyState(NULL);
51 if( keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT] )
55 if( gUI_Keymap[shiftState][Sym] )
56 return gUI_Keymap[shiftState][Sym];
58 // How nice of you, a unicode value
63 // Ok, we need to do work :(
68 case SDLK_UP: ret = KEY_UP; break;
69 case SDLK_DOWN: ret = KEY_DOWN; break;
70 case SDLK_LEFT: ret = KEY_LEFT; break;
71 case SDLK_RIGHT:ret = KEY_RIGHT;break;
72 case SDLK_CAPSLOCK: ret = KEY_CAPSLOCK; break;
73 case SDLK_F1: ret = KEY_F1; break;
74 case SDLK_F2: ret = KEY_F2; break;
75 case SDLK_F3: ret = KEY_F3; break;
76 case SDLK_F4: ret = KEY_F4; break;
77 case SDLK_F5: ret = KEY_F5; break;
78 case SDLK_F6: ret = KEY_F6; break;
79 case SDLK_F7: ret = KEY_F7; break;
80 case SDLK_F8: ret = KEY_F8; break;
81 case SDLK_F9: ret = KEY_F9; break;
82 case SDLK_F10: ret = KEY_F10; break;
83 case SDLK_F11: ret = KEY_F11; break;
84 case SDLK_F12: ret = KEY_F12; break;
86 printf("Unhandled key code %i\n", Sym);
91 gUI_Keymap[shiftState][Sym] = ret;
95 int UI_MainThread(void *Unused)
100 SDL_Init(SDL_INIT_VIDEO);
103 gScreen = SDL_SetVideoMode(giUI_Width, giUI_Height, 32, 0);
105 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", giUI_Width, giUI_Height, SDL_GetError());
109 SDL_WM_SetCaption("Acess2", "Acess2");
111 giUI_Width = gScreen->w;
112 giUI_Height = gScreen->h;
113 giUI_Pitch = gScreen->pitch;
115 SDL_EnableUNICODE(1);
119 while(SDL_PollEvent(&event))
128 acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
129 event.key.keysym.unicode);
131 if( gUI_KeyboardCallback )
132 gUI_KeyboardCallback(acess_sym);
136 acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
137 event.key.keysym.unicode);
139 if( gUI_KeyboardCallback )
140 gUI_KeyboardCallback(0x80000000|acess_sym);
150 void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap)
155 tmp = SDL_CreateRGBSurfaceFrom(Bitmap, SrcW, SrcH, 32, SrcW*4,
156 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
157 SDL_SetAlpha(tmp, 0, SDL_ALPHA_OPAQUE);
159 dstRect.x = DstX; dstRect.y = DstY;
161 SDL_BlitSurface(tmp, NULL, gScreen, &dstRect);
163 SDL_FreeSurface(tmp);
166 void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H)
171 srcRect.x = SrcX; srcRect.y = SrcY;
172 srcRect.w = W; srcRect.h = H;
173 dstRect.x = DstX; dstRect.y = DstY;
175 SDL_BlitSurface(gScreen, &srcRect, gScreen, &dstRect);
178 void UI_FillBitmap(int X, int Y, int W, int H, Uint32 Value)
182 dstRect.x = X; dstRect.y = Y;
183 dstRect.w = W; dstRect.h = H;
185 SDL_FillRect(gScreen, &dstRect, Value);
190 // No-Op, we're not using double buffering