-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangle.cpp
65 lines (57 loc) · 1.26 KB
/
Rectangle.cpp
1
2
3
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "Rectangle.h"
Rectangle::Rectangle() {
rect.x = position.x = 0;
rect.y = position.y = 0;
rect.w = dimensions.x = 1;
rect.h = dimensions.y = 1;
color.a = 0;
color.r = 0;
color.g = 0;
color.b = 0;
angle = 0;
}
Rectangle::Rectangle(int x, int y) {
*this =Rectangle();
setPosition(x, y);
}
Rectangle::Rectangle(int x, int y, int w, int h) {
*this = Rectangle(x, y);
setDimensions(w, h);
}
Rectangle::Rectangle(int x, int y, int w, int h, float ang) {
*this = Rectangle(x, y, w, h);
angle = ang;
}
Rectangle::Rectangle(int x, int y, int w, int h, int r, int g, int b) {
*this = Rectangle(x, y, w, h);
setColor(r, g, b);
}
void Rectangle::setColor(int r, int g, int b) {
color.a = 0;
color.r = r;
color.g = g;
color.b = b;
}
void Rectangle::setColor(int r, int g, int b, int a)
{
color.a = a;
color.r = r;
color.g = g;
color.b = b;
}
void Rectangle::setAngle(float ang) {
angle = ang;
}
void Rectangle::setPosition(int x, int y) {
rect.x = position.x = x;
rect.y = position.y = y;
}
void Rectangle::setDimensions(int w, int h) {
rect.w = dimensions.x = w;
rect.h = dimensions.y = h;
}
void Rectangle::render(SDL_Renderer* Renderer)
{
SDL_SetRenderDrawColor(Renderer, color.r, color.g, color.b, color.a);
SDL_RenderFillRect(Renderer, &rect);
}