Xcode-iOS/Demos/src/keyboard.c
changeset 11307 003462e40c4f
parent 11306 45fbdef6a227
child 11498 d4f87399777f
equal deleted inserted replaced
11306:45fbdef6a227 11307:003462e40c4f
   155 
   155 
   156 /* this function loads our font into an SDL_Texture and returns the SDL_Texture  */
   156 /* this function loads our font into an SDL_Texture and returns the SDL_Texture  */
   157 SDL_Texture*
   157 SDL_Texture*
   158 loadFont(void)
   158 loadFont(void)
   159 {
   159 {
   160 
       
   161     SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp");
   160     SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp");
   162 
   161 
   163     if (!surface) {
   162     if (!surface) {
   164         printf("Error loading bitmap: %s\n", SDL_GetError());
   163         printf("Error loading bitmap: %s\n", SDL_GetError());
   165         return 0;
   164         return 0;
   206 }
   205 }
   207 
   206 
   208 int
   207 int
   209 main(int argc, char *argv[])
   208 main(int argc, char *argv[])
   210 {
   209 {
   211     int index;                  /* index of last key we pushed in the bitmap font */
       
   212     SDL_Window *window;
   210     SDL_Window *window;
   213     SDL_Event event;            /* last event received */
   211     SDL_Event event;            /* last event received */
   214     SDL_Scancode scancode;      /* scancode of last key we pushed */
   212     SDL_Scancode scancode;      /* scancode of last key we pushed */
   215     int width;
   213     int width;
   216     int height;
   214     int height;
       
   215     int done;
   217 
   216 
   218     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   217     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   219         printf("Error initializing SDL: %s", SDL_GetError());
   218         printf("Error initializing SDL: %s", SDL_GetError());
   220     }
   219     }
   221     /* create window */
   220     /* create window */
   222     window = SDL_CreateWindow("iPhone keyboard test", 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
   221     window = SDL_CreateWindow("iOS keyboard test", 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
   223     /* create renderer */
   222     /* create renderer */
   224     renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
   223     renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC);
   225 
   224 
   226     SDL_GetWindowSize(window, &width, &height);
   225     SDL_GetWindowSize(window, &width, &height);
   227     SDL_RenderSetLogicalSize(renderer, width, height);
   226     SDL_RenderSetLogicalSize(renderer, width, height);
   228 
   227 
   229     /* load up our font */
   228     /* load up our font */
   230     loadFont();
   229     loadFont();
   231 
   230 
   232     int done = 0;
   231     done = 0;
   233 
       
   234     while (!done) {
   232     while (!done) {
   235         while (SDL_PollEvent(&event)) {
   233         while (SDL_PollEvent(&event)) {
   236             switch (event.type) {
   234             switch (event.type) {
   237             case SDL_QUIT:
   235             case SDL_QUIT:
   238                 done = 1;
   236                 done = 1;
   239                 break;
       
   240             case SDL_TEXTINPUT:
       
   241                 break;
   237                 break;
   242             case SDL_KEYDOWN:
   238             case SDL_KEYDOWN:
   243                 if (event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE) {
   239                 if (event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE) {
   244                     if (numChars > 0) {
   240                     if (numChars > 0) {
   245                         numChars--;
   241                         numChars--;
   267     }
   263     }
   268 
   264 
   269     SDL_DestroyTexture(texture);
   265     SDL_DestroyTexture(texture);
   270     SDL_DestroyRenderer(renderer);
   266     SDL_DestroyRenderer(renderer);
   271     SDL_DestroyWindow(window);
   267     SDL_DestroyWindow(window);
       
   268     SDL_Quit();
   272     return 0;
   269     return 0;
   273 }
   270 }