static void gl_ggiClear(GLcontext *ctx, GLbitfield mask) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; int x = ctx->DrawBuffer->_Xmin; int y = ctx->DrawBuffer->_Ymin; int w = ctx->DrawBuffer->_Xmax - x; int h = ctx->DrawBuffer->_Ymax - y; GLboolean all = (w == ctx->DrawBuffer->Width && h == ctx->DrawBuffer->height) GGIMESADPRINT_CORE("gl_ggiClear() called\n"); if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) { ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->clearcolor); if (all) { int w, h; w = LIBGGI_VIRTX(ggi_ctx->ggi_visual); h = LIBGGI_VIRTX(ggi_ctx->ggi_visual); ggiDrawBox(ggi_ctx->ggi_visual, 0, 0, w, h); } else { ggiDrawBox(ggi_ctx->ggi_visual, x, y, //FLIP(y), width, height); } ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->color); mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT); } _swrast_Clear(ctx, mask); }
int draw_window(struct window * w) { int i; /* clear background */ ggiSetGCForeground(w->vis, ggiMapColor(w->vis,&w->backgroundcolor)); ggiDrawBox(w->vis, w->xorigin, w->yorigin, w->xsize, w->ysize); /* draw border */ ggiSetGCForeground(w->vis, ggiMapColor(w->vis,&w->bordercolor)); for (i = w->borderwidth; i > 0; i--){ /*printf("border %d\n", i);*/ ggiDrawHLine(w->vis, w->xorigin, w->yorigin+i-1, w->xsize); ggiDrawHLine(w->vis, w->xorigin, w->yorigin+w->ysize-i, w->xsize); ggiDrawVLine(w->vis, w->xorigin+i-1, w->yorigin, w->ysize); ggiDrawVLine(w->vis, w->xorigin+w->xsize-i, w->yorigin, w->ysize); } ggiSetGCForeground(w->vis, ggiMapColor(w->vis,&w->titlecolor)); ggiSetGCBackground(w->vis, ggiMapColor(w->vis,&w->backgroundcolor)); ggiPuts(w->vis, w->xorigin+10, w->yorigin+/*2*/0, w->title); return 0; }
void x_cleardev(void) { #ifdef GGI ggiSetGCForeground (ggiVis, ggi_getcolor (0)); ggiFillscreen(ggiVis); ggiSetGCForeground (ggiVis, ggi_getcolor (xg_color)); #else vga_clear(); #endif }
static void perf_DRAWLINE(TeleUser *u, TeleCmdDrawLineData *d) { /* draw a solid line */ ggiSetGCForeground(vis, (ggi_pixel)d->pixel); ggiDrawLine(vis, d->x, d->y, d->xe, d->ye); } /* perf_DRAWLINE */
static void gl_ggiSetClearIndex(GLcontext *ctx, GLuint ci) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("gl_ggiSetClearIndex() called\n"); ggiSetGCForeground(ggi_ctx->ggi_visual, ci); ggi_ctx->clearcolor = (ggi_pixel)ci; }
static void testcase1(const char *desc) { ggi_visual_t vis; ggi_color green, back; int err; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); err = ggiSetGraphMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_8BIT); if(err < 0) { printassert(0, "Palettized mode not available.\n"); printsuccess(); ggiClose(vis); ggiExit(); return; } green.r = 100; green.g = 40000; green.b = 4000; err = ggiSetPalette(vis, GGI_PALETTE_DONTCARE, 1, &green); if (err < 0) { printfailure("Unable to install colormap with one entry.\n"); ggiClose(vis); ggiExit(); return; } printassert(err == (int)ggiMapColor(vis, &green), "ggiMapColor inconsistent with retval of ggiSetPalette.\n"); ggiUnmapPixel(vis, err, &back); if(green.r != back.r || green.g != back.g || green.b != back.b) { printfailure("Unexpected color from ggiUnmapPixel.\n"); ggiClose(vis); ggiExit(); return; } ggiSetGCForeground(vis, err); ggiDrawBox(vis, 0, 0, 3000, 3000); ggiFlush(vis); /* You should see a green square, how to test this? */ ggUSleep(5000000); printsuccess(); ggiClose(vis); ggiExit(); }
void x_line(int x1, int y1, int x2, int y2 ) { // draw line #ifndef TXTDEBUG #ifdef GGI ggiSetGCForeground (ggiVis, ggi_getcolor (xg_color)); ggiDrawLine (ggiVis, x1, y1, x2, y2); #else vga_drawline(x1,y1,x2,y2); #endif #endif }
void x_setcolor(int color) { #ifndef TXTDEBUG //set foreground color xg_color=color; #ifdef GGI ggiSetGCForeground (ggiVis, ggi_getcolor (xg_color)); #else vga_setrgbcolor(xg_hipal[3*xg_color]<<2,xg_hipal[3*xg_color+1]<<2,xg_hipal[3*xg_color+2]<<2); #endif #endif }
static void animate(ggi_visual_t vis, ggi_mode * mode, int j) { int f, w, h; ggi_pixel *buf; ggi_color c1, c2; c1.r = ((sin((double) j / 100) + 1) * 32768); c1.g = ((sin(2.094394 + (double) j / 100) + 1) * 32768); c1.b = ((sin(4.188789 + (double) j / 100) + 1) * 32768); c1.a = 0; c2.r = ((sin(3.141592 + (double) j / 100) + 1) * 32768); c2.g = ((sin(5.235986 + (double) j / 100) + 1) * 32768); c2.b = ((sin(7.330381 + (double) j / 100) + 1) * 32768); c2.a = 0; ggiSetGCForeground(vis, ggiMapColor(vis, &c1)); ggiSetGCBackground(vis, ggiMapColor(vis, &c2)); w = mode->virt.x / mode->frames; h = mode->virt.y / 5; buf = malloc(w * h * GT_SIZE(mode->graphtype)); if (buf == NULL) return; ggiSetOrigin(vis, j % (mode->virt.x - mode->visible.x + 1), j % (mode->virt.y - mode->visible.y + 1)); for (f = 0; f < mode->frames; f++) { int x, y, yspan; x = f * w; yspan = mode->virt.y - h; y = (j + (yspan * 2 * (f / mode->frames))) % (2 * yspan); y += yspan * 2 * f / mode->frames; y %= yspan * 2; if (y >= yspan) y = yspan * 2 - y; x += (int)(sin(3.14159264 * 4 * y / yspan) + 1) * (w * 1 / 10); ggiSetWriteFrame(vis, f); ggiSetReadFrame(vis, (f + 1) % mode->frames); animate_one_frame(vis, x, y, w * 4 / 5, h, buf, (x + w * (mode->frames - 1) + w / 2) % mode->virt.x); } free(buf); }
static void perf_DRAWBOX(TeleUser *u, TeleCmdDrawBoxData *d) { /* Put a solid box */ if ((d->x < 0) || (d->y < 0) || (d->x + d->width > vis_mode.virt.x) || (d->y + d->height > vis_mode.virt.y)) { fprintf(stderr, "teleserver: ILLEGAL DRAWBOX.\n"); return; } /* if */ ggiSetGCForeground(vis, (ggi_pixel)d->pixel); ggiDrawBox(vis, d->x, d->y, d->width, d->height); } /* perf_DRAWBOX */
static void gl_ggiSetClearColor(GLcontext *ctx, const GLfloat color[4]) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; ggi_color rgb; ggi_pixel col; GLubyte byteColor[3]; GGIMESADPRINT_CORE("gl_ggiSetClearColor() called\n"); CLAMPED_FLOAT_TO_UBYTE(byteColor[0], color[0]); CLAMPED_FLOAT_TO_UBYTE(byteColor[1], color[1]); CLAMPED_FLOAT_TO_UBYTE(byteColor[2], color[2]); rgb.r = (uint16)byteColor[0] << SHIFT; rgb.g = (uint16)byteColor[1] << SHIFT; rgb.b = (uint16)byteColor[2] << SHIFT; col = ggiMapColor(ggi_ctx->ggi_visual, &rgb); ggiSetGCForeground(ggi_ctx->ggi_visual, col); ggi_ctx->clearcolor = col; }
static void perf_PUTSTR(TeleUser *u, TeleCmdPutStrData *d) { /* Note: If your compiler fails here, then it * is _not_ ANSI C99 compliant */ int i; #ifdef _MSC_VER char *s = _alloca(d->length + 1); #else char s[d->length + 1]; #endif s[d->length] = '\0'; for(i = 0; i < d->length; ++i) { s[i] = (char)(d->text[i] & 0xFF); } /* for */ ggiSetGCForeground(vis, (ggi_pixel)d->fg); ggiSetGCBackground(vis, (ggi_pixel)d->bg); ggiPuts(vis, d->x, d->y, s); }
void x_bar(int xz, int yz, int xk, int yk) { #ifndef TXTDEBUG #ifdef GGI ggiSetGCForeground (ggiVis, ggi_getcolor (xg_fillc)); ggiDrawBox (ggiVis, xz, yz, xk-xz+1, yk-yz+1); #else unsigned char *palptr = xg_hipal + 3*xg_fillc; int r, g, b; r = ((int) (*palptr++)) << 2; g = ((int) (*palptr++)) << 2; b = ((int) (*palptr)) << 2; //printf ("box (%d): %d %d %d\n", xg_fillc, r, g, b); // rectangle filled with background color gl_fillbox(xz,yz,xk-xz+1,yk-yz+1, gl_rgbcolor(r,g,b)); #endif #endif }
int main(int argc, const char *argv[]) { ggi_visual_t vis; ggi_mode mode; int i, j, cx, cy, c; char buf[80]; /* Set up the random number generator */ srandom((unsigned)time(NULL)); /* Initialize LibGGI */ if (giiInit() < 0) { fprintf(stderr, "Cannot initialize LibGII!\n"); return 1; } if (ggiInit() < 0) { fprintf(stderr, "Cannot initialize LibGGI!\n"); giiExit(); return 1; } vis = ggNewStem(NULL); if (!vis) { fprintf(stderr, "Cannot open create stem!\n"); ggiExit(); giiExit(); return 1; } if (giiAttach(vis) < 0) { fprintf(stderr, "Cannot attach LibGII!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } if (ggiAttach(vis) < 0) { fprintf(stderr, "Cannot attach LibGGI!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } /* Open default visual */ if (ggiOpen(vis, NULL) < 0) { fprintf(stderr, "Cannot open default visual!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } /* Set visual to async mode (drawing not immediate) */ ggiSetFlags(vis, GGIFLAG_ASYNC); /* Set default mode, but with multiple buffering */ if (argc > 1) { ggiParseMode(argv[1], &mode); } else { ggiParseMode("", &mode); if (mode.frames < 2) mode.frames = 2; } if (ggiSetMode(vis, &mode)) { fprintf(stderr, "Cannot set mode!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } ggiGetCharSize(vis, &cx, &cy); /* Setup palette */ if (GT_SCHEME(mode.graphtype) == GT_PALETTE) { ggiSetColorfulPalette(vis); } /* Write something into each frame */ for (i = 0; i < mode.frames; i++) { if (ggiSetWriteFrame(vis, i)) { fprintf(stderr, "Cannot set write frame!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } ggiSetGCBackground(vis, ggiMapColor(vis, &white)); ggiSetGCForeground(vis, ggiMapColor(vis, &white)); ggiFillscreen(vis); } /* Clip a small border so that clipping can be verified. */ ggiSetGCClipping(vis, 5, 5, mode.virt.x - 5, mode.virt.y - 5); /* Write something into each frame */ for (i = 0; i < mode.frames; i++) { ggiSetWriteFrame(vis, i); ggiSetGCBackground(vis, ggiMapColor(vis, &black)); ggiSetGCForeground(vis, ggiMapColor(vis, &black)); ggiFillscreen(vis); snprintf(buf, sizeof(buf), "Hello World #%d!", i); for (j = 0; j < mode.virt.y; j += cy) { ggi_color col; int x = random() % mode.virt.x; int h = (random() & 0x7fff) + 0x8000; int l = (random() & 0x7fff); /* Use different colors for different frames */ col.r = ((i + 1) & 1) ? h : l; col.g = ((i + 1) & 2) ? h : l; col.b = ((i + 1) & 4) ? h : l; ggiSetGCForeground(vis, ggiMapColor(vis, &col)); ggiPuts(vis, x, j, buf); } /* Flush commands before proceeding to the next frame */ ggiFlush(vis); } /* Cycle through frames */ i = 0; j = 0; do { if (ggiSetDisplayFrame(vis, i)) { ggPanic("Cannot set display frame!\n"); } /* Wait */ c = GIIK_VOID; do { struct timeval tv = { 0, 0 }; int key; /* Flush command before waiting for input */ ggiFlush(vis); key = giiEventPoll(vis, emKeyPress, &tv); if (key & emKeyPress) c = giiGetc(vis); ggUSleep(50000); animate(vis, &mode, j); j++; } while (c == GIIK_VOID || GII_KTYP(c) == GII_KT_MOD); i = (i + 1) % mode.frames; } while (c != 'q' && c != 'Q' && c != 'x' && c != 'X' && c != GIIUC_Escape); ggiClose(vis); ggDelStem(vis); ggiExit(); giiExit(); return 0; }
static void testcase1(const char *desc) { int ret; ggi_visual_t vis; ggi_mode mode; ggi_pixel pixel_color; ggi_color color_color; #if 0 unsigned int j, size; const ggi_directbuffer *dbuf = NULL; #endif color_color.r = 0x0000; color_color.g = 0xffff; color_color.b = 0xffff; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; vis = ggNewStem(libggi, NULL); if (vis == NULL) { printfailure("Couldn't create stem for %s", DISPLAYSTR); return; } ret = ggiOpen(vis, DISPLAYSTR, NULL); if (ret != 0) { printfailure("Couldn't open %s", DISPLAYSTR); return; } #if 0 /* Here, XGGI would switch to async mode, * if there were a place to hook in ggiFlush() */ ggiSetFlags(vis, GGIFLAG_ASYNC); #endif /* Now check, if mansync is actually running * - note, we are in sync mode here. */ /* stop mansync. If it runs as it should, * we don't fail with an assertion here */ ret = MANSYNC_stop(STEM_API_DATA(vis, libggi, struct ggi_visual*)); if (ret != 0) { printfailure("BUG: mansync not running - forgot to call " "MANSYNC_start(vis) right after MANSYNC_init(vis)?\n"); goto exit_testcase; } /* now restart it */ ret = MANSYNC_start(STEM_API_DATA(vis, libggi, struct ggi_visual*)); if (ret != 0) { printfailure("BUG: mansync couldn't be relaunched\n"); goto exit_testcase; } ggiParseMode("", &mode); ggiCheckMode(vis, &mode); ret = ggiSetMode(vis, &mode); if (ret != GGI_OK) { printfailure("expected return value: \"%i\"\n" "actual return value: \"%i\"\n", GGI_OK, ret); goto exit_testcase; } /* Disable directbuffer as this is not required to * perform the test */ #if 0 ret = -1; size = GT_SIZE(mode.graphtype); for (j = 0; (dbuf = ggiDBGetBuffer(vis, j)) != NULL; j++) { if ((dbuf->type & GGI_DB_SIMPLE_PLB) && ((8*dbuf->buffer.plb.stride) % size) == 0) { /* found */ ret = GGI_OK; break; } } if (ret != GGI_OK) { printfailure("This mode and target has no suitable DirectBuffer\n"); goto exit_testcase; } if (ggiResourceAcquire(dbuf->resource, GGI_ACTYPE_WRITE | GGI_ACTYPE_READ) != 0) { printfailure("Unable to acquire DirectBuffer\n"); goto exit_testcase; } #endif /* ... and now draw something. */ pixel_color = ggiMapColor(vis, &color_color); ggiSetGCForeground(vis, pixel_color); ggiFillscreen(vis); #if 0 ggiResourceRelease(dbuf->resource); #endif exit_testcase: ggDelStem(vis); printsuccess(); return; }
void resolution(ggi_visual_t vis) { int xmax, ymax; ggi_mode currmode; ggiGetMode(vis, &currmode); xmax = currmode.visible.x; ymax = currmode.visible.y; ggiSetGCForeground(vis, blue); ggiDrawBox(vis, 0, 0, xmax, ymax); stripevert(vis, 0, 0, xmax - 1, ymax - 1, black, white, 1); ggiFlush(vis); if (waitabit(vis)) return; stripevert(vis, 0, 0, xmax - 1, ymax - 1, black, white, 2); ggiFlush(vis); if (waitabit(vis)) return; stripevert(vis, 0, 0, xmax - 1, ymax - 1, black, white, 3); ggiFlush(vis); if (waitabit(vis)) return; stripevert(vis, 0, 0, xmax - 1, ymax - 1, black, white, 4); ggiFlush(vis); if (waitabit(vis)) return; stripehor(vis, 0, 0, xmax - 1, ymax - 1, black, white, 1); ggiFlush(vis); if (waitabit(vis)) return; stripehor(vis, 0, 0, xmax - 1, ymax - 1, black, white, 2); ggiFlush(vis); if (waitabit(vis)) return; starone(vis, 0, 0, xmax - 1, ymax - 1, black, white); ggiFlush(vis); if (waitabit(vis)) return; starfive(vis, 0, 0, xmax - 1, ymax - 1, white, black); ggiFlush(vis); if (waitabit(vis)) return; startwoten(vis, 0, 0, xmax - 1, ymax - 1, white, black); ggiFlush(vis); if (waitabit(vis)) return; ggiSetGCForeground(vis, black); ggiDrawBox(vis, 0, 0, xmax, ymax); stripevert(vis, 1 * xmax / 16, 2 * ymax / 8, 3 * xmax / 16 - 1, 3 * ymax / 8 - 1, black, red, 4); stripevert(vis, 3 * xmax / 16, 2 * ymax / 8, 5 * xmax / 16 - 1, 3 * ymax / 8 - 1, black, red, 3); stripevert(vis, 5 * xmax / 16, 2 * ymax / 8, 7 * xmax / 16 - 1, 3 * ymax / 8 - 1, black, red, 2); stripevert(vis, 7 * xmax / 16, 2 * ymax / 8, 9 * xmax / 16 - 1, 3 * ymax / 8 - 1, black, red, 1); stripevert(vis, 9 * xmax / 16, 2 * ymax / 8, 11 * xmax / 16 - 1, 3 * ymax / 8 - 1, black, red, 2); stripevert(vis, 11 * xmax / 16, 2 * ymax / 8, 13 * xmax / 16 - 1, 3 * ymax / 8 - 1, black, red, 3); stripevert(vis, 13 * xmax / 16, 2 * ymax / 8, 15 * xmax / 16 - 1, 3 * ymax / 8 - 1, black, red, 4); stripevert(vis, 1 * xmax / 16, 3 * ymax / 8, 3 * xmax / 16 - 1, 4 * ymax / 8 - 1, black, green, 4); stripevert(vis, 3 * xmax / 16, 3 * ymax / 8, 5 * xmax / 16 - 1, 4 * ymax / 8 - 1, black, green, 3); stripevert(vis, 5 * xmax / 16, 3 * ymax / 8, 7 * xmax / 16 - 1, 4 * ymax / 8 - 1, black, green, 2); stripevert(vis, 7 * xmax / 16, 3 * ymax / 8, 9 * xmax / 16 - 1, 4 * ymax / 8 - 1, black, green, 1); stripevert(vis, 9 * xmax / 16, 3 * ymax / 8, 11 * xmax / 16 - 1, 4 * ymax / 8 - 1, black, green, 2); stripevert(vis, 11 * xmax / 16, 3 * ymax / 8, 13 * xmax / 16 - 1, 4 * ymax / 8 - 1, black, green, 3); stripevert(vis, 13 * xmax / 16, 3 * ymax / 8, 15 * xmax / 16 - 1, 4 * ymax / 8 - 1, black, green, 4); stripevert(vis, 1 * xmax / 16, 4 * ymax / 8, 3 * xmax / 16 - 1, 5 * ymax / 8 - 1, black, blue, 4); stripevert(vis, 3 * xmax / 16, 4 * ymax / 8, 5 * xmax / 16 - 1, 5 * ymax / 8 - 1, black, blue, 3); stripevert(vis, 5 * xmax / 16, 4 * ymax / 8, 7 * xmax / 16 - 1, 5 * ymax / 8 - 1, black, blue, 2); stripevert(vis, 7 * xmax / 16, 4 * ymax / 8, 9 * xmax / 16 - 1, 5 * ymax / 8 - 1, black, blue, 1); stripevert(vis, 9 * xmax / 16, 4 * ymax / 8, 11 * xmax / 16 - 1, 5 * ymax / 8 - 1, black, blue, 2); stripevert(vis, 11 * xmax / 16, 4 * ymax / 8, 13 * xmax / 16 - 1, 5 * ymax / 8 - 1, black, blue, 3); stripevert(vis, 13 * xmax / 16, 4 * ymax / 8, 15 * xmax / 16 - 1, 5 * ymax / 8 - 1, black, blue, 4); stripevert(vis, 1 * xmax / 16, 5 * ymax / 8, 3 * xmax / 16 - 1, 6 * ymax / 8 - 1, black, white, 4); stripevert(vis, 3 * xmax / 16, 5 * ymax / 8, 5 * xmax / 16 - 1, 6 * ymax / 8 - 1, black, white, 3); stripevert(vis, 5 * xmax / 16, 5 * ymax / 8, 7 * xmax / 16 - 1, 6 * ymax / 8 - 1, black, white, 2); stripevert(vis, 7 * xmax / 16, 5 * ymax / 8, 9 * xmax / 16 - 1, 6 * ymax / 8 - 1, black, white, 1); stripevert(vis, 9 * xmax / 16, 5 * ymax / 8, 11 * xmax / 16 - 1, 6 * ymax / 8 - 1, black, white, 2); stripevert(vis, 11 * xmax / 16, 5 * ymax / 8, 13 * xmax / 16 - 1, 6 * ymax / 8 - 1, black, white, 3); stripevert(vis, 13 * xmax / 16, 5 * ymax / 8, 15 * xmax / 16 - 1, 6 * ymax / 8 - 1, black, white, 4); ggiFlush(vis); if (waitabit(vis)) return; }
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; } }