コード例 #1
0
ファイル: window.c プロジェクト: Nekrofage/DoomRPi
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;
}
コード例 #2
0
ファイル: pageflip.c プロジェクト: antrik/libggi
static void animate_one_frame(ggi_visual_t vis, int x, int y, int w, int h,
			      ggi_pixel * buf, int x2)
{

	ggiDrawHLine(vis, x, y, w);
	ggiDrawHLine(vis, x, y + h - 1, w);
	ggiDrawVLine(vis, x, y, h);
	ggiDrawVLine(vis, x + w - 1, y, h);
	ggiDrawBox(vis, x + 2, y + 2, w - 4, h - 4);
	ggiGetBox(vis, x + 5, y + 5, w - 10, h / 2 - 7, buf);
	ggiPutBox(vis, x + 5, y + 5, w - 10, h / 2 - 7, buf);
	ggiCopyBox(vis, x + 5, y + h / 2, w - 10, h / 2 - 5, x + 5,
		   y + h / 2);
	ggiPuts(vis, x + 7, y + 7, "Get/Put");
	ggiPuts(vis, x + 7, y + h / 2 + 2, "Copy");

	ggiDrawBox(vis, x2, y, 5, 5);

}
コード例 #3
0
ファイル: teleserver.c プロジェクト: Nekrofage/DoomRPi
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);
}
コード例 #4
0
ファイル: pageflip.c プロジェクト: antrik/libggi
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;
}
コード例 #5
0
ファイル: ggitext.c プロジェクト: antrik/libggi
int ggiGraphTextPuts(ggi_visual_t vis,
		     int x, int y, int width, int height, 
		     int flags,
		     char * text )
{
	char * tmp;

	int txwidth;   /* width of the formatted text in pixels */
	int txheight;  /* height               "                */

	int posx;      /* reference position for the final puts */
	int posy;

	int h;

	if (flags & GGI_TEXT_FRAME){
		ggiDrawHLine(vis, x,y, width);
		ggiDrawHLine(vis, x,y+height, width);
		ggiDrawVLine(vis, x,y, height);
		ggiDrawVLine(vis, x+width, y,height);
	}

	txwidth = 0 ;	
	txheight= 0 ;
	tmp = text;

	while ( *tmp != '\000') {
		/*printf("%c",*tmp);*/
		txwidth += ggiGraphTextCharwidth(vis, * tmp);
		h = ggiGraphTextCharheight(vis,* tmp);
		if ( h > txheight){
			txheight = h;
		}
		tmp++;
	}

	posx = x;
	if (flags & GGI_TEXT_FRAME) {
		posx +=2;
		width -=4;
	}
	switch (flags & (GGI_TEXT_CENTER | GGI_TEXT_LEFT | GGI_TEXT_RIGHT
			  | GGI_TEXT_JUSTIFY)){
	case GGI_TEXT_CENTER: 
		posx += (width-txwidth)/2; break;
	case GGI_TEXT_LEFT:   
		break;
	case GGI_TEXT_RIGHT:
		posx += (width-txwidth);break;
	case GGI_TEXT_JUSTIFY:
		return -1 ; /* not implemented */
		break; /* never get here */
	default:
		return -1 ; /* not implemented */
		break; /* never get here */
	}

	posy = y;
	if (flags & GGI_TEXT_FRAME) {
		posy +=2;
		height -=4;
	}
	switch (flags & (GGI_TEXT_CENTER | GGI_TEXT_TOP | GGI_TEXT_BOTTOM)){
	case GGI_TEXT_CENTER: 
		posy += (height-txheight)/2; break;
	case GGI_TEXT_TOP:   
		break;
	case GGI_TEXT_BOTTOM:
		posy += (height-txheight);break;
	case GGI_TEXT_TOP | GGI_TEXT_BOTTOM:
		return -1 ; /* not implemented */
		break; /* never get here */
	default:
		return -1 ; /* not implemented */
		break; /* never get here */
	}

/*	printf("x=%d y=%d w=%d h=%d flags=%d posx=%d posy=%d\n",
**	x, y,width, height, flags, posx, posy);
*/

	ggiPuts(vis, posx, posy, text);
	return 0; 
}
コード例 #6
0
ファイル: ggitext.c プロジェクト: antrik/libggi
int ggiGraphTextLongPuts(ggi_visual_t vis,
			 int x, int y, int width, int height, 
			 int flags,
			 char * text )
