示例#1
0
文件: tbutil.cpp 项目: kybernetyk/gns
void print_tb(const char *str, int x, int y, uint16_t fg, uint16_t bg) {
	while (*str) {
		uint32_t uni;
		str += tb_utf8_char_to_unicode(&uni, str);
		tb_change_cell(x, y, uni, fg, bg);
		x++;
	}
}
示例#2
0
 /*
  * Starting from (x,y) we print the string character by character.
  */
 void Window::print(int x, int y, const std::string& s, uint16_t fg,
                    uint16_t bg) {
     // We work with the underlying C string
     auto str = s.c_str();
     for(int i = 0; i < s.size(); ++i) {
         uint32_t uni;
         tb_utf8_char_to_unicode(&uni, &str[i]);
         tb_change_cell(x, y, uni, fg, bg);
         ++x;
     }
     tb_present();
 }
示例#3
0
文件: luabox.c 项目: iskolbin/luabox
static int luabox_setcell( lua_State *L ) {
	const char *chstr = luaL_checkstring( L, 1 );
	int x = luaL_checkint( L, 2 );
	int y = luaL_checkint( L, 3 );
	uint16_t fg;
	uint16_t bg;
	uint32_t ch;

	tb_utf8_char_to_unicode( &ch, chstr );

	fg = lua_isnumber( L, 4 ) ? lua_tonumber( L, 4 ) : TB_DEFAULT;
	bg = lua_isnumber( L, 5 ) ? lua_tonumber( L, 5 ) : TB_DEFAULT;

	tb_change_cell( x, y, ch, fg, bg );

	return 0;
}
示例#4
0
文件: luabox.c 项目: iskolbin/luabox
static int luabox_fill( lua_State *L ) {
	const char *chstr = luaL_checkstring( L, 1 );
	int x0 = luaL_checkint( L, 2 );
	int y0 = luaL_checkint( L, 3 );
	int w = luaL_checkint( L, 4 );
	int h = luaL_checkint( L, 5 );
	uint16_t fg = lua_isnumber( L, 6 ) ? lua_tonumber( L, 6 ) : TB_DEFAULT;
	uint16_t bg = lua_isnumber( L, 7 ) ? lua_tonumber( L, 7 ) : TB_DEFAULT;
	int x, y;
	uint32_t ch;
	
	tb_utf8_char_to_unicode( &ch, chstr );
			
	for ( x = x0; x < x0 + w; x++ ) {
		for ( y = y0; y < y0 + h; y++ ) {
			tb_change_cell( x, y, ch, fg, bg );
		}
	}

	return 0;
}
示例#5
0
 void Window::print(int x, int y, char c, uint16_t fg, uint16_t bg) {
     uint32_t uni;
     tb_utf8_char_to_unicode(&uni, &c);
     tb_change_cell(x, y, uni, fg, bg);
     tb_present();
 }
示例#6
0
文件: luabox.c 项目: iskolbin/luabox
static int luabox_print( lua_State *L ) {
	const char *chstr = luaL_checkstring( L, 1 );
	int x = luaL_checkint( L, 2 );
	int y = luaL_checkint( L, 3 );
	uint16_t fg;
	uint16_t bg;
	int w;
	int h;
	int xfrom = x;
	int len;
	int lensaved;
	const char *chstrfrom = chstr;
	int mode;
	int CR = 0;
	int NL = 0;
	int wrapped = 0;

	lua_len( L, 1 );
	len = lensaved = (int) lua_tonumber( L, -1 );
	lua_pop( L, 1 );

	fg = lua_isnumber( L, 4 ) ? lua_tonumber( L, 4 ) : TB_DEFAULT;
	bg = lua_isnumber( L, 5 ) ? lua_tonumber( L, 5 ) : TB_DEFAULT;
	w = lua_isnumber( L, 6 ) ? lua_tonumber( L, 6 ) : tb_width();
	h = lua_isnumber( L, 7 ) ? lua_tonumber( L, 7 ) : tb_height();
	mode = lua_isnumber( L, 8 ) ? lua_tonumber( L, 8 ) : LUABOX_WRAP;

	w = w + xfrom;
	h = h + y;

	while ( len > 0 ) {
		uint32_t ch;
		int chlen = tb_utf8_char_to_unicode( &ch, chstr );

		if ( ch == '\n' && CR ) {
			CR = 0;
		} else if ( ch == '\r' || ch == '\n' ) {
			NL = 1;
		} else {
			tb_change_cell( x, y, ch, fg, bg );
			if ( x >= w-1 ) {
				NL = 1;
				wrapped = 1;
			} else {
				if ( wrapped && mode == LUABOX_WRAP && ( ch == ' ' || ch == '\t' ) && x == xfrom ) {
				} else {
					x++;
					wrapped = 0;
				}
			}
		}
		len -= chlen;
		chstr += chlen;

		if ( NL ) {
			NL = 0;
			if ( mode == LUABOX_TRUNC || y >= h-1 ) {
				break;
			} else {
				if ( ch == '\r' ) CR = 1;
				y++;
				x = xfrom;
			}
		}

		if ( len <= 0 && mode == LUABOX_REPEAT ) {
			chstr = chstrfrom;
			len = lensaved;
		}
	}

	return 0;
}