screen_clear()

This commit is contained in:
2021-04-25 21:19:12 -05:00
parent 0816c1ee66
commit 517800d85f

View File

@@ -20,11 +20,12 @@ void setCursor(int XPos, int YPos);
void getCursor(int* x, int* y);
void hideCursor();
void showCursor();
void clearScreen();
void clearScreen(short width, short height);
void closeScreen();
void closeScreen(short width, short height);
void writeAt(int x, int y, char ch);
void printFrame(vector<vector<char>> screen, short width, short height);
void screen_type(vector<vector<char>> &screen, string str, int x, int y, bool vertical);
void screen_clear(vector<vector<char>> &screen);
void eachFrame(vector<vector<char>> &screen, short width, short height);
Timer t = Timer();
@@ -58,10 +59,12 @@ int main(int argc, char **argv)
hideCursor();
t.setInterval([&]() {
t.setInterval([&]()
{
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
if (w.ws_row > 0 && w.ws_col > 0) {
if (w.ws_row > 0 && w.ws_col > 0)
{
//fill vector
screen.resize(w.ws_col);
@@ -81,7 +84,7 @@ int main(int argc, char **argv)
void beforeExit()
{
//clearScreen();
//closeScreen();
setCursor(0,0);
showCursor();
t.stop();
@@ -94,10 +97,12 @@ void beforeExit(int i)
beforeExit();
}
void setCursor(int XPos, int YPos) {
void setCursor(int XPos, int YPos)
{
printf("\033[%d;%dH",YPos+1,XPos+1);
}
void getCursor(int* x, int* y) {
void getCursor(int* x, int* y)
{
printf("\033[6n");
scanf("\033[%d;%dR", x, y);
}
@@ -122,13 +127,14 @@ void writeAt(int x, int y, char ch)
fflush(stdout);
}
void clearScreen() {
void closeScreen()
{
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
clearScreen(w.ws_col, w.ws_row);
closeScreen(w.ws_col, w.ws_row);
}
void clearScreen(short width, short height)
void closeScreen(short width, short height)
{
setCursor(0, 0);
for (int i = 0; i < height; i++)
@@ -149,7 +155,8 @@ void printFrame(vector<vector<char>> screen, short width, short height)
//cout << endl;
}
setCursor(0,0);
/*for (auto& col : screen) {
/*for (auto& col : screen)
{
for (auto& ch : col)
cout << ch;
cout << endl;
@@ -163,7 +170,8 @@ void screen_type(vector<vector<char>> &screen, string str, int x, int y, bool ve
int width = 0,
height = 0;
if (str.length()) {
if (str.length())
{
//str.append("\033[0m");
@@ -181,15 +189,25 @@ void screen_type(vector<vector<char>> &screen, string str, int x, int y, bool ve
}
for (int i = x, ii = 0, d = 0; ii < width; i++, ii++)
for (int j = y, jj = 0; jj < height; j++, jj++, d++) {
for (int j = y, jj = 0; jj < height; j++, jj++, d++)
{
//cout << str.at(d) << " " << i << "," << j << endl;
screen.at(i).at(j) = str.at(d);
}
}
void screen_clear(vector<vector<char>> &screen)
{
for (int i = 0; i < screen.size(); i++)
for (int j = 0; j < screen.at(i).size(); j++)
screen.at(i).at(j) = ' ';
}
void eachFrame(vector<vector<char>> &screen, short width, short height)
{
screen_clear(screen);
stringstream ss;
//ss << width << "x" << height;