/* in this case text is allowed to contain \n. */
/* the text itself is shown left-justified.    */
{
	char * tmp;
	char * tmpdest;

	struct line {
		char * text;
		struct line * next;
		int cpl ; /* chars per line */
		int x;  /* reference, to be calculated! */
		int y;
		int width;
		int height;
	} firstline;

	struct line * currline;
 
	int txwidth;   /* width of the formatted text in pixels */
	int txheight;  /* height               "                */

	int posx;      /* reference position for the final puts */
	int posy;

	int h;

	/* process lines */
	currline = &firstline;

	/* chars per line , and line headers */
	tmp = text;
	firstline.cpl = 0;
	while ( (* tmp) && (* tmp != '\n') ) {
		tmp ++;
		firstline.cpl++;
	}
	/*printf ("first line length %d\n", currline->cpl);*/
	while (* tmp){      /* until end of string */
		/*printf ("allocating line header");*/
		currline->next = (struct line *) malloc(sizeof(struct line));
		if (currline->next == NULL){
			ggPanic("Out of memory");
		}
		currline = currline -> next;
		currline -> next = NULL;
		currline -> cpl =0;
		tmp++; /* now at start of next line */

		while ( (* tmp) && (* tmp != '\n') ) {
			tmp ++;
			currline ->cpl++;
		}
		/*printf ("..line length %d\n", currline->cpl);*/
	}

	/* copy strings and add \0 */

	txwidth = 0;
	txheight = 0;

	currline = &firstline;
	tmp = text;
	while (currline != NULL) {
		tmpdest = (char *) malloc(sizeof(char)*
					  (currline->cpl+1));
		if ( (currline->text = tmpdest) == NULL){
			ggPanic("Out of memory");
		}
		currline -> width  = 0;
		currline -> height = 0;
		while ( (* tmp) && (* tmp != '\n') ) {
			*tmpdest = *tmp;
			/*printf("%c",*tmp);*/
			currline ->width += ggiGraphTextCharwidth(vis,* tmp);
			h = ggiGraphTextCharheight(vis, * tmp);
			if (h>currline -> height){
				currline -> height = h;
			}

			tmp ++;
			tmpdest ++;
			
		}
		*tmpdest= '\000';    /* endofstring */
		tmp++;
		/*printf(" h=%d, w=%d \n", currline->height, currline->width);*/
		if (currline->width > txwidth) {
			txwidth = currline ->width;
		}
		txheight += currline ->height;
		currline = currline->next;
	}
/*	printf("sum: h=%d w=%d\n", txheight, txwidth);*/


	if (flags & GGI_TEXT_FRAME){
		ggiDrawHLine(vis, x,y, width);
		ggiDrawHLine(vis, x,y+height, width);
		ggiDrawVLine(vis, x,y, height);
		ggiDrawVLine(vis, x+width, y,height);
	}


	posx = x;
	if (flags & GGI_TEXT_FRAME) {
		posx +=2;
		width -=4;
	}
	switch (flags & (GGI_TEXT_CENTER | GGI_TEXT_LEFT | GGI_TEXT_RIGHT
			  | GGI_TEXT_JUSTIFY)){
	case GGI_TEXT_CENTER: 
		posx += (width-txwidth)/2; break;
	case GGI_TEXT_LEFT:   
		break;
	case GGI_TEXT_RIGHT:
		posx += (width-txwidth);break;
	case GGI_TEXT_JUSTIFY:
		return -1 ; /* not implemented */
		break; /* never get here */
	default:
		return -1 ; /* not implemented */
		break; /* never get here */
	}

	posy = y;
	if (flags & GGI_TEXT_FRAME) {
		posy +=2;
		height -=4;
	}
	switch (flags & (GGI_TEXT_CENTER | GGI_TEXT_TOP | GGI_TEXT_BOTTOM)){
	case GGI_TEXT_CENTER: 
		posy += (height-txheight)/2; break;
	case GGI_TEXT_TOP:   
		break;
	case GGI_TEXT_BOTTOM:
		posy += (height-txheight);break;
	case GGI_TEXT_TOP | GGI_TEXT_BOTTOM:
		return -1 ; /* not implemented */
		break; /* never get here */
	default:
		return -1 ; /* not implemented */
		break; /* never get here */
	}


	currline = &firstline;
	while (currline != NULL) {
		/*
		**  currline->x = posx;
		**  currline->y = posy;
		*/
		/*printf("printing at %d,%d: %s\n", posx, posy, currline->text);*/
		ggiPuts(vis, posx, posy, currline->text);
		posy+=currline->height;
		currline = currline -> next;
	}

	currline = firstline.next;
	{
		struct line * t;
		while (currline != NULL){
			t = currline->next;
			free(currline);
			/*printf("free-");*/
			currline = t;
		}
	}

	return 0; 
}
コード例 #7
0
ファイル: menu.c プロジェクト: 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;
    }
}