Indentation fix.
This commit is contained in:
24
src/core.c
24
src/core.c
@@ -1073,16 +1073,16 @@ int lcoreSetShaderValueV( lua_State* L ) {
|
|||||||
|
|
||||||
/* t = values index. */
|
/* t = values index. */
|
||||||
int t = 3, i = 0;
|
int t = 3, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_isnumber( L, -1 ) ) {
|
if ( lua_isnumber( L, -1 ) ) {
|
||||||
floats[i] = lua_tonumber( L, -1 );
|
floats[i] = lua_tonumber( L, -1 );
|
||||||
ints[i] = lua_tointeger( L, -1 );
|
ints[i] = lua_tointeger( L, -1 );
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
/* Read values end. */
|
/* Read values end. */
|
||||||
|
|
||||||
@@ -1370,7 +1370,7 @@ int lcoreLoadRandomSequence( lua_State* L ) {
|
|||||||
|
|
||||||
for ( int i = 0; i < count; i++ ) {
|
for ( int i = 0; i < count; i++ ) {
|
||||||
lua_pushinteger( L, sequence[i] );
|
lua_pushinteger( L, sequence[i] );
|
||||||
lua_rawseti( L, -2, i + 1 );
|
lua_rawseti( L, -2, i + 1 );
|
||||||
}
|
}
|
||||||
UnloadRandomSequence( sequence );
|
UnloadRandomSequence( sequence );
|
||||||
|
|
||||||
@@ -1753,7 +1753,7 @@ int lcoreLoadDirectoryFiles( lua_State* L ) {
|
|||||||
|
|
||||||
for ( int i = 0; i < files.count; ++i ) {
|
for ( int i = 0; i < files.count; ++i ) {
|
||||||
lua_pushstring( L, files.paths[i] );
|
lua_pushstring( L, files.paths[i] );
|
||||||
lua_rawseti( L, -2, i+1 );
|
lua_rawseti( L, -2, i+1 );
|
||||||
}
|
}
|
||||||
UnloadDirectoryFiles( files );
|
UnloadDirectoryFiles( files );
|
||||||
|
|
||||||
@@ -1781,7 +1781,7 @@ int lcoreLoadDirectoryFilesEx( lua_State* L ) {
|
|||||||
|
|
||||||
for ( int i = 0; i < files.count; ++i ) {
|
for ( int i = 0; i < files.count; ++i ) {
|
||||||
lua_pushstring( L, files.paths[i] );
|
lua_pushstring( L, files.paths[i] );
|
||||||
lua_rawseti( L, -2, i+1 );
|
lua_rawseti( L, -2, i+1 );
|
||||||
}
|
}
|
||||||
UnloadDirectoryFiles( files );
|
UnloadDirectoryFiles( files );
|
||||||
|
|
||||||
@@ -3204,9 +3204,9 @@ int lcoreCamera3DYaw( lua_State* L ) {
|
|||||||
> RL.Camera3DPitch( camera3D camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp )
|
> RL.Camera3DPitch( camera3D camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp )
|
||||||
|
|
||||||
Rotates the camera around it's right vector, pitch is "looking up and down"
|
Rotates the camera around it's right vector, pitch is "looking up and down"
|
||||||
- lockView prevents camera overrotation (aka "somersaults")
|
- lockView prevents camera overrotation (aka "somersaults")
|
||||||
- rotateAroundTarget defines if rotation is around target or around it's position
|
- rotateAroundTarget defines if rotation is around target or around it's position
|
||||||
- rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
|
- rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
|
||||||
NOTE: angle must be provided in radians
|
NOTE: angle must be provided in radians
|
||||||
*/
|
*/
|
||||||
int lcoreCamera3DPitch( lua_State* L ) {
|
int lcoreCamera3DPitch( lua_State* L ) {
|
||||||
|
|||||||
212
src/models.c
212
src/models.c
@@ -11,99 +11,99 @@ void unloadMaterial( Material* material ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DrawBillboardProNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint ) {
|
void DrawBillboardProNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector3 up, Vector2 size, Vector2 origin, float rotation, Color tint ) {
|
||||||
// NOTE: Billboard size will maintain source rectangle aspect ratio, size will represent billboard width
|
// NOTE: Billboard size will maintain source rectangle aspect ratio, size will represent billboard width
|
||||||
// Vector2 sizeRatio = { size.x*(float)source.width/source.height, size.y };
|
// Vector2 sizeRatio = { size.x*(float)source.width/source.height, size.y };
|
||||||
Vector2 sizeRatio = { size.x, size.y };
|
Vector2 sizeRatio = { size.x, size.y };
|
||||||
|
|
||||||
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||||
|
|
||||||
Vector3 right = { matView.m0, matView.m4, matView.m8 };
|
Vector3 right = { matView.m0, matView.m4, matView.m8 };
|
||||||
//Vector3 up = { matView.m1, matView.m5, matView.m9 };
|
//Vector3 up = { matView.m1, matView.m5, matView.m9 };
|
||||||
|
|
||||||
Vector3 rightScaled = Vector3Scale(right, sizeRatio.x/2);
|
Vector3 rightScaled = Vector3Scale(right, sizeRatio.x/2);
|
||||||
Vector3 upScaled = Vector3Scale(up, sizeRatio.y/2);
|
Vector3 upScaled = Vector3Scale(up, sizeRatio.y/2);
|
||||||
|
|
||||||
Vector3 p1 = Vector3Add(rightScaled, upScaled);
|
Vector3 p1 = Vector3Add(rightScaled, upScaled);
|
||||||
Vector3 p2 = Vector3Subtract(rightScaled, upScaled);
|
Vector3 p2 = Vector3Subtract(rightScaled, upScaled);
|
||||||
|
|
||||||
Vector3 topLeft = Vector3Scale(p2, -1);
|
Vector3 topLeft = Vector3Scale(p2, -1);
|
||||||
Vector3 topRight = p1;
|
Vector3 topRight = p1;
|
||||||
Vector3 bottomRight = p2;
|
Vector3 bottomRight = p2;
|
||||||
Vector3 bottomLeft = Vector3Scale(p1, -1);
|
Vector3 bottomLeft = Vector3Scale(p1, -1);
|
||||||
|
|
||||||
if (rotation != 0.0f)
|
if (rotation != 0.0f)
|
||||||
{
|
{
|
||||||
float sinRotation = sinf(rotation*DEG2RAD);
|
float sinRotation = sinf(rotation*DEG2RAD);
|
||||||
float cosRotation = cosf(rotation*DEG2RAD);
|
float cosRotation = cosf(rotation*DEG2RAD);
|
||||||
|
|
||||||
// NOTE: (-1, 1) is the range where origin.x, origin.y is inside the texture
|
// NOTE: (-1, 1) is the range where origin.x, origin.y is inside the texture
|
||||||
float rotateAboutX = sizeRatio.x*origin.x/2;
|
float rotateAboutX = sizeRatio.x*origin.x/2;
|
||||||
float rotateAboutY = sizeRatio.y*origin.y/2;
|
float rotateAboutY = sizeRatio.y*origin.y/2;
|
||||||
|
|
||||||
float xtvalue, ytvalue;
|
float xtvalue, ytvalue;
|
||||||
float rotatedX, rotatedY;
|
float rotatedX, rotatedY;
|
||||||
|
|
||||||
xtvalue = Vector3DotProduct(right, topLeft) - rotateAboutX; // Project points to x and y coordinates on the billboard plane
|
xtvalue = Vector3DotProduct(right, topLeft) - rotateAboutX; // Project points to x and y coordinates on the billboard plane
|
||||||
ytvalue = Vector3DotProduct(up, topLeft) - rotateAboutY;
|
ytvalue = Vector3DotProduct(up, topLeft) - rotateAboutY;
|
||||||
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX; // Rotate about the point origin
|
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX; // Rotate about the point origin
|
||||||
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
|
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
|
||||||
topLeft = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX)); // Translate back to cartesian coordinates
|
topLeft = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX)); // Translate back to cartesian coordinates
|
||||||
|
|
||||||
xtvalue = Vector3DotProduct(right, topRight) - rotateAboutX;
|
xtvalue = Vector3DotProduct(right, topRight) - rotateAboutX;
|
||||||
ytvalue = Vector3DotProduct(up, topRight) - rotateAboutY;
|
ytvalue = Vector3DotProduct(up, topRight) - rotateAboutY;
|
||||||
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
|
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
|
||||||
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
|
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
|
||||||
topRight = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
|
topRight = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
|
||||||
|
|
||||||
xtvalue = Vector3DotProduct(right, bottomRight) - rotateAboutX;
|
xtvalue = Vector3DotProduct(right, bottomRight) - rotateAboutX;
|
||||||
ytvalue = Vector3DotProduct(up, bottomRight) - rotateAboutY;
|
ytvalue = Vector3DotProduct(up, bottomRight) - rotateAboutY;
|
||||||
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
|
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
|
||||||
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
|
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
|
||||||
bottomRight = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
|
bottomRight = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
|
||||||
|
|
||||||
xtvalue = Vector3DotProduct(right, bottomLeft)-rotateAboutX;
|
xtvalue = Vector3DotProduct(right, bottomLeft)-rotateAboutX;
|
||||||
ytvalue = Vector3DotProduct(up, bottomLeft)-rotateAboutY;
|
ytvalue = Vector3DotProduct(up, bottomLeft)-rotateAboutY;
|
||||||
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
|
rotatedX = xtvalue*cosRotation - ytvalue*sinRotation + rotateAboutX;
|
||||||
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
|
rotatedY = xtvalue*sinRotation + ytvalue*cosRotation + rotateAboutY;
|
||||||
bottomLeft = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
|
bottomLeft = Vector3Add(Vector3Scale(up, rotatedY), Vector3Scale(right, rotatedX));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate points to the draw center (position)
|
// Translate points to the draw center (position)
|
||||||
topLeft = Vector3Add(topLeft, position);
|
topLeft = Vector3Add(topLeft, position);
|
||||||
topRight = Vector3Add(topRight, position);
|
topRight = Vector3Add(topRight, position);
|
||||||
bottomRight = Vector3Add(bottomRight, position);
|
bottomRight = Vector3Add(bottomRight, position);
|
||||||
bottomLeft = Vector3Add(bottomLeft, position);
|
bottomLeft = Vector3Add(bottomLeft, position);
|
||||||
|
|
||||||
rlSetTexture(texture.id);
|
rlSetTexture(texture.id);
|
||||||
|
|
||||||
rlBegin(RL_QUADS);
|
rlBegin(RL_QUADS);
|
||||||
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
|
rlColor4ub(tint.r, tint.g, tint.b, tint.a);
|
||||||
|
|
||||||
// Bottom-left corner for texture and quad
|
// Bottom-left corner for texture and quad
|
||||||
rlTexCoord2f((float)source.x/texture.width, (float)source.y/texture.height);
|
rlTexCoord2f((float)source.x/texture.width, (float)source.y/texture.height);
|
||||||
rlVertex3f(topLeft.x, topLeft.y, topLeft.z);
|
rlVertex3f(topLeft.x, topLeft.y, topLeft.z);
|
||||||
|
|
||||||
// Top-left corner for texture and quad
|
// Top-left corner for texture and quad
|
||||||
rlTexCoord2f((float)source.x/texture.width, (float)(source.y + source.height)/texture.height);
|
rlTexCoord2f((float)source.x/texture.width, (float)(source.y + source.height)/texture.height);
|
||||||
rlVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z);
|
rlVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z);
|
||||||
|
|
||||||
// Top-right corner for texture and quad
|
// Top-right corner for texture and quad
|
||||||
rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)(source.y + source.height)/texture.height);
|
rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)(source.y + source.height)/texture.height);
|
||||||
rlVertex3f(bottomRight.x, bottomRight.y, bottomRight.z);
|
rlVertex3f(bottomRight.x, bottomRight.y, bottomRight.z);
|
||||||
|
|
||||||
// Bottom-right corner for texture and quad
|
// Bottom-right corner for texture and quad
|
||||||
rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)source.y/texture.height);
|
rlTexCoord2f((float)(source.x + source.width)/texture.width, (float)source.y/texture.height);
|
||||||
rlVertex3f(topRight.x, topRight.y, topRight.z);
|
rlVertex3f(topRight.x, topRight.y, topRight.z);
|
||||||
rlEnd();
|
rlEnd();
|
||||||
|
|
||||||
rlSetTexture(0);
|
rlSetTexture(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawBillboardRecNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint ) {
|
void DrawBillboardRecNoRatio( Camera camera, Texture2D texture, Rectangle source, Vector3 position, Vector2 size, Color tint ) {
|
||||||
// NOTE: Billboard locked on axis-Y
|
// NOTE: Billboard locked on axis-Y
|
||||||
Vector3 up = { 0.0f, 1.0f, 0.0f };
|
Vector3 up = { 0.0f, 1.0f, 0.0f };
|
||||||
|
|
||||||
DrawBillboardProNoRatio(camera, texture, source, position, up, size, Vector2Zero(), 0.0f, tint);
|
DrawBillboardProNoRatio(camera, texture, source, position, up, size, Vector2Zero(), 0.0f, tint);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -184,15 +184,15 @@ int lmodelsDrawTriangleStrip3D( lua_State* L ) {
|
|||||||
Vector3 points[ pointCount ];
|
Vector3 points[ pointCount ];
|
||||||
|
|
||||||
int t = 1, i = 0;
|
int t = 1, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_istable( L, -1 ) ) {
|
if ( lua_istable( L, -1 ) ) {
|
||||||
points[i] = uluaGetVector3( L, lua_gettop( L ) );
|
points[i] = uluaGetVector3( L, lua_gettop( L ) );
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
DrawTriangleStrip3D( points, pointCount, color );
|
DrawTriangleStrip3D( points, pointCount, color );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -412,43 +412,43 @@ int lmodelDrawQuad3DTexture( lua_State* L ) {
|
|||||||
Vector3 vertices[4] = { 0 };
|
Vector3 vertices[4] = { 0 };
|
||||||
|
|
||||||
int t = 2, i = 0;
|
int t = 2, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_istable( L, -1 ) && i < 4 ) {
|
if ( lua_istable( L, -1 ) && i < 4 ) {
|
||||||
vertices[i] = uluaGetVector3( L, lua_gettop( L ) );
|
vertices[i] = uluaGetVector3( L, lua_gettop( L ) );
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TexCoords. */
|
/* TexCoords. */
|
||||||
Vector2 texcoords[4] = { 0 };
|
Vector2 texcoords[4] = { 0 };
|
||||||
|
|
||||||
t = 3, i = 0;
|
t = 3, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_istable( L, -1 ) && i < 4 ) {
|
if ( lua_istable( L, -1 ) && i < 4 ) {
|
||||||
texcoords[i] = uluaGetVector2( L, lua_gettop( L ) );
|
texcoords[i] = uluaGetVector2( L, lua_gettop( L ) );
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Colors. */
|
/* Colors. */
|
||||||
Color colors[4] = { 0 };
|
Color colors[4] = { 0 };
|
||||||
|
|
||||||
t = 4, i = 0;
|
t = 4, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_istable( L, -1 ) && i < 4 ) {
|
if ( lua_istable( L, -1 ) && i < 4 ) {
|
||||||
colors[i] = uluaGetColor( L, lua_gettop( L ) );
|
colors[i] = uluaGetColor( L, lua_gettop( L ) );
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Normals. maybe something like Vector3Normalize(Vector3CrossProduct(Vector3Subtract(vB, vA), Vector3Subtract(vC, vA)));
|
//TODO Normals. maybe something like Vector3Normalize(Vector3CrossProduct(Vector3Subtract(vB, vA), Vector3Subtract(vC, vA)));
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ int lmodelDrawQuad3DTexture( lua_State* L ) {
|
|||||||
rlBegin( RL_QUADS );
|
rlBegin( RL_QUADS );
|
||||||
for ( i = 0; i < 4; ++i ) {
|
for ( i = 0; i < 4; ++i ) {
|
||||||
rlTexCoord2f( texcoords[i].x, texcoords[i].y );
|
rlTexCoord2f( texcoords[i].x, texcoords[i].y );
|
||||||
rlColor4ub( colors[i].r, colors[i].g, colors[i].b, colors[i].a );
|
rlColor4ub( colors[i].r, colors[i].g, colors[i].b, colors[i].a );
|
||||||
rlVertex3f( vertices[i].x, vertices[i].y, vertices[i].z );
|
rlVertex3f( vertices[i].x, vertices[i].y, vertices[i].z );
|
||||||
}
|
}
|
||||||
rlEnd();
|
rlEnd();
|
||||||
@@ -1170,15 +1170,15 @@ int lmodelsDrawMeshInstanced( lua_State* L ) {
|
|||||||
Matrix transforms[ instances ];
|
Matrix transforms[ instances ];
|
||||||
|
|
||||||
int t = 3, i = 0;
|
int t = 3, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_istable( L, -1 ) ) {
|
if ( lua_istable( L, -1 ) ) {
|
||||||
transforms[i] = uluaGetMatrix( L, lua_gettop( L ) );
|
transforms[i] = uluaGetMatrix( L, lua_gettop( L ) );
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
DrawMeshInstanced( *mesh, *material, transforms, instances );
|
DrawMeshInstanced( *mesh, *material, transforms, instances );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -2151,16 +2151,16 @@ Unload animation table data
|
|||||||
*/
|
*/
|
||||||
int lmodelsUnloadModelAnimations( lua_State* L ) {
|
int lmodelsUnloadModelAnimations( lua_State* L ) {
|
||||||
int t = 1, i = 0;
|
int t = 1, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_isuserdata( L, -1 ) ) {
|
if ( lua_isuserdata( L, -1 ) ) {
|
||||||
ModelAnimation* animation = uluaGetModelAnimation( L, lua_gettop( L ) );
|
ModelAnimation* animation = uluaGetModelAnimation( L, lua_gettop( L ) );
|
||||||
UnloadModelAnimation( *animation );
|
UnloadModelAnimation( *animation );
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ static void windowSizeEvent( GLFWwindow* window, int width, int height ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 3, 0 );
|
lua_createtable( L, 3, 0 );
|
||||||
lua_pushinteger( L, GLFW_WINDOW_SIZE_EVENT );
|
lua_pushinteger( L, GLFW_WINDOW_SIZE_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
@@ -119,11 +119,11 @@ static void windowSizeEvent( GLFWwindow* window, int width, int height ) {
|
|||||||
lua_pushinteger( L, height );
|
lua_pushinteger( L, height );
|
||||||
lua_setfield( L, -2, "height" );
|
lua_setfield( L, -2, "height" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,18 +146,18 @@ static void windowMaximizeEvent( GLFWwindow* window, int maximized ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 2, 0 );
|
lua_createtable( L, 2, 0 );
|
||||||
lua_pushinteger( L, GLFW_WINDOW_MAXIMIZE_EVENT );
|
lua_pushinteger( L, GLFW_WINDOW_MAXIMIZE_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
lua_pushinteger( L, maximized );
|
lua_pushinteger( L, maximized );
|
||||||
lua_setfield( L, -2, "maximized" );
|
lua_setfield( L, -2, "maximized" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,18 +180,18 @@ static void windowIconyfyEvent( GLFWwindow* window, int iconified ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 2, 0 );
|
lua_createtable( L, 2, 0 );
|
||||||
lua_pushinteger( L, GLFW_WINDOW_ICONYFY_EVENT );
|
lua_pushinteger( L, GLFW_WINDOW_ICONYFY_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
lua_pushinteger( L, iconified );
|
lua_pushinteger( L, iconified );
|
||||||
lua_setfield( L, -2, "iconified" );
|
lua_setfield( L, -2, "iconified" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,18 +212,18 @@ static void windowFocusEvent( GLFWwindow* window, int focused ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 2, 0 );
|
lua_createtable( L, 2, 0 );
|
||||||
lua_pushinteger( L, GLFW_WINDOW_FOCUS_EVENT );
|
lua_pushinteger( L, GLFW_WINDOW_FOCUS_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
lua_pushinteger( L, focused );
|
lua_pushinteger( L, focused );
|
||||||
lua_setfield( L, -2, "focused" );
|
lua_setfield( L, -2, "focused" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ static void windowDropEvent( GLFWwindow* window, int count, const char** paths )
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 3, 0 );
|
lua_createtable( L, 3, 0 );
|
||||||
lua_pushinteger( L, GLFW_WINDOW_DROP_EVENT );
|
lua_pushinteger( L, GLFW_WINDOW_DROP_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
@@ -259,11 +259,11 @@ static void windowDropEvent( GLFWwindow* window, int count, const char** paths )
|
|||||||
}
|
}
|
||||||
lua_setfield( L, -2, "paths" );
|
lua_setfield( L, -2, "paths" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,7 +288,7 @@ static void keyInputEvent( GLFWwindow* window, int key, int scancode, int action
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 5, 0 );
|
lua_createtable( L, 5, 0 );
|
||||||
lua_pushinteger( L, GLFW_KEY_EVENT );
|
lua_pushinteger( L, GLFW_KEY_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
@@ -301,11 +301,11 @@ static void keyInputEvent( GLFWwindow* window, int key, int scancode, int action
|
|||||||
lua_pushinteger( L, mods );
|
lua_pushinteger( L, mods );
|
||||||
lua_setfield( L, -2, "mods" );
|
lua_setfield( L, -2, "mods" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,18 +326,18 @@ static void charInputEvent( GLFWwindow* window, unsigned int key ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 2, 0 );
|
lua_createtable( L, 2, 0 );
|
||||||
lua_pushinteger( L, GLFW_CHAR_EVENT );
|
lua_pushinteger( L, GLFW_CHAR_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
lua_pushinteger( L, key );
|
lua_pushinteger( L, key );
|
||||||
lua_setfield( L, -2, "key" );
|
lua_setfield( L, -2, "key" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,7 +358,7 @@ static void mouseButtonInputEvent( GLFWwindow* window, int button, int action, i
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 4, 0 );
|
lua_createtable( L, 4, 0 );
|
||||||
lua_pushinteger( L, GLFW_MOUSE_BUTTON_EVENT );
|
lua_pushinteger( L, GLFW_MOUSE_BUTTON_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
@@ -369,11 +369,11 @@ static void mouseButtonInputEvent( GLFWwindow* window, int button, int action, i
|
|||||||
lua_pushinteger( L, mods );
|
lua_pushinteger( L, mods );
|
||||||
lua_setfield( L, -2, "mods" );
|
lua_setfield( L, -2, "mods" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,7 +394,7 @@ static void mouseCursorPosInputEvent( GLFWwindow* window, double x, double y ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 3, 0 );
|
lua_createtable( L, 3, 0 );
|
||||||
lua_pushinteger( L, GLFW_MOUSE_CURSOR_POS_EVENT );
|
lua_pushinteger( L, GLFW_MOUSE_CURSOR_POS_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
@@ -403,11 +403,11 @@ static void mouseCursorPosInputEvent( GLFWwindow* window, double x, double y ) {
|
|||||||
lua_pushnumber( L, y );
|
lua_pushnumber( L, y );
|
||||||
lua_setfield( L, -2, "y" );
|
lua_setfield( L, -2, "y" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +428,7 @@ static void mouseScrollInputEvent( GLFWwindow* window, double xoffset, double yo
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 3, 0 );
|
lua_createtable( L, 3, 0 );
|
||||||
lua_pushinteger( L, GLFW_MOUSE_SCROLL_EVENT );
|
lua_pushinteger( L, GLFW_MOUSE_SCROLL_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
@@ -437,11 +437,11 @@ static void mouseScrollInputEvent( GLFWwindow* window, double xoffset, double yo
|
|||||||
lua_pushnumber( L, yoffset );
|
lua_pushnumber( L, yoffset );
|
||||||
lua_setfield( L, -2, "yoffset" );
|
lua_setfield( L, -2, "yoffset" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,18 +462,18 @@ static void cursorEnterInputEvent( GLFWwindow* window, int enter ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 2, 0 );
|
lua_createtable( L, 2, 0 );
|
||||||
lua_pushinteger( L, GLFW_CURSOR_ENTER_EVENT );
|
lua_pushinteger( L, GLFW_CURSOR_ENTER_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
lua_pushinteger( L, enter );
|
lua_pushinteger( L, enter );
|
||||||
lua_setfield( L, -2, "enter" );
|
lua_setfield( L, -2, "enter" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,7 +496,7 @@ static void joystickEvent( int jid, int event ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 3, 0 );
|
lua_createtable( L, 3, 0 );
|
||||||
lua_pushinteger( L, GLFW_JOYSTICK_EVENT );
|
lua_pushinteger( L, GLFW_JOYSTICK_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
@@ -505,11 +505,11 @@ static void joystickEvent( int jid, int event ) {
|
|||||||
lua_pushinteger( L, event );
|
lua_pushinteger( L, event );
|
||||||
lua_setfield( L, -2, "event" );
|
lua_setfield( L, -2, "event" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,7 +528,7 @@ static void penTabletDataEvent( double x, double y, double z, double pressure, d
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 8, 0 );
|
lua_createtable( L, 8, 0 );
|
||||||
lua_pushinteger( L, GLFW_PEN_TABLET_DATA_EVENT );
|
lua_pushinteger( L, GLFW_PEN_TABLET_DATA_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
@@ -547,11 +547,11 @@ static void penTabletDataEvent( double x, double y, double z, double pressure, d
|
|||||||
lua_pushnumber( L, roll );
|
lua_pushnumber( L, roll );
|
||||||
lua_setfield( L, -2, "roll" );
|
lua_setfield( L, -2, "roll" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,18 +570,18 @@ static void penTabletCursorEvent( unsigned int identifier ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 2, 0 );
|
lua_createtable( L, 2, 0 );
|
||||||
lua_pushinteger( L, GLFW_PEN_TABLET_CURSOR_EVENT );
|
lua_pushinteger( L, GLFW_PEN_TABLET_CURSOR_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
lua_pushinteger( L, identifier );
|
lua_pushinteger( L, identifier );
|
||||||
lua_setfield( L, -2, "identifier" );
|
lua_setfield( L, -2, "identifier" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,18 +600,18 @@ static void penTabletProximityEvent( int proxState ) {
|
|||||||
lua_getglobal( L, "RL" );
|
lua_getglobal( L, "RL" );
|
||||||
lua_getfield( L, -1, "event" );
|
lua_getfield( L, -1, "event" );
|
||||||
|
|
||||||
if ( lua_isfunction( L, -1 ) ) {
|
if ( lua_isfunction( L, -1 ) ) {
|
||||||
lua_createtable( L, 2, 0 );
|
lua_createtable( L, 2, 0 );
|
||||||
lua_pushinteger( L, GLFW_PEN_TABLET_PROXIMITY_EVENT );
|
lua_pushinteger( L, GLFW_PEN_TABLET_PROXIMITY_EVENT );
|
||||||
lua_setfield( L, -2, "type" );
|
lua_setfield( L, -2, "type" );
|
||||||
lua_pushinteger( L, proxState );
|
lua_pushinteger( L, proxState );
|
||||||
lua_setfield( L, -2, "state" );
|
lua_setfield( L, -2, "state" );
|
||||||
|
|
||||||
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
if ( lua_pcall( L, 1, 0, tracebackidx ) != 0 ) {
|
||||||
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) );
|
||||||
state->run = false;
|
state->run = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_pop( L, -1 );
|
lua_pop( L, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/rlgl.c
12
src/rlgl.c
@@ -1726,17 +1726,17 @@ int lrlglSetShader( lua_State* L ) {
|
|||||||
unsigned int id = (unsigned int)luaL_checkinteger( L, 1 );
|
unsigned int id = (unsigned int)luaL_checkinteger( L, 1 );
|
||||||
|
|
||||||
int t = 2, i = 0;
|
int t = 2, i = 0;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( lua_isnumber( L, -1 ) ) {
|
if ( lua_isnumber( L, -1 ) ) {
|
||||||
if ( i < RL_MAX_SHADER_LOCATIONS ) {
|
if ( i < RL_MAX_SHADER_LOCATIONS ) {
|
||||||
state->RLGLcurrentShaderLocs[i] = lua_tointeger( L, -1 );
|
state->RLGLcurrentShaderLocs[i] = lua_tointeger( L, -1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
rlSetShader( id, state->RLGLcurrentShaderLocs );
|
rlSetShader( id, state->RLGLcurrentShaderLocs );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
#include "lua_core.h"
|
#include "lua_core.h"
|
||||||
|
|
||||||
inline int imin( int a, int b ) {
|
inline int imin( int a, int b ) {
|
||||||
return a < b ? a : b;
|
return a < b ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int imax( int a, int b ) {
|
inline int imax( int a, int b ) {
|
||||||
return a > b ? a : b;
|
return a > b ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ bool stateInit( int argn, const char** argc, const char* exePath ) {
|
|||||||
state->logLevelInvalid = LOG_ERROR;
|
state->logLevelInvalid = LOG_ERROR;
|
||||||
state->gcUnload = true;
|
state->gcUnload = true;
|
||||||
|
|
||||||
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" );
|
InitWindow( state->resolution.x, state->resolution.y, "ReiLua" );
|
||||||
|
|
||||||
if ( !IsWindowReady() ) {
|
if ( !IsWindowReady() ) {
|
||||||
state->hasWindow = false;
|
state->hasWindow = false;
|
||||||
|
|||||||
214
src/text.c
214
src/text.c
@@ -14,117 +14,117 @@ void unloadGlyphInfo( GlyphInfo* glyph ) {
|
|||||||
static int DrawTextBoxed( Font font, const char* text, Rectangle rec, float fontSize, float spacing,
|
static int DrawTextBoxed( Font font, const char* text, Rectangle rec, float fontSize, float spacing,
|
||||||
bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount )
|
bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount )
|
||||||
{
|
{
|
||||||
int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
|
int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
|
||||||
|
|
||||||
float textOffsetY = 0; // Offset between lines (on line break '\n')
|
float textOffsetY = 0; // Offset between lines (on line break '\n')
|
||||||
float textOffsetX = 0.0f; // Offset X to next character to draw
|
float textOffsetX = 0.0f; // Offset X to next character to draw
|
||||||
|
|
||||||
float scaleFactor = fontSize/(float)font.baseSize; // Character rectangle scaling factor
|
float scaleFactor = fontSize/(float)font.baseSize; // Character rectangle scaling factor
|
||||||
|
|
||||||
// Word/character wrapping mechanism variables
|
// Word/character wrapping mechanism variables
|
||||||
enum { MEASURE_STATE = 0, DRAW_STATE = 1 };
|
enum { MEASURE_STATE = 0, DRAW_STATE = 1 };
|
||||||
int state = wordWrap ? MEASURE_STATE : DRAW_STATE;
|
int state = wordWrap ? MEASURE_STATE : DRAW_STATE;
|
||||||
|
|
||||||
int startLine = -1; // Index where to begin drawing (where a line begins)
|
int startLine = -1; // Index where to begin drawing (where a line begins)
|
||||||
int endLine = -1; // Index where to stop drawing (where a line ends)
|
int endLine = -1; // Index where to stop drawing (where a line ends)
|
||||||
int lastk = -1; // Holds last value of the character position
|
int lastk = -1; // Holds last value of the character position
|
||||||
Color tint = BLACK;
|
Color tint = BLACK;
|
||||||
Color backTint = BLANK;
|
Color backTint = BLANK;
|
||||||
Vector2 mousePos = GetMousePosition();
|
Vector2 mousePos = GetMousePosition();
|
||||||
int mouseChar = -1;
|
int mouseChar = -1;
|
||||||
|
|
||||||
for ( int i = 0, k = 0; i < length; i++, k++)
|
for ( int i = 0, k = 0; i < length; i++, k++)
|
||||||
{
|
{
|
||||||
if ( i < tintCount ) {
|
if ( i < tintCount ) {
|
||||||
tint = tints[i];
|
tint = tints[i];
|
||||||
}
|
}
|
||||||
if ( i < backTintCount ) {
|
if ( i < backTintCount ) {
|
||||||
backTint = backTints[i];
|
backTint = backTints[i];
|
||||||
}
|
}
|
||||||
// Get next codepoint from byte string and glyph index in font
|
// Get next codepoint from byte string and glyph index in font
|
||||||
int codepointByteCount = 0;
|
int codepointByteCount = 0;
|
||||||
int codepoint = GetCodepoint(&text[i], &codepointByteCount);
|
int codepoint = GetCodepoint(&text[i], &codepointByteCount);
|
||||||
int index = GetGlyphIndex(font, codepoint);
|
int index = GetGlyphIndex(font, codepoint);
|
||||||
|
|
||||||
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
|
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
|
||||||
// but we need to draw all of the bad bytes using the '?' symbol moving one byte
|
// but we need to draw all of the bad bytes using the '?' symbol moving one byte
|
||||||
if (codepoint == 0x3f) codepointByteCount = 1;
|
if (codepoint == 0x3f) codepointByteCount = 1;
|
||||||
i += (codepointByteCount - 1);
|
i += (codepointByteCount - 1);
|
||||||
|
|
||||||
float glyphWidth = 0;
|
float glyphWidth = 0;
|
||||||
if (codepoint != '\n')
|
if (codepoint != '\n')
|
||||||
{
|
{
|
||||||
glyphWidth = (font.glyphs[index].advanceX == 0) ? font.recs[index].width*scaleFactor : font.glyphs[index].advanceX*scaleFactor;
|
glyphWidth = (font.glyphs[index].advanceX == 0) ? font.recs[index].width*scaleFactor : font.glyphs[index].advanceX*scaleFactor;
|
||||||
|
|
||||||
if (i + 1 < length) glyphWidth = glyphWidth + spacing;
|
if (i + 1 < length) glyphWidth = glyphWidth + spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container
|
// NOTE: When wordWrap is ON we first measure how much of the text we can draw before going outside of the rec container
|
||||||
// We store this info in startLine and endLine, then we change states, draw the text between those two variables
|
// We store this info in startLine and endLine, then we change states, draw the text between those two variables
|
||||||
// and change states again and again recursively until the end of the text (or until we get outside of the container).
|
// and change states again and again recursively until the end of the text (or until we get outside of the container).
|
||||||
// When wordWrap is OFF we don't need the measure state so we go to the drawing state immediately
|
// When wordWrap is OFF we don't need the measure state so we go to the drawing state immediately
|
||||||
// and begin drawing on the next line before we can get outside the container.
|
// and begin drawing on the next line before we can get outside the container.
|
||||||
if (state == MEASURE_STATE)
|
if (state == MEASURE_STATE)
|
||||||
{
|
{
|
||||||
// TODO: There are multiple types of spaces in UNICODE, maybe it's a good idea to add support for more
|
// TODO: There are multiple types of spaces in UNICODE, maybe it's a good idea to add support for more
|
||||||
// Ref: http://jkorpela.fi/chars/spaces.html
|
// Ref: http://jkorpela.fi/chars/spaces.html
|
||||||
if ((codepoint == ' ') || (codepoint == '\t') || (codepoint == '\n')) endLine = i;
|
if ((codepoint == ' ') || (codepoint == '\t') || (codepoint == '\n')) endLine = i;
|
||||||
|
|
||||||
if ((textOffsetX + glyphWidth) > rec.width)
|
if ((textOffsetX + glyphWidth) > rec.width)
|
||||||
{
|
{
|
||||||
endLine = (endLine < 1)? i : endLine;
|
endLine = (endLine < 1)? i : endLine;
|
||||||
if (i == endLine) endLine -= codepointByteCount;
|
if (i == endLine) endLine -= codepointByteCount;
|
||||||
if ((startLine + codepointByteCount) == endLine) endLine = (i - codepointByteCount);
|
if ((startLine + codepointByteCount) == endLine) endLine = (i - codepointByteCount);
|
||||||
|
|
||||||
state = !state;
|
state = !state;
|
||||||
}
|
}
|
||||||
else if ((i + 1) == length)
|
else if ((i + 1) == length)
|
||||||
{
|
{
|
||||||
endLine = i;
|
endLine = i;
|
||||||
state = !state;
|
state = !state;
|
||||||
}
|
}
|
||||||
else if (codepoint == '\n') state = !state;
|
else if (codepoint == '\n') state = !state;
|
||||||
|
|
||||||
if (state == DRAW_STATE)
|
if (state == DRAW_STATE)
|
||||||
{
|
{
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
i = startLine;
|
i = startLine;
|
||||||
glyphWidth = 0;
|
glyphWidth = 0;
|
||||||
|
|
||||||
// Save character position when we switch states
|
// Save character position when we switch states
|
||||||
int tmp = lastk;
|
int tmp = lastk;
|
||||||
lastk = k - 1;
|
lastk = k - 1;
|
||||||
k = tmp;
|
k = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (codepoint == '\n')
|
if (codepoint == '\n')
|
||||||
{
|
{
|
||||||
if (!wordWrap)
|
if (!wordWrap)
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width))
|
if (!wordWrap && ((textOffsetX + glyphWidth) > rec.width))
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When text overflows rectangle height limit, just stop drawing
|
// When text overflows rectangle height limit, just stop drawing
|
||||||
if ((textOffsetY + font.baseSize*scaleFactor) > rec.height) break;
|
if ((textOffsetY + font.baseSize*scaleFactor) > rec.height) break;
|
||||||
|
|
||||||
// Draw selection background
|
// Draw selection background
|
||||||
// bool isGlyphSelected = false;
|
// bool isGlyphSelected = false;
|
||||||
// if ((selectStart >= 0) && (k >= selectStart) && (k < (selectStart + selectLength)))
|
// if ((selectStart >= 0) && (k >= selectStart) && (k < (selectStart + selectLength)))
|
||||||
// {
|
// {
|
||||||
// DrawRectangleRec((Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, glyphWidth, (float)font.baseSize*scaleFactor }, selectBackTint);
|
// DrawRectangleRec((Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, glyphWidth, (float)font.baseSize*scaleFactor }, selectBackTint);
|
||||||
// isGlyphSelected = true;
|
// isGlyphSelected = true;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if ( CheckCollisionPointRec( mousePos, (Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, glyphWidth, (float)font.baseSize*scaleFactor } ) ) {
|
if ( CheckCollisionPointRec( mousePos, (Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, glyphWidth, (float)font.baseSize*scaleFactor } ) ) {
|
||||||
mouseChar = i;
|
mouseChar = i;
|
||||||
@@ -134,30 +134,30 @@ bool wordWrap, Color* tints, int tintCount, Color* backTints, int backTintCount
|
|||||||
DrawRectangleRec((Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, glyphWidth, (float)font.baseSize*scaleFactor }, backTint);
|
DrawRectangleRec((Rectangle){ rec.x + textOffsetX - 1, rec.y + textOffsetY, glyphWidth, (float)font.baseSize*scaleFactor }, backTint);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw current character glyph
|
// Draw current character glyph
|
||||||
if ((codepoint != ' ') && (codepoint != '\t'))
|
if ((codepoint != ' ') && (codepoint != '\t'))
|
||||||
{
|
{
|
||||||
// DrawTextCodepoint(font, codepoint, (Vector2){ rec.x + textOffsetX, rec.y + textOffsetY }, fontSize, isGlyphSelected? selectTint : tint);
|
// DrawTextCodepoint(font, codepoint, (Vector2){ rec.x + textOffsetX, rec.y + textOffsetY }, fontSize, isGlyphSelected? selectTint : tint);
|
||||||
DrawTextCodepoint( font, codepoint, (Vector2){ rec.x + textOffsetX, rec.y + textOffsetY }, fontSize, tint );
|
DrawTextCodepoint( font, codepoint, (Vector2){ rec.x + textOffsetX, rec.y + textOffsetY }, fontSize, tint );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wordWrap && (i == endLine))
|
if (wordWrap && (i == endLine))
|
||||||
{
|
{
|
||||||
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
textOffsetY += (font.baseSize + font.baseSize/2)*scaleFactor;
|
||||||
textOffsetX = 0;
|
textOffsetX = 0;
|
||||||
startLine = endLine;
|
startLine = endLine;
|
||||||
endLine = -1;
|
endLine = -1;
|
||||||
glyphWidth = 0;
|
glyphWidth = 0;
|
||||||
// selectStart += lastk - k;
|
// selectStart += lastk - k;
|
||||||
k = lastk;
|
k = lastk;
|
||||||
|
|
||||||
state = !state;
|
state = !state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((textOffsetX != 0) || (codepoint != ' ')) textOffsetX += glyphWidth; // avoid leading spaces
|
if ((textOffsetX != 0) || (codepoint != ' ')) textOffsetX += glyphWidth; // avoid leading spaces
|
||||||
}
|
}
|
||||||
return mouseChar;
|
return mouseChar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -817,7 +817,7 @@ int ltexturesLoadImageColors( lua_State* L ) {
|
|||||||
|
|
||||||
for ( int i = 0; i < colorCount; ++i ) {
|
for ( int i = 0; i < colorCount; ++i ) {
|
||||||
uluaPushColor( L, colors[i] );
|
uluaPushColor( L, colors[i] );
|
||||||
lua_rawseti( L, -2, i + 1 );
|
lua_rawseti( L, -2, i + 1 );
|
||||||
}
|
}
|
||||||
UnloadImageColors( colors );
|
UnloadImageColors( colors );
|
||||||
|
|
||||||
@@ -842,7 +842,7 @@ int ltexturesLoadImagePalette( lua_State* L ) {
|
|||||||
|
|
||||||
for ( int i = 0; i < colorCount; ++i ) {
|
for ( int i = 0; i < colorCount; ++i ) {
|
||||||
uluaPushColor( L, colors[i] );
|
uluaPushColor( L, colors[i] );
|
||||||
lua_rawseti( L, -2, i + 1 );
|
lua_rawseti( L, -2, i + 1 );
|
||||||
}
|
}
|
||||||
UnloadImagePalette( colors );
|
UnloadImagePalette( colors );
|
||||||
|
|
||||||
@@ -1251,9 +1251,9 @@ int ltexturesLoadRenderTextureFromData( lua_State* L ) {
|
|||||||
RenderTexture renTexture = { 0 };
|
RenderTexture renTexture = { 0 };
|
||||||
|
|
||||||
int t = 1;
|
int t = 1;
|
||||||
lua_pushnil( L );
|
lua_pushnil( L );
|
||||||
|
|
||||||
while ( lua_next( L, t ) != 0 ) {
|
while ( lua_next( L, t ) != 0 ) {
|
||||||
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
if ( strcmp( "id", (char*)lua_tostring( L, -2 ) ) == 0 ) {
|
||||||
renTexture.id = (unsigned int)luaL_checkinteger( L, -1 );
|
renTexture.id = (unsigned int)luaL_checkinteger( L, -1 );
|
||||||
}
|
}
|
||||||
@@ -1265,8 +1265,8 @@ int ltexturesLoadRenderTextureFromData( lua_State* L ) {
|
|||||||
Texture* depth = uluaGetTexture( L, -1 );
|
Texture* depth = uluaGetTexture( L, -1 );
|
||||||
renTexture.depth = *depth;
|
renTexture.depth = *depth;
|
||||||
}
|
}
|
||||||
lua_pop( L, 1 );
|
lua_pop( L, 1 );
|
||||||
}
|
}
|
||||||
uluaPushRenderTexture( L, renTexture );
|
uluaPushRenderTexture( L, renTexture );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user