Add new functions, update C sources

This commit is contained in:
Milan Nikolic 2017-03-10 15:01:42 +01:00
parent 1aabddd935
commit 732563d5c2
19 changed files with 541 additions and 647 deletions

View file

@ -1,14 +1,17 @@
/**********************************************************************************************
*
* raylib.shapes
* raylib.shapes - Basic functions to draw 2d Shapes and check collisions
*
* Basic functions to draw 2d Shapes and check collisions
* CONFIGURATION:
*
* External libs:
* rlgl - raylib OpenGL abstraction layer
* #define SUPPORT_QUADS_ONLY
* Draw shapes using only QUADS, vertex are accumulated in QUADS arrays (like textures)
*
* Module Configuration Flags:
* ...
* #define SUPPORT_TRIANGLES_ONLY
* Draw shapes using only TRIANGLES, vertex are accumulated in TRIANGLES arrays
*
*
* LICENSE: zlib/libpng
*
* Copyright (c) 2014-2016 Ramon Santamaria (@raysan5)
*
@ -100,6 +103,36 @@ void DrawLineV(Vector2 startPos, Vector2 endPos, Color color)
rlEnd();
}
// Draw a line defining thickness
void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
{
float dx = endPos.x - startPos.x;
float dy = endPos.y - startPos.y;
float d = sqrtf(dx*dx + dy*dy);
float angle = asinf(dy/d);
rlEnableTexture(GetDefaultTexture().id);
rlPushMatrix();
rlTranslatef((float)startPos.x, (float)startPos.y, 0);
rlRotatef(-RAD2DEG*angle, 0, 0, 1);
rlTranslatef(0, -thick/2.0f, 0);
rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a);
rlNormal3f(0.0f, 0.0f, 1.0f);
rlVertex2f(0.0f, 0.0f);
rlVertex2f(0.0f, thick);
rlVertex2f(d, thick);
rlVertex2f(d, 0.0f);
rlEnd();
rlPopMatrix();
rlDisableTexture();
}
// Draw a color-filled circle
void DrawCircle(int centerX, int centerY, float radius, Color color)
{
@ -190,6 +223,29 @@ void DrawRectangleRec(Rectangle rec, Color color)
DrawRectangle(rec.x, rec.y, rec.width, rec.height, color);
}
void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color)
{
rlEnableTexture(GetDefaultTexture().id);
rlPushMatrix();
rlTranslatef((float)rec.x, (float)rec.y, 0);
rlRotatef(rotation, 0, 0, 1);
rlTranslatef(-origin.x, -origin.y, 0);
rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a);
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer
rlVertex2f(0.0f, 0.0f);
rlVertex2f(0.0f, (float)rec.height);
rlVertex2f((float)rec.width, (float)rec.height);
rlVertex2f((float)rec.width, 0.0f);
rlEnd();
rlPopMatrix();
rlDisableTexture();
}
// Draw a gradient-filled rectangle
// NOTE: Gradient goes from bottom (color1) to top (color2)
void DrawRectangleGradient(int posX, int posY, int width, int height, Color color1, Color color2)