indent
authorSam Lantinga <slouken@libsdl.org>
Sun, 04 Jan 2009 23:41:09 +0000
changeset 2997e4f025078c1c
parent 2996 972a69e47cd9
child 2998 d364ee9b9c15
indent
src/video/SDL_rect.c
src/video/x11/SDL_x11events.c
test/testintersections.c
     1.1 --- a/src/video/SDL_rect.c	Sun Jan 04 23:36:53 2009 +0000
     1.2 +++ b/src/video/SDL_rect.c	Sun Jan 04 23:41:09 2009 +0000
     1.3 @@ -184,23 +184,22 @@
     1.4          return SDL_TRUE;
     1.5      }
     1.6  
     1.7 -    else
     1.8 -    {
     1.9 -    /* The task of clipping a line with finite slope ratios in a fixed-
    1.10 -     * precision coordinate space is not as immediately simple as it is
    1.11 -     * with coordinates of arbitrary precision. If the ratio of slopes
    1.12 -     * between the input line segment and the result line segment is not
    1.13 -     * a whole number, you have in fact *moved* the line segment a bit,
    1.14 -     * and there can be no avoiding it without more precision
    1.15 -     */
    1.16 -        int *x_result_[] = {X1, X2, NULL}, **x_result = x_result_;
    1.17 -        int *y_result_[] = {Y1, Y2, NULL}, **y_result = y_result_;
    1.18 +    else {
    1.19 +        /* The task of clipping a line with finite slope ratios in a fixed-
    1.20 +         * precision coordinate space is not as immediately simple as it is
    1.21 +         * with coordinates of arbitrary precision. If the ratio of slopes
    1.22 +         * between the input line segment and the result line segment is not
    1.23 +         * a whole number, you have in fact *moved* the line segment a bit,
    1.24 +         * and there can be no avoiding it without more precision
    1.25 +         */
    1.26 +        int *x_result_[] = { X1, X2, NULL }, **x_result = x_result_;
    1.27 +        int *y_result_[] = { Y1, Y2, NULL }, **y_result = y_result_;
    1.28          SDL_bool intersection = SDL_FALSE;
    1.29          double b, m, left, right, bottom, top;
    1.30          int xl, xh, yl, yh;
    1.31  
    1.32          /* solve mx+b line formula */
    1.33 -        m = (double)(y1-y2) / (double)(x1-x2);
    1.34 +        m = (double) (y1 - y2) / (double) (x1 - x2);
    1.35          b = y2 - m * (double) x2;
    1.36  
    1.37          /* find some linear intersections */
    1.38 @@ -232,8 +231,8 @@
    1.39              x_result++;
    1.40              y_result++;
    1.41              intersection = SDL_TRUE;
    1.42 -        } else /* it was determined earlier that *both* end-points are not contained */
    1.43 -
    1.44 +        } else
    1.45 +            /* it was determined earlier that *both* end-points are not contained */
    1.46          if (RISING(rectx1, x2, rectx2) && RISING(recty1, y2, recty2)) {
    1.47              **(x_result++) = x2;
    1.48              **(y_result++) = y2;
    1.49 @@ -246,21 +245,24 @@
    1.50              intersection = SDL_TRUE;
    1.51          }
    1.52  
    1.53 -        if (*x_result == NULL) return intersection;
    1.54 +        if (*x_result == NULL)
    1.55 +            return intersection;
    1.56          if (RISING(recty1, right, recty2) && RISING(xl, rectx2, xh)) {
    1.57              **(x_result++) = rectx2;
    1.58              **(y_result++) = (int) right;
    1.59              intersection = SDL_TRUE;
    1.60          }
    1.61  
    1.62 -        if (*x_result == NULL) return intersection;
    1.63 +        if (*x_result == NULL)
    1.64 +            return intersection;
    1.65          if (RISING(rectx1, top, rectx2) && RISING(yl, recty1, yh)) {
    1.66              **(x_result++) = (int) top;
    1.67              **(y_result++) = recty1;
    1.68              intersection = SDL_TRUE;
    1.69          }
    1.70  
    1.71 -        if (*x_result == NULL) return intersection;
    1.72 +        if (*x_result == NULL)
    1.73 +            return intersection;
    1.74          if (RISING(rectx1, bottom, rectx2) && RISING(yl, recty2, yh)) {
    1.75              **(x_result++) = (int) bottom;
    1.76              **(y_result++) = recty2;
     2.1 --- a/src/video/x11/SDL_x11events.c	Sun Jan 04 23:36:53 2009 +0000
     2.2 +++ b/src/video/x11/SDL_x11events.c	Sun Jan 04 23:41:09 2009 +0000
     2.3 @@ -292,17 +292,21 @@
     2.4                      switch (xevent.type) {
     2.5                      case MotionNotify:
     2.6  #ifdef DEBUG_MOTION
     2.7 -                        printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
     2.8 +                        printf("X11 motion: %d,%d\n", xevent.xmotion.x,
     2.9 +                               xevent.xmotion.y);
    2.10  #endif
    2.11 -                        SDL_SendMouseMotion(mouse->id, 0, xevent.xmotion.x, xevent.xmotion.y, 0);
    2.12 +                        SDL_SendMouseMotion(mouse->id, 0, xevent.xmotion.x,
    2.13 +                                            xevent.xmotion.y, 0);
    2.14                          break;
    2.15  
    2.16                      case ButtonPress:
    2.17 -                        SDL_SendMouseButton(mouse->id, SDL_PRESSED, xevent.xbutton.button);
    2.18 +                        SDL_SendMouseButton(mouse->id, SDL_PRESSED,
    2.19 +                                            xevent.xbutton.button);
    2.20                          break;
    2.21  
    2.22                      case ButtonRelease:
    2.23 -                        SDL_SendMouseButton(mouse->id, SDL_RELEASED, xevent.xbutton.button);
    2.24 +                        SDL_SendMouseButton(mouse->id, SDL_RELEASED,
    2.25 +                                            xevent.xbutton.button);
    2.26                          break;
    2.27                      }
    2.28                      continue;
     3.1 --- a/test/testintersections.c	Sun Jan 04 23:36:53 2009 +0000
     3.2 +++ b/test/testintersections.c	Sun Jan 04 23:41:09 2009 +0000
     3.3 @@ -67,9 +67,13 @@
     3.4  #define MAX_LINES 16
     3.5  int num_lines = 0;
     3.6  SDL_Rect lines[MAX_LINES];
     3.7 -static int add_line(int x1, int y1, int x2, int y2) {
     3.8 -    if (num_lines >= MAX_LINES) return 0;
     3.9 -    if ((x1 == x2) && (y1 == y2)) return 0;
    3.10 +static int
    3.11 +add_line(int x1, int y1, int x2, int y2)
    3.12 +{
    3.13 +    if (num_lines >= MAX_LINES)
    3.14 +        return 0;
    3.15 +    if ((x1 == x2) && (y1 == y2))
    3.16 +        return 0;
    3.17  
    3.18      printf("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2);
    3.19      lines[num_lines].x = x1;
    3.20 @@ -110,14 +114,21 @@
    3.21  #define MAX_RECTS 16
    3.22  int num_rects = 0;
    3.23  SDL_Rect rects[MAX_RECTS];
    3.24 -static int add_rect(int x1, int y1, int x2, int y2) {
    3.25 -    if (num_rects >= MAX_RECTS) return 0;
    3.26 -    if ((x1 == x2) || (y1 == y2)) return 0;
    3.27 +static int
    3.28 +add_rect(int x1, int y1, int x2, int y2)
    3.29 +{
    3.30 +    if (num_rects >= MAX_RECTS)
    3.31 +        return 0;
    3.32 +    if ((x1 == x2) || (y1 == y2))
    3.33 +        return 0;
    3.34  
    3.35 -    if (x1 > x2) SWAP(int, x1, x2);
    3.36 -    if (y1 > y2) SWAP(int, y1, y2);
    3.37 +    if (x1 > x2)
    3.38 +        SWAP(int, x1, x2);
    3.39 +    if (y1 > y2)
    3.40 +        SWAP(int, y1, y2);
    3.41  
    3.42 -    printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, x2-x1, y2-y1);
    3.43 +    printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2,
    3.44 +           x2 - x1, y2 - y1);
    3.45  
    3.46      rects[num_rects].x = x1;
    3.47      rects[num_rects].y = y1;
    3.48 @@ -155,21 +166,21 @@
    3.49      SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
    3.50  
    3.51      for (i = 0; i < num_rects; i++)
    3.52 -    for (j = 0; j < num_lines; j++) {
    3.53 -        int x1, y1, x2, y2;
    3.54 -        SDL_Rect r;
    3.55 -        
    3.56 -        r = rects[i];
    3.57 -        x1 = lines[j].x;
    3.58 -        y1 = lines[j].y;
    3.59 -        x2 = lines[j].w;
    3.60 -        y2 = lines[j].h;
    3.61 +        for (j = 0; j < num_lines; j++) {
    3.62 +            int x1, y1, x2, y2;
    3.63 +            SDL_Rect r;
    3.64  
    3.65 -        if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
    3.66 -            SDL_SetRenderDrawColor(0, 255, 55, 255);
    3.67 -            SDL_RenderLine(x1, y1, x2, y2);
    3.68 +            r = rects[i];
    3.69 +            x1 = lines[j].x;
    3.70 +            y1 = lines[j].y;
    3.71 +            x2 = lines[j].w;
    3.72 +            y2 = lines[j].h;
    3.73 +
    3.74 +            if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
    3.75 +                SDL_SetRenderDrawColor(0, 255, 55, 255);
    3.76 +                SDL_RenderLine(x1, y1, x2, y2);
    3.77 +            }
    3.78          }
    3.79 -    }
    3.80  
    3.81      SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
    3.82  }
    3.83 @@ -182,13 +193,13 @@
    3.84      SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
    3.85  
    3.86      for (i = 0; i < num_rects; i++)
    3.87 -    for (j = i+1; j < num_rects; j++) {
    3.88 -        SDL_Rect r;
    3.89 -        if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
    3.90 -            SDL_SetRenderDrawColor(255, 200, 0, 255);
    3.91 -            SDL_RenderFill(&r);
    3.92 +        for (j = i + 1; j < num_rects; j++) {
    3.93 +            SDL_Rect r;
    3.94 +            if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
    3.95 +                SDL_SetRenderDrawColor(255, 200, 0, 255);
    3.96 +                SDL_RenderFill(&r);
    3.97 +            }
    3.98          }
    3.99 -    }
   3.100  
   3.101      SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
   3.102  }
   3.103 @@ -285,21 +296,29 @@
   3.104              case SDL_MOUSEBUTTONUP:
   3.105                  if (event.button.which == 0) {
   3.106                      if (event.button.button == 3)
   3.107 -                        add_line(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y);
   3.108 +                        add_line(mouse_begin_x, mouse_begin_y, event.button.x,
   3.109 +                                 event.button.y);
   3.110                      if (event.button.button == 1)
   3.111 -                        add_rect(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y);
   3.112 +                        add_rect(mouse_begin_x, mouse_begin_y, event.button.x,
   3.113 +                                 event.button.y);
   3.114                  }
   3.115                  break;
   3.116              case SDL_KEYDOWN:
   3.117                  switch (event.key.keysym.sym) {
   3.118 -                    case 'l':
   3.119 -                        if (event.key.keysym.mod & KMOD_SHIFT) num_lines = 0;
   3.120 -                        else add_line(rand()%640, rand()%480, rand()%640, rand()%480);
   3.121 -                        break;
   3.122 -                    case 'r':
   3.123 -                        if (event.key.keysym.mod & KMOD_SHIFT) num_rects = 0;
   3.124 -                        else add_rect(rand()%640, rand()%480, rand()%640, rand()%480);
   3.125 -                        break;
   3.126 +                case 'l':
   3.127 +                    if (event.key.keysym.mod & KMOD_SHIFT)
   3.128 +                        num_lines = 0;
   3.129 +                    else
   3.130 +                        add_line(rand() % 640, rand() % 480, rand() % 640,
   3.131 +                                 rand() % 480);
   3.132 +                    break;
   3.133 +                case 'r':
   3.134 +                    if (event.key.keysym.mod & KMOD_SHIFT)
   3.135 +                        num_rects = 0;
   3.136 +                    else
   3.137 +                        add_rect(rand() % 640, rand() % 480, rand() % 640,
   3.138 +                                 rand() % 480);
   3.139 +                    break;
   3.140                  }
   3.141                  break;
   3.142              case SDL_WINDOWEVENT: