Update C sources, add new functions and rename package to

This commit is contained in:
Milan Nikolic 2018-10-08 18:56:34 +02:00
parent 391c25482d
commit 08aa518a46
156 changed files with 34542 additions and 19573 deletions

View file

@ -153,9 +153,9 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
for (int i = 1; i <= LINE_DIVISIONS; i++)
{
// Cubic easing in-out
// NOTE: Easing is calcutated only for y position value
current.y = EaseCubicInOut(i, startPos.y, endPos.y - startPos.y, LINE_DIVISIONS);
current.x = previous.x + (endPos.x - startPos.x)/LINE_DIVISIONS;
// NOTE: Easing is calculated only for y position value
current.y = EaseCubicInOut((float)i, startPos.y, endPos.y - startPos.y, (float)LINE_DIVISIONS);
current.x = previous.x + (endPos.x - startPos.x)/ (float)LINE_DIVISIONS;
DrawLineEx(previous, current, thick, color);
@ -173,6 +173,8 @@ void DrawCircle(int centerX, int centerY, float radius, Color color)
// NOTE: Gradient goes from center (color1) to border (color2)
void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2)
{
if (rlCheckBufferLimit(RL_TRIANGLES, 3*36)) rlglDraw();
rlBegin(RL_TRIANGLES);
for (int i = 0; i < 360; i += 10)
{
@ -189,8 +191,10 @@ void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Co
// Draw a color-filled circle (Vector version)
// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
void DrawCircleV(Vector2 center, float radius, Color color)
{
{
#if defined(SUPPORT_QUADS_DRAW_MODE)
if (rlCheckBufferLimit(RL_QUADS, 4*(36/2))) rlglDraw();
rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS);
@ -207,6 +211,8 @@ void DrawCircleV(Vector2 center, float radius, Color color)
rlDisableTexture();
#else
if (rlCheckBufferLimit(RL_TRIANGLES, 3*(36/2))) rlglDraw();
rlBegin(RL_TRIANGLES);
for (int i = 0; i < 360; i += 10)
{
@ -223,6 +229,8 @@ void DrawCircleV(Vector2 center, float radius, Color color)
// Draw circle outline
void DrawCircleLines(int centerX, int centerY, float radius, Color color)
{
if (rlCheckBufferLimit(RL_LINES, 2*36)) rlglDraw();
rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a);
@ -251,27 +259,27 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
#if defined(SUPPORT_QUADS_DRAW_MODE)
#if defined(SUPPORT_FONT_TEXTURE)
// Draw rectangle using font texture white character
rlEnableTexture(GetDefaultFont().texture.id);
rlEnableTexture(GetFontDefault().texture.id);
rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a);
rlNormal3f(0.0f, 0.0f, 1.0f);
// NOTE: Default raylib font character 95 is a white square
rlTexCoord2f((float)GetDefaultFont().chars[95].rec.x/GetDefaultFont().texture.width,
(float)GetDefaultFont().chars[95].rec.y/GetDefaultFont().texture.height);
rlTexCoord2f((float)GetFontDefault().chars[95].rec.x/GetFontDefault().texture.width,
(float)GetFontDefault().chars[95].rec.y/GetFontDefault().texture.height);
rlVertex2f(position.x, position.y);
rlTexCoord2f((float)GetDefaultFont().chars[95].rec.x/GetDefaultFont().texture.width,
(float)(GetDefaultFont().chars[95].rec.y + GetDefaultFont().chars[95].rec.height)/GetDefaultFont().texture.height);
rlTexCoord2f((float)GetFontDefault().chars[95].rec.x/GetFontDefault().texture.width,
(float)(GetFontDefault().chars[95].rec.y + GetFontDefault().chars[95].rec.height)/GetFontDefault().texture.height);
rlVertex2f(position.x, position.y + size.y);
rlTexCoord2f((float)(GetDefaultFont().chars[95].rec.x + GetDefaultFont().chars[95].rec.width)/GetDefaultFont().texture.width,
(float)(GetDefaultFont().chars[95].rec.y + GetDefaultFont().chars[95].rec.height)/GetDefaultFont().texture.height);
rlTexCoord2f((float)(GetFontDefault().chars[95].rec.x + GetFontDefault().chars[95].rec.width)/GetFontDefault().texture.width,
(float)(GetFontDefault().chars[95].rec.y + GetFontDefault().chars[95].rec.height)/GetFontDefault().texture.height);
rlVertex2f(position.x + size.x, position.y + size.y);
rlTexCoord2f((float)(GetDefaultFont().chars[95].rec.x + GetDefaultFont().chars[95].rec.width)/GetDefaultFont().texture.width,
(float)GetDefaultFont().chars[95].rec.y/GetDefaultFont().texture.height);
rlTexCoord2f((float)(GetFontDefault().chars[95].rec.x + GetFontDefault().chars[95].rec.width)/GetFontDefault().texture.width,
(float)GetFontDefault().chars[95].rec.y/GetFontDefault().texture.height);
rlVertex2f(position.x + size.x, position.y);
rlEnd();
@ -316,7 +324,7 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
// Draw a color-filled rectangle
void DrawRectangleRec(Rectangle rec, Color color)
{
DrawRectangle(rec.x, rec.y, rec.width, rec.height, color);
DrawRectangle((int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, color);
}
void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color)
@ -346,14 +354,14 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color
// NOTE: Gradient goes from bottom (color1) to top (color2)
void DrawRectangleGradientV(int posX, int posY, int width, int height, Color color1, Color color2)
{
DrawRectangleGradientEx((Rectangle){ posX, posY, width, height }, color1, color2, color2, color1);
DrawRectangleGradientEx((Rectangle){ (float)posX, (float)posY, (float)width, (float)height }, color1, color2, color2, color1);
}
// Draw a horizontal-gradient-filled rectangle
// NOTE: Gradient goes from bottom (color1) to top (color2)
void DrawRectangleGradientH(int posX, int posY, int width, int height, Color color1, Color color2)
{
DrawRectangleGradientEx((Rectangle){ posX, posY, width, height }, color1, color1, color2, color2);
DrawRectangleGradientEx((Rectangle){ (float)posX, (float)posY, (float)width, (float)height }, color1, color1, color2, color2);
}
// Draw a gradient-filled rectangle
@ -362,30 +370,30 @@ void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3,
{
#if defined(SUPPORT_FONT_TEXTURE)
// Draw rectangle using font texture white character
rlEnableTexture(GetDefaultFont().texture.id);
rlEnableTexture(GetFontDefault().texture.id);
rlBegin(RL_QUADS);
rlNormal3f(0.0f, 0.0f, 1.0f);
// NOTE: Default raylib font character 95 is a white square
rlColor4ub(col1.r, col1.g, col1.b, col1.a);
rlTexCoord2f(GetDefaultFont().chars[95].rec.x/GetDefaultFont().texture.width,
GetDefaultFont().chars[95].rec.y/GetDefaultFont().texture.height);
rlTexCoord2f(GetFontDefault().chars[95].rec.x/GetFontDefault().texture.width,
GetFontDefault().chars[95].rec.y/GetFontDefault().texture.height);
rlVertex2f(rec.x, rec.y);
rlColor4ub(col2.r, col2.g, col2.b, col2.a);
rlTexCoord2f(GetDefaultFont().chars[95].rec.x/GetDefaultFont().texture.width,
(GetDefaultFont().chars[95].rec.y + GetDefaultFont().chars[95].rec.height)/GetDefaultFont().texture.height);
rlTexCoord2f(GetFontDefault().chars[95].rec.x/GetFontDefault().texture.width,
(GetFontDefault().chars[95].rec.y + GetFontDefault().chars[95].rec.height)/GetFontDefault().texture.height);
rlVertex2f(rec.x, rec.y + rec.height);
rlColor4ub(col3.r, col3.g, col3.b, col3.a);
rlTexCoord2f((GetDefaultFont().chars[95].rec.x + GetDefaultFont().chars[95].rec.width)/GetDefaultFont().texture.width,
(GetDefaultFont().chars[95].rec.y + GetDefaultFont().chars[95].rec.height)/GetDefaultFont().texture.height);
rlTexCoord2f((GetFontDefault().chars[95].rec.x + GetFontDefault().chars[95].rec.width)/GetFontDefault().texture.width,
(GetFontDefault().chars[95].rec.y + GetFontDefault().chars[95].rec.height)/GetFontDefault().texture.height);
rlVertex2f(rec.x + rec.width, rec.y + rec.height);
rlColor4ub(col4.r, col4.g, col4.b, col4.a);
rlTexCoord2f((GetDefaultFont().chars[95].rec.x + GetDefaultFont().chars[95].rec.width)/GetDefaultFont().texture.width,
GetDefaultFont().chars[95].rec.y/GetDefaultFont().texture.height);
rlTexCoord2f((GetFontDefault().chars[95].rec.x + GetFontDefault().chars[95].rec.width)/GetFontDefault().texture.width,
GetFontDefault().chars[95].rec.y/GetFontDefault().texture.height);
rlVertex2f(rec.x + rec.width, rec.y);
rlEnd();
@ -449,14 +457,14 @@ void DrawRectangleLinesEx(Rectangle rec, int lineThick, Color color)
{
if (lineThick > rec.width || lineThick > rec.height)
{
if(rec.width > rec.height) lineThick = rec.height/2;
else if (rec.width < rec.height) lineThick = rec.width/2;
if(rec.width > rec.height) lineThick = (int)rec.height/2;
else if (rec.width < rec.height) lineThick = (int)rec.width/2;
}
DrawRectangle(rec.x, rec.y, rec.width, lineThick, color);
DrawRectangle(rec.x - lineThick + rec.width, rec.y + lineThick, lineThick, rec.height - lineThick*2, color);
DrawRectangle(rec.x, rec.y + rec.height - lineThick, rec.width, lineThick, color);
DrawRectangle(rec.x, rec.y + lineThick, lineThick, rec.height - lineThick*2, color);
DrawRectangle( (int)rec.x, (int)rec.y, (int)rec.width, lineThick, color);
DrawRectangle( (int)(rec.x - lineThick + rec.width), (int)(rec.y + lineThick), lineThick, (int)(rec.height - lineThick*2.0f), color);
DrawRectangle( (int)rec.x, (int)(rec.y + rec.height - lineThick), (int)rec.width, lineThick, color);
DrawRectangle( (int)rec.x, (int)(rec.y + lineThick), lineThick, (int)(rec.height - lineThick*2), color);
}
// Draw a triangle
@ -504,6 +512,8 @@ void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color)
{
if (sides < 3) sides = 3;
if (rlCheckBufferLimit(RL_QUADS, 4*(360/sides))) rlglDraw();
rlPushMatrix();
rlTranslatef(center.x, center.y, 0.0);
@ -544,6 +554,8 @@ void DrawPolyEx(Vector2 *points, int pointsCount, Color color)
{
if (pointsCount >= 3)
{
if (rlCheckBufferLimit(RL_QUADS, pointsCount)) rlglDraw();
#if defined(SUPPORT_QUADS_DRAW_MODE)
rlEnableTexture(GetTextureDefault().id); // Default white texture
@ -579,6 +591,8 @@ void DrawPolyExLines(Vector2 *points, int pointsCount, Color color)
{
if (pointsCount >= 2)
{
if (rlCheckBufferLimit(RL_LINES, pointsCount)) rlglDraw();
rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a);
@ -633,11 +647,9 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2)
{
bool collision = false;
int dx = abs((rec1.x + rec1.width/2) - (rec2.x + rec2.width/2));
int dy = abs((rec1.y + rec1.height/2) - (rec2.y + rec2.height/2));
if ((dx <= (rec1.width/2 + rec2.width/2)) && ((dy <= (rec1.height/2 + rec2.height/2)))) collision = true;
if ((rec1.x <= (rec2.x + rec2.width) && (rec1.x + rec1.width) >= rec2.x) &&
(rec1.y <= (rec2.y + rec2.height) && (rec1.y + rec1.height) >= rec2.y)) collision = true;
return collision;
}
@ -661,11 +673,11 @@ bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, floa
// NOTE: Reviewed version to take into account corner limit case
bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
{
int recCenterX = rec.x + rec.width/2;
int recCenterY = rec.y + rec.height/2;
int recCenterX = (int)(rec.x + rec.width/2.0f);
int recCenterY = (int)(rec.y + rec.height/2.0f);
float dx = fabsf(center.x - recCenterX);
float dy = fabsf(center.y - recCenterY);
float dx = (float)fabs(center.x - recCenterX);
float dy = (float)fabs(center.y - recCenterY);
if (dx > (rec.width/2.0f + radius)) { return false; }
if (dy > (rec.height/2.0f + radius)) { return false; }
@ -686,8 +698,8 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
if (CheckCollisionRecs(rec1, rec2))
{
int dxx = abs(rec1.x - rec2.x);
int dyy = abs(rec1.y - rec2.y);
float dxx = (float)fabs(rec1.x - rec2.x);
float dyy = (float)fabs(rec1.y - rec2.y);
if (rec1.x <= rec2.x)
{
@ -754,8 +766,8 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
// NOTE: Required for DrawLineBezier()
static float EaseCubicInOut(float t, float b, float c, float d)
{
if ((t /= 0.5*d) < 1)
return 0.5*c*t*t*t + b;
if ((t /= 0.5f*d) < 1)
return 0.5f*c*t*t*t + b;
t -= 2;
return 0.5*c*(t*t*t + 2) + b;
return 0.5f*c*(t*t*t + 2.0f) + b;
}