mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Added ctr.gfx.color lib; color.setDefault and color.getDefault working
This commit is contained in:
parent
2584e46816
commit
3441dd266f
3 changed files with 53 additions and 2 deletions
|
|
@ -15,8 +15,13 @@ while os.run() do
|
||||||
if keys.held.down then y = y + 1 end
|
if keys.held.down then y = y + 1 end
|
||||||
|
|
||||||
gfx.startFrame()
|
gfx.startFrame()
|
||||||
|
|
||||||
|
gfx.color.setDefault(0xFF0000FF)
|
||||||
gfx.rectangle(x, y, 10, 10)
|
gfx.rectangle(x, y, 10, 10)
|
||||||
|
|
||||||
|
gfx.color.setDefault(0x00FFFFFF)
|
||||||
gfx.rectangle(240, 150, 120, 10)
|
gfx.rectangle(240, 150, 120, 10)
|
||||||
|
|
||||||
gfx.endFrame()
|
gfx.endFrame()
|
||||||
|
|
||||||
gfx.render()
|
gfx.render()
|
||||||
|
|
|
||||||
33
source/color.c
Normal file
33
source/color.c
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#include <sf2d.h>
|
||||||
|
|
||||||
|
#include <lua.h>
|
||||||
|
#include <lauxlib.h>
|
||||||
|
|
||||||
|
u32 color_default = RGBA8(255, 255, 255, 255);
|
||||||
|
|
||||||
|
static int color_setDefault(lua_State *L) {
|
||||||
|
color_default = luaL_checkinteger(L, 1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int color_getDefault(lua_State *L) {
|
||||||
|
lua_pushinteger(L, color_default);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct luaL_Reg color_lib[] = {
|
||||||
|
{ "setDefault", color_setDefault },
|
||||||
|
{ "getDefault", color_getDefault },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
int luaopen_color_lib(lua_State *L) {
|
||||||
|
luaL_newlib(L, color_lib);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void load_color_lib(lua_State *L) {
|
||||||
|
luaL_requiref(L, "ctr.gfx.color", luaopen_color_lib, false);
|
||||||
|
}
|
||||||
17
source/gfx.c
17
source/gfx.c
|
|
@ -3,7 +3,9 @@
|
||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lauxlib.h>
|
#include <lauxlib.h>
|
||||||
|
|
||||||
u32 defaultColor = RGBA8(255, 255, 255, 255);
|
int load_color_lib(lua_State *L);
|
||||||
|
|
||||||
|
u32 color_default;
|
||||||
|
|
||||||
static int gfx_startFrame(lua_State *L) {
|
static int gfx_startFrame(lua_State *L) {
|
||||||
sf2d_start_frame(GFX_TOP, GFX_LEFT);
|
sf2d_start_frame(GFX_TOP, GFX_LEFT);
|
||||||
|
|
@ -28,7 +30,7 @@ static int gfx_rectangle(lua_State *L) {
|
||||||
int y = luaL_checkinteger(L, 2);
|
int y = luaL_checkinteger(L, 2);
|
||||||
int width = luaL_checkinteger(L, 3);
|
int width = luaL_checkinteger(L, 3);
|
||||||
int height = luaL_checkinteger(L, 4);
|
int height = luaL_checkinteger(L, 4);
|
||||||
u32 color = luaL_optinteger(L, 5, defaultColor);
|
u32 color = luaL_optinteger(L, 5, color_default);
|
||||||
|
|
||||||
sf2d_draw_rectangle(x, y, width, height, color);
|
sf2d_draw_rectangle(x, y, width, height, color);
|
||||||
|
|
||||||
|
|
@ -43,8 +45,19 @@ static const struct luaL_Reg gfx_lib[] = {
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct { char *name; int (*load)(lua_State *L); } gfx_libs[] = {
|
||||||
|
{ "color", load_color_lib },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
int luaopen_gfx_lib(lua_State *L) {
|
int luaopen_gfx_lib(lua_State *L) {
|
||||||
luaL_newlib(L, gfx_lib);
|
luaL_newlib(L, gfx_lib);
|
||||||
|
|
||||||
|
for (int i = 0; gfx_libs[i].name; i++) {
|
||||||
|
gfx_libs[i].load(L);
|
||||||
|
lua_setfield(L, -2, gfx_libs[i].name);
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue