Xcode-iOS/Demos/src/keyboard.c
changeset 10370 d90965a3b100
parent 10127 42e35c82335d
child 11306 45fbdef6a227
equal deleted inserted replaced
10369:001cbf1fda90 10370:d90965a3b100
   130     It is used for positioning each character of text
   130     It is used for positioning each character of text
   131 */
   131 */
   132 void
   132 void
   133 getPositionForCharNumber(int n, int *x, int *y)
   133 getPositionForCharNumber(int n, int *x, int *y)
   134 {
   134 {
       
   135     int renderW, renderH;
       
   136     SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);
       
   137 
   135     int x_padding = 16;         /* padding space on left and right side of screen */
   138     int x_padding = 16;         /* padding space on left and right side of screen */
   136     int y_padding = 32;         /* padding space at top of screen */
   139     int y_padding = 32;         /* padding space at top of screen */
   137     /* figure out the number of characters that can fit horizontally across the screen */
   140     /* figure out the number of characters that can fit horizontally across the screen */
   138     int max_x_chars = (SCREEN_WIDTH - 2 * x_padding) / GLYPH_SIZE_SCREEN;
   141     int max_x_chars = (renderW - 2 * x_padding) / GLYPH_SIZE_SCREEN;
   139     int line_separation = 5;    /* pixels between each line */
   142     int line_separation = 5;    /* pixels between each line */
   140     *x = (n % max_x_chars) * GLYPH_SIZE_SCREEN + x_padding;
   143     *x = (n % max_x_chars) * GLYPH_SIZE_SCREEN + x_padding;
   141     *y = (n / max_x_chars) * (GLYPH_SIZE_SCREEN + line_separation) +
   144     *y = (n / max_x_chars) * (GLYPH_SIZE_SCREEN + line_separation) +
   142         y_padding;
   145         y_padding;
   143 }
   146 }
   226 }
   229 }
   227 
   230 
   228 int
   231 int
   229 main(int argc, char *argv[])
   232 main(int argc, char *argv[])
   230 {
   233 {
   231 
       
   232     int index;                  /* index of last key we pushed in the bitmap font */
   234     int index;                  /* index of last key we pushed in the bitmap font */
   233     SDL_Window *window;
   235     SDL_Window *window;
   234     SDL_Event event;            /* last event received */
   236     SDL_Event event;            /* last event received */
   235     SDL_Keymod mod;             /* key modifiers of last key we pushed */
   237     SDL_Keymod mod;             /* key modifiers of last key we pushed */
   236     SDL_Scancode scancode;      /* scancode of last key we pushed */
   238     SDL_Scancode scancode;      /* scancode of last key we pushed */
       
   239     int width;
       
   240     int height;
   237 
   241 
   238     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   242     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   239         printf("Error initializing SDL: %s", SDL_GetError());
   243         printf("Error initializing SDL: %s", SDL_GetError());
   240     }
   244     }
   241     /* create window */
   245     /* create window */
   242     window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
   246     window = SDL_CreateWindow("iPhone keyboard test", 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
   243     /* create renderer */
   247     /* create renderer */
   244     renderer = SDL_CreateRenderer(window, -1, 0);
   248     renderer = SDL_CreateRenderer(window, -1, 0);
       
   249 
       
   250     SDL_GetWindowSize(window, &width, &height);
       
   251     SDL_RenderSetLogicalSize(renderer, width, height);
   245 
   252 
   246     /* load up our font */
   253     /* load up our font */
   247     loadFont();
   254     loadFont();
   248 
   255 
   249     /* draw the background, we'll just paint over it */
   256     /* draw the background, we'll just paint over it */