Exit function and N-Patch fix.
This commit is contained in:
6
API.md
6
API.md
@@ -31,6 +31,12 @@ This function can be used for custom log message handling.
|
||||
|
||||
---
|
||||
|
||||
> function exit()
|
||||
|
||||
This function will be called on program close. Cleanup could be done here.
|
||||
|
||||
---
|
||||
|
||||
## Globals - ConfigFlags
|
||||
|
||||
FLAG_VSYNC_HINT
|
||||
|
||||
@@ -5,6 +5,8 @@ KEY CHANGES:
|
||||
- ADDED: This changelog.
|
||||
- ADDED: Lua interpreter mode.
|
||||
- ADDED: Easings extra module.
|
||||
- ADDED: exit function.
|
||||
- FIX: uluaGetNPatchInfo fix for RL_DrawTextureNPatch. Guess this was never tested and did not work at all >:E.
|
||||
|
||||
Detailed changes:
|
||||
ADDED: Help argument.
|
||||
|
||||
25
examples/n-patches/main.lua
Normal file
25
examples/n-patches/main.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
local dstRec = { 160.0, 160.0, 8.0, 8.0 };
|
||||
local origin = { 0.0, 0.0 }
|
||||
|
||||
-- local ninePatchInfo = { { 0.0, 0.0, 24.0, 24.0 }, 8, 8, 8, 8, NPATCH_NINE_PATCH }
|
||||
local ninePatchInfo = { source = { 0, 0, 24.0, 24.0 }, left = 8, top = 8, right = 8, bottom = 8, layout = NPATCH_NINE_PATCH }
|
||||
|
||||
local nPatchTexture = RL_LoadTexture( RL_GetBasePath().."../resources/images/n-patch.png" )
|
||||
|
||||
function init()
|
||||
RL_SetWindowTitle( "N-Patches" )
|
||||
RL_SetWindowState( FLAG_VSYNC_HINT )
|
||||
end
|
||||
|
||||
function process( delta )
|
||||
local mousePosition = RL_GetMousePosition();
|
||||
|
||||
-- Resize the n-patch based on mouse position
|
||||
dstRec[3] = mousePosition[1] - dstRec[1];
|
||||
dstRec[4] = mousePosition[2] - dstRec[2];
|
||||
end
|
||||
|
||||
function draw()
|
||||
RL_ClearBackground( RAYWHITE )
|
||||
RL_DrawTextureNPatch( nPatchTexture, ninePatchInfo, dstRec, origin, 0.0, WHITE )
|
||||
end
|
||||
BIN
examples/resources/images/n-patch.png
Normal file
BIN
examples/resources/images/n-patch.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.9 KiB |
@@ -5,6 +5,7 @@ int luaTraceback( lua_State *L );
|
||||
bool luaCallMain();
|
||||
void luaCallProcess();
|
||||
void luaCallDraw();
|
||||
void luaCallExit();
|
||||
void luaRegister();
|
||||
/* Lua Util functions */
|
||||
Color uluaGetColor( lua_State *L );
|
||||
|
||||
@@ -645,6 +645,23 @@ void luaCallDraw() {
|
||||
lua_pop( L, -1 );
|
||||
}
|
||||
|
||||
void luaCallExit() {
|
||||
lua_State *L = state->luaState;
|
||||
lua_pushcfunction( L, luaTraceback );
|
||||
int tracebackidx = lua_gettop(L);
|
||||
|
||||
lua_getglobal( L, "exit" );
|
||||
|
||||
if ( lua_isfunction( L, -1 ) ) {
|
||||
if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) {
|
||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||
state->run = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
lua_pop( L, -1 );
|
||||
}
|
||||
|
||||
void luaRegister() {
|
||||
lua_State *L = state->luaState;
|
||||
|
||||
@@ -1730,54 +1747,53 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ) {
|
||||
lua_pushnil( L );
|
||||
|
||||
while ( lua_next( L, t ) != 0 ) {
|
||||
if ( lua_isnumber( L, -1 ) ) {
|
||||
if ( lua_isnumber( L, -2 ) ) {
|
||||
switch ( i ) {
|
||||
case 0:
|
||||
npatch.source = uluaGetRectangle( L );
|
||||
break;
|
||||
case 1:
|
||||
npatch.left = lua_tointeger( L, -1 );
|
||||
break;
|
||||
case 2:
|
||||
npatch.top = lua_tointeger( L, -1 );
|
||||
break;
|
||||
case 3:
|
||||
npatch.right = lua_tointeger( L, -1 );
|
||||
break;
|
||||
case 4:
|
||||
npatch.bottom = lua_tointeger( L, -1 );
|
||||
break;
|
||||
case 5:
|
||||
npatch.layout = lua_tointeger( L, -1 );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ( lua_isstring( L, -2 ) ) {
|
||||
if ( strcmp( "source", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
/* Do not check type since there should be table and ints. */
|
||||
if ( lua_isnumber( L, -2 ) ) {
|
||||
switch ( i ) {
|
||||
case 0:
|
||||
npatch.source = uluaGetRectangle( L );
|
||||
}
|
||||
else if ( strcmp( "left", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
break;
|
||||
case 1:
|
||||
npatch.left = lua_tointeger( L, -1 );
|
||||
}
|
||||
else if ( strcmp( "top", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
break;
|
||||
case 2:
|
||||
npatch.top = lua_tointeger( L, -1 );
|
||||
}
|
||||
else if ( strcmp( "right", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
break;
|
||||
case 3:
|
||||
npatch.right = lua_tointeger( L, -1 );
|
||||
}
|
||||
else if ( strcmp( "bottom", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
break;
|
||||
case 4:
|
||||
npatch.bottom = lua_tointeger( L, -1 );
|
||||
}
|
||||
else if ( strcmp( "layout", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
break;
|
||||
case 5:
|
||||
npatch.layout = lua_tointeger( L, -1 );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
lua_pop( L, 1 );
|
||||
}
|
||||
else if ( lua_isstring( L, -2 ) ) {
|
||||
if ( strcmp( "source", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
npatch.source = uluaGetRectangle( L );
|
||||
}
|
||||
else if ( strcmp( "left", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
npatch.left = lua_tointeger( L, -1 );
|
||||
}
|
||||
else if ( strcmp( "top", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
npatch.top = lua_tointeger( L, -1 );
|
||||
}
|
||||
else if ( strcmp( "right", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
npatch.right = lua_tointeger( L, -1 );
|
||||
}
|
||||
else if ( strcmp( "bottom", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
npatch.bottom = lua_tointeger( L, -1 );
|
||||
}
|
||||
else if ( strcmp( "layout", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||
npatch.layout = lua_tointeger( L, -1 );
|
||||
}
|
||||
}
|
||||
i++;
|
||||
lua_pop( L, 1 );
|
||||
}
|
||||
return npatch;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ int main( int argn, const char **argc ) {
|
||||
luaCallProcess();
|
||||
luaCallDraw();
|
||||
}
|
||||
luaCallExit();
|
||||
}
|
||||
|
||||
stateFree();
|
||||
|
||||
@@ -2099,6 +2099,7 @@ int ltexturesDrawTextureNPatch( lua_State *L ) {
|
||||
Rectangle dest = uluaGetRectangle( L );
|
||||
lua_pop( L, 1 );
|
||||
NPatchInfo nPatchInfo = uluaGetNPatchInfo( L );
|
||||
|
||||
lua_pop( L, 1 );
|
||||
size_t texId = lua_tointeger( L, -1 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user