Mercurial > sdl-ios-xcode
comparison src/video/SDL_drawline.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 | 27d8b12e0e8e |
children | c8bed77b0386 |
comparison
equal
deleted
inserted
replaced
3535:b403f790df65 | 3536:0267b8b1595c |
---|---|
25 | 25 |
26 | 26 |
27 int | 27 int |
28 SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) | 28 SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, 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_DrawLine(): Unsupported surface format"); | 37 SDL_SetError("SDL_DrawLine(): Unsupported surface format"); |
33 return (-1); | 38 return -1; |
34 } | 39 } |
35 | 40 |
36 /* Perform clipping */ | 41 /* Perform clipping */ |
42 /* FIXME: We don't actually want to clip, as it may change line slope */ | |
37 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { | 43 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { |
38 return (0); | 44 return (0); |
39 } | 45 } |
40 | 46 |
41 switch (dst->format->BytesPerPixel) { | 47 switch (dst->format->BytesPerPixel) { |
53 break; | 59 break; |
54 } | 60 } |
55 return 0; | 61 return 0; |
56 } | 62 } |
57 | 63 |
64 int | |
65 SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, | |
66 Uint32 color) | |
67 { | |
68 int i; | |
69 | |
70 if (!dst) { | |
71 SDL_SetError("Passed NULL destination surface"); | |
72 return -1; | |
73 } | |
74 | |
75 /* This function doesn't work on surfaces < 8 bpp */ | |
76 if (dst->format->BitsPerPixel < 8) { | |
77 SDL_SetError("SDL_DrawLine(): Unsupported surface format"); | |
78 return -1; | |
79 } | |
80 | |
81 if (count < 2) { | |
82 return 0; | |
83 } | |
84 | |
85 for (i = 1; i < count; ++i) { | |
86 int x1 = points[i-1].x; | |
87 int y1 = points[i-1].y; | |
88 int x2 = points[i].x; | |
89 int y2 = points[i].y; | |
90 | |
91 /* Perform clipping */ | |
92 /* FIXME: We don't actually want to clip, as it may change line slope */ | |
93 if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { | |
94 continue; | |
95 } | |
96 | |
97 switch (dst->format->BytesPerPixel) { | |
98 case 1: | |
99 DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1); | |
100 break; | |
101 case 2: | |
102 DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2); | |
103 break; | |
104 case 3: | |
105 SDL_Unsupported(); | |
106 return -1; | |
107 case 4: | |
108 DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4); | |
109 break; | |
110 } | |
111 } | |
112 return 0; | |
113 } | |
114 | |
58 /* vi: set ts=4 sw=4 expandtab: */ | 115 /* vi: set ts=4 sw=4 expandtab: */ |