1

当我执行此代码时,我创建的边框的左侧将在右上角的框中被覆盖。即使代码看起来相同,问题似乎也仅限于该区域。如何防止它覆盖我的边框?我正在使用 g++ -lncurses 编译并在 Ubuntu 终端中运行

#include <ncurses.h>
#include <string.h> 
#define WINDOWY 24
#define WINDOWX 80
#define ROW1 3
#define RROW1 1
#define COL1 2
#define COL2 23
#define COL3 33 
#define COL4 38
#define MEMORYROW 9
#define MEMORYCOL 1
#define COMMANDROW 1
#define COMMANDCOL 41


int closeUp(void);
void printMockup(void);
void drawBorders(void);
WINDOW *create_newwin(int height, int width, int starty, int startx);

int main()
{
    char input = ' ';
    int row,col;    

    //initialize ncurses stuff
    initscr();      
    cbreak();
    curs_set(0);

    //check window is right size
    getmaxyx(stdscr,row,col);
    if (row < WINDOWY || col < WINDOWX)
    {
        printw("You need to increase the terminal size to at least 24 x 70");
        return closeUp();
    }

    //draw border
    drawBorders();

    //draw UI
    printMockup();

    getch();
    endwin();

    return 0;
}



int closeUp(void)
{
    getch();
    endwin();
    return 0;
}



void printMockup(void)
{
    mvprintw(1, 2, "6808 Emulator");
    mvprintw(ROW1, COL1, "Accumulator:");
    mvprintw(ROW1, COL2, "0x00");
    mvprintw(ROW1+1, COL1, "Program Counter:");
    mvprintw(ROW1+1, COL2, "0x0000");
    mvprintw(ROW1+2, COL1, "Stack Pointer:");
    mvprintw(ROW1+2, COL2, "0x0000");
    mvprintw(ROW1+3, COL1, "Index Register Low:");
    mvprintw(ROW1+3, COL2, "0x00");
    mvprintw(ROW1+4, COL1, "Index Register High:");
    mvprintw(ROW1+4, COL2, "0x00");

    mvprintw(RROW1, COL3, "PC:");
    mvprintw(RROW1, COL4, "0");
    mvprintw(RROW1+1, COL3, "C:");
    mvprintw(RROW1+1, COL4, "0");
    mvprintw(RROW1+2, COL3, "Z:");
    mvprintw(RROW1+2, COL4, "0");
    mvprintw(RROW1+3, COL3, "N:");
    mvprintw(RROW1+3, COL4, "0");
    mvprintw(RROW1+4, COL3, "I:");
    mvprintw(RROW1+4, COL4, "0");
    mvprintw(RROW1+5, COL3, "H:");
    mvprintw(RROW1+5, COL4, "0");
    mvprintw(RROW1+6, COL3, "V:");
    mvprintw(RROW1+6, COL4, "0");

    mvprintw(COMMANDROW+1, COMMANDCOL+11, "r - Run");
    mvprintw(COMMANDROW+2, COMMANDCOL+11, "s - Step");
    mvprintw(COMMANDROW+3, COMMANDCOL+11, "a - Auto-step");
    mvprintw(COMMANDROW+4, COMMANDCOL+11, "x - Reset");
    mvprintw(COMMANDROW+5, COMMANDCOL+11, "m - Main menu");

    mvprintw(MEMORYROW+1, MEMORYCOL+1, "PC:");
    mvprintw(MEMORYROW+1, MEMORYCOL+1, "0");

}



WINDOW *create_newwin(int height, int width, int starty, int startx)
{   
    WINDOW *local_win;

    local_win = newwin(height, width, starty, startx);
    //wborder(local_win, '|', '|', '-', '-', '+', '+', '+', '+');
    box(local_win, 0 , 0);
    wrefresh(local_win);

    return local_win;
}



void drawBorders(void)
{
    refresh();
    create_newwin(WINDOWY, WINDOWX, 0, 0);
    create_newwin(WINDOWY-(WINDOWY-MEMORYROW-1)-2, WINDOWX-COMMANDCOL-1, COMMANDROW, COMMANDCOL);
    create_newwin(WINDOWY-MEMORYROW-1, WINDOWX-MEMORYCOL-1, MEMORYROW, MEMORYCOL);
}
4

1 回答 1

0

您通常会打印到一个窗口中,然后刷新它。对于这个特殊问题,我们可以通过只关注您的“命令窗口”来解决它。给定代码的结构,创建一个全局变量来保存命令窗口指针。

WINDOW *command_window;

然后,从您的drawBorders()函数初始化它。

command_window = create_newwin(WINDOWY-(WINDOWY-MEMORYROW-1)-2,
                               WINDOWX-COMMANDCOL-1,
                               COMMANDROW, COMMANDCOL);

修改将命令打印到主窗口的代码以将其打印到主窗口中command_window。然后,刷新command_window.

mvwprintw(command_window, 1, 11, "r - Run");
mvwprintw(command_window, 2, 11, "s - Step");
mvwprintw(command_window, 3, 11, "a - Auto-step");
mvwprintw(command_window, 4, 11, "x - Reset");
mvwprintw(command_window, 5, 11, "m - Main menu");
wrefresh(command_window);
于 2013-03-08T01:04:11.450 回答