Updated API to not include 'rgb' and on the lua side, to use [0.0, 1.0]
instead of [0, 255].
This commit is contained in:
parent
bc1f39d12c
commit
36fc3d377d
@ -24,10 +24,10 @@ int main(void)
|
|||||||
int r = (int)(255.0 * (0.5 + 0.5*sin(t*a + (double)(x) / 50.0)));
|
int r = (int)(255.0 * (0.5 + 0.5*sin(t*a + (double)(x) / 50.0)));
|
||||||
int g = (int)(255.0 * (0.5 + 0.5*sin(0.8 + t*b + (double)(x) / 50.0)));
|
int g = (int)(255.0 * (0.5 + 0.5*sin(0.8 + t*b + (double)(x) / 50.0)));
|
||||||
int b = (int)(255.0 * (0.5 + 0.5*sin(1.3 + t*c + (double)(x) / 50.0)));
|
int b = (int)(255.0 * (0.5 + 0.5*sin(1.3 + t*c + (double)(x) / 50.0)));
|
||||||
btui_set_bg_rgb(bt,
|
btui_set_bg(bt,
|
||||||
(r < 0 ? 0 : (r > 255 ? 255 : r)),
|
(r < 0 ? 0 : (r > 255 ? 255 : r)),
|
||||||
(g < 0 ? 0 : (g > 255 ? 255 : g)),
|
(g < 0 ? 0 : (g > 255 ? 255 : g)),
|
||||||
(b < 0 ? 0 : (b > 255 ? 255 : b)));
|
(b < 0 ? 0 : (b > 255 ? 255 : b)));
|
||||||
btui_puts(bt, " ");
|
btui_puts(bt, " ");
|
||||||
}
|
}
|
||||||
btui_flush(bt);
|
btui_flush(bt);
|
||||||
|
34
Lua/lbtui.c
34
Lua/lbtui.c
@ -149,13 +149,16 @@ static int Lbtui_withfg(lua_State *L)
|
|||||||
if (bt == NULL) luaL_error(L, "Not a BTUI object");
|
if (bt == NULL) luaL_error(L, "Not a BTUI object");
|
||||||
if (lua_gettop(L) < 5) luaL_error(L, "Expected r,g,b values and a function");
|
if (lua_gettop(L) < 5) luaL_error(L, "Expected r,g,b values and a function");
|
||||||
int isnum;
|
int isnum;
|
||||||
int r = lua_tointegerx(L, 2, &isnum);
|
lua_Number r = lua_tonumberx(L, 2, &isnum);
|
||||||
if (!isnum) luaL_error(L, "Expected integer r value");
|
if (!isnum) luaL_argerror(L, 2, "expected number for red value");
|
||||||
int g = lua_tointegerx(L, 3, &isnum);
|
lua_Number g = lua_tonumberx(L, 3, &isnum);
|
||||||
if (!isnum) luaL_error(L, "Expected integer g value");
|
if (!isnum) luaL_argerror(L, 3, "expected number for green value");
|
||||||
int b = lua_tointegerx(L, 4, &isnum);
|
lua_Number b = lua_tonumberx(L, 4, &isnum);
|
||||||
if (!isnum) luaL_error(L, "Expected integer b value");
|
if (!isnum) luaL_argerror(L, 4, "expected number for blue value");
|
||||||
btui_set_fg_rgb(*bt, r, g, b);
|
btui_set_fg(*bt,
|
||||||
|
r < 0.0 ? 0 : (r > 1.0 ? 255 : (int)(255.0 * r)),
|
||||||
|
g < 0.0 ? 0 : (g > 1.0 ? 255 : (int)(255.0 * g)),
|
||||||
|
b < 0.0 ? 0 : (b > 1.0 ? 255 : (int)(255.0 * b)));
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
int status = lua_pcall(L, 0, LUA_MULTRET, 0);
|
int status = lua_pcall(L, 0, LUA_MULTRET, 0);
|
||||||
btui_set_attributes(*bt, BTUI_FG_NORMAL);
|
btui_set_attributes(*bt, BTUI_FG_NORMAL);
|
||||||
@ -170,13 +173,16 @@ static int Lbtui_withbg(lua_State *L)
|
|||||||
if (bt == NULL) luaL_error(L, "Not a BTUI object");
|
if (bt == NULL) luaL_error(L, "Not a BTUI object");
|
||||||
if (lua_gettop(L) < 5) luaL_error(L, "Expected r,g,b values and a function");
|
if (lua_gettop(L) < 5) luaL_error(L, "Expected r,g,b values and a function");
|
||||||
int isnum;
|
int isnum;
|
||||||
int r = lua_tointegerx(L, 2, &isnum);
|
lua_Number r = lua_tonumberx(L, 2, &isnum);
|
||||||
if (!isnum) luaL_error(L, "Expected integer r value");
|
if (!isnum) luaL_argerror(L, 2, "expected number for red value");
|
||||||
int g = lua_tointegerx(L, 3, &isnum);
|
lua_Number g = lua_tonumberx(L, 3, &isnum);
|
||||||
if (!isnum) luaL_error(L, "Expected integer g value");
|
if (!isnum) luaL_argerror(L, 3, "expected number for green value");
|
||||||
int b = lua_tointegerx(L, 4, &isnum);
|
lua_Number b = lua_tonumberx(L, 4, &isnum);
|
||||||
if (!isnum) luaL_error(L, "Expected integer b value");
|
if (!isnum) luaL_argerror(L, 4, "expected number for blue value");
|
||||||
btui_set_bg_rgb(*bt, r, g, b);
|
btui_set_bg(*bt,
|
||||||
|
r < 0.0 ? 0 : (r > 1.0 ? 255 : (int)(255.0 * r)),
|
||||||
|
g < 0.0 ? 0 : (g > 1.0 ? 255 : (int)(255.0 * g)),
|
||||||
|
b < 0.0 ? 0 : (b > 1.0 ? 255 : (int)(255.0 * b)));
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
int status = lua_pcall(L, 0, LUA_MULTRET, 0);
|
int status = lua_pcall(L, 0, LUA_MULTRET, 0);
|
||||||
btui_set_attributes(*bt, BTUI_BG_NORMAL);
|
btui_set_attributes(*bt, BTUI_BG_NORMAL);
|
||||||
|
@ -16,7 +16,7 @@ btui(function(bt)
|
|||||||
|
|
||||||
bt:clear()
|
bt:clear()
|
||||||
bt:move(x, y)
|
bt:move(x, y)
|
||||||
bt:withbg(150,225,80, function()
|
bt:withbg(.8,.95,.2, function()
|
||||||
bt:withfg(0,0,0, function()
|
bt:withfg(0,0,0, function()
|
||||||
bt:print(" Pressed: ", key, " ")
|
bt:print(" Pressed: ", key, " ")
|
||||||
end)
|
end)
|
||||||
|
8
btui.h
8
btui.h
@ -35,8 +35,8 @@ int btui_move_cursor(btui_t *bt, int x, int y);
|
|||||||
char *btui_keyname(int key, char *buf);
|
char *btui_keyname(int key, char *buf);
|
||||||
int btui_keynamed(const char *name);
|
int btui_keynamed(const char *name);
|
||||||
int btui_set_attributes(btui_t *bt, attr_t attrs);
|
int btui_set_attributes(btui_t *bt, attr_t attrs);
|
||||||
int btui_set_fg_rgb(btui_t *bt, unsigned char r, unsigned char g, unsigned char b);
|
int btui_set_fg(btui_t *bt, unsigned char r, unsigned char g, unsigned char b);
|
||||||
int btui_set_bg_rgb(btui_t *bt, unsigned char r, unsigned char g, unsigned char b);
|
int btui_set_bg(btui_t *bt, unsigned char r, unsigned char g, unsigned char b);
|
||||||
int btui_set_fg_hex(btui_t *bt, int hex);
|
int btui_set_fg_hex(btui_t *bt, int hex);
|
||||||
int btui_set_bg_hex(btui_t *bt, int hex);
|
int btui_set_bg_hex(btui_t *bt, int hex);
|
||||||
#define btui_printf(bt, ...) fprintf((bt)->out, __VA_ARGS__)
|
#define btui_printf(bt, ...) fprintf((bt)->out, __VA_ARGS__)
|
||||||
@ -497,12 +497,12 @@ int btui_move_cursor(btui_t *bt, int x, int y)
|
|||||||
return fprintf(bt->out, "\033[%d;%dH", y+1, x+1);
|
return fprintf(bt->out, "\033[%d;%dH", y+1, x+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int btui_set_fg_rgb(btui_t *bt, unsigned char r, unsigned char g, unsigned char b)
|
int btui_set_fg(btui_t *bt, unsigned char r, unsigned char g, unsigned char b)
|
||||||
{
|
{
|
||||||
return fprintf(bt->out, "\033[38;2;%d;%d;%dm", r, g, b);
|
return fprintf(bt->out, "\033[38;2;%d;%d;%dm", r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
int btui_set_bg_rgb(btui_t *bt, unsigned char r, unsigned char g, unsigned char b)
|
int btui_set_bg(btui_t *bt, unsigned char r, unsigned char g, unsigned char b)
|
||||||
{
|
{
|
||||||
return fprintf(bt->out, "\033[48;2;%d;%d;%dm", r, g, b);
|
return fprintf(bt->out, "\033[48;2;%d;%d;%dm", r, g, b);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user