test/testdraw2.c
changeset 5297 1800dc39b74c
parent 5184 d976b67150c5
child 5535 96594ac5fd1a
     1.1 --- a/test/testdraw2.c	Mon Feb 14 11:50:18 2011 -0600
     1.2 +++ b/test/testdraw2.c	Tue Feb 15 13:59:59 2011 -0800
     1.3 @@ -19,14 +19,14 @@
     1.4  static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
     1.5  
     1.6  void
     1.7 -DrawPoints(SDL_Window * window, SDL_Renderer * renderer)
     1.8 +DrawPoints(SDL_Renderer * renderer)
     1.9  {
    1.10      int i;
    1.11      int x, y;
    1.12 -    int window_w, window_h;
    1.13 +    SDL_Rect viewport;
    1.14  
    1.15      /* Query the sizes */
    1.16 -    SDL_GetWindowSize(window, &window_w, &window_h);
    1.17 +    SDL_RenderGetViewport(renderer, &viewport);
    1.18  
    1.19      for (i = 0; i < num_objects * 4; ++i) {
    1.20          /* Cycle the color and alpha, if desired */
    1.21 @@ -55,21 +55,21 @@
    1.22          SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
    1.23                                 (Uint8) current_color, (Uint8) current_alpha);
    1.24  
    1.25 -        x = rand() % window_w;
    1.26 -        y = rand() % window_h;
    1.27 +        x = rand() % viewport.w;
    1.28 +        y = rand() % viewport.h;
    1.29          SDL_RenderDrawPoint(renderer, x, y);
    1.30      }
    1.31  }
    1.32  
    1.33  void
    1.34 -DrawLines(SDL_Window * window, SDL_Renderer * renderer)
    1.35 +DrawLines(SDL_Renderer * renderer)
    1.36  {
    1.37      int i;
    1.38      int x1, y1, x2, y2;
    1.39 -    int window_w, window_h;
    1.40 +    SDL_Rect viewport;
    1.41  
    1.42      /* Query the sizes */
    1.43 -    SDL_GetWindowSize(window, &window_w, &window_h);
    1.44 +    SDL_RenderGetViewport(renderer, &viewport);
    1.45  
    1.46      for (i = 0; i < num_objects; ++i) {
    1.47          /* Cycle the color and alpha, if desired */
    1.48 @@ -99,29 +99,29 @@
    1.49                                 (Uint8) current_color, (Uint8) current_alpha);
    1.50  
    1.51          if (i == 0) {
    1.52 -            SDL_RenderDrawLine(renderer, 0, 0, window_w - 1, window_h - 1);
    1.53 -            SDL_RenderDrawLine(renderer, 0, window_h - 1, window_w - 1, 0);
    1.54 -            SDL_RenderDrawLine(renderer, 0, window_h / 2, window_w - 1, window_h / 2);
    1.55 -            SDL_RenderDrawLine(renderer, window_w / 2, 0, window_w / 2, window_h - 1);
    1.56 +            SDL_RenderDrawLine(renderer, 0, 0, viewport.w - 1, viewport.h - 1);
    1.57 +            SDL_RenderDrawLine(renderer, 0, viewport.h - 1, viewport.w - 1, 0);
    1.58 +            SDL_RenderDrawLine(renderer, 0, viewport.h / 2, viewport.w - 1, viewport.h / 2);
    1.59 +            SDL_RenderDrawLine(renderer, viewport.w / 2, 0, viewport.w / 2, viewport.h - 1);
    1.60          } else {
    1.61 -            x1 = (rand() % (window_w*2)) - window_w;
    1.62 -            x2 = (rand() % (window_w*2)) - window_w;
    1.63 -            y1 = (rand() % (window_h*2)) - window_h;
    1.64 -            y2 = (rand() % (window_h*2)) - window_h;
    1.65 +            x1 = (rand() % (viewport.w*2)) - viewport.w;
    1.66 +            x2 = (rand() % (viewport.w*2)) - viewport.w;
    1.67 +            y1 = (rand() % (viewport.h*2)) - viewport.h;
    1.68 +            y2 = (rand() % (viewport.h*2)) - viewport.h;
    1.69              SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
    1.70          }
    1.71      }
    1.72  }
    1.73  
    1.74  void
    1.75 -DrawRects(SDL_Window * window, SDL_Renderer * renderer)
    1.76 +DrawRects(SDL_Renderer * renderer)
    1.77  {
    1.78      int i;
    1.79      SDL_Rect rect;
    1.80 -    int window_w, window_h;
    1.81 +    SDL_Rect viewport;
    1.82  
    1.83      /* Query the sizes */
    1.84 -    SDL_GetWindowSize(window, &window_w, &window_h);
    1.85 +    SDL_RenderGetViewport(renderer, &viewport);
    1.86  
    1.87      for (i = 0; i < num_objects / 4; ++i) {
    1.88          /* Cycle the color and alpha, if desired */
    1.89 @@ -150,10 +150,10 @@
    1.90          SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
    1.91                                 (Uint8) current_color, (Uint8) current_alpha);
    1.92  
    1.93 -        rect.w = rand() % (window_h / 2);
    1.94 -        rect.h = rand() % (window_h / 2);
    1.95 -        rect.x = (rand() % (window_w*2) - window_w) - (rect.w / 2);
    1.96 -        rect.y = (rand() % (window_h*2) - window_h) - (rect.h / 2);
    1.97 +        rect.w = rand() % (viewport.h / 2);
    1.98 +        rect.h = rand() % (viewport.h / 2);
    1.99 +        rect.x = (rand() % (viewport.w*2) - viewport.w) - (rect.w / 2);
   1.100 +        rect.y = (rand() % (viewport.h*2) - viewport.h) - (rect.h / 2);
   1.101          SDL_RenderFillRect(renderer, &rect);
   1.102      }
   1.103  }
   1.104 @@ -243,9 +243,9 @@
   1.105              SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   1.106              SDL_RenderClear(renderer);
   1.107  
   1.108 -            DrawRects(state->windows[i], renderer);
   1.109 -            DrawLines(state->windows[i], renderer);
   1.110 -            DrawPoints(state->windows[i], renderer);
   1.111 +            DrawRects(renderer);
   1.112 +            DrawLines(renderer);
   1.113 +            DrawPoints(renderer);
   1.114  
   1.115              SDL_RenderPresent(renderer);
   1.116          }