示例#1
0
文件: console.c 项目: DashYang/sim
static VALUE
console_cursor_set(VALUE io, VALUE cpos)
{
    cpos = rb_convert_type(cpos, T_ARRAY, "Array", "to_ary");
    if (RARRAY_LEN(cpos) != 2) rb_raise(rb_eArgError, "expected 2D coordinate");
    return console_goto(io, RARRAY_AREF(cpos, 0), RARRAY_AREF(cpos, 1));
}
示例#2
0
文件: ncconsole.c 项目: rofl0r/concol
// prints a char and advances cursor
void console_printchar(struct Console* self, int c, unsigned int attributes) {
	int maxy, maxx;
	getmaxyx(stdscr, maxy, maxx);
	(void) maxy;
	int newx = self->cursor.x == maxx ? 1 : self->cursor.x + 1;
	int newy = self->cursor.x == maxx ? self->cursor.y + 1 : self->cursor.y;
	console_addchar(self, c, attributes);
	console_goto(self, newx, newy);
}
示例#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
static u08 cmd_goto(const u08 *cmd, u08 len)
{
  if(len > 5) {
    return CMD_SYNTAX_ERR;
  }
  
  u08 x,y;
  if(!parse_byte(cmd+1,&x)) {
    return CMD_NO_BYTE;
  }
  if(!parse_byte(cmd+3,&y)) {
    return CMD_NO_BYTE;
  }
  
  console_t *c = console_get_current();
  console_goto(c, x, y);
  return CMD_OK;
}
示例#5
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;
}