Mercurial > sdl-ios-xcode
diff 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 |
line wrap: on
line diff
--- a/src/video/SDL_video.c Mon Dec 07 10:08:24 2009 +0000 +++ b/src/video/SDL_video.c Wed Dec 09 15:56:56 2009 +0000 @@ -2485,82 +2485,118 @@ int SDL_RenderPoint(int x, int y) { + SDL_Point point; + + point.x = x; + point.y = y; + return SDL_RenderPoints(&point, 1); +} + +int +SDL_RenderPoints(const SDL_Point * points, int count) +{ SDL_Renderer *renderer; - SDL_Window *window; + + if (!points) { + SDL_SetError("SDL_RenderPoints(): Passed NULL points"); + return -1; + } renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } - if (!renderer->RenderPoint) { + if (!renderer->RenderPoints) { SDL_Unsupported(); return -1; } - window = SDL_GetWindowFromID(renderer->window); - if (x < 0 || y < 0 || x >= window->w || y >= window->h) { + if (count < 1) { return 0; } - return renderer->RenderPoint(renderer, x, y); + return renderer->RenderPoints(renderer, points, count); } int SDL_RenderLine(int x1, int y1, int x2, int y2) { + SDL_Point points[2]; + + points[0].x = x1; + points[0].y = y1; + points[1].x = x2; + points[1].y = y2; + return SDL_RenderLines(points, 2); +} + +int +SDL_RenderLines(const SDL_Point * points, int count) +{ SDL_Renderer *renderer; - SDL_Window *window; - SDL_Rect real_rect; - - if (x1 == x2 && y1 == y2) { - return SDL_RenderPoint(x1, y1); + + if (!points) { + SDL_SetError("SDL_RenderLines(): Passed NULL points"); + return -1; } renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } - if (!renderer->RenderLine) { + if (!renderer->RenderLines) { SDL_Unsupported(); return -1; } - window = SDL_GetWindowFromID(renderer->window); - - real_rect.x = 0; - real_rect.y = 0; - real_rect.w = window->w; - real_rect.h = window->h; - if (!SDL_IntersectRectAndLine(&real_rect, &x1, &y1, &x2, &y2)) { - return (0); - } - return renderer->RenderLine(renderer, x1, y1, x2, y2); + if (count < 2) { + return 0; + } + return renderer->RenderLines(renderer, points, count); } int -SDL_RenderFill(const SDL_Rect * rect) +SDL_RenderRect(const SDL_Rect * rect) +{ + return SDL_RenderRects(&rect, 1); +} + +int +SDL_RenderRects(const SDL_Rect ** rects, int count) { SDL_Renderer *renderer; - SDL_Window *window; - SDL_Rect real_rect; + int i; + + if (!rects) { + SDL_SetError("SDL_RenderRects(): Passed NULL rects"); + return -1; + } renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } - if (!renderer->RenderFill) { + if (!renderer->RenderRects) { SDL_Unsupported(); return -1; } - window = SDL_GetWindowFromID(renderer->window); - - real_rect.x = 0; - real_rect.y = 0; - real_rect.w = window->w; - real_rect.h = window->h; - if (rect) { - if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { - return 0; + if (count < 1) { + return 0; + } + /* Check for NULL rect, which means fill entire window */ + for (i = 0; i < count; ++i) { + if (rects[i] == NULL) { + SDL_Window *window; + SDL_Rect full_rect; + SDL_Rect *rect; + + window = SDL_GetWindowFromID(renderer->window); + full_rect.x = 0; + full_rect.y = 0; + full_rect.w = window->w; + full_rect.h = window->h; + rect = &full_rect; + return renderer->RenderRects(renderer, &rect, 1); } } - return renderer->RenderFill(renderer, &real_rect); + return renderer->RenderRects(renderer, rects, count); } int