| 2498 | } |
| 2499 | |
| 2500 | static int |
| 2501 | RenderDrawLinesWithRectsF(SDL_Renderer * renderer, |
| 2502 | const SDL_FPoint * points, const int count) |
| 2503 | { |
| 2504 | SDL_FRect *frect; |
| 2505 | SDL_FRect *frects; |
| 2506 | SDL_FPoint fpoints[2]; |
| 2507 | int i, nrects = 0; |
| 2508 | int retval = 0; |
| 2509 | SDL_bool isstack; |
| 2510 | |
| 2511 | frects = SDL_small_alloc(SDL_FRect, count-1, &isstack); |
| 2512 | if (!frects) { |
| 2513 | return SDL_OutOfMemory(); |
| 2514 | } |
| 2515 | |
| 2516 | for (i = 0; i < count-1; ++i) { |
| 2517 | if (points[i].x == points[i+1].x) { |
| 2518 | const int minY = (int)SDL_min(points[i].y, points[i+1].y); |
| 2519 | const int maxY = (int)SDL_max(points[i].y, points[i+1].y); |
| 2520 | |
| 2521 | frect = &frects[nrects++]; |
| 2522 | frect->x = points[i].x * renderer->scale.x; |
| 2523 | frect->y = minY * renderer->scale.y; |
| 2524 | frect->w = renderer->scale.x; |
| 2525 | frect->h = (maxY - minY + 1) * renderer->scale.y; |
| 2526 | } else if (points[i].y == points[i+1].y) { |
| 2527 | const int minX = (int)SDL_min(points[i].x, points[i+1].x); |
| 2528 | const int maxX = (int)SDL_max(points[i].x, points[i+1].x); |
| 2529 | |
| 2530 | frect = &frects[nrects++]; |
| 2531 | frect->x = minX * renderer->scale.x; |
| 2532 | frect->y = points[i].y * renderer->scale.y; |
| 2533 | frect->w = (maxX - minX + 1) * renderer->scale.x; |
| 2534 | frect->h = renderer->scale.y; |
| 2535 | } else { |
| 2536 | /* FIXME: We can't use a rect for this line... */ |
| 2537 | fpoints[0].x = points[i].x * renderer->scale.x; |
| 2538 | fpoints[0].y = points[i].y * renderer->scale.y; |
| 2539 | fpoints[1].x = points[i+1].x * renderer->scale.x; |
| 2540 | fpoints[1].y = points[i+1].y * renderer->scale.y; |
| 2541 | retval += QueueCmdDrawLines(renderer, fpoints, 2); |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | retval += QueueCmdFillRects(renderer, frects, nrects); |
| 2546 | |
| 2547 | SDL_small_free(frects, isstack); |
| 2548 | |
| 2549 | if (retval < 0) { |
| 2550 | retval = -1; |
| 2551 | } |
| 2552 | return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer); |
| 2553 | } |
| 2554 | |
| 2555 | int |
| 2556 | SDL_RenderDrawLines(SDL_Renderer * renderer, |
no test coverage detected