0

I'm new to stackoverflow.com so I'll do my best to explain my problem :)

I'm currently working on an "arcade game" project for my school and I have made a menu using ncurses where I can choose games / graphical library to use. I have made this menu resizeable so when the terminal shrunk, I move the windows and resize them (layout-like). Now I have to incorporate a text field to enter your name and I want that to be resizeable as well.

I have a FIELD inside a FORM inside a WINDOW in my program and no matter what I do, the window moves but the field stay in place...

I have made a test-program where I try to move a text field using arrow keys. As expected the little box (the window) moves but not the field.

#include <curses.h>
#include <form.h>

void move_window(WINDOW *window, int y, int x)
{
    //clear();
    wclear(window); // DON'T KNOW WHY IT DOESN'T CLEAR SCREEN
    mvprintw(0, 0, "Y[%d] : X[%d]", y, x);
    mvwin(window, y - 1, x - 1);
    box(window, 0, 0);
    wrefresh(window);
    //refresh();
}

int main()
{
    WINDOW *window;
    FIELD *fields[2];
    FORM *form;
    int x = 20;
    int y = 20;
    int ch;

    initscr();
    keypad(stdscr, TRUE);
    noecho();
    cbreak();

    fields[0] = new_field(1, 10, y, x, 0, 0);
    fields[1] = NULL;
    set_field_opts(fields[0], O_VISIBLE | O_PUBLIC | O_EDIT | O_ACTIVE | O_STATIC);
    set_field_back(fields[0], A_UNDERLINE);
    window = newwin(3, 12, y - 1, x - 1);
    form = new_form(fields);
    set_form_win(form, window);
    post_form(form);
    refresh();
    move_window(window, y, x);

    while ((ch = getch()) != 27) {
        switch (ch) {
            case KEY_LEFT:
                x--;
                move_window(window, y, x);
                break;
            case KEY_RIGHT:
                x++;
                move_window(window, y, x);
                break;
            case KEY_UP:
                y--;
                move_window(window, y, x);
                break;
            case KEY_DOWN:
                y++;
                move_window(window, y, x);
                break;
            case KEY_BACKSPACE:
            case 127:
                form_driver(form, REQ_DEL_PREV);
                break;
            default:
                form_driver(form, ch);
                break;
        }
    }
    unpost_form(form);
    free_form(form);
    free_field(fields[0]);
    endwin();
    return 0;
}

I compile using : gcc ncurse.cpp -lncurses -lform && ./a.out

Can you explain to me what I am doing wrong in this ? I didn't found anything to solve this myself :/

PS : Sorry for my rusty english...

Maxime B.
  • 1
  • 1

0 Answers0