Commit 2b04928c authored by Sam Lantinga's avatar Sam Lantinga

Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()

Fixed line drawing so when blending a sequence of lines there are no overlapping pixels drawn.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%404344
parent e4c73114
...@@ -203,11 +203,6 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, ...@@ -203,11 +203,6 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
return -1; return -1;
} }
if (blendMode < SDL_BLENDMODE_BLEND) {
Uint32 color = SDL_MapRGBA(dst->format, r, g, b, a);
return SDL_FillRect(dst, rect, color);
}
/* This function doesn't work on surfaces < 8 bpp */ /* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) { if (dst->format->BitsPerPixel < 8) {
SDL_SetError("SDL_BlendFillRect(): Unsupported surface format"); SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
...@@ -281,11 +276,6 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, ...@@ -281,11 +276,6 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
return -1; return -1;
} }
if (blendMode < SDL_BLENDMODE_BLEND) {
Uint32 color = SDL_MapRGBA(dst->format, r, g, b, a);
return SDL_FillRects(dst, rects, color);
}
/* This function doesn't work on surfaces < 8 bpp */ /* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) { if (dst->format->BitsPerPixel < 8) {
SDL_SetError("SDL_BlendFillRects(): Unsupported surface format"); SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
......
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2009 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "SDL_video.h"
int
SDL_BlendRect(SDL_Surface * dst, const SDL_Rect * rect,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
SDL_Rect full_rect;
SDL_Point points[5];
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
/* If 'rect' == NULL, then outline the whole surface */
if (!rect) {
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = dst->w;
full_rect.h = dst->h;
rect = &full_rect;
}
points[0].x = rect->x;
points[0].y = rect->y;
points[1].x = rect->x+rect->w-1;
points[1].y = rect->y;
points[2].x = rect->x+rect->w-1;
points[2].y = rect->y+rect->h-1;
points[3].x = rect->x;
points[3].y = rect->y+rect->h-1;
points[4].x = rect->x;
points[4].y = rect->y;
return SDL_BlendLines(dst, points, 5, blendMode, r, g, b, a);
}
int
SDL_BlendRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
int i;
for (i = 0; i < count; ++i) {
if (SDL_BlendRect(dst, rects[i], blendMode, r, g, b, a) < 0) {
return -1;
}
}
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */
...@@ -283,7 +283,7 @@ do { \ ...@@ -283,7 +283,7 @@ do { \
#define ABS(_x) ((_x) < 0 ? -(_x) : (_x)) #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
#define BRESENHAM(x1, y1, x2, y2, op) \ #define BRESENHAM(x1, y1, x2, y2, op, draw_end) \
{ \ { \
int i, deltax, deltay, numpixels; \ int i, deltax, deltay, numpixels; \
int d, dinc1, dinc2; \ int d, dinc1, dinc2; \
...@@ -325,6 +325,9 @@ do { \ ...@@ -325,6 +325,9 @@ do { \
x = x1; \ x = x1; \
y = y1; \ y = y1; \
\ \
if (!draw_end) { \
--numpixels; \
} \
for (i = 0; i < numpixels; ++i) { \ for (i = 0; i < numpixels; ++i) { \
op(x, y); \ op(x, y); \
if (d < 0) { \ if (d < 0) { \
...@@ -338,10 +341,11 @@ do { \ ...@@ -338,10 +341,11 @@ do { \
} \ } \
} \ } \
} }
#define DRAWLINE(x0, y0, x1, y1, op) BRESENHAM(x0, y0, x1, y1, op) #define DRAWLINE BRESENHAM
/* /*
* Define draw rect macro * Define draw rect macro
* (not tested, this level of optimization not needed ... yet?)
*/ */
#define DRAWRECT(type, op) \ #define DRAWRECT(type, op) \
do { \ do { \
......
...@@ -46,16 +46,16 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) ...@@ -46,16 +46,16 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
switch (dst->format->BytesPerPixel) { switch (dst->format->BytesPerPixel) {
case 1: case 1:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1); DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1, SDL_TRUE);
break; break;
case 2: case 2:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2); DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2, SDL_TRUE);
break; break;
case 3: case 3:
SDL_Unsupported(); SDL_Unsupported();
return -1; return -1;
case 4: case 4:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4); DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4, SDL_TRUE);
break; break;
} }
return 0; return 0;
...@@ -96,16 +96,16 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, ...@@ -96,16 +96,16 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
switch (dst->format->BytesPerPixel) { switch (dst->format->BytesPerPixel) {
case 1: case 1:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1); DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1, SDL_TRUE);
break; break;
case 2: case 2:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2); DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2, SDL_TRUE);
break; break;
case 3: case 3:
SDL_Unsupported(); SDL_Unsupported();
return -1; return -1;
case 4: case 4:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4); DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4, SDL_TRUE);
break; break;
} }
} }
......
This diff is collapsed.
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