-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw.cpp
181 lines (163 loc) · 5.91 KB
/
draw.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/// @file draw.cpp
/// Functions that handles the drawing and display of various elements
/*
This program 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 3 of the License, or (at your option) any later version.
This program 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
program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "draw.h"
#include "file_io.h"
void drawLogo(int row, int col) {
const int wordWidth = 73; // Width of the longest word
const int wordHeight = 8; // Height for each word
std::vector<std::string> logo = parseLogo();
std::cout << textClear << setCursorPosition(0, 0);
// Will not print logo if terminal cannot fit
if (row > wordHeight && col > wordWidth) {
// Will use fileIO for this
for (int i = 0; i < 9; i++) {
std::cout << logo[i] << "\n";
}
time::sleep(sleepMedium);
std::cout << textClear << setCursorPosition(0, 0);
time::sleep(sleepShort);
for (int i = 9; i < 18; i++) {
std::cout << logo[i] << "\n";
}
time::sleep(sleepMedium);
std::cout << textClear << setCursorPosition(0, 0);
time::sleep(sleepShort);
for (int i = 18; i < 27; i++) {
std::cout << logo[i] << "\n";
}
time::sleep(sleepMedium);
}
else {
std::cout << "Welcome to Stock Market Simulator!\n";
}
std::cout << textClear << setCursorPosition(0, 0);
}
void drawRoundInfo(
int row, int col, int round, float balance, std::string player, float indexHSI) {
std::ignore = row; // Shutup compiler
std::cout << setCursorPosition(2, 5);
std::cout << "Round " << round;
if (player.size() > 15) {
std::cout << setCursorPosition(4, 0);
std::cout << player.erase(12) << "...";
}
else {
std::cout << setCursorPosition(
4, static_cast<int>((15 - player.size()) / 2 + 1));
std::cout << player;
}
std::cout << setCursorPosition(2, col - 10);
std::cout << "$" << balance;
std::cout << setCursorPosition(4, col - 12);
std::cout << " HSI: " << indexHSI;
}
void drawEventBar(int row, int col) {
std::ignore = row; // Shutup compiler
int width = col - 32;
std::cout << setCursorPosition(2, 16) << "\u250C";
for (int i = 0; i < width - 1; i++) {
std::cout << "\u2500";
}
std::cout << "\u2510" << setCursorPosition(3, 16) << "\u2502";
std::cout << setCursorPosition(3, width + 16) << "\u2502";
std::cout << setCursorPosition(4, 16) << "\u2514";
for (int i = 0; i < width - 1; i++) {
std::cout << "\u2500";
}
std::cout << "\u2518";
}
void listEvents(int row, int col, std::vector<Stock_event> events) {
int height;
int width = col - 20;
if (static_cast<int>(events.size()) < row - 10) {
if (static_cast<int>(events.size()) != 0) {
height = static_cast<int>(events.size()) + 2;
}
else {
height = 3;
}
}
else {
height = row - 10;
}
std::cout << setCursorPosition(6, 10) << "\u250C";
for (int i = 0; i < width - 1; i++) {
std::cout << "\u2500";
}
std::cout << "\u2510";
for (int i = 0; i < height; i++) {
std::cout << setCursorPosition(i + 7, 10);
std::cout << "\u2502";
std::cout << setCursorPosition(i + 7, width + 10);
std::cout << "\u2502";
}
std::cout << setCursorPosition(height + 7, 10) << "\u2514";
for (int i = 0; i < width - 1; i++) {
std::cout << "\u2500";
}
std::cout << "\u2518";
std::cout << setCursorPosition(7, 11);
for (int i = 0; i < width - 1; i++) {
std::cout << " ";
}
if (static_cast<int>(events.size()) == 0) {
std::cout << setCursorPosition(8, 11);
std::cout << "There are currently no events!";
for (int i = 0; i < width - 31; i++) {
std::cout << " ";
}
std::cout << setCursorPosition(9, 11);
for (int i = 0; i < width - 1; i++) {
std::cout << " ";
}
}
else {
for (int i = 1; i < static_cast<int>(events.size()) + 1; i++) {
std::cout << setCursorPosition(i + 7, 11);
std::cout << i << ". " << events[i - 1].text;
int digits = (((i) / 10) + 1);
for (int j = 0;
j < width - static_cast<int>(events[i - 1].text.size()) - 3 - digits;
j++) {
std::cout << " ";
}
}
std::cout << setCursorPosition(static_cast<int>(events.size()) + 8, 11);
for (int i = 0; i < width - 1; i++) {
std::cout << " ";
}
}
}
void drawButton(int row, int col) {
int width;
int buttons;
std::vector<std::string> options = {"[B] Buy", "[S] Sell", "[T] Toggle View",
"[E] Events", "[N] Next Round", "[X] Exit"}; // Add stuff here
buttons = options.size();
width = (col / buttons);
std::cout << textReset << setCursorPosition(row - 1, 3);
for (int i = 0; i < buttons; i++) {
i % 2 == 0 ? std::cout << bgWhite << textBlack
: std::cout << bgBlack << textWhite;
for (int j = 0; j < static_cast<int>((width - options[i].length()) / 2); j++) {
std::cout << " ";
}
std::cout << textBold << options[i] << "\x1b[22m";
for (int j = 0; j < static_cast<int>((width - options[i].length() -
(width - options[i].length()) / 2));
j++) {
std::cout << " ";
}
}
std::cout << textReset << "\n";
}