test/testintersections.c
changeset 5297 1800dc39b74c
parent 5184 d976b67150c5
child 5535 96594ac5fd1a
     1.1 --- a/test/testintersections.c	Mon Feb 14 11:50:18 2011 -0600
     1.2 +++ b/test/testintersections.c	Tue Feb 15 13:59:59 2011 -0800
     1.3 @@ -20,14 +20,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 @@ -56,8 +56,8 @@
    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 @@ -84,23 +84,23 @@
    1.33  
    1.34  
    1.35  void
    1.36 -DrawLines(SDL_Window * window, SDL_Renderer * renderer)
    1.37 +DrawLines(SDL_Renderer * renderer)
    1.38  {
    1.39      int i;
    1.40      int x1, y1, x2, y2;
    1.41 -    int window_w, window_h;
    1.42 +    SDL_Rect viewport;
    1.43  
    1.44      /* Query the sizes */
    1.45 -    SDL_GetWindowSize(window, &window_w, &window_h);
    1.46 +    SDL_RenderGetViewport(renderer, &viewport);
    1.47 +
    1.48 +    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    1.49  
    1.50      for (i = 0; i < num_lines; ++i) {
    1.51 -        SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    1.52 -
    1.53          if (i == -1) {
    1.54 -            SDL_RenderDrawLine(renderer, 0, 0, window_w - 1, window_h - 1);
    1.55 -            SDL_RenderDrawLine(renderer, 0, window_h - 1, window_w - 1, 0);
    1.56 -            SDL_RenderDrawLine(renderer, 0, window_h / 2, window_w - 1, window_h / 2);
    1.57 -            SDL_RenderDrawLine(renderer, window_w / 2, 0, window_w / 2, window_h - 1);
    1.58 +            SDL_RenderDrawLine(renderer, 0, 0, viewport.w - 1, viewport.h - 1);
    1.59 +            SDL_RenderDrawLine(renderer, 0, viewport.h - 1, viewport.w - 1, 0);
    1.60 +            SDL_RenderDrawLine(renderer, 0, viewport.h / 2, viewport.w - 1, viewport.h / 2);
    1.61 +            SDL_RenderDrawLine(renderer, viewport.w / 2, 0, viewport.w / 2, viewport.h - 1);
    1.62          } else {
    1.63              SDL_RenderDrawLine(renderer, lines[i].x, lines[i].y, lines[i].w, lines[i].h);
    1.64          }
    1.65 @@ -135,27 +135,18 @@
    1.66  }
    1.67  
    1.68  static void
    1.69 -DrawRects(SDL_Window * window, SDL_Renderer * renderer)
    1.70 +DrawRects(SDL_Renderer * renderer)
    1.71  {
    1.72 -    int i;
    1.73 -    int window_w, window_h;
    1.74 -
    1.75 -    /* Query the sizes */
    1.76 -    SDL_GetWindowSize(window, &window_w, &window_h);
    1.77 -
    1.78 -    for (i = 0; i < num_rects; ++i) {
    1.79 -        SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
    1.80 -        SDL_RenderFillRect(renderer, &rects[i]);
    1.81 -    }
    1.82 +    SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
    1.83 +    SDL_RenderFillRects(renderer, rects, num_rects);
    1.84  }
    1.85  
    1.86  static void
    1.87 -DrawRectLineIntersections(SDL_Window * window, SDL_Renderer * renderer)
    1.88 +DrawRectLineIntersections(SDL_Renderer * renderer)
    1.89  {
    1.90 -    int i, j, window_w, window_h;
    1.91 +    int i, j;
    1.92  
    1.93 -    /* Query the sizes */
    1.94 -    SDL_GetWindowSize(window, &window_w, &window_h);
    1.95 +    SDL_SetRenderDrawColor(renderer, 0, 255, 55, 255);
    1.96  
    1.97      for (i = 0; i < num_rects; i++)
    1.98          for (j = 0; j < num_lines; j++) {
    1.99 @@ -169,22 +160,22 @@
   1.100              y2 = lines[j].h;
   1.101  
   1.102              if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
   1.103 -                SDL_SetRenderDrawColor(renderer, 0, 255, 55, 255);
   1.104                  SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
   1.105              }
   1.106          }
   1.107  }
   1.108  
   1.109  static void
   1.110 -DrawRectRectIntersections(SDL_Window * window, SDL_Renderer * renderer)
   1.111 +DrawRectRectIntersections(SDL_Renderer * renderer)
   1.112  {
   1.113      int i, j;
   1.114  
   1.115 +    SDL_SetRenderDrawColor(renderer, 255, 200, 0, 255);
   1.116 +
   1.117      for (i = 0; i < num_rects; i++)
   1.118          for (j = i + 1; j < num_rects; j++) {
   1.119              SDL_Rect r;
   1.120              if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
   1.121 -                SDL_SetRenderDrawColor(renderer, 255, 200, 0, 255);
   1.122                  SDL_RenderFillRect(renderer, &r);
   1.123              }
   1.124          }
   1.125 @@ -310,11 +301,11 @@
   1.126              SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
   1.127              SDL_RenderClear(renderer);
   1.128  
   1.129 -            DrawRects(state->windows[i], renderer);
   1.130 -            DrawPoints(state->windows[i], renderer);
   1.131 -            DrawRectRectIntersections(state->windows[i], renderer);
   1.132 -            DrawLines(state->windows[i], renderer);
   1.133 -            DrawRectLineIntersections(state->windows[i], renderer);
   1.134 +            DrawRects(renderer);
   1.135 +            DrawPoints(renderer);
   1.136 +            DrawRectRectIntersections(renderer);
   1.137 +            DrawLines(renderer);
   1.138 +            DrawRectLineIntersections(renderer);
   1.139  
   1.140              SDL_RenderPresent(renderer);
   1.141          }