Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
115 lines (97 loc) · 3.09 KB

SDL_drawline.c

File metadata and controls

115 lines (97 loc) · 3.09 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
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"
Dec 21, 2008
Dec 21, 2008
24
#include "SDL_draw.h"
Dec 20, 2008
Dec 20, 2008
25
Dec 21, 2008
Dec 21, 2008
27
int
28
29
SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
{
Dec 9, 2009
Dec 9, 2009
30
31
32
33
34
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
35
36
37
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) {
SDL_SetError("SDL_DrawLine(): Unsupported surface format");
Dec 9, 2009
Dec 9, 2009
38
return -1;
39
40
41
}
/* Perform clipping */
Dec 9, 2009
Dec 9, 2009
42
/* FIXME: We don't actually want to clip, as it may change line slope */
Dec 23, 2008
Dec 23, 2008
43
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
Dec 23, 2008
Dec 23, 2008
44
45
return (0);
}
Dec 20, 2008
Dec 20, 2008
47
48
switch (dst->format->BytesPerPixel) {
case 1:
Dec 21, 2008
Dec 21, 2008
49
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
Dec 20, 2008
Dec 20, 2008
50
51
break;
case 2:
Dec 21, 2008
Dec 21, 2008
52
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
Dec 20, 2008
Dec 20, 2008
53
54
55
56
57
break;
case 3:
SDL_Unsupported();
return -1;
case 4:
Dec 21, 2008
Dec 21, 2008
58
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
Dec 20, 2008
Dec 20, 2008
59
60
61
break;
}
return 0;
Dec 9, 2009
Dec 9, 2009
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
int
SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
Uint32 color)
{
int i;
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) {
SDL_SetError("SDL_DrawLine(): Unsupported surface format");
return -1;
}
if (count < 2) {
return 0;
}
for (i = 1; i < count; ++i) {
int x1 = points[i-1].x;
int y1 = points[i-1].y;
int x2 = points[i].x;
int y2 = points[i].y;
/* Perform clipping */
/* FIXME: We don't actually want to clip, as it may change line slope */
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
continue;
}
switch (dst->format->BytesPerPixel) {
case 1:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
break;
case 2:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
break;
case 3:
SDL_Unsupported();
return -1;
case 4:
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
break;
}
}
return 0;
}
115
/* vi: set ts=4 sw=4 expandtab: */