slouken@2901
|
1 |
/*
|
slouken@2901
|
2 |
SDL - Simple DirectMedia Layer
|
slouken@2901
|
3 |
Copyright (C) 1997-2009 Sam Lantinga
|
slouken@2901
|
4 |
|
slouken@2901
|
5 |
This library is free software; you can redistribute it and/or
|
slouken@2901
|
6 |
modify it under the terms of the GNU Lesser General Public
|
slouken@2901
|
7 |
License as published by the Free Software Foundation; either
|
slouken@2901
|
8 |
version 2.1 of the License, or (at your option) any later version.
|
slouken@2901
|
9 |
|
slouken@2901
|
10 |
This library is distributed in the hope that it will be useful,
|
slouken@2901
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
slouken@2901
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
slouken@2901
|
13 |
Lesser General Public License for more details.
|
slouken@2901
|
14 |
|
slouken@2901
|
15 |
You should have received a copy of the GNU Lesser General Public
|
slouken@2901
|
16 |
License along with this library; if not, write to the Free Software
|
slouken@2901
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
slouken@2901
|
18 |
|
slouken@2901
|
19 |
Sam Lantinga
|
slouken@2901
|
20 |
slouken@libsdl.org
|
slouken@2901
|
21 |
*/
|
slouken@2901
|
22 |
#include "SDL_config.h"
|
slouken@2901
|
23 |
|
slouken@2901
|
24 |
#include "SDL_draw.h"
|
slouken@2901
|
25 |
|
slouken@2901
|
26 |
|
slouken@2901
|
27 |
int
|
slouken@2901
|
28 |
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
|
slouken@2901
|
29 |
{
|
slouken@3536
|
30 |
if (!dst) {
|
slouken@3536
|
31 |
SDL_SetError("Passed NULL destination surface");
|
slouken@3536
|
32 |
return -1;
|
slouken@3536
|
33 |
}
|
slouken@3536
|
34 |
|
slouken@2901
|
35 |
/* This function doesn't work on surfaces < 8 bpp */
|
slouken@2901
|
36 |
if (dst->format->BitsPerPixel < 8) {
|
slouken@3160
|
37 |
SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
|
slouken@3536
|
38 |
return -1;
|
slouken@2901
|
39 |
}
|
slouken@2901
|
40 |
|
slouken@2901
|
41 |
/* Perform clipping */
|
slouken@2901
|
42 |
if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
|
slouken@2901
|
43 |
x >= (dst->clip_rect.x + dst->clip_rect.w) ||
|
slouken@2901
|
44 |
y >= (dst->clip_rect.y + dst->clip_rect.h)) {
|
slouken@2901
|
45 |
return 0;
|
slouken@2901
|
46 |
}
|
slouken@2901
|
47 |
|
slouken@2901
|
48 |
switch (dst->format->BytesPerPixel) {
|
slouken@2901
|
49 |
case 1:
|
slouken@3596
|
50 |
DRAW_FASTSETPIXELXY1(x, y);
|
slouken@2901
|
51 |
break;
|
slouken@2901
|
52 |
case 2:
|
slouken@3596
|
53 |
DRAW_FASTSETPIXELXY2(x, y);
|
slouken@2901
|
54 |
break;
|
slouken@2901
|
55 |
case 3:
|
slouken@2901
|
56 |
SDL_Unsupported();
|
slouken@2901
|
57 |
return -1;
|
slouken@2901
|
58 |
case 4:
|
slouken@3596
|
59 |
DRAW_FASTSETPIXELXY4(x, y);
|
slouken@2901
|
60 |
break;
|
slouken@2901
|
61 |
}
|
slouken@2901
|
62 |
return 0;
|
slouken@2901
|
63 |
}
|
slouken@2901
|
64 |
|
slouken@3536
|
65 |
int
|
slouken@3536
|
66 |
SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
slouken@3536
|
67 |
Uint32 color)
|
slouken@3536
|
68 |
{
|
slouken@3536
|
69 |
int minx, miny;
|
slouken@3536
|
70 |
int maxx, maxy;
|
slouken@3536
|
71 |
int i;
|
slouken@3536
|
72 |
int x, y;
|
slouken@3536
|
73 |
|
slouken@3536
|
74 |
if (!dst) {
|
slouken@3536
|
75 |
SDL_SetError("Passed NULL destination surface");
|
slouken@3536
|
76 |
return -1;
|
slouken@3536
|
77 |
}
|
slouken@3536
|
78 |
|
slouken@3536
|
79 |
/* This function doesn't work on surfaces < 8 bpp */
|
slouken@3536
|
80 |
if (dst->format->BitsPerPixel < 8) {
|
slouken@3536
|
81 |
SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
|
slouken@3536
|
82 |
return -1;
|
slouken@3536
|
83 |
}
|
slouken@3536
|
84 |
|
slouken@3536
|
85 |
minx = dst->clip_rect.x;
|
slouken@3536
|
86 |
maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
|
slouken@3536
|
87 |
miny = dst->clip_rect.y;
|
slouken@3536
|
88 |
maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
|
slouken@3536
|
89 |
|
slouken@3536
|
90 |
for (i = 0; i < count; ++i) {
|
slouken@3536
|
91 |
x = points[i].x;
|
slouken@3536
|
92 |
y = points[i].y;
|
slouken@3536
|
93 |
|
slouken@3536
|
94 |
if (x < minx || x > maxx || y < miny || y > maxy) {
|
slouken@3536
|
95 |
continue;
|
slouken@3536
|
96 |
}
|
slouken@3536
|
97 |
|
slouken@3536
|
98 |
switch (dst->format->BytesPerPixel) {
|
slouken@3536
|
99 |
case 1:
|
slouken@3596
|
100 |
DRAW_FASTSETPIXELXY1(x, y);
|
slouken@3536
|
101 |
break;
|
slouken@3536
|
102 |
case 2:
|
slouken@3596
|
103 |
DRAW_FASTSETPIXELXY2(x, y);
|
slouken@3536
|
104 |
break;
|
slouken@3536
|
105 |
case 3:
|
slouken@3536
|
106 |
SDL_Unsupported();
|
slouken@3536
|
107 |
return -1;
|
slouken@3536
|
108 |
case 4:
|
slouken@3596
|
109 |
DRAW_FASTSETPIXELXY4(x, y);
|
slouken@3536
|
110 |
break;
|
slouken@3536
|
111 |
}
|
slouken@3536
|
112 |
}
|
slouken@3536
|
113 |
return 0;
|
slouken@3536
|
114 |
}
|
slouken@3536
|
115 |
|
slouken@2901
|
116 |
/* vi: set ts=4 sw=4 expandtab: */
|