Xcode-iOS/Demos/src/keyboard.c
changeset 10370 d90965a3b100
parent 10127 42e35c82335d
child 11306 45fbdef6a227
     1.1 --- a/Xcode-iOS/Demos/src/keyboard.c	Sun Sep 25 00:21:12 2016 -0300
     1.2 +++ b/Xcode-iOS/Demos/src/keyboard.c	Sun Sep 25 00:23:35 2016 -0300
     1.3 @@ -132,10 +132,13 @@
     1.4  void
     1.5  getPositionForCharNumber(int n, int *x, int *y)
     1.6  {
     1.7 +    int renderW, renderH;
     1.8 +    SDL_RenderGetLogicalSize(renderer, &renderW, &renderH);
     1.9 +
    1.10      int x_padding = 16;         /* padding space on left and right side of screen */
    1.11      int y_padding = 32;         /* padding space at top of screen */
    1.12      /* figure out the number of characters that can fit horizontally across the screen */
    1.13 -    int max_x_chars = (SCREEN_WIDTH - 2 * x_padding) / GLYPH_SIZE_SCREEN;
    1.14 +    int max_x_chars = (renderW - 2 * x_padding) / GLYPH_SIZE_SCREEN;
    1.15      int line_separation = 5;    /* pixels between each line */
    1.16      *x = (n % max_x_chars) * GLYPH_SIZE_SCREEN + x_padding;
    1.17      *y = (n / max_x_chars) * (GLYPH_SIZE_SCREEN + line_separation) +
    1.18 @@ -228,21 +231,25 @@
    1.19  int
    1.20  main(int argc, char *argv[])
    1.21  {
    1.22 -
    1.23      int index;                  /* index of last key we pushed in the bitmap font */
    1.24      SDL_Window *window;
    1.25      SDL_Event event;            /* last event received */
    1.26      SDL_Keymod mod;             /* key modifiers of last key we pushed */
    1.27      SDL_Scancode scancode;      /* scancode of last key we pushed */
    1.28 +    int width;
    1.29 +    int height;
    1.30  
    1.31      if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    1.32          printf("Error initializing SDL: %s", SDL_GetError());
    1.33      }
    1.34      /* create window */
    1.35 -    window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
    1.36 +    window = SDL_CreateWindow("iPhone keyboard test", 0, 0, 320, 480, SDL_WINDOW_ALLOW_HIGHDPI);
    1.37      /* create renderer */
    1.38      renderer = SDL_CreateRenderer(window, -1, 0);
    1.39  
    1.40 +    SDL_GetWindowSize(window, &width, &height);
    1.41 +    SDL_RenderSetLogicalSize(renderer, width, height);
    1.42 +
    1.43      /* load up our font */
    1.44      loadFont();
    1.45