]> git.localhorst.tv Git - l2e.git/blob - src/sdl/utility.cpp
fixed sdl::OutlineRect for rects with x or y < 0
[l2e.git] / src / sdl / utility.cpp
1 #include "utility.h"
2
3 #include <cmath>
4
5 using math::Vector;
6
7 namespace sdl {
8
9 void HorizontalLine(SDL_Surface *dst, const Vector<int> &position, unsigned int length, Uint32 color) {
10         SDL_Rect destRect;
11         destRect.x = position.X();
12         destRect.y = position.Y();
13         destRect.w = length;
14         destRect.h = 1;
15         SDL_FillRect(dst, &destRect, color);
16 }
17
18 void VerticalLine(SDL_Surface *dst, const math::Vector<int> &position, unsigned int length, Uint32 color) {
19         SDL_Rect destRect;
20         destRect.x = position.X();
21         destRect.y = position.Y();
22         destRect.w = 1;
23         destRect.h = length;
24         SDL_FillRect(dst, &destRect, color);
25 }
26
27
28 void OutlineRect(SDL_Surface *dst, const Vector<int> &from, const Vector<int> &to, Uint32 color) {
29         SDL_Rect destRect;
30         destRect.x = std::min(from.X(), to.X());
31         destRect.y = std::min(from.Y(), to.Y());
32         destRect.w = std::abs(from.X() - to.X());
33         destRect.h = std::abs(from.Y() - to.Y());
34         OutlineRect(dst, &destRect, color);
35 }
36
37 void OutlineRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color) {
38         SDL_Rect destRect;
39         destRect.x = dstrect->x;
40         destRect.y = dstrect->y;
41         destRect.w = dstrect->w;
42         destRect.h = 1;
43         SDL_FillRect(dst, &destRect, color);
44         destRect.x = dstrect->x;
45         destRect.y = dstrect->y + dstrect->h - 1;
46         destRect.w = dstrect->w;
47         destRect.h = 1;
48         SDL_FillRect(dst, &destRect, color);
49         destRect.x = dstrect->x;
50         destRect.y = dstrect->y;
51         destRect.w = 1;
52         destRect.h = dstrect->h;
53         SDL_FillRect(dst, &destRect, color);
54         destRect.x = dstrect->x + dstrect->w - 1;
55         destRect.y = dstrect->y;
56         destRect.w = 1;
57         destRect.h = dstrect->h;
58         SDL_FillRect(dst, &destRect, color);
59 }
60
61 }