V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
laobaozi
V2EX  ›  C

搞过 necurses 前辈请教一个问题: 在清除 window 的 border 时,左上角总会残留是什么情况

  •  
  •   laobaozi · 2016-11-29 22:12:04 +08:00 · 1816 次点击
    这是一个创建于 2907 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在按下方向右键时,光标会先向右移动一位,

    x----0        x----o          xx----o      xxxx----o
    |    |   ->    |    |   ->	   |    |  ->     |    |
    x----o         x----o          X----o         x----o
    

    需要再次按下方向右键才会右移,但是左上角的字符会清理不掉,但是别的方向键没有这个现象,问题出在哪里呢 代码很简单:

    #include <ncurses.h>
    #include <locale.h>
    
    WINDOW *create_new_window(int height, int width, int start_y, int start_x);
    void destroy_window(WINDOW *win);
    
    int main(int argc, char *argv[])
    {
        WINDOW *my_win;
    
        int start_x, start_y, width, height;
        int ch;
    
        setlocale(LC_ALL, "");
        initscr();
        raw();
        keypad(stdscr, TRUE);
        height = 4;
        width = 8;
        start_y = (LINES - height) / 2;
        start_x = (COLS - width) / 2 + 1;
        printw("按下 F1 退出");
        refresh();
    
        my_win = create_new_window(height, width, start_y, start_x);
        while((ch = getch()) != KEY_F(1))
        {
    
            switch (ch)
            {
                case KEY_UP:
                    destroy_window(my_win);
                    my_win = create_new_window(height, width, --start_y, start_x);
                    break;
                case KEY_RIGHT:
                    destroy_window(my_win);
                    my_win = create_new_window(height, width, start_y, ++start_x);
                    break;
                case KEY_DOWN:
                    destroy_window(my_win);
                    my_win = create_new_window(height, width, ++start_y, start_x);
                    break;
                case KEY_LEFT:
                    destroy_window(my_win);
                    my_win = create_new_window(height, width, start_y, --start_x);
                    break;
            }
        }
    
        endwin();
        return 0;
    
    }
    
    WINDOW *create_new_window(int height, int width, int start_y, int start_x)
    {
        WINDOW *window;
        window = newwin(height, width, start_y, start_x);
    
        wborder(window, '|', '|', '-', '-', 'x', 'o', 'x', 'o');
    
        wrefresh(window);
        return window;
    }
    
    
    void destroy_window(WINDOW *window)
    {
        wborder(window, 1, 1, 1, 1, 1, 1, 1, 1);
        wrefresh(window);
        delwin(window);
    }
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3421 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:54 · PVG 12:54 · LAX 20:54 · JFK 23:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.