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
|
## Globals - ConfigFlags
|
||||||
|
|
||||||
FLAG_VSYNC_HINT
|
FLAG_VSYNC_HINT
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ KEY CHANGES:
|
|||||||
- ADDED: This changelog.
|
- ADDED: This changelog.
|
||||||
- ADDED: Lua interpreter mode.
|
- ADDED: Lua interpreter mode.
|
||||||
- ADDED: Easings extra module.
|
- 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:
|
Detailed changes:
|
||||||
ADDED: Help argument.
|
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();
|
bool luaCallMain();
|
||||||
void luaCallProcess();
|
void luaCallProcess();
|
||||||
void luaCallDraw();
|
void luaCallDraw();
|
||||||
|
void luaCallExit();
|
||||||
void luaRegister();
|
void luaRegister();
|
||||||
/* Lua Util functions */
|
/* Lua Util functions */
|
||||||
Color uluaGetColor( lua_State *L );
|
Color uluaGetColor( lua_State *L );
|
||||||
|
|||||||
@@ -645,6 +645,23 @@ void luaCallDraw() {
|
|||||||
lua_pop( L, -1 );
|
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() {
|
void luaRegister() {
|
||||||
lua_State *L = state->luaState;
|
lua_State *L = state->luaState;
|
||||||
|
|
||||||
@@ -1730,7 +1747,7 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ) {
|
|||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_isnumber( L, -1 ) ) {
|
/* Do not check type since there should be table and ints. */
|
||||||
if ( lua_isnumber( L, -2 ) ) {
|
if ( lua_isnumber( L, -2 ) ) {
|
||||||
switch ( i ) {
|
switch ( i ) {
|
||||||
case 0:
|
case 0:
|
||||||
@@ -1778,7 +1795,6 @@ NPatchInfo uluaGetNPatchInfo( lua_State *L ) {
|
|||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return npatch;
|
return npatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ int main( int argn, const char **argc ) {
|
|||||||
luaCallProcess();
|
luaCallProcess();
|
||||||
luaCallDraw();
|
luaCallDraw();
|
||||||
}
|
}
|
||||||
|
luaCallExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
stateFree();
|
stateFree();
|
||||||
|
|||||||
@@ -2099,6 +2099,7 @@ int ltexturesDrawTextureNPatch( lua_State *L ) {
|
|||||||
Rectangle dest = uluaGetRectangle( L );
|
Rectangle dest = uluaGetRectangle( L );
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
NPatchInfo nPatchInfo = uluaGetNPatchInfo( L );
|
NPatchInfo nPatchInfo = uluaGetNPatchInfo( L );
|
||||||
|
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
size_t texId = lua_tointeger( L, -1 );
|
size_t texId = lua_tointeger( L, -1 );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user