/* */
/******************************************************************************/
+/*
+ * $Id: xmas.c,v 1.12 1998/01/18 01:13:47 tom Exp $
+ */
#include <test.priv.h>
#include <signal.h>
#define FROMWHO "Mark Hessling - (M.Hessling@gu.edu.au)"
+static int my_bg = COLOR_BLACK;
static int y_pos, x_pos;
static WINDOW
static int blinkit(void);
static RETSIGTYPE done(int sig) GCC_NORETURN ;
+static void
+set_color(WINDOW *win, chtype color)
+{
+ if (has_colors()) {
+ static bool *pairs;
+ int n = (color + 1);
+ if (pairs == 0)
+ pairs = (bool *)calloc(COLORS+1, sizeof(bool));
+ if (!pairs[n]) {
+ init_pair(n, color, my_bg);
+ pairs[n] = TRUE;
+ }
+ wattroff(win, A_COLOR);
+ wattron(win, COLOR_PAIR(n));
+ }
+}
+
+static void
+unset_color(WINDOW *win)
+{
+ if (has_colors())
+ wattrset(win, COLOR_PAIR(0));
+}
+
+static void
+look_out(int msecs)
+{
+ napms(msecs);
+ if (getch() != ERR) {
+ beep();
+ done(0);
+ }
+}
+
int main(
int argc GCC_UNUSED,
char **argv GCC_UNUSED)
signal(SIGHUP,done);
signal(SIGQUIT,done);
#endif
+ if (has_colors()) {
+ start_color();
+#ifdef NCURSES_VERSION
+ if (use_default_colors() == OK)
+ my_bg = -1;
+#endif
+ }
+ curs_set(0);
treescrn = newwin(16,27,3,53);
treescrn2 = newwin(16,27,3,53);
/***********************************************/
cbreak();
nodelay(stdscr,TRUE);
- do {
+ for (;;) {
clear();
werase(treescrn);
touchwin(w_del_msg);
werase(treescrn8);
touchwin(treescrn8);
refresh();
- napms(150);
+ look_out(150);
boxit();
refresh();
- napms(150);
+ look_out(150);
seas();
refresh();
- napms(150);
+ look_out(150);
greet();
refresh();
- napms(150);
+ look_out(150);
fromwho();
refresh();
- napms(150);
+ look_out(150);
tree();
- napms(150);
+ look_out(150);
balls();
- napms(150);
+ look_out(150);
star();
- napms(150);
+ look_out(150);
strng1();
strng2();
strng3();
mvwaddch(treescrn7, 12, 14, ' ');
- napms(150);
+ look_out(150);
reindeer();
touchwin(w_holiday);
wrefresh(w_holiday);
wrefresh(w_del_msg);
- napms(500);
+ look_out(500);
for(loopy = 0;loopy < 100;loopy++) {
blinkit();
}
#ifdef NOLOOP
done(0);
#endif
-
}
- while(getch() == (ERR));
-/* while(!typeahead(stdin));*/
- done(0);
/*NOTREACHED*/
}
static int tree(void)
{
+ set_color(treescrn, COLOR_GREEN);
mvwaddch(treescrn, 1, 11, (chtype)'/');
mvwaddch(treescrn, 2, 11, (chtype)'/');
mvwaddch(treescrn, 3, 10, (chtype)'/');
mvwaddstr(treescrn, 14, 11, "| |");
mvwaddstr(treescrn, 15, 11, "|_|");
+ unset_color(treescrn);
wrefresh(treescrn);
wrefresh(w_del_msg);
static int balls(void)
{
-
overlay(treescrn, treescrn2);
+ set_color(treescrn2, COLOR_BLUE);
mvwaddch(treescrn2, 3, 9, (chtype)'@');
mvwaddch(treescrn2, 3, 15, (chtype)'@');
mvwaddch(treescrn2, 4, 8, (chtype)'@');
mvwaddch(treescrn2, 12, 1, (chtype)'@');
mvwaddch(treescrn2, 12, 23, (chtype)'@');
+ unset_color(treescrn2);
wrefresh(treescrn2);
wrefresh(w_del_msg);
return( 0 );
static int star(void)
{
- wstandout(treescrn2);
+ wattrset(treescrn2, A_BOLD | A_BLINK);
+ set_color(treescrn2, COLOR_YELLOW);
+
mvwaddch(treescrn2, 0, 12, (chtype)'*');
wstandend(treescrn2);
+ unset_color(treescrn2);
wrefresh(treescrn2);
wrefresh(w_del_msg);
return( 0 );
static int strng1(void)
{
+ wattrset(treescrn2, A_BOLD | A_BLINK);
+ set_color(treescrn2, COLOR_WHITE);
+
mvwaddch(treescrn2, 3, 13, (chtype)'\'');
mvwaddch(treescrn2, 3, 12, (chtype)':');
mvwaddch(treescrn2, 3, 11, (chtype)'.');
+ wattroff(treescrn2, A_BOLD | A_BLINK);
+ unset_color(treescrn2);
+
wrefresh(treescrn2);
wrefresh(w_del_msg);
return( 0 );
static int strng2(void)
{
+ wattrset(treescrn2, A_BOLD | A_BLINK);
+ set_color(treescrn2, COLOR_WHITE);
+
mvwaddch(treescrn2, 5, 14, (chtype)'\'');
mvwaddch(treescrn2, 5, 13, (chtype)':');
mvwaddch(treescrn2, 5, 12, (chtype)'.');
mvwaddch(treescrn2, 6, 10, (chtype)'\'');
mvwaddch(treescrn2, 6, 9, (chtype)':');
+ wattroff(treescrn2, A_BOLD | A_BLINK);
+ unset_color(treescrn2);
+
wrefresh(treescrn2);
wrefresh(w_del_msg);
return( 0 );
static int strng3(void)
{
+ wattrset(treescrn2, A_BOLD | A_BLINK);
+ set_color(treescrn2, COLOR_WHITE);
+
mvwaddch(treescrn2, 7, 16, (chtype)'\'');
mvwaddch(treescrn2, 7, 15, (chtype)':');
mvwaddch(treescrn2, 7, 14, (chtype)'.');
mvwaddch(treescrn2, 8, 10, (chtype)'.');
mvwaddch(treescrn2, 8, 9, (chtype)',');
+ wattroff(treescrn2, A_BOLD | A_BLINK);
+ unset_color(treescrn2);
+
wrefresh(treescrn2);
wrefresh(w_del_msg);
return( 0 );
static int strng4(void)
{
+ wattrset(treescrn2, A_BOLD | A_BLINK);
+ set_color(treescrn2, COLOR_WHITE);
+
mvwaddch(treescrn2, 9, 17, (chtype)'\'');
mvwaddch(treescrn2, 9, 16, (chtype)':');
mvwaddch(treescrn2, 9, 15, (chtype)'.');
mvwaddch(treescrn2, 11, 6, (chtype)',');
mvwaddch(treescrn2, 12, 5, (chtype)'\'');
+ wattroff(treescrn2, A_BOLD | A_BLINK);
+ unset_color(treescrn2);
+
wrefresh(treescrn2);
wrefresh(w_del_msg);
return( 0 );
static int strng5(void)
{
+ wattrset(treescrn2, A_BOLD | A_BLINK);
+ set_color(treescrn2, COLOR_WHITE);
+
mvwaddch(treescrn2, 11, 19, (chtype)'\'');
mvwaddch(treescrn2, 11, 18, (chtype)':');
mvwaddch(treescrn2, 11, 17, (chtype)'.');
mvwaddch(treescrn2, 12, 13, (chtype)'.');
mvwaddch(treescrn2, 12, 12, (chtype)',');
+ wattroff(treescrn2, A_BOLD | A_BLINK);
+ unset_color(treescrn2);
+
/* save a fully lit tree */
overlay(treescrn2, treescrn);
mvwin(win, y, x);
wrefresh(win);
wrefresh(w_del_msg);
- napms(5);
+ look_out(5);
}
static int reindeer(void)
werase(dotdeer0);
wrefresh(dotdeer0);
wrefresh(w_del_msg);
- napms(50);
+ look_out(50);
}
}
}
}
- napms(300);
+ look_out(300);
y_pos = 1;
signal(SIGHUP,done);
signal(SIGQUIT,done);
#endif
- clear();
+ move(LINES-1,0);
refresh();
endwin();
+ curs_set(1);
exit(EXIT_SUCCESS);
}