diff --git a/Makefile b/Makefile index 4e7c8b1..4b0a104 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ SRC = $(addprefix $(SRC_DIR), $(SRC_FILE)) OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILE)) INC = $(addprefix $(INC_DIR), $(INC_FILE)) -LIB = +LIB = -lncurses CC = gcc diff --git a/example.c b/example.c new file mode 100644 index 0000000..d5e0ea7 --- /dev/null +++ b/example.c @@ -0,0 +1,82 @@ +#include + + +WINDOW *create_newwin(int height, int width, int starty, int startx); +void destroy_win(WINDOW *local_win); + +int main(int argc, char *argv[]) +{ WINDOW *my_win; + int startx, starty, width, height; + int ch; + + initscr(); /* Start curses mode */ + cbreak(); /* Line buffering disabled, Pass on + * everty thing to me */ + keypad(stdscr, TRUE); /* I need that nifty F1 */ + + height = 3; + width = 10; + starty = (LINES - height) / 2; /* Calculating for a center placement */ + startx = (COLS - width) / 2; /* of the window */ + printw("Press F1 to exit"); + refresh(); + my_win = create_newwin(height, width, starty, startx); + + while((ch = getch()) != KEY_F(1)) + { switch(ch) + { case KEY_LEFT: + destroy_win(my_win); + my_win = create_newwin(height, width, starty,--startx); + break; + case KEY_RIGHT: + destroy_win(my_win); + my_win = create_newwin(height, width, starty,++startx); + break; + case KEY_UP: + destroy_win(my_win); + my_win = create_newwin(height, width, --starty,startx); + break; + case KEY_DOWN: + destroy_win(my_win); + my_win = create_newwin(height, width, ++starty,startx); + break; + } + } + + endwin(); /* End curses mode */ + return 0; +} + +WINDOW *create_newwin(int height, int width, int starty, int startx) +{ WINDOW *local_win; + + local_win = newwin(height, width, starty, startx); + box(local_win, 0 , 0); /* 0, 0 gives default characters + * for the vertical and horizontal + * lines */ + wrefresh(local_win); /* Show that box */ + + return local_win; +} + +void destroy_win(WINDOW *local_win) +{ + /* box(local_win, ' ', ' '); : This won't produce the desired + * result of erasing the window. It will leave it's four corners + * and so an ugly remnant of window. + */ + wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); + /* The parameters taken are + * 1. win: the window on which to operate + * 2. ls: character to be used for the left side of the window + * 3. rs: character to be used for the right side of the window + * 4. ts: character to be used for the top side of the window + * 5. bs: character to be used for the bottom side of the window + * 6. tl: character to be used for the top left corner of the window + * 7. tr: character to be used for the top right corner of the window + * 8. bl: character to be used for the bottom left corner of the window + * 9. br: character to be used for the bottom right corner of the window + */ + wrefresh(local_win); + delwin(local_win); +} \ No newline at end of file diff --git a/inc/ncurses.h b/inc/ncurses.h index 0fc96cf..c6c740c 100644 --- a/inc/ncurses.h +++ b/inc/ncurses.h @@ -2,8 +2,8 @@ #define __NCURSES__ + #include #include "macros.h" #endif - \ No newline at end of file diff --git a/src/main.c b/src/main.c index ff5ed9a..129ac08 100644 --- a/src/main.c +++ b/src/main.c @@ -4,5 +4,30 @@ int main(int argc, char **argv) { (void)argc; (void)argv; - return (SUCCESS); + const int height = 3; + const int width = 4; + WINDOW *game; + + initscr(); + cbreak(); + game = newwin(height, width, 0, 0); + box(game, 0, 0); + wrefresh(game); + // start_color(); + // init_pair(0, COLOR_BLACK, COLOR_RED); + // init_pair(1, COLOR_BLACK, COLOR_GREEN); + // attron(COLOR_PAIR(0)); + // wprintw(game, "^[[0;31;40m"); + // wprintw(game, "Hello World !!!"); + // for (int i = 0; i < argc; i++) + // { + // attron(COLOR_PAIR(1 - i % 2)); + // wprintw(game, argv[i]); + // wprintw(game, " "); + // } + // wrefresh(game); + wgetch(game); + endwin(); + + return SUCCESS; }