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

Latest commit

 

History

History
58 lines (48 loc) · 1.68 KB

SDL_drawline.c

File metadata and controls

58 lines (48 loc) · 1.68 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
30
31
32
33
34
35
36
SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
{
/* This function doesn't work on surfaces < 8 bpp */
if (dst->format->BitsPerPixel < 8) {
SDL_SetError("SDL_DrawLine(): Unsupported surface format");
return (-1);
}
/* Perform clipping */
Dec 23, 2008
Dec 23, 2008
37
if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
Dec 23, 2008
Dec 23, 2008
38
39
return (0);
}
Dec 20, 2008
Dec 20, 2008
41
42
switch (dst->format->BytesPerPixel) {
case 1:
Dec 21, 2008
Dec 21, 2008
43
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
Dec 20, 2008
Dec 20, 2008
44
45
break;
case 2:
Dec 21, 2008
Dec 21, 2008
46
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
Dec 20, 2008
Dec 20, 2008
47
48
49
50
51
break;
case 3:
SDL_Unsupported();
return -1;
case 4:
Dec 21, 2008
Dec 21, 2008
52
DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
Dec 20, 2008
Dec 20, 2008
53
54
55
break;
}
return 0;
56
57
58
}
/* vi: set ts=4 sw=4 expandtab: */