-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrame.cpp
72 lines (61 loc) · 1.61 KB
/
Frame.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
66
67
68
69
70
71
72
#include "Frame.h"
#include "DisplayManager.h"
#include "LogManager.h"
namespace df {
//Creates an empty frame
Frame::Frame() {
m_width = 0;
m_height = 0;
m_frame_str = "";
}
//Create frame of indicated width and height with string
Frame::Frame(int new_width, int new_height, std::string frame_str) {
setWidth(new_width);
setHeight(new_height);
setString(frame_str);
}
//Set width of frame
void Frame::setWidth(int new_width) {
m_width=new_width;
}
//Get width of frame
int Frame::getWidth() const {
return m_width;
}
//Set height of frame
void Frame::setHeight(int new_height) {
m_height = new_height;
}
//Get height of frame
int Frame::getHeight() const {
return m_height;
}
//Set frame characters (stored as string)
void Frame::setString(std::string new_frame_str) {
m_frame_str = new_frame_str;
}
//Get frame characters (stored as string)
std::string Frame::getString() const {
return m_frame_str;
}
//Draw self, centered at position (x,y) with color
//Return 0 if ok, else -1
//Note: top-left coordinate is (0,0)
int Frame::draw(Vector position, Color color) const {
if (m_frame_str.empty()) {
return -1;
}
//Determine offset since centered at position
int x_offset = getWidth();
int y_offset = getHeight();
//Draw character by character
for (int y = 0; y < m_height; y++) {
for (int x = 0; x < m_width; x++) {
Vector temp_pos(position.getX() + x - x_offset,
position.getY() + y - y_offset);
DM.drawCh(temp_pos, m_frame_str[(y*m_width) + x], color);
}
}
return 0;
}
}