使用ncurses在运行时创建动态窗口

时间:2015-04-27 06:42:09

标签: dynamic window ncurses creation

不确定ncurses是否可以实现这一点。所有文档和示例都表明在编译时已知多个窗口的创建。 我想做这样的事情。

 #include <ncurses.h>

WINDOW *create_newwin(int height, int width, int starty, int startx);
void star(int x,int y,int r);
 void newbox(int x,int y,int r);

int main(int argc, char *argv[])
{       
    int startx, starty, width, height;
    int ch,sze;

    initscr();                      /* Start curses mode            */
    cbreak();                       /* Line buffering disabled, Pass on
                                     * everty thing to me           */
    //printf("%s\n",argv[1]);
    sze = atoi(argv[1]);
    starty = (LINES - sze) / 2;  /* Calculating for a center placement */
    startx = (COLS - sze) / 2;    /* of the window                */

    refresh();
    star(startx,starty,sze);

    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 star(int x,int y,int r)
{
if(r>0)
{
star(x-r,y+r,r/2);
star(x+r,y+r,r/2);
star(x-r,y-r,r/2);
star(x+r,y-r,r/2);
 newbox(x,y,r);
 }
}

void newbox(int x,int y,int r)
 {
  WINDOW *mywin;
   mywin = create_newwin(2*r, 2*r, y, x);
 }

我认为你会使用new关键字和malloc。我希望的目标是生成一种具有重叠窗口的分形显示。函数星是递归的,它将创建传递给newbox函数的参数。那里的任何人都使用ncurses在运行时创建窗口?

1 个答案:

答案 0 :(得分:1)

(n)curses函数newwinWINDOW结构分配空间并返回该结构。 stdscrcurscr窗口同样在<{3}}或newterm中使用newwin进行分配stdscrcurscr与其他窗口之间的主要区别在于,它们以预定义的方式在整个库中使用,并且无法释放。可以使用initscr释放其他窗口。这些都不是“静态的”。

相应的手册页有此基本信息。

ncurses delwin显示如何创建在代码中不明确的窗口,例如,提示用户移动光标以开始创建窗口,然后移动以选择结束(左上角)与右下角相对,在下面的菜单项g中)。同样地,一些使用递归,例如,绘制一系列嵌套的盒装窗口(下面的菜单项aA,用于测试example programs)。这些都在主测试程序中完成,其菜单如下所示:

Welcome to ncurses 5.9.20150502.  Press ? for help.
This is the ncurses main menu
a = keyboard and mouse input test
A = wide-character keyboard and mouse input test
b = character attribute test
B = wide-character attribute test
c = color test pattern
C = color test pattern using wide-character calls
d = edit RGB color values
e = exercise soft keys
E = exercise soft keys using wide-characters
f = display ACS characters
F = display Wide-ACS characters
g = display windows and scrolling
i = test of flushinp()
k = display character attributes
m = menu code test
o = exercise panels library
O = exercise panels with wide-characters
p = exercise pad features
q = quit
r = exercise forms code
s = overlapping-refresh test
t = set trace level
? = repeat this command summary
> 
相关问题