不确定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在运行时创建窗口?
答案 0 :(得分:1)
(n)curses函数newwin
为WINDOW
结构分配空间并返回该结构。 stdscr
和curscr
窗口同样在<{3}}或newterm
中使用newwin
进行分配。 stdscr
和curscr
与其他窗口之间的主要区别在于,它们以预定义的方式在整个库中使用,并且无法释放。可以使用initscr
释放其他窗口。这些都不是“静态的”。
相应的手册页有此基本信息。
ncurses delwin
显示如何创建在代码中不明确的窗口,例如,提示用户移动光标以开始创建窗口,然后移动以选择结束(左上角)与右下角相对,在下面的菜单项g
中)。同样地,一些使用递归,例如,绘制一系列嵌套的盒装窗口(下面的菜单项a
或A
,用于测试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
>