예제 #1
0
파일: ncconsole.c 프로젝트: rofl0r/concol
// sends the right "colorpair" to ncurses
void console_initoutput(struct Console* con) {
	struct NcConsole *self = &con->backend.nc;
	int i;
	if (self->active.fgcol == -1) console_setcolor(con, 1, RGB(0xFF, 0xFF, 0xFF));
	if (self->active.bgcol == -1) console_setcolor(con, 0, RGB(0, 0, 0));
	if(self->lastused.fgcol == self->active.fgcol && self->lastused.bgcol == self->active.bgcol)
		return;

	PDEBUG("initoutput: with fg: %d, bg: %d\n", self->active.fgcol, self->active.bgcol);

	for(i = 0; i <= MAX_PAIR; i++) {
		if(self->pairs[i].fgcol == self->active.fgcol) {
				if (self->pairs[i].bgcol != self->active.bgcol)
					continue;
				else {
					console_usecolorpair(self, i);
					return;
				}
		} else if (self->pairs[i].fgcol == -1) {
				console_setcolorpair(self, i, self->active.fgcol, self->active.bgcol);
				console_usecolorpair(self, i);
				return;
		}
	}
	return; // "colorpair not found");
}
예제 #2
0
파일: cmd_tetris.c 프로젝트: qioixiy/xboot
/*
 * refresh game area
 */
