#include <ncurses.h>
// // 가상 윈도우를 만들어 본다 // #include <ncurses.h>
WINDOW *create_newwin(int height, int width, int starty, int startx); void destroy_win(WINDOW *local_win);
int main(void) { WINDOW *my_win; int startx, starty, width, height; int ch;
initscr(); /* Start curses mode */
keypad(stdscr, TRUE); /* I need that nifty F8 */
// sector #01 cbreak(); /* Line buffering disabled, Pass on everty thing to me */
height = 9; width = 30;
starty = (LINES - height) / 2; /* Calculating for a center placement */ startx = (COLS - width) / 2; /* of the window */
printw("Press F8 to exit"); refresh();
// sector #02 my_win = create_newwin(height, width, starty, startx);
// sector #03 while((ch = getch()) != KEY_F(8)) { switch(ch) { case KEY_LEFT: // sector #04 destroy_win(my_win); my_win = create_newwin(height, width, starty, --startx); // sector #05 wprintw(my_win,"left"); wrefresh(my_win); break; case KEY_RIGHT: destroy_win(my_win); my_win = create_newwin(height, width, starty,++startx); wprintw(my_win,"right"); wrefresh(my_win); break; case KEY_UP: destroy_win(my_win); my_win = create_newwin(height, width, --starty,startx); wprintw(my_win,"up"); wrefresh(my_win); break; case KEY_DOWN: destroy_win(my_win); my_win = create_newwin(height, width, ++starty,startx); wprintw(my_win,"down"); wrefresh(my_win); break; } } endwin(); /* End curses mode */ return 0; }
WINDOW *create_newwin(int height, int width, int starty, int startx) { WINDOW *local_win;
// sector #06 local_win = newwin(height, width, starty, startx);
// sector #07 #if 1 box(local_win, 0 , 0); /* 0, 0 gives default characters for the vertical and horizontal lines */ #else wborder(local_win, '|', '|', '.', '.', '+', '+', '+', '+'); #endif 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. */ // sector #08 wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' '); /* The parameters taken are * 1. win: the window on which to operate * 2. ls: 윈도우 좌 라인 * 3. rs: 윈도우 우 라인 * 4. ts: 윈도우 상 라인 * 5. bs: 윈도우 하 라인 * 6. tl: 윈도우 좌상 포인트 * 7. tr: 윈도우 우상 포인트 * 8. bl: 윈도우 좌하 포인트 * 9. br: 윈도우 우하 포인트 */ wrefresh(local_win); delwin(local_win); }
/* 07_window.c */
|