Пример #1
0
static int lua_tb_init( lua_State *L ) {
	int err = tb_init();
	struct luabox_State *lbstate;

	if ( err ) {
		lua_pushnil( L );
		lua_pushinteger( L, err );
		return 2;
	}

	if ( lua_gettop( L ) >= 1 ) {
		if ( lua_isnumber( L, 1 )) {
			uint16_t inputmode = (uint16_t) lua_tonumber( L, 1 );
			tb_select_input_mode( inputmode );
		}
	}

	if ( lua_gettop( L ) >= 2 ) {
		if ( lua_isnumber( L, 2 )) {
			uint16_t ouputmode = (uint16_t) lua_tonumber( L, 2 );
			tb_select_output_mode( ouputmode );
		}
	}

	lua_pushlightuserdata( L, L );
	lbstate = lua_newuserdata( L, sizeof *lbstate );
	lua_settable( L, LUA_REGISTRYINDEX );

	return 0;
}
Пример #2
0
 /*
  * The ctor calls the init function to initialize the termbox library, which
  * returns
  * -1 if unsupported terminal,
  * -2 if failed to open tty,
  * -3 unix pipe error.
  */
 Window::Window() {
     // TODO: ignored ret code for now
     int ret = tb_init();
     // input = {};
     // tb_clear();
     tb_select_output_mode(TB_OUTPUT_NORMAL);
     tb_present();
 }
Пример #3
0
	inline
	Manager(std::unique_ptr<Widget>&& widget) {
		tb_init();
		tb_select_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE);
		tb_select_output_mode(TB_OUTPUT_256);

		root = std::move(widget);
		resize(tb_width(), tb_height());
	}
Пример #4
0
static int luabox_gray_internal( lua_State *L, lua_Number mul ) {
	lua_Number gr, offset = 0;
	switch ( tb_select_output_mode( TB_OUTPUT_CURRENT )) {
		case TB_OUTPUT_NORMAL: 
			luaL_error( L, "wrong output mode for grayscale colors: NORMAL" );
			return 0;
		case TB_OUTPUT_216: 
			luaL_error( L, "wrong output mode for grayscale colors: 216" );
			return 0;
		case TB_OUTPUT_256:
			offset = 0xe8;
		case TB_OUTPUT_GRAYSCALE:
			gr = mul * luaL_checknumber( L, -1 );
			lua_pushnumber( L, gr + offset );
			return 1;
		default:
			luaL_error( L, "wrong output mode for grayscale colors: UNKNOWN" );
			return 0;
	}
}
Пример #5
0
static int luabox_rgb_internal( lua_State *L, uint16_t mul ) {
	uint16_t r, g, b, offset = 0;
	switch ( tb_select_output_mode( TB_OUTPUT_CURRENT )) {
		case TB_OUTPUT_NORMAL: 
			luaL_error( L, "wrong output mode for RGB colors: NORMAL" );
			return 0;
		case TB_OUTPUT_GRAYSCALE: 
			luaL_error( L, "wrong output mode for RGB colors: GRAYSCALE" );
			return 0;
		case TB_OUTPUT_256:
			offset = 0x10;
		case TB_OUTPUT_216: 
			r = mul*luaL_checknumber( L, 1 ); r *= (LUABOX_RGBCOLORMAX+1) * (LUABOX_RGBCOLORMAX+1);
			g = mul*luaL_checknumber( L, 2 ); g *= (LUABOX_RGBCOLORMAX+1);
			b = mul*luaL_checknumber( L, 3 );
			lua_pushnumber( L, (r + g + b) + offset );
			return 1;
		default:
			luaL_error( L, "wrong output mode for RGB colors: UNKNOWN" );
			return 0;
	}
}
Пример #6
0
static int lua_tb_select_output_mode( lua_State *L ) {
	int mode = luaL_checkint( L, 1 );
	lua_pushnumber( L, tb_select_output_mode( mode ));
	return 1;
}