10 #include <api_drv_keyboard.h>
13 extern void AcessNative_Exit(void);
16 int UI_Initialise(int MaxWidth, int MaxHeight);
17 void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap);
18 void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H);
19 void UI_FillBitmap(int X, int Y, int W, int H, Uint32 Value);
24 SDL_Thread *gInputThread;
28 tUI_KeybardCallback gUI_KeyboardCallback;
29 Uint32 gUI_Keymap[2][SDLK_LAST]; // Upper/Lower case
32 int UI_Initialise(int MaxWidth, int MaxHeight)
34 // Changed when the video mode is set
35 giUI_Width = MaxWidth;
36 giUI_Height = MaxHeight;
39 SDL_Init(SDL_INIT_VIDEO);
40 printf("UI attempting %ix%i %ibpp\n", giUI_Width, giUI_Height, 32);
41 gScreen = SDL_SetVideoMode(giUI_Width, giUI_Height, 32, 0);
43 fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", giUI_Width, giUI_Height, SDL_GetError());
47 SDL_WM_SetCaption("Acess2", "Acess2");
49 giUI_Width = gScreen->w;
50 giUI_Height = gScreen->h;
51 giUI_Pitch = gScreen->pitch;
53 printf("UI window %ix%i %i bytes per line\n", giUI_Width, giUI_Height, giUI_Pitch);
60 Uint32 UI_GetAcessKeyFromSDL(SDLKey Sym, Uint16 Unicode)
62 Uint8 *keystate = SDL_GetKeyState(NULL);
66 if( keystate[SDLK_RSHIFT] || keystate[SDLK_LSHIFT] )
70 if( gUI_Keymap[shiftState][Sym] )
71 return gUI_Keymap[shiftState][Sym];
73 // Enter key on acess returns \n, but SDL returns \r
74 if( Sym == SDLK_RETURN )
77 // How nice of you, a unicode value
82 // Ok, we need to do work :(
87 case SDLK_UP: ret = KEY_UP; break;
88 case SDLK_DOWN: ret = KEY_DOWN; break;
89 case SDLK_LEFT: ret = KEY_LEFT; break;
90 case SDLK_RIGHT:ret = KEY_RIGHT;break;
91 case SDLK_CAPSLOCK: ret = KEY_CAPSLOCK; break;
92 case SDLK_F1: ret = KEY_F1; break;
93 case SDLK_F2: ret = KEY_F2; break;
94 case SDLK_F3: ret = KEY_F3; break;
95 case SDLK_F4: ret = KEY_F4; break;
96 case SDLK_F5: ret = KEY_F5; break;
97 case SDLK_F6: ret = KEY_F6; break;
98 case SDLK_F7: ret = KEY_F7; break;
99 case SDLK_F8: ret = KEY_F8; break;
100 case SDLK_F9: ret = KEY_F9; break;
101 case SDLK_F10: ret = KEY_F10; break;
102 case SDLK_F11: ret = KEY_F11; break;
103 case SDLK_F12: ret = KEY_F12; break;
104 case SDLK_RETURN: ret = '\n'; break;
106 printf("Unhandled key code %i\n", Sym);
111 gUI_Keymap[shiftState][Sym] = ret;
115 void UI_MainLoop(void)
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(KEY_ACTION_RAWSYM|event.key.keysym.sym);
136 gUI_KeyboardCallback(KEY_ACTION_PRESS|acess_sym);
141 acess_sym = UI_GetAcessKeyFromSDL(event.key.keysym.sym,
142 event.key.keysym.unicode);
144 if( gUI_KeyboardCallback ) {
145 gUI_KeyboardCallback(KEY_ACTION_RAWSYM|event.key.keysym.sym);
146 gUI_KeyboardCallback(KEY_ACTION_RELEASE|acess_sym);
157 void UI_BlitBitmap(int DstX, int DstY, int SrcW, int SrcH, Uint32 *Bitmap)
162 // printf("UI_BlitBitmap: Blit to (%i,%i) from %p (%ix%i 32bpp bitmap)\n",
163 // DstX, DstY, Bitmap, SrcW, SrcH);
165 tmp = SDL_CreateRGBSurfaceFrom(Bitmap, SrcW, SrcH, 32, SrcW*4,
166 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000);
167 SDL_SetAlpha(tmp, 0, SDL_ALPHA_OPAQUE);
169 dstRect.x = DstX; dstRect.y = DstY;
170 dstRect.w = -1; dstRect.h = -1;
172 SDL_BlitSurface(tmp, NULL, gScreen, &dstRect);
173 //SDL_BlitSurface(tmp, NULL, gScreen, NULL);
175 SDL_FreeSurface(tmp);
176 // SDL_Flip(gScreen);
179 void UI_BlitFramebuffer(int DstX, int DstY, int SrcX, int SrcY, int W, int H)
184 srcRect.x = SrcX; srcRect.y = SrcY;
185 srcRect.w = W; srcRect.h = H;
186 dstRect.x = DstX; dstRect.y = DstY;
188 SDL_BlitSurface(gScreen, &srcRect, gScreen, &dstRect);
191 void UI_FillBitmap(int X, int Y, int W, int H, Uint32 Value)
195 dstRect.x = X; dstRect.y = Y;
196 dstRect.w = W; dstRect.h = H;
198 // printf("UI_FillBitmap: gScreen = %p\n", gScreen);
199 SDL_FillRect(gScreen, &dstRect, Value);
204 // TODO: Keep track of changed rectangle
205 SDL_UpdateRect(gScreen, 0, 0, giUI_Width, giUI_Height);