Exemplo n.º 1
0
int ggiGetc(ggi_visual_t vis)
{
	gii_event ev;

	/* Block until we get a key. */
	giiEventRead(vis->input, &ev, emKeyPress | emKeyRepeat);

	return ev.key.sym;
}
Exemplo n.º 2
0
int ggiEventRead(ggi_visual *vis, gii_event *ev, gii_event_mask mask)
{
	return giiEventRead(vis->input, ev, mask);
}
Exemplo n.º 3
0
Arquivo: menu.c Projeto: antrik/libggi
int do_menu(struct menu * m , int selected)
{

    /* select a menu item by either a number or with arrow keys */

    int i;

    int evmask;
    gii_event ev;
    struct timeval t= {0,0};
    int oldselection = selected;

    draw_window(&m->w);

    if (m->toptext != NULL) {
        ggiSetGCForeground(m->w.vis,
                           ggiMapColor(m->w.vis,&m->toptextcolor));
        /* FIXME*/
        ggiPuts(m->w.vis, m->w.xorigin+m->toptextx,
                m->w.yorigin+m->toptexty, m->toptext);
    }

    if (m->bottomtext != NULL) {
        ggiSetGCForeground(m->w.vis,
                           ggiMapColor(m->w.vis,&m->bottomtextcolor));
        /* FIXME*/
        ggiPuts(m->w.vis, m->w.xorigin+m->bottomtextx,
                m->w.yorigin+m->bottomtexty, m->bottomtext);
    }

    for (i = 0; i<=m->lastentry; i++) {
        if (i!=selected) {
            ggiSetGCForeground(m->w.vis,
                               ggiMapColor(m->w.vis,&m->entrycolor));
            ggiSetGCBackground(m->w.vis,
                               ggiMapColor(m->w.vis,&m->w.backgroundcolor));
        } else {
            ggiSetGCForeground(m->w.vis,
                               ggiMapColor(m->w.vis,&m->selectedcolor));
            ggiSetGCBackground(m->w.vis,
                               ggiMapColor(m->w.vis,
                                           &m->selectedbackgroundcolor));
        }
        ggiPuts( m->w.vis,
                 m->w.xorigin + m->entry[i].x,
                 m->w.yorigin + m->entry[i].y,
                 m->entry[i].text);
    }
    for (;;) {
        /* if we are in asynchronous mode, we must guarantee */
        /* the user sees he's next.                          */
        ggiFlush(m->w.vis);

        /* get a keypress */
        evmask = emKey;
        giiEventPoll(m->w.vis, evmask, NULL);
        while (giiEventPoll(m->w.vis, evmask,&t)) {
            do {
                giiEventRead(m->w.vis,&ev, evmask);
            } while (!((1<<ev.any.type)&evmask));
            switch(ev.any.type) {
            case evKeyPress:
            case evKeyRepeat:
                switch(ev.key.sym) {
                case '1':
                    selected = 0;
                    break;
                case '2':
                    selected = 1;
                    break;
                case '3':
                    selected = 2;
                    break;
                case '4':
                    selected = 3;
                    break;
                case '5':
                    selected = 4;
                    break;
                case '6':
                    selected = 5;
                    break;
                case '7':
                    selected = 6;
                    break;
                case '8':
                    selected = 7;
                    break;
                case '9':
                    selected = 8;
                    break;
                case GIIK_Up:
                    selected--;
                    break;
                case GIIK_Down:
                    selected++;
                    break;
                case GIIK_Enter:
                    ggiFlush(m->w.vis);
                    /* just to make sure */
                    return (selected);
                    break; /* never get here */
                case GIIUC_Escape:
                    ggiFlush(m->w.vis);
                    /* just to make sure */
                    return (-1);
                default:
                    /*printf("unknown sym=%4x code=%4x\n", ev.key.sym, ev.key.code);*/
                    break;
                }
            default: /*printf("can't handle this event yet.\n");*/
                break;
            }
        }

        ggiSetGCForeground(m->w.vis,
                           ggiMapColor(m->w.vis,&m->entrycolor));
        ggiSetGCBackground(m->w.vis,
                           ggiMapColor(m->w.vis,&m->w.backgroundcolor));
        ggiPuts( m->w.vis,
                 m->w.xorigin+m->entry[oldselection].x,
                 m->w.yorigin+m->entry[oldselection].y,
                 m->entry[oldselection].text);
        if (selected<0) selected = 0;
        if (selected > m->lastentry) selected = m->lastentry;

        ggiSetGCForeground(m->w.vis,
                           ggiMapColor(m->w.vis,&m->selectedcolor));
        ggiSetGCBackground(m->w.vis,
                           ggiMapColor(m->w.vis,
                                       &m->selectedbackgroundcolor));
        ggiPuts( m->w.vis,
                 m->w.xorigin + m->entry[selected].x,
                 m->w.yorigin + m->entry[selected].y,
                 m->entry[selected].text);
        oldselection = selected;
    }
}