-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.cpp
64 lines (48 loc) · 2.83 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
#include "Header.h"
bool rectangle::is_in_rec(position other_pos, float add_dist) {
return other_pos.x < x + (wighth / 2) + add_dist && other_pos.x > x - (wighth / 2) - add_dist && other_pos.y < y + (hight / 2) + add_dist && other_pos.y > y - (hight / 2) - add_dist;
}
bool rectangle::is_in_rec(int in_x, int in_y, float add_dist) {
return in_x < x + (wighth / 2) + add_dist && in_x > x - (wighth / 2) - add_dist && in_y < y + (hight / 2) + add_dist && in_y > y - (hight / 2) - add_dist;
}
void rectangle::draw_rec(std::vector<std::string>* screen_vec, Screen& screen, char fill, int add_val) {
int y_coord = (screen.coord_to_vec_space(y, 'y') - 1);
int x_coord = screen.coord_to_vec_space(x, 'x');
float now_hight = add_val + hight;
float now_wighth = add_val + wighth;
std::string line = std::string(now_wighth, fill);
for (int iy = y_coord - floor(now_hight / 2); iy < y_coord + ceil(now_hight / 2) && iy < (&screen)->rows; iy++) {
if (iy >= 0 && x_coord + (now_wighth / 2) < (&screen)->cols * 2 && x_coord - (now_wighth / 2) > 0) {
(*screen_vec)[iy].replace(x_coord - (now_wighth / 2), now_wighth, line);
//(*screen_vec)[rows - 6].replace(cols - 6, image.size(), image);
}
}
}
void rectangle::draw_frame(std::vector<std::string>* screen_vec, Screen& screen, int add_val) {
int y_coord = (screen.coord_to_vec_space(y, 'y') - 1);
int x_coord = screen.coord_to_vec_space(x, 'x');
float now_hight = add_val + hight;
float now_wighth = add_val + wighth;
std::string bord_lines;
std::string mid_lines;
if (is_big) {
bord_lines = std::string(now_wighth, '#');
mid_lines = '#' + std::string(now_wighth - 2, ' ') + '#';
}
else {
bord_lines = std::string(now_wighth, '-');
mid_lines = '|' + std::string(now_wighth - 2, ' ') + '|';
}
for (int iy = y_coord - floor(now_hight / 2) + 1; iy < y_coord + ceil(now_hight / 2) - 1 && iy < (&screen)->rows; iy++) {
if (iy >= 0 && x_coord + (now_wighth / 2) < (&screen)->cols * 2 && x_coord - (now_wighth / 2) > 0 && x_coord - (now_wighth / 2) + now_wighth < (*screen_vec)[iy].size()) {
(*screen_vec)[iy].replace(x_coord - (now_wighth / 2), now_wighth, mid_lines);
//(*screen_vec)[rows - 6].replace(cols - 6, image.size(), image);
}
}
if (x_coord - (now_wighth / 2) >= 0 && y_coord + ceil(now_hight / 2) - 1 >= 0 && y_coord + ceil(now_hight / 2) - 1 <= (&screen)->rows) {
(*screen_vec)[y_coord + ceil(now_hight / 2) - 1].replace(x_coord - (now_wighth / 2), now_wighth, bord_lines);
}
if (x_coord - (now_wighth / 2) >= 0 && y_coord - floor(now_hight / 2) >= 0 && y_coord - floor(now_hight / 2) <= (&screen)->rows) {
(*screen_vec)[y_coord - floor(now_hight / 2)].replace(x_coord - (now_wighth / 2), now_wighth, bord_lines);
}
}