comparison src/video/SDL_drawpoint.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 210e209b87cc
children f638ded38b8a
comparison
equal deleted inserted replaced
3535:b403f790df65 3536:0267b8b1595c
25 25
26 26
27 int 27 int
28 SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) 28 SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
29 { 29 {
30 if (!dst) {
31 SDL_SetError("Passed NULL destination surface");
32 return -1;
33 }
34
30 /* This function doesn't work on surfaces < 8 bpp */ 35 /* This function doesn't work on surfaces < 8 bpp */
31 if (dst->format->BitsPerPixel < 8) { 36 if (dst->format->BitsPerPixel < 8) {
32 SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); 37 SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
33 return (-1); 38 return -1;
34 } 39 }
35 40
36 /* Perform clipping */ 41 /* Perform clipping */
37 if (x < dst->clip_rect.x || y < dst->clip_rect.y || 42 if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
38 x >= (dst->clip_rect.x + dst->clip_rect.w) || 43 x >= (dst->clip_rect.x + dst->clip_rect.w) ||
55 break; 60 break;
56 } 61 }
57 return 0; 62 return 0;
58 } 63 }
59 64
65 int
66 SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
67 Uint32 color)
68 {
69 int minx, miny;
70 int maxx, maxy;
71 int i;
72 int x, y;
73
74 if (!dst) {
75 SDL_SetError("Passed NULL destination surface");
76 return -1;
77 }
78
79 /* This function doesn't work on surfaces < 8 bpp */
80 if (dst->format->BitsPerPixel < 8) {
81 SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
82 return -1;
83 }
84
85 minx = dst->clip_rect.x;
86 maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
87 miny = dst->clip_rect.y;
88 maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
89
90 for (i = 0; i < count; ++i) {
91 x = points[i].x;
92 y = points[i].y;
93
94 if (x < minx || x > maxx || y < miny || y > maxy) {
95 continue;
96 }
97
98 switch (dst->format->BytesPerPixel) {
99 case 1:
100 DRAW_FASTSETPIXEL1(x, y);
101 break;
102 case 2:
103 DRAW_FASTSETPIXEL2(x, y);
104 break;
105 case 3:
106 SDL_Unsupported();
107 return -1;
108 case 4:
109 DRAW_FASTSETPIXEL4(x, y);
110 break;
111 }
112 }
113 return 0;
114 }
115
60 /* vi: set ts=4 sw=4 expandtab: */ 116 /* vi: set ts=4 sw=4 expandtab: */