Skip to content

Commit

Permalink
Add move()/put() function and make Logo variables private
Browse files Browse the repository at this point in the history
  • Loading branch information
applearon committed Aug 1, 2024
1 parent caf2f4a commit 8263348
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 20 deletions.
32 changes: 27 additions & 5 deletions src/logo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ std::vector<std::string> getLogoFromFile(char *filename, int *logo_len, int *num
}

Logo::Logo(int y, int x, int height, int length, std::vector<std::string> &logo) {
this->pos = {y, x};
this->position = {y, x};
this->size = {height, length};
this->logo = logo;
};

bool Logo::print() {
move(pos.y, pos.x);
::move(position.y, position.x);
attron(COLOR_PAIR(1));
for (int i = 0; i < size.y; ++i) {
move(pos.y + i, pos.x);
::move(position.y + i, position.x);
printw("%s", logo[i].data());
}
attroff(COLOR_PAIR(1));
Expand All @@ -54,9 +54,31 @@ bool Logo::print() {
bool Logo::clear() {
std::string tmp(size.x, ' ');
for (int i = 0; i < size.y; ++i) {
move(pos.y + i, pos.x);
::move(position.y + i, position.x);
printw("%s", tmp.data());
}
return true;
}
}

bool Logo::move(int y, int x, const pos &min_size, const pos &max_size) {
clear();
this->position.y += y;
this->position.x += x;
print();
return true;
}

bool Logo::put(int y, int x, const pos &min_size, const pos &max_size) {
clear();
this->position.y = y;
this->position.x = x;
print();
return true;
}

const pos Logo::getPos() {
return this->position;
}
const pos Logo::getSize() {
return this->size;
}
11 changes: 8 additions & 3 deletions src/logo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ struct pos {
class Logo {

public:
struct pos pos;
struct pos size;
std::vector<std::string> logo;
Logo(int y, int x, int height, int length, std::vector<std::string> &logo);
bool move(int y, int x, const pos &min_size, const pos &max_size);
bool put(int y, int x, const pos &min_size, const pos &max_size);
bool print();
bool clear();

const pos getPos();
const pos getSize();
private:
pos position;
pos size;
std::vector<std::string> logo;
};

#endif
23 changes: 11 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ void *mainLoop(void *inp) {
int y_dir = -1;
int y_mag = 1, x_mag = 2; // Slope

//int x = 20,y = 20;
logo.pos = {20, 20};
int times = 0;
int fadeOut = 2 + 0; // n showing at any time
std::vector<int> lastFiveX(fadeOut);
Expand Down Expand Up @@ -95,28 +93,29 @@ void *mainLoop(void *inp) {
move(0,0);
printw("%d\n%d", input, color / 5);
}
if (logo.pos.y >= cols - logo.size.y) {
if (logo.getPos().y >= cols - logo.getSize().y) {
y_dir = -1;
} else if (logo.pos.y <= 0) {
} else if (logo.getPos().y <= 0) {
y_dir = 1;
}
if (logo.pos.x >= rows - logo.size.x) {
if (logo.getPos().x >= rows - logo.getSize().x) {
x_dir = -1;
} else if (logo.pos.x <= 1) {
} else if (logo.getPos().x <= 1) {
x_dir = 1;
}
logo.clear();
logo.pos.y += y_dir * y_mag;
logo.pos.x += x_dir * x_mag;
//logo.clear();
//logo.pos.y += y_dir * y_mag;
//logo.pos.x += x_dir * x_mag;
if (gay) {
color = (color % 70) + 1;
init_pair(1, (color / 10) + 1, COLOR_BLACK);
}
times = (times + 1) % fadeOut;
lastFiveX[times] = logo.pos.x;
lastFiveY[times] = logo.pos.y;
lastFiveX[times] = logo.getPos().x;
lastFiveY[times] = logo.getPos().y;
prevFrame = curFrame;
logo.print();
logo.move(y_dir * y_mag, x_dir * x_mag, {0, 0}, {rows, cols});
//logo.print();
//clearLogo(lastFiveY[(times + 1) % fadeOut], lastFiveX[(times + 1) % fadeOut], logo_len, logo_height);
//printLogo(logo, y, x, logo_len, logo_height);
refresh();
Expand Down

0 comments on commit 8263348

Please sign in to comment.