static void refresh(void)
{
	struct console * con = get_console_stdout();
	s32_t w, h;
	s32_t x, y, xp, yp;

	if(!con)
		return;

	for(y=0; y < GAME_AREA_HEIGHT; y++)
	{
		if(map.dirty[y] == FALSE)
			continue;

		for(x=0; x < GAME_AREA_WIDTH; x++)
		{
			console_getwh(con, &w, &h);
			xp = (w - GAME_AREA_WIDTH) / 2;
			yp = (h - GAME_AREA_HEIGHT) / 2;
			console_gotoxy(con, xp + x, yp + y);
			if(map.screen[x][y] != TCOLOR_BLACK)
				console_setcolor(con, TCOLOR_BLACK, map.screen[x][y]);
			else
				console_setcolor(con, TCOLOR_WHITE, TCOLOR_BLACK);
			console_putcode(con, UNICODE_SPACE);
		}
		map.dirty[y] = FALSE;
    }
}
예제 #3
0
static void draw(Console *t, bmp4* b) {
	int x,y;
	unsigned *p = b->data;
	for(y=0;y<b->height;y++) for(x=0;x<b->width;x++) {
		console_setcolor(t, 0, *((rgb_t*) p));
		console_goto(t, x, y);
		console_addchar(t, ' ', 0);
		p++;
	}
	console_refresh(t);
}
예제 #4
0
int main(int argc, char** argv) {
	char* filename;
	int scaleFullScreen = 0;
	Console co;
	Console* t = &co;
	int cx; int cy;
	int w, h;
	int iterX, iterY;

	struct Pix* pngfile;
	struct Pix* ping;
	struct Pix* palette;
	struct Pix* pix32;
	int i, ix, iy;
	int c;
	
	for (i = 1; i<argc; i++) {
		if (strlen(argv[i]) > 1 && !memcmp(argv[i], "-f", 2)) 
			scaleFullScreen=1;
		else filename = argv[i];
	}

	if (access(filename, R_OK)) {
		puts("file not found!");
		puts("c0npix by rofl0r");
		puts("================");
		printf("arguments: %s [-f] somefile.[jpg|png|bmp|tiff]\n", argv[0]);
		puts("where -f means scale to fullscreen");
		puts("export TERM=xterm-256color before usage is recommended.");
		exit(1);
	}

	console_init(t);
	point reso = {800, 600};
	console_init_graphics(&co, reso, FONT);

	console_getbounds(t, &cx, &cy);

	pngfile = pixRead(filename);

	pixGetDimensions(pngfile, &w, &h, NULL);

	ping = pixScale(pngfile, 2.0, 1.0 );
	
	pixDestroy(&pngfile);
	
	palette = pixOctreeColorQuant(ping, 240, 1);
	
	if (palette == NULL) { puts("palette is nul"); goto finish_him; }

	pix32 = pixConvertTo32(palette);

	iterX = pix32->w;
	iterY = pix32->h;

	int* bufptr = (int*) pix32->data;
	if (bufptr == NULL) {
		puts("bufptr is null");
		goto finish_him;
	}
	
	int startx = 0;
	int starty = 0;
	
	paint:
	for(iy = starty; iy < starty + cy; iy++) {
		bufptr = (int*) pix32->data + (iy * pix32->w) + startx;
		for(ix = startx; ix < startx + cx; ix++) {
			console_setcolor(t, 0, *((rgb_t*) bufptr));
			console_goto(t, ix - startx, iy - starty);
			console_addchar(t, ' ', 0);
			bufptr++;
		}
	}
	console_draw(t);
	//console_printfxy(t, 0, 0, "%d", (int) c);
	
	while ((c = console_getkey(t)) != 'q') {

		console_setcolor(t, 0, RGB(0,0,0));
		
		switch(c) {
			case CK_CURSOR_UP: 
				if(starty > 0) starty--;
				break;
			case CK_CURSOR_DOWN:
				if(starty < (int) pix32->h - cy)
					starty++;
				break;
			case CK_CURSOR_LEFT:
				if(startx > 0)
					startx--;
				break;
			case CK_CURSOR_RIGHT:
				if(startx < (int) pix32->w - cx)
					startx++;
				break;
			default:
				goto loopend; // ignore mouse movement and similar stuff
				break;
		}
		goto paint;
		loopend: ;
	}
	
	pixDestroy(&palette);
	pixDestroy(&pix32);

	console_refresh(t);
	
	finish_him:
	//console_getkey(t);
	
	console_cleanup(t);

	return 0;
}
예제 #5
0
파일: cmd_tetris.c 프로젝트: qioixiy/xboot
static int tetris(int argc, char ** argv)
{
	struct console * con = get_console_stdout();
	u32_t x, y, shape;
	u32_t newx, newy, newshape;
	bool_t fell = FALSE;
	bool_t try_again = FALSE;
	u32_t code;

	if(!con)
		return -1;

	console_setcursor(con, FALSE);
	console_cls(con);

	srand(jiffies + rand());

	do {
		screen_init();

		y = 3;
		x = GAME_AREA_WIDTH / 2;
		shape = rand() % ARRAY_SIZE(shapes);
        shape_draw(x, y, shape);
        refresh();

        while(1)
        {
            newx = x;
            newy = y;
            newshape = shape;

            if(console_stdin_getcode_with_timeout(&code, 250))
            {
    			switch(code)
    			{
    			case 0x10:	/* up */
    				newshape = shapes[shape].plus90;
    				fell = FALSE;
    				break;

    			case 0xe:	/* down */
                    if(y < GAME_AREA_HEIGHT - 1)
                        newy = y + 1;
                    fell = TRUE;
    				break;

    			case 0x2:	/* left */
    				if(x > 0)
    					newx = x - 1;
    				fell = FALSE;
    				break;

    			case 0x6:	/* right */
    				if(x < GAME_AREA_WIDTH - 1)
    					newx = x + 1;
    				fell = FALSE;
    				break;

    			default:
    				newy++;
    				fell = TRUE;
    				break;
    			}

            }
            else
            {
				newy++;
				fell = TRUE;
            }

	        if((newx == x) && (newy == y) && (newshape == shape))
	            continue;

	        shape_erase(x, y, shape);
	        if(shape_hit(newx, newy, newshape) == FALSE)
	        {
				x = newx;
	            y = newy;
	            shape = newshape;
	        }
	        else if(fell == TRUE)
	        {
	            shape_draw(x, y, shape);

	    		y = 3;
	    		x = GAME_AREA_WIDTH / 2;
	    		shape = rand() % ARRAY_SIZE(shapes);
	    		collapse();

	            if(shape_hit(x, y, shape))
	            {
	            	try_again = FALSE;
	            	break;
	            }
	        }

	        shape_draw(x, y, shape);
	        refresh();
        }
	}while(try_again);

	console_setcursor(con, TRUE);
	console_setcolor(con, TCOLOR_WHITE, TCOLOR_BLACK);
	console_cls(con);

	return 0;
}