コード例 #1
0
ファイル: ui.c プロジェクト: thmzlt/tic
static int ui_draw_chars(char *chars, int x, int y, uint16_t fg, uint16_t bg) {
    int width = tb_width();
    int pointer = 0;
    int counter = 0;
    int length;
    mbstate_t state;
    wchar_t ch;

    // Initialize multi-byte state
    mbrlen(NULL, 0, &state);

    while (chars[pointer] != '\0') {
        length = mbrtowc(&ch, chars + pointer, 4, &state);

        tb_change_cell(x + pointer, y, ch, fg, bg);
        pointer += length;
        counter++;
    }

    // Draw spaces for the remaining of the line
    for (int i = counter; i < width; i++) {
        tb_change_cell(x + i, y, ' ', fg, bg);
    }

    return counter;
}
コード例 #2
0
void tb_fill(int x, int y, int w, int h, char symbol,
             uint16_t fg, uint16_t bg) {
  for (int i = x; i < x + w; ++i) {
    for (int j = y; j < y + h; ++j) {
      tb_change_cell(i, j, symbol, fg, bg);
    }
  }
}
コード例 #3
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++;
	}
}
コード例 #4
0
ファイル: termbox_stubs.c プロジェクト: pacemkr/ocaml-termbox
void tbstub_change_cell(value caml_x, value caml_y, value caml_ch, value caml_fg, value caml_bg) {

	CAMLparam5(caml_x, caml_y, caml_ch, caml_fg, caml_bg);

	tb_change_cell(Int_val(caml_x), Int_val(caml_y), Int32_val(caml_ch), Int_val(caml_fg), Int_val(caml_bg));

	CAMLreturn0;
}
コード例 #5
0
ファイル: qtermboxcore.cpp プロジェクト: ssharunas/qtermbox
/*!
	\brief Prints string with foreground and background styles.
	String is wrapped up to \a width. If width is -1, no wrapping is done.
	If string is shorter than width remaining space is filled with spaces.
	No more than \a height lines are printed. Height is ignored if it is less than 0.

	\param x - position from left side of the screen.
	\param y - position from top of the screen.
	\param w - width of string.
	\param h - height of string.
	\param str - string to print.
	\param fg - foreground style.
	\param bg - background style.
	*/
void putCell(unsigned int x, unsigned int y, int w, int h, QString str, QTermboxStyle fg, QTermboxStyle bg){
	Q_ASSERT_X(QTermboxCorePrivate::wasInitialized(), "putCell", "Termbox was not initialized.");

	int remainingWidth = str.length();

	if(w <= 0)
		w = str.length();

	int line = 0;

	//fill text
	while(remainingWidth > 0){

		for(int i = 0; i < qMin(remainingWidth, w); i++){
			tb_change_cell(x + i, y + line, str[line * w + i].unicode(), fg.style(), bg.style());
		}

		remainingWidth -= w;

		if(remainingWidth > 0)
			line++;

		if(h > 0 && line >= h)
			return;
	}

	//fill remaining unfinished empty line
	for(int i = x + w - 1; remainingWidth < 0; remainingWidth++, i--){
		tb_change_cell(i, y + line, ' ', fg.style(), bg.style());
	}

	//fill empty height
	if(h > 0){
		line++;
		while(line < h){

			for(unsigned int i = x + w - 1; i >= x; i--){
				tb_change_cell(i, y + line, ' ', fg.style(), bg.style());
			}

			line++;
		}
	}
}
コード例 #6
0
ファイル: cppbox.cpp プロジェクト: gregstula/cppbox
 /*
  * 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();
 }
コード例 #7
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;
}
コード例 #8
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;
}
コード例 #9
0
void tb_draw_string(int x, int y, const std::string &str,
                    uint16_t fg, uint16_t bg) {
  for (std::size_t i = 0; i < str.size(); ++i) {
    tb_change_cell(x + i, y, str.at(i), fg, bg);
  }
}
コード例 #10
0
ファイル: paint.c プロジェクト: skilstak/usr-share-skilstak
void updateAndDrawButtons(int *current, int x, int y, int mx, int my, int n, void (*attrFunc)(int, uint32_t*, uint16_t*, uint16_t*)) {
	int lx = x;
	int ly = y;
	for (int i = 0; i < n; i++) {
		if (lx <= mx && mx <= lx+3 && ly <= my && my <= ly+1) {
			*current = i;
		}
		uint32_t r;
		uint16_t fg, bg;
		(*attrFunc)(i, &r, &fg, &bg);
                tb_change_cell(lx+0, ly+0, r, fg, bg);
                tb_change_cell(lx+1, ly+0, r, fg, bg);
                tb_change_cell(lx+2, ly+0, r, fg, bg);
                tb_change_cell(lx+3, ly+0, r, fg, bg);
                tb_change_cell(lx+0, ly+1, r, fg, bg);
                tb_change_cell(lx+1, ly+1, r, fg, bg);
                tb_change_cell(lx+2, ly+1, r, fg, bg);
                tb_change_cell(lx+3, ly+1, r, fg, bg);
                lx += 4;
	}
	lx = x;
	ly = y;
        for (int i = 0; i < n; i++) {
                if (*current == i) {
                        uint16_t fg = TB_RED | TB_BOLD;
                        uint16_t bg = TB_DEFAULT;
                        tb_change_cell(lx+0, ly+2, '^', fg, bg);
                        tb_change_cell(lx+1, ly+2, '^', fg, bg);
                        tb_change_cell(lx+2, ly+2, '^', fg, bg);
                        tb_change_cell(lx+3, ly+2, '^', fg, bg);
                }
                lx += 4;
        }
}
コード例 #11
0
ファイル: cppbox.cpp プロジェクト: gregstula/cppbox
 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();
 }
コード例 #12
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;
}
コード例 #13
0
ファイル: billboard.c プロジェクト: codegangsta/billboard
static void draw() {
    tb_clear();
    tb_change_cell(0, 0, 'A', 0, 1);
    tb_present();
}
コード例 #14
0
ファイル: qtermboxcore.cpp プロジェクト: ssharunas/qtermbox
/*!
	\brief Puts cell at specified position.

	\param x - position from left side of the screen.
	\param y - position from top of the screen.
	\param ch - char of cell.
	\param fg - foreground style of cell.
	\param bg - background style of cell.
	*/
void putCell(unsigned int x, unsigned int y, QChar ch, QTermboxStyle fg, QTermboxStyle bg){
	Q_ASSERT_X(QTermboxCorePrivate::wasInitialized(), "putCell", "Termbox was not initialized.");
	tb_change_cell(x, y, ch.unicode(), fg.style(), bg.style());
}