Added color mode
This commit is contained in:
31
nclock.c
31
nclock.c
@@ -28,6 +28,21 @@ int main(int argc, char **argv) {
|
|||||||
sa.sa_handler = handle_winch;
|
sa.sa_handler = handle_winch;
|
||||||
sigaction(SIGWINCH, &sa, NULL);
|
sigaction(SIGWINCH, &sa, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
start_color(); //Enables multi color mode
|
||||||
|
|
||||||
|
/* Initialize custom color pairs */
|
||||||
|
/* Color pair index must be > 0 */
|
||||||
|
/* init_pair(index, foreground color, background color); */
|
||||||
|
/* Color pairs are called by attron(COLOR_PAIR(1)); */
|
||||||
|
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
||||||
|
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||||
|
init_pair(3, COLOR_RED, COLOR_BLACK);
|
||||||
|
init_pair(4, COLOR_YELLOW, COLOR_BLACK);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Define the state struct
|
//Define the state struct
|
||||||
state s = {0};
|
state s = {0};
|
||||||
|
|
||||||
@@ -47,18 +62,22 @@ void initState(state *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void drawNumber(int starty, int startx, int num) {
|
void drawNumber(int starty, int startx, int num) {
|
||||||
|
static int currentColor = 0;
|
||||||
|
if (++currentColor > 4) {
|
||||||
|
currentColor = 1;
|
||||||
|
}
|
||||||
int i, j, numarr[2];
|
int i, j, numarr[2];
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
numarr[i] = num % 10;
|
numarr[i] = num % 10;
|
||||||
num /= 10;
|
num /= 10;
|
||||||
}
|
}
|
||||||
|
enColor(currentColor);
|
||||||
for (j = 0; j < 2; j++) {
|
for (j = 0; j < 2; j++) {
|
||||||
for (i = 0; i < 5; i++) {
|
for (i = 0; i < 5; i++) {
|
||||||
mvprintw(starty + i, startx + (6 * j), number[numarr[1 - j]][i]);
|
mvprintw(starty + i, startx + (6 * j), number[numarr[1 - j]][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
disColor(currentColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawColon(int starty, int startx) {
|
void drawColon(int starty, int startx) {
|
||||||
@@ -96,3 +115,11 @@ void draw(state *s) {
|
|||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enColor(int color) {
|
||||||
|
attron(COLOR_PAIR(color));
|
||||||
|
}
|
||||||
|
|
||||||
|
void disColor(int color) {
|
||||||
|
attroff(COLOR_PAIR(color));
|
||||||
|
}
|
||||||
|
2
nclock.h
2
nclock.h
@@ -18,3 +18,5 @@ void drawNumber(int starty, int startx, int num);
|
|||||||
void drawTime(state *s, int hour, int min, int sec);
|
void drawTime(state *s, int hour, int min, int sec);
|
||||||
void drawColon(int starty, int startx);
|
void drawColon(int starty, int startx);
|
||||||
void draw(state *s);
|
void draw(state *s);
|
||||||
|
void enColor(int color);
|
||||||
|
void disColor(int color);
|
||||||
|
Reference in New Issue
Block a user