Mercurial > sdl-ios-xcode
comparison src/video/SDL_video.c @ 3536:0267b8b1595c
Added interfaces for batch drawing of points, lines and rects:
SDL_DrawPoints()
SDL_BlendPoints()
SDL_BlendLines()
SDL_DrawLines()
SDL_FillRects()
SDL_BlendRects()
SDL_RenderPoints()
SDL_RenderLines()
SDL_RenderRects()
Renamed SDL_RenderFill() to SDL_RenderRect()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 09 Dec 2009 15:56:56 +0000 |
parents | 59ff7a2beb57 |
children | 3ad09fdbfcb0 |
comparison
equal
deleted
inserted
replaced
3535:b403f790df65 | 3536:0267b8b1595c |
---|---|
2483 } | 2483 } |
2484 | 2484 |
2485 int | 2485 int |
2486 SDL_RenderPoint(int x, int y) | 2486 SDL_RenderPoint(int x, int y) |
2487 { | 2487 { |
2488 SDL_Point point; | |
2489 | |
2490 point.x = x; | |
2491 point.y = y; | |
2492 return SDL_RenderPoints(&point, 1); | |
2493 } | |
2494 | |
2495 int | |
2496 SDL_RenderPoints(const SDL_Point * points, int count) | |
2497 { | |
2488 SDL_Renderer *renderer; | 2498 SDL_Renderer *renderer; |
2489 SDL_Window *window; | 2499 |
2500 if (!points) { | |
2501 SDL_SetError("SDL_RenderPoints(): Passed NULL points"); | |
2502 return -1; | |
2503 } | |
2490 | 2504 |
2491 renderer = SDL_GetCurrentRenderer(SDL_TRUE); | 2505 renderer = SDL_GetCurrentRenderer(SDL_TRUE); |
2492 if (!renderer) { | 2506 if (!renderer) { |
2493 return -1; | 2507 return -1; |
2494 } | 2508 } |
2495 if (!renderer->RenderPoint) { | 2509 if (!renderer->RenderPoints) { |
2496 SDL_Unsupported(); | 2510 SDL_Unsupported(); |
2497 return -1; | 2511 return -1; |
2498 } | 2512 } |
2499 window = SDL_GetWindowFromID(renderer->window); | 2513 if (count < 1) { |
2500 if (x < 0 || y < 0 || x >= window->w || y >= window->h) { | |
2501 return 0; | 2514 return 0; |
2502 } | 2515 } |
2503 return renderer->RenderPoint(renderer, x, y); | 2516 return renderer->RenderPoints(renderer, points, count); |
2504 } | 2517 } |
2505 | 2518 |
2506 int | 2519 int |
2507 SDL_RenderLine(int x1, int y1, int x2, int y2) | 2520 SDL_RenderLine(int x1, int y1, int x2, int y2) |
2508 { | 2521 { |
2522 SDL_Point points[2]; | |
2523 | |
2524 points[0].x = x1; | |
2525 points[0].y = y1; | |
2526 points[1].x = x2; | |
2527 points[1].y = y2; | |
2528 return SDL_RenderLines(points, 2); | |
2529 } | |
2530 | |
2531 int | |
2532 SDL_RenderLines(const SDL_Point * points, int count) | |
2533 { | |
2509 SDL_Renderer *renderer; | 2534 SDL_Renderer *renderer; |
2510 SDL_Window *window; | 2535 |
2511 SDL_Rect real_rect; | 2536 if (!points) { |
2512 | 2537 SDL_SetError("SDL_RenderLines(): Passed NULL points"); |
2513 if (x1 == x2 && y1 == y2) { | 2538 return -1; |
2514 return SDL_RenderPoint(x1, y1); | |
2515 } | 2539 } |
2516 | 2540 |
2517 renderer = SDL_GetCurrentRenderer(SDL_TRUE); | 2541 renderer = SDL_GetCurrentRenderer(SDL_TRUE); |
2518 if (!renderer) { | 2542 if (!renderer) { |
2519 return -1; | 2543 return -1; |
2520 } | 2544 } |
2521 if (!renderer->RenderLine) { | 2545 if (!renderer->RenderLines) { |
2522 SDL_Unsupported(); | 2546 SDL_Unsupported(); |
2523 return -1; | 2547 return -1; |
2524 } | 2548 } |
2525 window = SDL_GetWindowFromID(renderer->window); | 2549 if (count < 2) { |
2526 | 2550 return 0; |
2527 real_rect.x = 0; | 2551 } |
2528 real_rect.y = 0; | 2552 return renderer->RenderLines(renderer, points, count); |
2529 real_rect.w = window->w; | 2553 } |
2530 real_rect.h = window->h; | 2554 |
2531 if (!SDL_IntersectRectAndLine(&real_rect, &x1, &y1, &x2, &y2)) { | 2555 int |
2532 return (0); | 2556 SDL_RenderRect(const SDL_Rect * rect) |
2533 } | 2557 { |
2534 return renderer->RenderLine(renderer, x1, y1, x2, y2); | 2558 return SDL_RenderRects(&rect, 1); |
2535 } | 2559 } |
2536 | 2560 |
2537 int | 2561 int |
2538 SDL_RenderFill(const SDL_Rect * rect) | 2562 SDL_RenderRects(const SDL_Rect ** rects, int count) |
2539 { | 2563 { |
2540 SDL_Renderer *renderer; | 2564 SDL_Renderer *renderer; |
2541 SDL_Window *window; | 2565 int i; |
2542 SDL_Rect real_rect; | 2566 |
2567 if (!rects) { | |
2568 SDL_SetError("SDL_RenderRects(): Passed NULL rects"); | |
2569 return -1; | |
2570 } | |
2543 | 2571 |
2544 renderer = SDL_GetCurrentRenderer(SDL_TRUE); | 2572 renderer = SDL_GetCurrentRenderer(SDL_TRUE); |
2545 if (!renderer) { | 2573 if (!renderer) { |
2546 return -1; | 2574 return -1; |
2547 } | 2575 } |
2548 if (!renderer->RenderFill) { | 2576 if (!renderer->RenderRects) { |
2549 SDL_Unsupported(); | 2577 SDL_Unsupported(); |
2550 return -1; | 2578 return -1; |
2551 } | 2579 } |
2552 window = SDL_GetWindowFromID(renderer->window); | 2580 if (count < 1) { |
2553 | 2581 return 0; |
2554 real_rect.x = 0; | 2582 } |
2555 real_rect.y = 0; | 2583 /* Check for NULL rect, which means fill entire window */ |
2556 real_rect.w = window->w; | 2584 for (i = 0; i < count; ++i) { |
2557 real_rect.h = window->h; | 2585 if (rects[i] == NULL) { |
2558 if (rect) { | 2586 SDL_Window *window; |
2559 if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { | 2587 SDL_Rect full_rect; |
2560 return 0; | 2588 SDL_Rect *rect; |
2561 } | 2589 |
2562 } | 2590 window = SDL_GetWindowFromID(renderer->window); |
2563 return renderer->RenderFill(renderer, &real_rect); | 2591 full_rect.x = 0; |
2592 full_rect.y = 0; | |
2593 full_rect.w = window->w; | |
2594 full_rect.h = window->h; | |
2595 rect = &full_rect; | |
2596 return renderer->RenderRects(renderer, &rect, 1); | |
2597 } | |
2598 } | |
2599 return renderer->RenderRects(renderer, rects, count); | |
2564 } | 2600 } |
2565 | 2601 |
2566 int | 2602 int |
2567 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, | 2603 SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect * srcrect, |
2568 const SDL_Rect * dstrect) | 2604 const SDL_Rect * dstrect) |