summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2017-03-05 21:04:07 +0100
committerraysan5 <[email protected]>2017-03-05 21:04:07 +0100
commit59038bae96bf8e9ae96ce3432ddbde96590f4642 (patch)
treed0f62d5ad956f2e2055a8e64d00ca9eb31a11966
parentaaf9c648d3de5454878531d44abd3c8a663af769 (diff)
downloadraylib-59038bae96bf8e9ae96ce3432ddbde96590f4642.tar.gz
raylib-59038bae96bf8e9ae96ce3432ddbde96590f4642.zip
Added function: DrawLineEx()
Supports line thickness
-rw-r--r--examples/core_basic_window.c22
-rw-r--r--src/raylib.h15
-rw-r--r--src/shapes.c30
3 files changed, 59 insertions, 8 deletions
diff --git a/examples/core_basic_window.c b/examples/core_basic_window.c
index fb83400a..888f3460 100644
--- a/examples/core_basic_window.c
+++ b/examples/core_basic_window.c
@@ -39,6 +39,11 @@ int main()
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
+ float dx = 600 - 100;
+ float dy = 105 - 405;
+
+ float d = sqrtf(dx*dx + dy*dy);
+ float angle = asinf(dy/d);
//----------------------------------------------------------------------------------
// Draw
@@ -47,7 +52,22 @@ int main()
ClearBackground(RAYWHITE);
- DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
+ //DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
+
+ DrawRectangle(100, 400, 1, 10, BLACK);
+ DrawRectangle(96, 404, 10, 1, BLACK);
+
+ DrawRectangle(600, 100, 1, 10, BLACK);
+ DrawRectangle(596, 104, 10, 1, BLACK);
+
+ DrawLine(100, 405, 600, 105, RED);
+
+ // Draw lines using textures
+ /*
+ DrawTexturePro(GetDefaultTexture(), (Rectangle){ 0, 0, GetDefaultTexture().width, GetDefaultTexture().height },
+ (Rectangle){ 100, 405, (float)GetDefaultTexture().width*d, 1 },
+ (Vector2){ 0, (float)GetDefaultTexture().height/2 }, -RAD2DEG*angle, BLUE);
+ */
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/src/raylib.h b/src/raylib.h
index beda833c..b0f03bbe 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -98,13 +98,13 @@
#define RAD2DEG (180.0f/PI)
// raylib Config Flags
-#define FLAG_SHOW_LOGO 1 // Set this flag to show raylib logo at startup
-#define FLAG_FULLSCREEN_MODE 2 // Set this flag to run program in fullscreen
-#define FLAG_WINDOW_RESIZABLE 4 // Set this flag to allow resizable window
-#define FLAG_WINDOW_DECORATED 8 // Set this flag to show window decoration (frame and buttons)
-#define FLAG_WINDOW_TRANSPARENT 16 // Set this flag to allow transparent window
-#define FLAG_MSAA_4X_HINT 32 // Set this flag to try enabling MSAA 4X
-#define FLAG_VSYNC_HINT 64 // Set this flag to try enabling V-Sync on GPU
+#define FLAG_SHOW_LOGO 1 // Set to show raylib logo at startup
+#define FLAG_FULLSCREEN_MODE 2 // Set to run program in fullscreen
+#define FLAG_WINDOW_RESIZABLE 4 // Set to allow resizable window
+#define FLAG_WINDOW_DECORATED 8 // Set to show window decoration (frame and buttons)
+#define FLAG_WINDOW_TRANSPARENT 16 // Set to allow transparent window
+#define FLAG_MSAA_4X_HINT 32 // Set to try enabling MSAA 4X
+#define FLAG_VSYNC_HINT 64 // Set to try enabling V-Sync on GPU
// Keyboard Function Keys
#define KEY_SPACE 32
@@ -763,6 +763,7 @@ RLAPI void DrawPixel(int posX, int posY, Color color);
RLAPI void DrawPixelV(Vector2 position, Color color); // Draw a pixel (Vector version)
RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line
RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version)
+RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line defining thickness
RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle
RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle
RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version)
diff --git a/src/shapes.c b/src/shapes.c
index a42b0551..9cbe1da4 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -103,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)
{