diff options
| author | jussi | 2022-02-22 15:06:23 +0200 |
|---|---|---|
| committer | jussi | 2022-02-22 15:06:23 +0200 |
| commit | a7f58b3261565b59e508c659ae3a7f1964a5bad5 (patch) | |
| tree | e9e337687923e0997885d1b55f735d82bf29c6ed | |
| parent | 8800de59fa704cfe60ac980db079b44042639684 (diff) | |
| download | reilua-enhanced-a7f58b3261565b59e508c659ae3a7f1964a5bad5.tar.gz reilua-enhanced-a7f58b3261565b59e508c659ae3a7f1964a5bad5.tar.bz2 reilua-enhanced-a7f58b3261565b59e508c659ae3a7f1964a5bad5.zip | |
Touch and gestures.
| -rw-r--r-- | API.md | 142 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | devnotes | 7 | ||||
| -rw-r--r-- | examples/snake/main.lua | 5 | ||||
| -rw-r--r-- | include/core.h | 11 | ||||
| -rw-r--r-- | include/text.h | 4 | ||||
| -rw-r--r-- | src/core.c | 176 | ||||
| -rw-r--r-- | src/lua_core.c | 27 | ||||
| -rw-r--r-- | src/main.c | 1 | ||||
| -rw-r--r-- | src/text.c | 69 |
10 files changed, 429 insertions, 14 deletions
@@ -276,6 +276,30 @@ SHADER_ATTRIB_VEC3 SHADER_ATTRIB_VEC4 +## Globals - Gesture + +GESTURE_NONE + +GESTURE_TAP + +GESTURE_DOUBLETAP + +GESTURE_HOLD + +GESTURE_DRAG + +GESTURE_SWIPE_RIGHT + +GESTURE_SWIPE_LEFT + +GESTURE_SWIPE_UP + +GESTURE_SWIPE_DOWN + +GESTURE_PINCH_IN + +GESTURE_PINCH_OUT + ## Globals - Colors WHITE @@ -579,16 +603,20 @@ Set target FPS ( maximum ) --- -> RL_GetFrameTime() +> delta = RL_GetFrameTime() Get time in seconds for last frame drawn ( Delta time ) +- Success return float + --- -> RL_GetTime() +> time = RL_GetTime() Get elapsed time in seconds since InitWindow() +- Success return float + --- ## Core - Misc @@ -978,6 +1006,98 @@ Set mouse position XY --- +> position = RL_GetTouchPosition( int index ) + +Get touch position XY for a touch point index ( relative to screen size ) + +- Failure return false +- Success return Vector2 + +--- + +> id = RL_GetTouchPointId( int index ) + +Get touch point identifier for given index + +- Failure return false +- Success return int + +--- + +> count = RL_GetTouchPointCount() + +Get touch point identifier for given index + +- Success return int + +--- + +> success = RL_SetGesturesEnabled( unsigned int flags ) + +Enable a set of gestures using flags + +- Failure return false +- Success return true + +--- + +> detected = RL_IsGestureDetected( int gesture ) + +Check if a gesture have been detected + +- Failure return nil +- Success return bool + +--- + +> gesture = RL_GetGestureDetected() + +Get latest detected gesture + +- Success return int + +--- + +> time = RL_GetGestureHoldDuration() + +Get gesture hold time in milliseconds + +- Success return float + +--- + +> vector = RL_GetGestureDragVector() + +Get gesture drag vector + +- Success return Vector2 + +--- + +> angle = RL_GetGestureDragAngle() + +Get gesture drag angle + +- Success return float + +--- + +> vector = RL_GetGesturePinchVector() + +Get gesture pinch delta + +- Success return Vector2 + +--- + +> angle = RL_GetGesturePinchAngle() + +Get gesture pinch angle + +- Success return float + +--- + ## Core - File --- @@ -1702,6 +1822,15 @@ Load font from file into GPU memory ( VRAM ) --- +> success = RL_UnloadFont( Font font ) + +Unload Font from GPU memory ( VRAM ) + +- Failure return false +- Success return true + +--- + ## Text - Draw --- @@ -1724,6 +1853,15 @@ Draw text using font and additional parameters --- +> success = RL_DrawTextPro( Font font, const char text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint ) + +Draw text using Font and pro parameters ( rotation ) + +- Failure return false +- Success return true + +--- + ## Models - Basic --- @@ -183,7 +183,6 @@ We can now build the game. You can use the command it top of the "CMakeLists.txt ``` cmake .. -DCMAKE_TOOLCHAIN_FILE=<YOUR PATH HERE>/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DPLATFORM=Web - make ``` @@ -4,17 +4,14 @@ Backlog { * Raygui * Advanced controls * Core - * File drop * Screen-space-related - * Cursor-related + * Files drop * Text - * Fonts - * More draw functions + * More Font loading/unloading functions * Codepoints * String management. At least TextSplit. * Audio * Wave - * Gestures * Raymath * Quaternions * Physac diff --git a/examples/snake/main.lua b/examples/snake/main.lua index 74b7191..13cff1f 100644 --- a/examples/snake/main.lua +++ b/examples/snake/main.lua @@ -210,8 +210,13 @@ function draw() drawGrass() drawSnake() drawApple() + + if gameState == STATE.OVER then + RL_DrawText( 0, "Press Enter to\nrestart", { 10, 10 }, 10, 2, WHITE ) + end RL_EndTextureMode() + -- Draw framebuffer to window. RL_SetTextureSource( TEXTURE_SOURCE_RENDER_TEXTURE ) RL_DrawTexturePro( framebuffer, { 0, 0, RESOLUTION[1], -RESOLUTION[2] }, { 0, 0, winSize[1], winSize[2] }, { 0, 0 }, 0.0, WHITE ) diff --git a/include/core.h b/include/core.h index b277356..8d855be 100644 --- a/include/core.h +++ b/include/core.h @@ -99,3 +99,14 @@ int lcoreGetMousePosition( lua_State *L ); int lcoreGetMouseDelta( lua_State *L ); int lcoreGetMouseWheelMove( lua_State *L ); int lcoreSetMousePosition( lua_State *L ); +int lcoreGetTouchPosition( lua_State *L ); +int lcoreGetTouchPointId( lua_State *L ); +int lcoreGetTouchPointCount( lua_State *L ); +int lcoreSetGesturesEnabled( lua_State *L ); +int lcoreIsGestureDetected( lua_State *L ); +int lcoreGetGestureDetected( lua_State *L ); +int lcoreGetGestureHoldDuration( lua_State *L ); +int lcoreGetGestureDragVector( lua_State *L ); +int lcoreGetGestureDragAngle( lua_State *L ); +int lcoreGetGesturePinchVector( lua_State *L ); +int lcoreGetGesturePinchAngle( lua_State *L ); diff --git a/include/text.h b/include/text.h index e9cced8..c1e7b3e 100644 --- a/include/text.h +++ b/include/text.h @@ -3,7 +3,9 @@ /* Validators. */ bool validFont( size_t id ); /* Loading. */ -int lmodelsLoadFont( lua_State *L ); +int ltextLoadFont( lua_State *L ); +int ltextUnloadFont( lua_State *L ); /* Drawing. */ int ltextDrawFPS( lua_State *L ); int ltextDrawText( lua_State *L ); +int ltextDrawTextPro( lua_State *L ); @@ -326,9 +326,11 @@ int lcoreSetTargetFPS( lua_State *L ) { } /* -> RL_GetFrameTime() +> delta = RL_GetFrameTime() Get time in seconds for last frame drawn ( Delta time ) + +- Success return float */ int lcoreGetFrameTime( lua_State *L ) { lua_pushnumber( L, GetFrameTime() ); @@ -337,9 +339,11 @@ int lcoreGetFrameTime( lua_State *L ) { } /* -> RL_GetTime() +> time = RL_GetTime() Get elapsed time in seconds since InitWindow() + +- Success return float */ int lcoreGetTime( lua_State *L ) { lua_pushnumber( L, GetTime() ); @@ -1265,6 +1269,174 @@ int lcoreSetMousePosition( lua_State *L ) { } /* +> position = RL_GetTouchPosition( int index ) + +Get touch position XY for a touch point index ( relative to screen size ) + +- Failure return false +- Success return Vector2 +*/ +int lcoreGetTouchPosition( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetTouchPosition( int index )" ); + lua_pushboolean( L, false ); + return 1; + } + uluaPushVector2( L, GetTouchPosition( lua_tointeger( L, -1 ) ) ); + + return 1; +} + +/* +> id = RL_GetTouchPointId( int index ) + +Get touch point identifier for given index + +- Failure return false +- Success return int +*/ +int lcoreGetTouchPointId( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_GetTouchPointId( int index )" ); + lua_pushboolean( L, false ); + return 1; + } + lua_pushinteger( L, GetTouchPointId( lua_tointeger( L, -1 ) ) ); + + return 1; +} + +/* +> count = RL_GetTouchPointCount() + +Get touch point identifier for given index + +- Success return int +*/ +int lcoreGetTouchPointCount( lua_State *L ) { + lua_pushinteger( L, GetTouchPointCount() ); + + return 1; +} + +/* +> success = RL_SetGesturesEnabled( unsigned int flags ) + +Enable a set of gestures using flags + +- Failure return false +- Success return true +*/ +int lcoreSetGesturesEnabled( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_SetGesturesEnabled( unsigned int flags )" ); + lua_pushboolean( L, false ); + return 1; + } + SetGesturesEnabled( (unsigned int)lua_tointeger( L, -1 ) ); + lua_pushboolean( L, true ); + + return 1; +} + +/* +> detected = RL_IsGestureDetected( int gesture ) + +Check if a gesture have been detected + +- Failure return nil +- Success return bool +*/ +int lcoreIsGestureDetected( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_IsGestureDetected( int gesture )" ); + lua_pushnil( L ); + return 1; + } + lua_pushboolean( L, IsGestureDetected( lua_tointeger( L, -1 ) ) ); + + return 1; +} + +/* +> gesture = RL_GetGestureDetected() + +Get latest detected gesture + +- Success return int +*/ +int lcoreGetGestureDetected( lua_State *L ) { + lua_pushinteger( L, GetGestureDetected() ); + + return 1; +} + +/* +> time = RL_GetGestureHoldDuration() + +Get gesture hold time in milliseconds + +- Success return float +*/ +int lcoreGetGestureHoldDuration( lua_State *L ) { + lua_pushnumber( L, GetGestureHoldDuration() ); + + return 1; +} + +/* +> vector = RL_GetGestureDragVector() + +Get gesture drag vector + +- Success return Vector2 +*/ +int lcoreGetGestureDragVector( lua_State *L ) { + uluaPushVector2( L, GetGestureDragVector() ); + + return 1; +} + +/* +> angle = RL_GetGestureDragAngle() + +Get gesture drag angle + +- Success return float +*/ +int lcoreGetGestureDragAngle( lua_State *L ) { + lua_pushnumber( L, GetGestureDragAngle() ); + + return 1; +} + +/* +> vector = RL_GetGesturePinchVector() + +Get gesture pinch delta + +- Success return Vector2 +*/ +int lcoreGetGesturePinchVector( lua_State *L ) { + uluaPushVector2( L, GetGesturePinchVector() ); + + return 1; +} + +/* +> angle = RL_GetGesturePinchAngle() + +Get gesture pinch angle + +- Success return float +*/ +int lcoreGetGesturePinchAngle( lua_State *L ) { + lua_pushnumber( L, GetGesturePinchAngle() ); + + return 1; +} + +/* ## Core - File */ diff --git a/src/lua_core.c b/src/lua_core.c index 54be454..42b3f22 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -156,6 +156,18 @@ void defineGlobals() { assignGlobalInt( SHADER_ATTRIB_VEC2, "SHADER_ATTRIB_VEC2" ); assignGlobalInt( SHADER_ATTRIB_VEC3, "SHADER_ATTRIB_VEC3" ); assignGlobalInt( SHADER_ATTRIB_VEC4, "SHADER_ATTRIB_VEC4" ); + /* Gesture */ + assignGlobalInt( GESTURE_NONE, "GESTURE_NONE" ); + assignGlobalInt( GESTURE_TAP, "GESTURE_TAP" ); + assignGlobalInt( GESTURE_DOUBLETAP, "GESTURE_DOUBLETAP" ); + assignGlobalInt( GESTURE_HOLD, "GESTURE_HOLD" ); + assignGlobalInt( GESTURE_DRAG, "GESTURE_DRAG" ); + assignGlobalInt( GESTURE_SWIPE_RIGHT, "GESTURE_SWIPE_RIGHT" ); + assignGlobalInt( GESTURE_SWIPE_LEFT, "GESTURE_SWIPE_LEFT" ); + assignGlobalInt( GESTURE_SWIPE_UP, "GESTURE_SWIPE_UP" ); + assignGlobalInt( GESTURE_SWIPE_DOWN, "GESTURE_SWIPE_DOWN" ); + assignGlobalInt( GESTURE_PINCH_IN, "GESTURE_PINCH_IN" ); + assignGlobalInt( GESTURE_PINCH_OUT, "GESTURE_PINCH_OUT" ); /* Colors */ assignGlobalColor( WHITE, "WHITE" ); assignGlobalColor( BLACK, "BLACK" ); @@ -402,6 +414,17 @@ void luaRegister() { lua_register( L, "RL_GetMouseDelta", lcoreGetMouseDelta ); lua_register( L, "RL_GetMouseWheelMove", lcoreGetMouseWheelMove ); lua_register( L, "RL_SetMousePosition", lcoreSetMousePosition ); + lua_register( L, "RL_GetTouchPosition", lcoreGetTouchPosition ); + lua_register( L, "RL_GetTouchPointId", lcoreGetTouchPointId ); + lua_register( L, "RL_GetTouchPointCount", lcoreGetTouchPointCount ); + lua_register( L, "RL_SetGesturesEnabled", lcoreSetGesturesEnabled ); + lua_register( L, "RL_IsGestureDetected", lcoreIsGestureDetected ); + lua_register( L, "RL_GetGestureDetected", lcoreGetGestureDetected ); + lua_register( L, "RL_GetGestureHoldDuration", lcoreGetGestureHoldDuration ); + lua_register( L, "RL_GetGestureDragVector", lcoreGetGestureDragVector ); + lua_register( L, "RL_GetGestureDragAngle", lcoreGetGestureDragAngle ); + lua_register( L, "RL_GetGesturePinchVector", lcoreGetGesturePinchVector ); + lua_register( L, "RL_GetGesturePinchAngle", lcoreGetGesturePinchAngle ); /* Shapes. */ /* Drawing. */ @@ -532,10 +555,12 @@ void luaRegister() { /* Text. */ /* Loading. */ - lua_register( L, "RL_LoadFont", lmodelsLoadFont ); + lua_register( L, "RL_LoadFont", ltextLoadFont ); + lua_register( L, "RL_UnloadFont", ltextUnloadFont ); /* Drawing. */ lua_register( L, "RL_DrawFPS", ltextDrawFPS ); lua_register( L, "RL_DrawText", ltextDrawText ); + lua_register( L, "RL_DrawTextPro", ltextDrawTextPro ); /* Audio. */ /* Sound. */ @@ -19,6 +19,7 @@ int main( int argn, const char **argc ) { sprintf( exePath, "%s/", GetWorkingDirectory() ); } + TraceLog( LOG_INFO, "ReiLua %d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH ); stateInit( exePath ); while ( state->run ) { @@ -40,7 +40,7 @@ Load font from file into GPU memory ( VRAM ) - Failure return -1 - Success return int */ -int lmodelsLoadFont( lua_State *L ) { +int ltextLoadFont( lua_State *L ) { if ( !lua_isstring( L, -1 ) ) { TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_LoadFont( string fileName )" ); lua_pushinteger( L, -1 ); @@ -62,6 +62,33 @@ int lmodelsLoadFont( lua_State *L ) { } /* +> success = RL_UnloadFont( Font font ) + +Unload Font from GPU memory ( VRAM ) + +- Failure return false +- Success return true +*/ +int ltextUnloadFont( lua_State *L ) { + if ( !lua_isnumber( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_UnloadFont( Font font )" ); + lua_pushboolean( L, false ); + return 1; + } + size_t id = lua_tointeger( L, -1 ); + + if ( !validFont( id ) ) { + lua_pushboolean( L, false ); + return 1; + } + UnloadFont( *state->fonts[ id ] ); + state->fonts[ id ] = NULL; + lua_pushboolean( L, true ); + + return 1; +} + +/* ## Text - Draw */ @@ -116,9 +143,47 @@ int ltextDrawText( lua_State *L ) { lua_pushboolean( L, false ); return 1; } - DrawTextEx( *state->fonts[ fontId ], lua_tostring( L, -1 ), position, fontSize, spacing, color ); lua_pushboolean( L, true ); return 1; } + +/* +> success = RL_DrawTextPro( Font font, const char text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint ) + +Draw text using Font and pro parameters ( rotation ) + +- Failure return false +- Success return true +*/ +int ltextDrawTextPro( lua_State *L ) { + if ( !lua_isnumber( L, -8 ) || !lua_isstring( L, -7 ) || !lua_istable( L, -6 ) || !lua_istable( L, -5 ) + || !lua_isnumber( L, -4 ) || !lua_isnumber( L, -3 ) || !lua_isnumber( L, -2 ) || !lua_istable( L, -1 ) ) { + TraceLog( LOG_WARNING, "%s", "Bad call of function. RL_DrawTextPro( Font font, const char text, Vector2 position, Vector2 origin, float rotation, float fontSize, float spacing, Color tint )" ); + lua_pushboolean( L, false ); + return 1; + } + Color color = uluaGetColor( L ); + lua_pop( L, 1 ); + float spacing = lua_tonumber( L, -1 ); + lua_pop( L, 1 ); + float fontSize = lua_tonumber( L, -1 ); + lua_pop( L, 1 ); + float rotation = lua_tonumber( L, -1 ); + lua_pop( L, 1 ); + Vector2 origin = uluaGetVector2( L ); + lua_pop( L, 1 ); + Vector2 position = uluaGetVector2( L ); + lua_pop( L, 1 ); + size_t fontId = lua_tointeger( L, -2 ); + + if ( !validFont( fontId ) ) { + lua_pushboolean( L, false ); + return 1; + } + DrawTextPro( *state->fonts[ fontId ], lua_tostring( L, -1 ), position, origin, rotation, fontSize, spacing, color ); + lua_pushboolean( L, true ); + + return 1; +} |
