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);
42 while(gScreen == NULL)
48 Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode)
50 Uint8 *keystate = SDL_GetKeyState(NULL);
54 if( keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT] )
58 if( gUI_Keymap[shiftState][Sym] )
59 return gUI_Keymap[shiftState][Sym];
61 // How nice of you, a unicode value
66 // Ok, we need to do work :(
71 case SDLK_UP: ret = KEY_UP; break;
72 case SDLK_DOWN: ret = KEY_DOWN; break;
73 case SDLK_LEFT: ret = KEY_LEFT; break;
74 case SDLK_RIGHT:ret = KEY_RIGHT;break;
75 case SDLK_CAPSLOCK: ret = KEY_CAPSLOCK; break;
76 case SDLK_F1: ret = KEY_F1; break;
77 case SDLK_F2: ret = KEY_F2; break;
78 case SDLK_F3: ret = KEY_F3; break;
79 case SDLK_F4: ret = KEY_F4; break;
80 case SDLK_F5: ret = KEY_F5; break;
81 case SDLK_F6: ret = KEY_F6; break;
82 case SDLK_F7: ret = KEY_F7; break;
83 case SDLK_F8: ret = KEY_F8; break;
84 case SDLK_F9: ret = KEY_F9; break;
85 case SDLK_F10: ret = KEY_F10; break;
86 case SDLK_F11: ret = KEY_F11; break;
87 case SDLK_F12: ret = KEY_F12; break;
89 printf("Unhandled key code %i\n", Sym);
94 gUI_Keymap[shiftState][Sym] = ret;
98 int UI_MainThread(void *Unused)
103 SDL_Init(SDL_INIT_VIDEO);
106 gScreen = SDL_SetVideoMode(giUI_Width, giUI_Height, 32, 0);
108 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", giUI_Width, giUI_Height, SDL_GetError());
112 SDL_WM_SetCaption("Acess2", "Acess2");
114 giUI_Width = gScreen->w;
115 giUI_Height = gScreen->h;
116 giUI_Pitch = gScreen->pitch;
118 SDL_EnableUNICODE(1);
122 while(SDL_PollEvent(&event))
131 acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
132 event.key.keysym.unicode);
134 if( gUI_KeyboardCallback )
135 gUI_KeyboardCallback(acess_sym);
139 acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
140 event.key.keysym.unicode);
142 if( gUI_KeyboardCallback )
143 gUI_KeyboardCallback(0x80000000|acess_sym);
153 void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap)
158 // printf("UI_BlitBitmap: Blit to (%i,%i) from %p (%ix%i 32bpp bitmap)\n",
159 // DstX, DstY, Bitmap, SrcW, SrcH);
161 tmp = SDL_CreateRGBSurfaceFrom(Bitmap, SrcW, SrcH, 32, SrcW*4,
162 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
163 SDL_SetAlpha(tmp, 0, SDL_ALPHA_OPAQUE);
165 dstRect.x = DstX; dstRect.y = DstY;
166 dstRect.w = -1; dstRect.h = -1;
168 SDL_BlitSurface(tmp, NULL, gScreen, &dstRect);
169 //SDL_BlitSurface(tmp, NULL, gScreen, NULL);
171 SDL_FreeSurface(tmp);
172 // SDL_Flip(gScreen);
175 void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H)
180 srcRect.x = SrcX; srcRect.y = SrcY;
181 srcRect.w = W; srcRect.h = H;
182 dstRect.x = DstX; dstRect.y = DstY;
184 SDL_BlitSurface(gScreen, &srcRect, gScreen, &dstRect);
187 void UI_FillBitmap(int X, int Y, int W, int H, Uint32 Value)
191 dstRect.x = X; dstRect.y = Y;
192 dstRect.w = W; dstRect.h = H;
194 // printf("UI_FillBitmap: gScreen = %p\n", gScreen);
195 SDL_FillRect(gScreen, &dstRect, Value);
200 // TODO: Keep track of changed rectangle
201 SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height);