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

Latest commit

 

History

History
74 lines (61 loc) · 1.97 KB

SDL_drawrect.c

File metadata and controls

74 lines (61 loc) · 1.97 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Jan 24, 2010
Jan 24, 2010
3
Copyright (C) 1997-2010 Sam Lantinga
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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"
#include "SDL_video.h"
int
SDL_DrawRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
{
Dec 18, 2009
Dec 18, 2009
30
31
SDL_Rect full_rect;
SDL_Point points[5];
32
33
34
35
36
37
if (!dst) {
SDL_SetError("Passed NULL destination surface");
return -1;
}
Dec 18, 2009
Dec 18, 2009
38
39
40
41
42
43
44
/* If 'rect' == NULL, then outline the whole surface */
if (!rect) {
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = dst->w;
full_rect.h = dst->h;
rect = &full_rect;
45
46
}
Dec 18, 2009
Dec 18, 2009
47
48
49
50
51
52
53
54
55
56
57
points[0].x = rect->x;
points[0].y = rect->y;
points[1].x = rect->x+rect->w-1;
points[1].y = rect->y;
points[2].x = rect->x+rect->w-1;
points[2].y = rect->y+rect->h-1;
points[3].x = rect->x;
points[3].y = rect->y+rect->h-1;
points[4].x = rect->x;
points[4].y = rect->y;
return SDL_DrawLines(dst, points, 5, color);
58
59
60
61
62
63
64
65
66
}
int
SDL_DrawRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
Uint32 color)
{
int i;
for (i = 0; i < count; ++i) {
Dec 18, 2009
Dec 18, 2009
67
68
69
if (SDL_DrawRect(dst, rects[i], color) < 0) {
return -1;
}
70
}
Dec 18, 2009
Dec 18, 2009
71
return 0;
72
73
74
}
/* vi: set ts=4 sw=4 expandtab: */