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