Commit ba8f64f2 authored by Sam Lantinga's avatar Sam Lantinga

indent

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403459
parent dade1f12
...@@ -184,8 +184,7 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, ...@@ -184,8 +184,7 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2,
return SDL_TRUE; return SDL_TRUE;
} }
else else {
{
/* The task of clipping a line with finite slope ratios in a fixed- /* The task of clipping a line with finite slope ratios in a fixed-
* precision coordinate space is not as immediately simple as it is * precision coordinate space is not as immediately simple as it is
* with coordinates of arbitrary precision. If the ratio of slopes * with coordinates of arbitrary precision. If the ratio of slopes
...@@ -193,14 +192,14 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, ...@@ -193,14 +192,14 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2,
* a whole number, you have in fact *moved* the line segment a bit, * a whole number, you have in fact *moved* the line segment a bit,
* and there can be no avoiding it without more precision * and there can be no avoiding it without more precision
*/ */
int *x_result_[] = {X1, X2, NULL}, **x_result = x_result_; int *x_result_[] = { X1, X2, NULL }, **x_result = x_result_;
int *y_result_[] = {Y1, Y2, NULL}, **y_result = y_result_; int *y_result_[] = { Y1, Y2, NULL }, **y_result = y_result_;
SDL_bool intersection = SDL_FALSE; SDL_bool intersection = SDL_FALSE;
double b, m, left, right, bottom, top; double b, m, left, right, bottom, top;
int xl, xh, yl, yh; int xl, xh, yl, yh;
/* solve mx+b line formula */ /* solve mx+b line formula */
m = (double)(y1-y2) / (double)(x1-x2); m = (double) (y1 - y2) / (double) (x1 - x2);
b = y2 - m * (double) x2; b = y2 - m * (double) x2;
/* find some linear intersections */ /* find some linear intersections */
...@@ -232,8 +231,8 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, ...@@ -232,8 +231,8 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2,
x_result++; x_result++;
y_result++; y_result++;
intersection = SDL_TRUE; intersection = SDL_TRUE;
} else /* it was determined earlier that *both* end-points are not contained */ } else
/* it was determined earlier that *both* end-points are not contained */
if (RISING(rectx1, x2, rectx2) && RISING(recty1, y2, recty2)) { if (RISING(rectx1, x2, rectx2) && RISING(recty1, y2, recty2)) {
**(x_result++) = x2; **(x_result++) = x2;
**(y_result++) = y2; **(y_result++) = y2;
...@@ -246,21 +245,24 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, ...@@ -246,21 +245,24 @@ SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2,
intersection = SDL_TRUE; intersection = SDL_TRUE;
} }
if (*x_result == NULL) return intersection; if (*x_result == NULL)
return intersection;
if (RISING(recty1, right, recty2) && RISING(xl, rectx2, xh)) { if (RISING(recty1, right, recty2) && RISING(xl, rectx2, xh)) {
**(x_result++) = rectx2; **(x_result++) = rectx2;
**(y_result++) = (int) right; **(y_result++) = (int) right;
intersection = SDL_TRUE; intersection = SDL_TRUE;
} }
if (*x_result == NULL) return intersection; if (*x_result == NULL)
return intersection;
if (RISING(rectx1, top, rectx2) && RISING(yl, recty1, yh)) { if (RISING(rectx1, top, rectx2) && RISING(yl, recty1, yh)) {
**(x_result++) = (int) top; **(x_result++) = (int) top;
**(y_result++) = recty1; **(y_result++) = recty1;
intersection = SDL_TRUE; intersection = SDL_TRUE;
} }
if (*x_result == NULL) return intersection; if (*x_result == NULL)
return intersection;
if (RISING(rectx1, bottom, rectx2) && RISING(yl, recty2, yh)) { if (RISING(rectx1, bottom, rectx2) && RISING(yl, recty2, yh)) {
**(x_result++) = (int) bottom; **(x_result++) = (int) bottom;
**(y_result++) = recty2; **(y_result++) = recty2;
......
...@@ -292,17 +292,21 @@ X11_DispatchEvent(_THIS) ...@@ -292,17 +292,21 @@ X11_DispatchEvent(_THIS)
switch (xevent.type) { switch (xevent.type) {
case MotionNotify: case MotionNotify:
#ifdef DEBUG_MOTION #ifdef DEBUG_MOTION
printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); printf("X11 motion: %d,%d\n", xevent.xmotion.x,
xevent.xmotion.y);
#endif #endif
SDL_SendMouseMotion(mouse->id, 0, xevent.xmotion.x, xevent.xmotion.y, 0); SDL_SendMouseMotion(mouse->id, 0, xevent.xmotion.x,
xevent.xmotion.y, 0);
break; break;
case ButtonPress: case ButtonPress:
SDL_SendMouseButton(mouse->id, SDL_PRESSED, xevent.xbutton.button); SDL_SendMouseButton(mouse->id, SDL_PRESSED,
xevent.xbutton.button);
break; break;
case ButtonRelease: case ButtonRelease:
SDL_SendMouseButton(mouse->id, SDL_RELEASED, xevent.xbutton.button); SDL_SendMouseButton(mouse->id, SDL_RELEASED,
xevent.xbutton.button);
break; break;
} }
continue; continue;
......
...@@ -67,9 +67,13 @@ DrawPoints(SDL_WindowID window) ...@@ -67,9 +67,13 @@ DrawPoints(SDL_WindowID window)
#define MAX_LINES 16 #define MAX_LINES 16
int num_lines = 0; int num_lines = 0;
SDL_Rect lines[MAX_LINES]; SDL_Rect lines[MAX_LINES];
static int add_line(int x1, int y1, int x2, int y2) { static int
if (num_lines >= MAX_LINES) return 0; add_line(int x1, int y1, int x2, int y2)
if ((x1 == x2) && (y1 == y2)) return 0; {
if (num_lines >= MAX_LINES)
return 0;
if ((x1 == x2) && (y1 == y2))
return 0;
printf("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2); printf("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2);
lines[num_lines].x = x1; lines[num_lines].x = x1;
...@@ -110,14 +114,21 @@ DrawLines(SDL_WindowID window) ...@@ -110,14 +114,21 @@ DrawLines(SDL_WindowID window)
#define MAX_RECTS 16 #define MAX_RECTS 16
int num_rects = 0; int num_rects = 0;
SDL_Rect rects[MAX_RECTS]; SDL_Rect rects[MAX_RECTS];
static int add_rect(int x1, int y1, int x2, int y2) { static int
if (num_rects >= MAX_RECTS) return 0; add_rect(int x1, int y1, int x2, int y2)
if ((x1 == x2) || (y1 == y2)) return 0; {
if (num_rects >= MAX_RECTS)
return 0;
if ((x1 == x2) || (y1 == y2))
return 0;
if (x1 > x2) SWAP(int, x1, x2); if (x1 > x2)
if (y1 > y2) SWAP(int, y1, y2); SWAP(int, x1, x2);
if (y1 > y2)
SWAP(int, y1, y2);
printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2, x2-x1, y2-y1); printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2,
x2 - x1, y2 - y1);
rects[num_rects].x = x1; rects[num_rects].x = x1;
rects[num_rects].y = y1; rects[num_rects].y = y1;
...@@ -182,7 +193,7 @@ DrawRectRectIntersections(SDL_WindowID window) ...@@ -182,7 +193,7 @@ DrawRectRectIntersections(SDL_WindowID window)
SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE);
for (i = 0; i < num_rects; i++) for (i = 0; i < num_rects; i++)
for (j = i+1; j < num_rects; j++) { for (j = i + 1; j < num_rects; j++) {
SDL_Rect r; SDL_Rect r;
if (SDL_IntersectRect(&rects[i], &rects[j], &r)) { if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
SDL_SetRenderDrawColor(255, 200, 0, 255); SDL_SetRenderDrawColor(255, 200, 0, 255);
...@@ -285,20 +296,28 @@ main(int argc, char *argv[]) ...@@ -285,20 +296,28 @@ main(int argc, char *argv[])
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (event.button.which == 0) { if (event.button.which == 0) {
if (event.button.button == 3) if (event.button.button == 3)
add_line(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y); add_line(mouse_begin_x, mouse_begin_y, event.button.x,
event.button.y);
if (event.button.button == 1) if (event.button.button == 1)
add_rect(mouse_begin_x, mouse_begin_y, event.button.x, event.button.y); add_rect(mouse_begin_x, mouse_begin_y, event.button.x,
event.button.y);
} }
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch (event.key.keysym.sym) { switch (event.key.keysym.sym) {
case 'l': case 'l':
if (event.key.keysym.mod & KMOD_SHIFT) num_lines = 0; if (event.key.keysym.mod & KMOD_SHIFT)
else add_line(rand()%640, rand()%480, rand()%640, rand()%480); num_lines = 0;
else
add_line(rand() % 640, rand() % 480, rand() % 640,
rand() % 480);
break; break;
case 'r': case 'r':
if (event.key.keysym.mod & KMOD_SHIFT) num_rects = 0; if (event.key.keysym.mod & KMOD_SHIFT)
else add_rect(rand()%640, rand()%480, rand()%640, rand()%480); num_rects = 0;
else
add_rect(rand() % 640, rand() % 480, rand() % 640,
rand() % 480);
break; break;
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment