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 // Enter key on acess returns \n, but SDL returns \r
62 if( Sym == SDLK_RETURN )
65 // How nice of you, a unicode value
70 // Ok, we need to do work :(
75 case SDLK_UP: ret = KEY_UP; break;
76 case SDLK_DOWN: ret = KEY_DOWN; break;
77 case SDLK_LEFT: ret = KEY_LEFT; break;
78 case SDLK_RIGHT:ret = KEY_RIGHT;break;
79 case SDLK_CAPSLOCK: ret = KEY_CAPSLOCK; break;
80 case SDLK_F1: ret = KEY_F1; break;
81 case SDLK_F2: ret = KEY_F2; break;
82 case SDLK_F3: ret = KEY_F3; break;
83 case SDLK_F4: ret = KEY_F4; break;
84 case SDLK_F5: ret = KEY_F5; break;
85 case SDLK_F6: ret = KEY_F6; break;
86 case SDLK_F7: ret = KEY_F7; break;
87 case SDLK_F8: ret = KEY_F8; break;
88 case SDLK_F9: ret = KEY_F9; break;
89 case SDLK_F10: ret = KEY_F10; break;
90 case SDLK_F11: ret = KEY_F11; break;
91 case SDLK_F12: ret = KEY_F12; break;
92 case SDLK_RETURN: ret = '\n'; break;
94 printf("Unhandled key code %i\n", Sym);
99 gUI_Keymap[shiftState][Sym] = ret;
103 int UI_MainThread(void *Unused)
108 SDL_Init(SDL_INIT_VIDEO);
111 gScreen = SDL_SetVideoMode(giUI_Width, giUI_Height, 32, 0);
113 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", giUI_Width, giUI_Height, SDL_GetError());
117 SDL_WM_SetCaption("Acess2", "Acess2");
119 giUI_Width = gScreen->w;
120 giUI_Height = gScreen->h;
121 giUI_Pitch = gScreen->pitch;
123 SDL_EnableUNICODE(1);
127 while(SDL_PollEvent(&event))
136 acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
137 event.key.keysym.unicode);
139 if( gUI_KeyboardCallback )
140 gUI_KeyboardCallback(acess_sym);
144 acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
145 event.key.keysym.unicode);
147 if( gUI_KeyboardCallback )
148 gUI_KeyboardCallback(0x80000000|acess_sym);
158 void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap)
163 // printf("UI_BlitBitmap: Blit to (%i,%i) from %p (%ix%i 32bpp bitmap)\n",
164 // DstX, DstY, Bitmap, SrcW, SrcH);
166 tmp = SDL_CreateRGBSurfaceFrom(Bitmap, SrcW, SrcH, 32, SrcW*4,
167 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
168 SDL_SetAlpha(tmp, 0, SDL_ALPHA_OPAQUE);
170 dstRect.x = DstX; dstRect.y = DstY;
171 dstRect.w = -1; dstRect.h = -1;
173 SDL_BlitSurface(tmp, NULL, gScreen, &dstRect);
174 //SDL_BlitSurface(tmp, NULL, gScreen, NULL);
176 SDL_FreeSurface(tmp);
177 // SDL_Flip(gScreen);
180 void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H)
185 srcRect.x = SrcX; srcRect.y = SrcY;
186 srcRect.w = W; srcRect.h = H;
187 dstRect.x = DstX; dstRect.y = DstY;
189 SDL_BlitSurface(gScreen, &srcRect, gScreen, &dstRect);
192 void UI_FillBitmap(int X, int Y, int W, int H, Uint32 Value)
196 dstRect.x = X; dstRect.y = Y;
197 dstRect.w = W; dstRect.h = H;
199 // printf("UI_FillBitmap: gScreen = %p\n", gScreen);
200 SDL_FillRect(gScreen, &dstRect, Value);
205 // TODO: Keep track of changed rectangle
206 SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height);