diff options
| -rw-r--r-- | API.md | 103 | ||||
| -rw-r--r-- | examples/platformer/main.lua | 2 | ||||
| -rw-r--r-- | examples/pong_vec/main.lua | 4 | ||||
| -rw-r--r-- | include/core.h | 17 | ||||
| -rw-r--r-- | src/core.c | 222 | ||||
| -rw-r--r-- | src/lua_core.c | 17 |
6 files changed, 346 insertions, 19 deletions
@@ -1558,7 +1558,7 @@ Unload shader from GPU memory ( VRAM ) --- -## Core - Input +## Core - Input-related Keyboard --- @@ -1589,6 +1589,15 @@ Detect if a key has been released once --- +> released = RL_IsKeyUp( int key ) + +Check if a key is NOT being pressed + +- Failure return nil +- Success return bool + +--- + > keycode = RL_GetKeyPressed() Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty @@ -1611,6 +1620,10 @@ Set a custom key to exit program ( default is ESC ) --- +## Core - Input-related Gamepad + +--- + > available = RL_IsGamepadAvailable( int gamepad ) Detect if a gamepad is available @@ -1674,6 +1687,10 @@ Return gamepad internal name id --- +## Core - Input-related Mouse + +--- + > pressed = RL_IsMouseButtonPressed( int button ) Detect if a mouse button has been pressed once @@ -1701,6 +1718,15 @@ Detect if a mouse button has been released once --- +> released = RL_IsMouseButtonUp( int button ) + +Check if a mouse button is NOT being pressed + +- Failure return nil +- Success return bool + +--- + > position = RL_GetMousePosition() Returns mouse position @@ -1717,6 +1743,33 @@ Get mouse delta between frames --- +> success = RL_SetMousePosition( Vector2 position ) + +Set mouse position XY + +- Failure return false +- Success return true + +--- + +> success = RL_SetMouseOffset( Vector2 offset ) + +Set mouse offset + +- Failure return false +- Success return true + +--- + +> success = RL_SetMouseScale( Vector2 scale ) + +Set mouse scaling + +- Failure return false +- Success return true + +--- + > movement = RL_GetMouseWheelMove() Returns mouse wheel movement Y @@ -1725,15 +1778,19 @@ Returns mouse wheel movement Y --- -> success = RL_SetMousePosition( Vector2 position ) +> success = RL_SetMouseCursor( int cursor ) -Set mouse position XY +Set mouse cursor - Failure return false - Success return true --- +## Core - Input-related Touch + +--- + > position = RL_GetTouchPosition( int index ) Get touch position XY for a touch point index ( relative to screen size ) @@ -1760,6 +1817,10 @@ Get touch point identifier for given index --- +## Core - Input-related Gestures + +--- + > success = RL_SetGesturesEnabled( unsigned int flags ) Enable a set of gestures using flags @@ -2213,6 +2274,42 @@ Update camera position for selected mode --- +> success = RL_SetCameraPanControl( int keyPan ) + +Set camera pan key to combine with mouse movement ( free camera ) + +- Failure return false +- Success return true + +--- + +> success = RL_SetCameraAltControl( int keyAlt ) + +Set camera alt key to combine with mouse movement ( free camera ) + +- Failure return false +- Success return true + +--- + +> success = RL_SetCameraSmoothZoomControl( int keySmoothZoom ) + +Set camera smooth zoom key to combine with mouse ( free camera ) + +- Failure return false +- Success return true + +--- + +> success = RL_SetCameraMoveControls( int keyFront, int keyBack, int keyRight, int keyLeft, int keyUp, int keyDown ) + +Set camera move controls ( 1st person and 3rd person cameras ) + +- Failure return false +- Success return true + +--- + ## Core - Screen-space --- diff --git a/examples/platformer/main.lua b/examples/platformer/main.lua index b92999d..bef5786 100644 --- a/examples/platformer/main.lua +++ b/examples/platformer/main.lua @@ -103,7 +103,7 @@ end local function tileCollision( entity ) local vPos = entity.pos + entity.vel -- Future pos with current vel. local vRect = util.tableClone( entity.colRect ) - local tinyGap = 0.001 -- Tiny slit between collisionRect and tile to prevent getting stuck on all seams. + local tinyGap = 0.001 -- Tiny gap between collisionRect and tile to prevent getting stuck on all seams. -- Move test rect to predicted position. vRect[1] = vPos.x - vRect[3] / 2 diff --git a/examples/pong_vec/main.lua b/examples/pong_vec/main.lua index ed406e1..705e68f 100644 --- a/examples/pong_vec/main.lua +++ b/examples/pong_vec/main.lua @@ -70,9 +70,9 @@ end function process( delta ) -- Left player controls. - if RL_IsKeyDown( string.byte( "W" ) ) and 0 < playerLeft.pos.y then + if RL_IsKeyDown( KEY_W ) and 0 < playerLeft.pos.y then playerLeft.pos.y = playerLeft.pos.y - PLAYER_SPEED * delta - elseif RL_IsKeyDown( string.byte( "S" ) ) and playerLeft.pos.y + playerLeft.size.y < winSize.y then + elseif RL_IsKeyDown( KEY_S ) and playerLeft.pos.y + playerLeft.size.y < winSize.y then playerLeft.pos.y = playerLeft.pos.y + PLAYER_SPEED * delta end diff --git a/include/core.h b/include/core.h index f115921..e433ae8 100644 --- a/include/core.h +++ b/include/core.h @@ -115,13 +115,19 @@ int lcoreGetCamera3DFovy( lua_State *L ); int lcoreGetCamera3DProjection( lua_State *L ); int lcoreUpdateCamera3D( lua_State *L ); int lcoreSetCamera3DMode( lua_State *L ); -/* Input. */ +int lcoreSetCameraPanControl( lua_State *L ); +int lcoreSetCameraAltControl( lua_State *L ); +int lcoreSetCameraSmoothZoomControl( lua_State *L ); +int lcoreSetCameraMoveControls( lua_State *L ); +/* Input-related Keyboard. */ int lcoreIsKeyPressed( lua_State *L ); int lcoreIsKeyDown( lua_State *L ); int lcoreIsKeyReleased( lua_State *L ); +int lcoreIsKeyUp( lua_State *L ); int lcoreGetKeyPressed( lua_State *L ); int lcoreGetCharPressed( lua_State *L ); int lcoreSetExitKey( lua_State *L ); +/* Input-related Gamepad. */ int lcoreIsGamepadAvailable( lua_State *L ); int lcoreIsGamepadButtonPressed( lua_State *L ); int lcoreIsGamepadButtonDown( lua_State *L ); @@ -129,16 +135,23 @@ int lcoreIsGamepadButtonReleased( lua_State *L ); int lcoreGetGamepadAxisCount( lua_State *L ); int lcoreGetGamepadAxisMovement( lua_State *L ); int lcoreGetGamepadName( lua_State *L ); +/* Input-related Mouse. */ int lcoreIsMouseButtonPressed( lua_State *L ); int lcoreIsMouseButtonDown( lua_State *L ); int lcoreIsMouseButtonReleased( lua_State *L ); +int lcoreIsMouseButtonUp( lua_State *L ); int lcoreGetMousePosition( lua_State *L ); int lcoreGetMouseDelta( lua_State *L ); -int lcoreGetMouseWheelMove( lua_State *L ); int lcoreSetMousePosition( lua_State *L ); +int lcoreSetMouseOffset( lua_State *L ); +int lcoreSetMouseScale( lua_State *L ); +int lcoreGetMouseWheelMove( lua_State *L ); +int lcoreSetMouseCursor( lua_State *L ); +/* Input-related Touch */ int lcoreGetTouchPosition( lua_State *L ); int lcoreGetTouchPointId( lua_State *L ); int lcoreGetTouchPointCount( lua_State *L ); +/* Input-related Gestures. */ int lcoreSetGesturesEnabled( lua_State *L ); int lcoreIsGestureDetected( lua_State *L ); int lcoreGetGestureDetected( lua_State *L ); @@ -1304,7 +1304,7 @@ int lcoreUnloadShader( lua_State *L ) { } /* -## Core - Input +## Core - Input-related Keyboard */ /* @@ -1362,6 +1362,24 @@ int lcoreIsKeyReleased( lua_State *L ) { } /* +> released = RL_IsKeyUp( int key ) + +Check if a key is NOT being pressed + +- Failure return nil +- Success return bool +*/ +int lcoreIsKeyUp( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_IsKeyUp( int key )" ); + lua_pushnil( L ); + return 1; + } + lua_pushboolean( L, IsKeyUp( lua_tointeger( L, -1 ) ) ); + return 1; +} + +/* > keycode = RL_GetKeyPressed() Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty @@ -1404,6 +1422,10 @@ int lcoreSetExitKey( lua_State *L ) { } /* +## Core - Input-related Gamepad +*/ + +/* > available = RL_IsGamepadAvailable( int gamepad ) Detect if a gamepad is available @@ -1530,6 +1552,10 @@ int lcoreGetGamepadName( lua_State *L ) { } /* +## Core - Input-related Mouse +*/ + +/* > pressed = RL_IsMouseButtonPressed( int button ) Detect if a mouse button has been pressed once @@ -1584,6 +1610,24 @@ int lcoreIsMouseButtonReleased( lua_State *L ) { } /* +> released = RL_IsMouseButtonUp( int button ) + +Check if a mouse button is NOT being pressed + +- Failure return nil +- Success return bool +*/ +int lcoreIsMouseButtonUp( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_IsMouseButtonUp( int button )" ); + lua_pushnil( L ); + return 1; + } + lua_pushboolean( L, IsMouseButtonUp( lua_tointeger( L, -1 ) ) ); + return 1; +} + +/* > position = RL_GetMousePosition() Returns mouse position @@ -1608,6 +1652,72 @@ int lcoreGetMouseDelta( lua_State *L ) { } /* +> success = RL_SetMousePosition( Vector2 position ) + +Set mouse position XY + +- Failure return false +- Success return true +*/ +int lcoreSetMousePosition( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetMousePosition( Vector2 position )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector2 pos = uluaGetVector2( L ); + + SetMousePosition( pos.x, pos.y ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL_SetMouseOffset( Vector2 offset ) + +Set mouse offset + +- Failure return false +- Success return true +*/ +int lcoreSetMouseOffset( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetMouseOffset( Vector2 offset )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector2 offset = uluaGetVector2( L ); + + SetMouseOffset( offset.x, offset.y ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL_SetMouseScale( Vector2 scale ) + +Set mouse scaling + +- Failure return false +- Success return true +*/ +int lcoreSetMouseScale( lua_State *L ) { + if ( !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetMouseScale( Vector2 scale )" ); + lua_pushboolean( L, false ); + return 1; + } + Vector2 scale = uluaGetVector2( L ); + + SetMouseScale( scale.x, scale.y ); + lua_pushboolean( L, true ); + + return 1; +} + +/* > movement = RL_GetMouseWheelMove() Returns mouse wheel movement Y @@ -1620,28 +1730,30 @@ int lcoreGetMouseWheelMove( lua_State *L ) { } /* -> success = RL_SetMousePosition( Vector2 position ) +> success = RL_SetMouseCursor( int cursor ) -Set mouse position XY +Set mouse cursor - Failure return false - Success return true */ -int lcoreSetMousePosition( lua_State *L ) { - if ( !lua_istable( L, -1 ) ) { - TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetMousePosition( Vector2 position )" ); +int lcoreSetMouseCursor( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetMouseCursor( int cursor )" ); lua_pushboolean( L, false ); return 1; } - Vector2 pos = uluaGetVector2( L ); - - SetMousePosition( pos.x, pos.y ); + SetMouseCursor( lua_tointeger( L, -1 ) ); lua_pushboolean( L, true ); return 1; } /* +## Core - Input-related Touch +*/ + +/* > position = RL_GetTouchPosition( int index ) Get touch position XY for a touch point index ( relative to screen size ) @@ -1693,6 +1805,10 @@ int lcoreGetTouchPointCount( lua_State *L ) { } /* +## Core - Input-related Gestures +*/ + +/* > success = RL_SetGesturesEnabled( unsigned int flags ) Enable a set of gestures using flags @@ -2812,6 +2928,94 @@ int lcoreUpdateCamera3D( lua_State *L ) { } /* +> success = RL_SetCameraPanControl( int keyPan ) + +Set camera pan key to combine with mouse movement ( free camera ) + +- Failure return false +- Success return true +*/ +int lcoreSetCameraPanControl( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetCameraPanControl( int keyPan )" ); + lua_pushboolean( L, false ); + return 1; + } + SetCameraPanControl( lua_tointeger( L, -1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL_SetCameraAltControl( int keyAlt ) + +Set camera alt key to combine with mouse movement ( free camera ) + +- Failure return false +- Success return true +*/ +int lcoreSetCameraAltControl( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetCameraAltControl( int keyAlt )" ); + lua_pushboolean( L, false ); + return 1; + } + SetCameraAltControl( lua_tointeger( L, -1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL_SetCameraSmoothZoomControl( int keySmoothZoom ) + +Set camera smooth zoom key to combine with mouse ( free camera ) + +- Failure return false +- Success return true +*/ +int lcoreSetCameraSmoothZoomControl( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetCameraSmoothZoomControl( int keySmoothZoom )" ); + lua_pushboolean( L, false ); + return 1; + } + SetCameraSmoothZoomControl( lua_tointeger( L, -1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> success = RL_SetCameraMoveControls( int keyFront, int keyBack, int keyRight, int keyLeft, int keyUp, int keyDown ) + +Set camera move controls ( 1st person and 3rd person cameras ) + +- Failure return false +- Success return true +*/ +int lcoreSetCameraMoveControls( lua_State *L ) { + if ( !lua_isnumber( L, -6 ) || !lua_isnumber( L, -5 ) || !lua_isnumber( L, -4 ) + || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetCameraMoveControls( int keyFront, int keyBack, int keyRight, int keyLeft, int keyUp, int keyDown )" ); + lua_pushboolean( L, false ); + return 1; + } + int keyDown = lua_tointeger( L, -1 ); + int keyUp = lua_tointeger( L, -2 ); + int keyLeft = lua_tointeger( L, -3 ); + int keyRight = lua_tointeger( L, -4 ); + int keyBack = lua_tointeger( L, -5 ); + int keyFront = lua_tointeger( L, -6 ); + + SetCameraMoveControls( keyFront, keyBack, keyRight, keyLeft, keyUp, keyDown ); + lua_pushboolean( L, true ); + + return 1; +} + +/* ## Core - Screen-space */ diff --git a/src/lua_core.c b/src/lua_core.c index 5289a07..17afffb 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -747,13 +747,19 @@ void luaRegister() { lua_register( L, "RL_GetCamera3DProjection", lcoreGetCamera3DProjection ); lua_register( L, "RL_UpdateCamera3D", lcoreUpdateCamera3D ); lua_register( L, "RL_SetCamera3DMode", lcoreSetCamera3DMode ); - /* Input. */ + lua_register( L, "RL_SetCameraPanControl", lcoreSetCameraPanControl ); + lua_register( L, "RL_SetCameraAltControl", lcoreSetCameraAltControl ); + lua_register( L, "RL_SetCameraSmoothZoomControl", lcoreSetCameraSmoothZoomControl ); + lua_register( L, "RL_SetCameraMoveControls", lcoreSetCameraMoveControls ); + /* Input-related Keyboard. */ lua_register( L, "RL_IsKeyPressed", lcoreIsKeyPressed ); lua_register( L, "RL_IsKeyDown", lcoreIsKeyDown ); lua_register( L, "RL_IsKeyReleased", lcoreIsKeyReleased ); + lua_register( L, "RL_IsKeyUp", lcoreIsKeyUp ); lua_register( L, "RL_GetKeyPressed", lcoreGetKeyPressed ); lua_register( L, "RL_GetCharPressed", lcoreGetCharPressed ); lua_register( L, "RL_SetExitKey", lcoreSetExitKey ); + /* Input-related Gamepad. */ lua_register( L, "RL_IsGamepadAvailable", lcoreIsGamepadAvailable ); lua_register( L, "RL_IsGamepadButtonPressed", lcoreIsGamepadButtonPressed ); lua_register( L, "RL_IsGamepadButtonDown", lcoreIsGamepadButtonDown ); @@ -761,16 +767,23 @@ void luaRegister() { lua_register( L, "RL_GetGamepadAxisCount", lcoreGetGamepadAxisCount ); lua_register( L, "RL_GetGamepadAxisMovement", lcoreGetGamepadAxisMovement ); lua_register( L, "RL_GetGamepadName", lcoreGetGamepadName ); + /* Input-related Mouse. */ lua_register( L, "RL_IsMouseButtonPressed", lcoreIsMouseButtonPressed ); lua_register( L, "RL_IsMouseButtonDown", lcoreIsMouseButtonDown ); lua_register( L, "RL_IsMouseButtonReleased", lcoreIsMouseButtonReleased ); + lua_register( L, "RL_IsMouseButtonUp", lcoreIsMouseButtonUp ); lua_register( L, "RL_GetMousePosition", lcoreGetMousePosition ); lua_register( L, "RL_GetMouseDelta", lcoreGetMouseDelta ); - lua_register( L, "RL_GetMouseWheelMove", lcoreGetMouseWheelMove ); lua_register( L, "RL_SetMousePosition", lcoreSetMousePosition ); + lua_register( L, "RL_SetMouseOffset", lcoreSetMouseOffset ); + lua_register( L, "RL_SetMouseScale", lcoreSetMouseScale ); + lua_register( L, "RL_GetMouseWheelMove", lcoreGetMouseWheelMove ); + lua_register( L, "RL_SetMouseCursor", lcoreSetMouseCursor ); + /* Input-related Touch */ lua_register( L, "RL_GetTouchPosition", lcoreGetTouchPosition ); lua_register( L, "RL_GetTouchPointId", lcoreGetTouchPointId ); lua_register( L, "RL_GetTouchPointCount", lcoreGetTouchPointCount ); + /* Input-related Gestures. */ lua_register( L, "RL_SetGesturesEnabled", lcoreSetGesturesEnabled ); lua_register( L, "RL_IsGestureDetected", lcoreIsGestureDetected ); lua_register( L, "RL_GetGestureDetected", lcoreGetGestureDetected ); |
