summaryrefslogtreecommitdiffhomepage
path: root/examples/src/shapes
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-14 17:57:45 +0200
committerRay <[email protected]>2019-05-14 17:57:45 +0200
commit5a27bcaf7115e46a5123e9857007d940998f0650 (patch)
tree7179c6a1b4d700c9685dd51cc76cb2b2c90b9609 /examples/src/shapes
parent423fdd699225ee9686c44a606bf83272b4c77802 (diff)
downloadraylib.com-5a27bcaf7115e46a5123e9857007d940998f0650.tar.gz
raylib.com-5a27bcaf7115e46a5123e9857007d940998f0650.zip
Review examples collection -WIP-
WARNING: Examples list has been reviewed but examples haven't been recompiled yet... that's not trivial...
Diffstat (limited to 'examples/src/shapes')
-rw-r--r--examples/src/shapes/shapes_basic_shapes.c17
-rw-r--r--examples/src/shapes/shapes_bouncing_ball.c76
-rw-r--r--examples/src/shapes/shapes_collision_area.c108
-rw-r--r--examples/src/shapes/shapes_colors_palette.c114
-rw-r--r--examples/src/shapes/shapes_draw_circle_sector.c81
-rw-r--r--examples/src/shapes/shapes_draw_rectangle_rounded.c89
-rw-r--r--examples/src/shapes/shapes_draw_ring.c94
-rw-r--r--examples/src/shapes/shapes_easings_ball_anim.c110
-rw-r--r--examples/src/shapes/shapes_easings_box_anim.c136
-rw-r--r--examples/src/shapes/shapes_easings_rectangle_array.c118
-rw-r--r--examples/src/shapes/shapes_following_eyes.c104
-rw-r--r--examples/src/shapes/shapes_logo_raylib_anim.c4
-rw-r--r--examples/src/shapes/shapes_rectangle_scaling.c94
13 files changed, 1079 insertions, 66 deletions
diff --git a/examples/src/shapes/shapes_basic_shapes.c b/examples/src/shapes/shapes_basic_shapes.c
index 4b7cc26..67eea9d 100644
--- a/examples/src/shapes/shapes_basic_shapes.c
+++ b/examples/src/shapes/shapes_basic_shapes.c
@@ -39,26 +39,27 @@ int main()
DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);
- DrawLine(18, 42, screenWidth - 18, 42, BLACK);
-
DrawCircle(screenWidth/4, 120, 35, DARKBLUE);
- DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE);
- DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE);
DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
+ DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); // NOTE: Uses QUADS internally, not lines
DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
- DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE);
DrawTriangle((Vector2){screenWidth/4*3, 80},
(Vector2){screenWidth/4*3 - 60, 150},
(Vector2){screenWidth/4*3 + 60, 150}, VIOLET);
+ DrawPoly((Vector2){screenWidth/4*3, 320}, 6, 80, 0, BROWN);
+
+ DrawCircleGradient(screenWidth/4, 220, 60, GREEN, SKYBLUE);
+
+ // NOTE: We draw all LINES based shapes together to optimize internal drawing,
+ // this way, all LINES are rendered in a single draw pass
+ DrawLine(18, 42, screenWidth - 18, 42, BLACK);
+ DrawCircleLines(screenWidth/4, 340, 80, DARKBLUE);
DrawTriangleLines((Vector2){screenWidth/4*3, 160},
(Vector2){screenWidth/4*3 - 20, 230},
(Vector2){screenWidth/4*3 + 20, 230}, DARKBLUE);
-
- DrawPoly((Vector2){screenWidth/4*3, 320}, 6, 80, 0, BROWN);
-
EndDrawing();
//----------------------------------------------------------------------------------
}
diff --git a/examples/src/shapes/shapes_bouncing_ball.c b/examples/src/shapes/shapes_bouncing_ball.c
new file mode 100644
index 0000000..6b27c9d
--- /dev/null
+++ b/examples/src/shapes/shapes_bouncing_ball.c
@@ -0,0 +1,76 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - bouncing ball
+*
+* This example has been created using raylib 1.0 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2013 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+int main()
+{
+ // Initialization
+ //---------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - bouncing ball");
+
+ Vector2 ballPosition = { GetScreenWidth()/2, GetScreenHeight()/2 };
+ Vector2 ballSpeed = { 5.0f, 4.0f };
+ int ballRadius = 20;
+
+ bool pause = 0;
+ int framesCounter = 0;
+
+ SetTargetFPS(60);
+ //----------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //-----------------------------------------------------
+ if (IsKeyPressed(KEY_SPACE)) pause = !pause;
+
+ if (!pause)
+ {
+ ballPosition.x += ballSpeed.x;
+ ballPosition.y += ballSpeed.y;
+
+ // Check walls collision for bouncing
+ if ((ballPosition.x >= (GetScreenWidth() - ballRadius)) || (ballPosition.x <= ballRadius)) ballSpeed.x *= -1.0f;
+ if ((ballPosition.y >= (GetScreenHeight() - ballRadius)) || (ballPosition.y <= ballRadius)) ballSpeed.y *= -1.0f;
+ }
+ else framesCounter++;
+ //-----------------------------------------------------
+
+ // Draw
+ //-----------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawCircleV(ballPosition, ballRadius, MAROON);
+ DrawText("PRESS SPACE to PAUSE BALL MOVEMENT", 10, GetScreenHeight() - 25, 20, LIGHTGRAY);
+
+ // On pause, we draw a blinking message
+ if (pause && ((framesCounter/30)%2)) DrawText("PAUSED", 350, 200, 30, GRAY);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //-----------------------------------------------------
+ }
+
+ // De-Initialization
+ //---------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //----------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/shapes/shapes_collision_area.c b/examples/src/shapes/shapes_collision_area.c
new file mode 100644
index 0000000..e61623a
--- /dev/null
+++ b/examples/src/shapes/shapes_collision_area.c
@@ -0,0 +1,108 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - collision area
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2013-2019 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+#include <stdlib.h> // Required for abs()
+
+int main()
+{
+ // Initialization
+ //---------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - collision area");
+
+ // Box A: Moving box
+ Rectangle boxA = { 10, GetScreenHeight()/2 - 50, 200, 100 };
+ int boxASpeedX = 4;
+
+ // Box B: Mouse moved box
+ Rectangle boxB = { GetScreenWidth()/2 - 30, GetScreenHeight()/2 - 30, 60, 60 };
+
+ Rectangle boxCollision = { 0 }; // Collision rectangle
+
+ int screenUpperLimit = 40; // Top menu limits
+
+ bool pause = false; // Movement pause
+ bool collision = false; // Collision detection
+
+ SetTargetFPS(60);
+ //----------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //-----------------------------------------------------
+ // Move box if not paused
+ if (!pause) boxA.x += boxASpeedX;
+
+ // Bounce box on x screen limits
+ if (((boxA.x + boxA.width) >= GetScreenWidth()) || (boxA.x <= 0)) boxASpeedX *= -1;
+
+ // Update player-controlled-box (box02)
+ boxB.x = GetMouseX() - boxB.width/2;
+ boxB.y = GetMouseY() - boxB.height/2;
+
+ // Make sure Box B does not go out of move area limits
+ if ((boxB.x + boxB.width) >= GetScreenWidth()) boxB.x = GetScreenWidth() - boxB.width;
+ else if (boxB.x <= 0) boxB.x = 0;
+
+ if ((boxB.y + boxB.height) >= GetScreenHeight()) boxB.y = GetScreenHeight() - boxB.height;
+ else if (boxB.y <= screenUpperLimit) boxB.y = screenUpperLimit;
+
+ // Check boxes collision
+ collision = CheckCollisionRecs(boxA, boxB);
+
+ // Get collision rectangle (only on collision)
+ if (collision) boxCollision = GetCollisionRec(boxA, boxB);
+
+ // Pause Box A movement
+ if (IsKeyPressed(KEY_SPACE)) pause = !pause;
+ //-----------------------------------------------------
+
+ // Draw
+ //-----------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawRectangle(0, 0, screenWidth, screenUpperLimit, collision? RED : BLACK);
+
+ DrawRectangleRec(boxA, GOLD);
+ DrawRectangleRec(boxB, BLUE);
+
+ if (collision)
+ {
+ // Draw collision area
+ DrawRectangleRec(boxCollision, LIME);
+
+ // Draw collision message
+ DrawText("COLLISION!", GetScreenWidth()/2 - MeasureText("COLLISION!", 20)/2, screenUpperLimit/2 - 10, 20, BLACK);
+
+ // Draw collision area
+ DrawText(FormatText("Collision Area: %i", (int)boxCollision.width*(int)boxCollision.height), GetScreenWidth()/2 - 100, screenUpperLimit + 10, 20, BLACK);
+ }
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //-----------------------------------------------------
+ }
+
+ // De-Initialization
+ //---------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //----------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/shapes/shapes_colors_palette.c b/examples/src/shapes/shapes_colors_palette.c
index dcab862..d6ac30a 100644
--- a/examples/src/shapes/shapes_colors_palette.c
+++ b/examples/src/shapes/shapes_colors_palette.c
@@ -1,26 +1,53 @@
/*******************************************************************************************
*
-* raylib [shapes] example - Draw raylib custom color palette
+* raylib [shapes] example - Colors palette
*
-* This example has been created using raylib 1.0 (www.raylib.com)
+* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
+#define MAX_COLORS_COUNT 21 // Number of colors available
+
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
- int screenWidth = 800;
- int screenHeight = 450;
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - colors palette");
+
+ Color colors[MAX_COLORS_COUNT] = {
+ DARKGRAY, MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, DARKBROWN,
+ GRAY, RED, GOLD, LIME, BLUE, VIOLET, BROWN, LIGHTGRAY, PINK, YELLOW,
+ GREEN, SKYBLUE, PURPLE, BEIGE };
+
+ const char *colorNames[MAX_COLORS_COUNT] = {
+ "DARKGRAY", "MAROON", "ORANGE", "DARKGREEN", "DARKBLUE", "DARKPURPLE",
+ "DARKBROWN", "GRAY", "RED", "GOLD", "LIME", "BLUE", "VIOLET", "BROWN",
+ "LIGHTGRAY", "PINK", "YELLOW", "GREEN", "SKYBLUE", "PURPLE", "BEIGE" };
+
+ Rectangle colorsRecs[MAX_COLORS_COUNT] = { 0 }; // Rectangles array
+
+ // Fills colorsRecs data (for every rectangle)
+ for (int i = 0; i < MAX_COLORS_COUNT; i++)
+ {
+ colorsRecs[i].x = 20 + 100*(i%7) + 10*(i%7);
+ colorsRecs[i].y = 80 + 100*(i/7) + 10*(i/7);
+ colorsRecs[i].width = 100;
+ colorsRecs[i].height = 100;
+ }
+
+ int colorState[MAX_COLORS_COUNT] = { 0 }; // Color state: 0-DEFAULT, 1-MOUSE_HOVER
- InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
-
- SetTargetFPS(60);
+ Vector2 mousePoint;
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
@@ -28,7 +55,13 @@ int main()
{
// Update
//----------------------------------------------------------------------------------
- // TODO: Update your variables here
+ mousePoint = GetMousePosition();
+
+ for (int i = 0; i < MAX_COLORS_COUNT; i++)
+ {
+ if (CheckCollisionPointRec(mousePoint, colorsRecs[i])) colorState[i] = 1;
+ else colorState[i] = 0;
+ }
//----------------------------------------------------------------------------------
// Draw
@@ -36,53 +69,22 @@ int main()
BeginDrawing();
ClearBackground(RAYWHITE);
+
+ DrawText("raylib colors palette", 28, 42, 20, BLACK);
+ DrawText("press SPACE to see all colors", GetScreenWidth() - 180, GetScreenHeight() - 40, 10, GRAY);
- DrawText("raylib color palette", 28, 42, 20, BLACK);
-
- DrawRectangle(26, 80, 100, 100, DARKGRAY);
- DrawRectangle(26, 188, 100, 100, GRAY);
- DrawRectangle(26, 296, 100, 100, LIGHTGRAY);
- DrawRectangle(134, 80, 100, 100, MAROON);
- DrawRectangle(134, 188, 100, 100, RED);
- DrawRectangle(134, 296, 100, 100, PINK);
- DrawRectangle(242, 80, 100, 100, ORANGE);
- DrawRectangle(242, 188, 100, 100, GOLD);
- DrawRectangle(242, 296, 100, 100, YELLOW);
- DrawRectangle(350, 80, 100, 100, DARKGREEN);
- DrawRectangle(350, 188, 100, 100, LIME);
- DrawRectangle(350, 296, 100, 100, GREEN);
- DrawRectangle(458, 80, 100, 100, DARKBLUE);
- DrawRectangle(458, 188, 100, 100, BLUE);
- DrawRectangle(458, 296, 100, 100, SKYBLUE);
- DrawRectangle(566, 80, 100, 100, DARKPURPLE);
- DrawRectangle(566, 188, 100, 100, VIOLET);
- DrawRectangle(566, 296, 100, 100, PURPLE);
- DrawRectangle(674, 80, 100, 100, DARKBROWN);
- DrawRectangle(674, 188, 100, 100, BROWN);
- DrawRectangle(674, 296, 100, 100, BEIGE);
-
-
- DrawText("DARKGRAY", 65, 166, 10, BLACK);
- DrawText("GRAY", 93, 274, 10, BLACK);
- DrawText("LIGHTGRAY", 61, 382, 10, BLACK);
- DrawText("MAROON", 186, 166, 10, BLACK);
- DrawText("RED", 208, 274, 10, BLACK);
- DrawText("PINK", 204, 382, 10, BLACK);
- DrawText("ORANGE", 295, 166, 10, BLACK);
- DrawText("GOLD", 310, 274, 10, BLACK);
- DrawText("YELLOW", 300, 382, 10, BLACK);
- DrawText("DARKGREEN", 382, 166, 10, BLACK);
- DrawText("LIME", 420, 274, 10, BLACK);
- DrawText("GREEN", 410, 382, 10, BLACK);
- DrawText("DARKBLUE", 498, 166, 10, BLACK);
- DrawText("BLUE", 526, 274, 10, BLACK);
- DrawText("SKYBLUE", 505, 382, 10, BLACK);
- DrawText("DARKPURPLE", 592, 166, 10, BLACK);
- DrawText("VIOLET", 621, 274, 10, BLACK);
- DrawText("PURPLE", 620, 382, 10, BLACK);
- DrawText("DARKBROWN", 705, 166, 10, BLACK);
- DrawText("BROWN", 733, 274, 10, BLACK);
- DrawText("BEIGE", 737, 382, 10, BLACK);
+ for (int i = 0; i < MAX_COLORS_COUNT; i++) // Draw all rectangles
+ {
+ DrawRectangleRec(colorsRecs[i], Fade(colors[i], colorState[i]? 0.6f : 1.0f));
+
+ if (IsKeyDown(KEY_SPACE) || colorState[i])
+ {
+ DrawRectangle(colorsRecs[i].x, colorsRecs[i].y + colorsRecs[i].height - 26, colorsRecs[i].width, 20, BLACK);
+ DrawRectangleLinesEx(colorsRecs[i], 6, Fade(BLACK, 0.3f));
+ DrawText(colorNames[i], colorsRecs[i].x + colorsRecs[i].width - MeasureText(colorNames[i], 10) - 12,
+ colorsRecs[i].y + colorsRecs[i].height - 20, 10, colors[i]);
+ }
+ }
EndDrawing();
//----------------------------------------------------------------------------------
@@ -90,7 +92,7 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- CloseWindow(); // Close window and OpenGL context
+ CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
diff --git a/examples/src/shapes/shapes_draw_circle_sector.c b/examples/src/shapes/shapes_draw_circle_sector.c
new file mode 100644
index 0000000..597b85a
--- /dev/null
+++ b/examples/src/shapes/shapes_draw_circle_sector.c
@@ -0,0 +1,81 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - draw circle sector (with gui options)
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include <raylib.h>
+
+#define RAYGUI_IMPLEMENTATION
+#include "raygui.h" // Required for GUI controls
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw circle sector");
+
+ Vector2 center = {(GetScreenWidth() - 300)/2, GetScreenHeight()/2 };
+
+ float outerRadius = 180.f;
+ int startAngle = 0;
+ int endAngle = 180;
+ int segments = 0;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // NOTE: All variables update happens inside GUI control functions
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
+ DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
+
+ DrawCircleSector(center, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.3));
+ DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.6));
+
+ // Draw GUI controls
+ //------------------------------------------------------------------------------
+ startAngle = GuiSliderBar((Rectangle){ 600, 40, 120, 20}, "StartAngle", startAngle, 0, 720, true );
+ endAngle = GuiSliderBar((Rectangle){ 600, 70, 120, 20}, "EndAngle", endAngle, 0, 720, true);
+
+ outerRadius = GuiSliderBar((Rectangle){ 600, 140, 120, 20}, "Radius", outerRadius, 0, 200, true);
+ segments = GuiSliderBar((Rectangle){ 600, 170, 120, 20}, "Segments", segments, 0, 100, true);
+ //------------------------------------------------------------------------------
+
+ DrawText(FormatText("MODE: %s", (segments >= 4)? "MANUAL" : "AUTO"), 600, 200, 10, (segments >= 4)? MAROON : DARKGRAY);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/shapes/shapes_draw_rectangle_rounded.c b/examples/src/shapes/shapes_draw_rectangle_rounded.c
new file mode 100644
index 0000000..e36e273
--- /dev/null
+++ b/examples/src/shapes/shapes_draw_rectangle_rounded.c
@@ -0,0 +1,89 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - draw rectangle rounded (with gui options)
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include <raylib.h>
+
+#define RAYGUI_IMPLEMENTATION
+#include "raygui.h" // Required for GUI controls
+
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw rectangle rounded");
+
+ float roundness = 0.2f;
+ int width = 200;
+ int height = 100;
+ int segments = 0;
+ int lineThick = 1;
+
+ bool drawRect = false;
+ bool drawRoundedRect = true;
+ bool drawRoundedLines = false;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ Rectangle rec = { (GetScreenWidth() - width - 250)/2, (GetScreenHeight() - height)/2, width, height };
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawLine(560, 0, 560, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
+ DrawRectangle(560, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
+
+ if (drawRect) DrawRectangleRec(rec, Fade(GOLD, 0.6));
+ if (drawRoundedRect) DrawRectangleRounded(rec, roundness, segments, Fade(MAROON, 0.2));
+ if (drawRoundedLines) DrawRectangleRoundedLines(rec,roundness, segments, lineThick, Fade(MAROON, 0.4));
+
+ // Draw GUI controls
+ //------------------------------------------------------------------------------
+ width = GuiSliderBar((Rectangle){ 640, 40, 105, 20 }, "Width", width, 0, GetScreenWidth() - 300, true );
+ height = GuiSliderBar((Rectangle){ 640, 70, 105, 20 }, "Height", height, 0, GetScreenHeight() - 50, true);
+ roundness = GuiSliderBar((Rectangle){ 640, 140, 105, 20 }, "Roundness", roundness, 0.0f, 1.0f, true);
+ lineThick = GuiSliderBar((Rectangle){ 640, 170, 105, 20 }, "Thickness", lineThick, 0, 20, true);
+ segments = GuiSliderBar((Rectangle){ 640, 240, 105, 20}, "Segments", segments, 0, 60, true);
+
+ drawRoundedRect = GuiCheckBox((Rectangle){ 640, 320, 20, 20 }, "DrawRoundedRect", drawRoundedRect);
+ drawRoundedLines = GuiCheckBox((Rectangle){ 640, 350, 20, 20 }, "DrawRoundedLines", drawRoundedLines);
+ drawRect = GuiCheckBox((Rectangle){ 640, 380, 20, 20}, "DrawRect", drawRect);
+ //------------------------------------------------------------------------------
+
+ DrawText(FormatText("MODE: %s", (segments >= 4)? "MANUAL" : "AUTO"), 640, 280, 10, (segments >= 4)? MAROON : DARKGRAY);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+}
diff --git a/examples/src/shapes/shapes_draw_ring.c b/examples/src/shapes/shapes_draw_ring.c
new file mode 100644
index 0000000..44a3ec5
--- /dev/null
+++ b/examples/src/shapes/shapes_draw_ring.c
@@ -0,0 +1,94 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - draw ring (with gui options)
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include <raylib.h>
+
+#define RAYGUI_IMPLEMENTATION
+#include "raygui.h" // Required for GUI controls
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw ring");
+
+ Vector2 center = {(GetScreenWidth() - 300)/2, GetScreenHeight()/2 };
+
+ float innerRadius = 80.0f;
+ float outerRadius = 190.0f;
+
+ int startAngle = 0;
+ int endAngle = 360;
+ int segments = 0;
+
+ bool drawRing = true;
+ bool drawRingLines = false;
+ bool drawCircleLines = false;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // NOTE: All variables update happens inside GUI control functions
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
+ DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
+
+ if (drawRing) DrawRing(center, innerRadius, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.3));
+ if (drawRingLines) DrawRingLines(center, innerRadius, outerRadius, startAngle, endAngle, segments, Fade(BLACK, 0.4));
+ if (drawCircleLines) DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, Fade(BLACK, 0.4));
+
+ // Draw GUI controls
+ //------------------------------------------------------------------------------
+ startAngle = GuiSliderBar((Rectangle){ 600, 40, 120, 20 }, "StartAngle", startAngle, -450, 450, true);
+ endAngle = GuiSliderBar((Rectangle){ 600, 70, 120, 20 }, "EndAngle", endAngle, -450, 450, true);
+
+ innerRadius = GuiSliderBar((Rectangle){ 600, 140, 120, 20 }, "InnerRadius", innerRadius, 0, 100, true);
+ outerRadius = GuiSliderBar((Rectangle){ 600, 170, 120, 20 }, "OuterRadius", outerRadius, 0, 200, true);
+
+ segments = GuiSliderBar((Rectangle){ 600, 240, 120, 20 }, "Segments", segments, 0, 100, true);
+
+ drawRing = GuiCheckBox((Rectangle){ 600, 320, 20, 20 }, "Draw Ring", drawRing);
+ drawRingLines = GuiCheckBox((Rectangle){ 600, 350, 20, 20 }, "Draw RingLines", drawRingLines);
+ drawCircleLines = GuiCheckBox((Rectangle){ 600, 380, 20, 20 }, "Draw CircleLines", drawCircleLines);
+ //------------------------------------------------------------------------------
+
+ DrawText(FormatText("MODE: %s", (segments >= 4)? "MANUAL" : "AUTO"), 600, 270, 10, (segments >= 4)? MAROON : DARKGRAY);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/shapes/shapes_easings_ball_anim.c b/examples/src/shapes/shapes_easings_ball_anim.c
new file mode 100644
index 0000000..4477203
--- /dev/null
+++ b/examples/src/shapes/shapes_easings_ball_anim.c
@@ -0,0 +1,110 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - easings ball anim
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#include "easings.h" // Required for easing functions
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - easings ball anim");
+
+ // Ball variable value to be animated with easings
+ int ballPositionX = -100;
+ int ballRadius = 20;
+ float ballAlpha = 0.0f;
+
+ int state = 0;
+ int framesCounter = 0;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (state == 0) // Move ball position X with easing
+ {
+ framesCounter++;
+ ballPositionX = EaseElasticOut(framesCounter, -100, screenWidth/2 + 100, 120);
+
+ if (framesCounter >= 120)
+ {
+ framesCounter = 0;
+ state = 1;
+ }
+ }
+ else if (state == 1) // Increase ball radius with easing
+ {
+ framesCounter++;
+ ballRadius = EaseElasticIn(framesCounter, 20, 500, 200);
+
+ if (framesCounter >= 200)
+ {
+ framesCounter = 0;
+ state = 2;
+ }
+ }
+ else if (state == 2) // Change ball alpha with easing (background color blending)
+ {
+ framesCounter++;
+ ballAlpha = EaseCubicOut(framesCounter, 0.0f, 1.0f, 200);
+
+ if (framesCounter >= 200)
+ {
+ framesCounter = 0;
+ state = 3;
+ }
+ }
+ else if (state == 3) // Reset state to play again
+ {
+ if (IsKeyPressed(KEY_ENTER))
+ {
+ // Reset required variables to play again
+ ballPositionX = -100;
+ ballRadius = 20;
+ ballAlpha = 0.0f;
+ state = 0;
+ }
+ }
+
+ if (IsKeyPressed(KEY_R)) framesCounter = 0;
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ if (state >= 2) DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
+ DrawCircle(ballPositionX, 200, ballRadius, Fade(RED, 1.0f - ballAlpha));
+
+ if (state == 3) DrawText("PRESS [ENTER] TO PLAY AGAIN!", 240, 200, 20, BLACK);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/shapes/shapes_easings_box_anim.c b/examples/src/shapes/shapes_easings_box_anim.c
new file mode 100644
index 0000000..c74cb2a
--- /dev/null
+++ b/examples/src/shapes/shapes_easings_box_anim.c
@@ -0,0 +1,136 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - easings box anim
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#include "easings.h" // Required for easing functions
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - easings box anim");
+
+ // Box variables to be animated with easings
+ Rectangle rec = { GetScreenWidth()/2, -100, 100, 100 };
+ float rotation = 0.0f;
+ float alpha = 1.0f;
+
+ int state = 0;
+ int framesCounter = 0;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ switch (state)
+ {
+ case 0: // Move box down to center of screen
+ {
+ framesCounter++;
+
+ // NOTE: Remember that 3rd parameter of easing function refers to
+ // desired value variation, do not confuse it with expected final value!
+ rec.y = EaseElasticOut(framesCounter, -100, GetScreenHeight()/2 + 100, 120);
+
+ if (framesCounter >= 120)
+ {
+ framesCounter = 0;
+ state = 1;
+ }
+ } break;
+ case 1: // Scale box to an horizontal bar
+ {
+ framesCounter++;
+ rec.height = EaseBounceOut(framesCounter, 100, -90, 120);
+ rec.width = EaseBounceOut(framesCounter, 100, GetScreenWidth(), 120);
+
+ if (framesCounter >= 120)
+ {
+ framesCounter = 0;
+ state = 2;
+ }
+ } break;
+ case 2: // Rotate horizontal bar rectangle
+ {
+ framesCounter++;
+ rotation = EaseQuadOut(framesCounter, 0.0f, 270.0f, 240);
+
+ if (framesCounter >= 240)
+ {
+ framesCounter = 0;
+ state = 3;
+ }
+ } break;
+ case 3: // Increase bar size to fill all screen
+ {
+ framesCounter++;
+ rec.height = EaseCircOut(framesCounter, 10, GetScreenWidth(), 120);
+
+ if (framesCounter >= 120)
+ {
+ framesCounter = 0;
+ state = 4;
+ }
+ } break;
+ case 4: // Fade out animation
+ {
+ framesCounter++;
+ alpha = EaseSineOut(framesCounter, 1.0f, -1.0f, 160);
+
+ if (framesCounter >= 160)
+ {
+ framesCounter = 0;
+ state = 5;
+ }
+ } break;
+ default: break;
+ }
+
+ // Reset animation at any moment
+ if (IsKeyPressed(KEY_SPACE))
+ {
+ rec = (Rectangle){ GetScreenWidth()/2, -100, 100, 100 };
+ rotation = 0.0f;
+ alpha = 1.0f;
+ state = 0;
+ framesCounter = 0;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawRectanglePro(rec, (Vector2){ rec.width/2, rec.height/2 }, rotation, Fade(BLACK, alpha));
+
+ DrawText("PRESS [SPACE] TO RESET BOX ANIMATION!", 10, GetScreenHeight() - 25, 20, LIGHTGRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/shapes/shapes_easings_rectangle_array.c b/examples/src/shapes/shapes_easings_rectangle_array.c
new file mode 100644
index 0000000..27bad5c
--- /dev/null
+++ b/examples/src/shapes/shapes_easings_rectangle_array.c
@@ -0,0 +1,118 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - easings rectangle array
+*
+* NOTE: This example requires 'easings.h' library, provided on raylib/src. Just copy
+* the library to same directory as example or make sure it's available on include path.
+*
+* This example has been created using raylib 2.0 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#include "easings.h" // Required for easing functions
+
+#define RECS_WIDTH 50
+#define RECS_HEIGHT 50
+
+#define MAX_RECS_X 800/RECS_WIDTH
+#define MAX_RECS_Y 450/RECS_HEIGHT
+
+#define PLAY_TIME_IN_FRAMES 240 // At 60 fps = 4 seconds
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - easings rectangle array");
+
+ Rectangle recs[MAX_RECS_X*MAX_RECS_Y];
+
+ for (int y = 0; y < MAX_RECS_Y; y++)
+ {
+ for (int x = 0; x < MAX_RECS_X; x++)
+ {
+ recs[y*MAX_RECS_X + x].x = RECS_WIDTH/2 + RECS_WIDTH*x;
+ recs[y*MAX_RECS_X + x].y = RECS_HEIGHT/2 + RECS_HEIGHT*y;
+ recs[y*MAX_RECS_X + x].width = RECS_WIDTH;
+ recs[y*MAX_RECS_X + x].height = RECS_HEIGHT;
+ }
+ }
+
+ float rotation = 0.0f;
+ int framesCounter = 0;
+ int state = 0; // Rectangles animation state: 0-Playing, 1-Finished
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ if (state == 0)
+ {
+ framesCounter++;
+
+ for (int i = 0; i < MAX_RECS_X*MAX_RECS_Y; i++)
+ {
+ recs[i].height = EaseCircOut(framesCounter, RECS_HEIGHT, -RECS_HEIGHT, PLAY_TIME_IN_FRAMES);
+ recs[i].width = EaseCircOut(framesCounter, RECS_WIDTH, -RECS_WIDTH, PLAY_TIME_IN_FRAMES);
+
+ if (recs[i].height < 0) recs[i].height = 0;
+ if (recs[i].width < 0) recs[i].width = 0;
+
+ if ((recs[i].height == 0) && (recs[i].width == 0)) state = 1; // Finish playing
+
+ rotation = EaseLinearIn(framesCounter, 0.0f, 360.0f, PLAY_TIME_IN_FRAMES);
+ }
+ }
+ else if ((state == 1) && IsKeyPressed(KEY_SPACE))
+ {
+ // When animation has finished, press space to restart
+ framesCounter = 0;
+
+ for (int i = 0; i < MAX_RECS_X*MAX_RECS_Y; i++)
+ {
+ recs[i].height = RECS_HEIGHT;
+ recs[i].width = RECS_WIDTH;
+ }
+
+ state = 0;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ if (state == 0)
+ {
+ for (int i = 0; i < MAX_RECS_X*MAX_RECS_Y; i++)
+ {
+ DrawRectanglePro(recs[i], (Vector2){ recs[i].width/2, recs[i].height/2 }, rotation, RED);
+ }
+ }
+ else if (state == 1) DrawText("PRESS [SPACE] TO PLAY AGAIN!", 240, 200, 20, GRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/shapes/shapes_following_eyes.c b/examples/src/shapes/shapes_following_eyes.c
new file mode 100644
index 0000000..e99a7e0
--- /dev/null
+++ b/examples/src/shapes/shapes_following_eyes.c
@@ -0,0 +1,104 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - following eyes
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2013-2019 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#include <math.h> // Required for: atan2f()
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - following eyes");
+
+ Vector2 scleraLeftPosition = { GetScreenWidth()/2 - 100, GetScreenHeight()/2 };
+ Vector2 scleraRightPosition = { GetScreenWidth()/2 + 100, GetScreenHeight()/2 };
+ float scleraRadius = 80;
+
+ Vector2 irisLeftPosition = { GetScreenWidth()/2 - 100, GetScreenHeight()/2 };
+ Vector2 irisRightPosition = { GetScreenWidth()/2 + 100, GetScreenHeight()/2};
+ float irisRadius = 24;
+
+ float angle;
+ float dx, dy, dxx, dyy;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ irisLeftPosition = GetMousePosition();
+ irisRightPosition = GetMousePosition();
+
+ // Check not inside the left eye sclera
+ if (!CheckCollisionPointCircle(irisLeftPosition, scleraLeftPosition, scleraRadius - 20))
+ {
+ dx = irisLeftPosition.x - scleraLeftPosition.x;
+ dy = irisLeftPosition.y - scleraLeftPosition.y;
+
+ angle = atan2f(dy, dx);
+
+ dxx = (scleraRadius - irisRadius)*cosf(angle);
+ dyy = (scleraRadius - irisRadius)*sinf(angle);
+
+ irisLeftPosition.x = scleraLeftPosition.x + dxx;
+ irisLeftPosition.y = scleraLeftPosition.y + dyy;
+ }
+
+ // Check not inside the right eye sclera
+ if (!CheckCollisionPointCircle(irisRightPosition, scleraRightPosition, scleraRadius - 20))
+ {
+ dx = irisRightPosition.x - scleraRightPosition.x;
+ dy = irisRightPosition.y - scleraRightPosition.y;
+
+ angle = atan2f(dy, dx);
+
+ dxx = (scleraRadius - irisRadius)*cosf(angle);
+ dyy = (scleraRadius - irisRadius)*sinf(angle);
+
+ irisRightPosition.x = scleraRightPosition.x + dxx;
+ irisRightPosition.y = scleraRightPosition.y + dyy;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawCircleV(scleraLeftPosition, scleraRadius, LIGHTGRAY);
+ DrawCircleV(irisLeftPosition, irisRadius, BROWN);
+ DrawCircleV(irisLeftPosition, 10, BLACK);
+
+ DrawCircleV(scleraRightPosition, scleraRadius, LIGHTGRAY);
+ DrawCircleV(irisRightPosition, irisRadius, DARKGREEN);
+ DrawCircleV(irisRightPosition, 10, BLACK);
+
+ DrawFPS(10, 10);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/src/shapes/shapes_logo_raylib_anim.c b/examples/src/shapes/shapes_logo_raylib_anim.c
index c6d3796..9be1d96 100644
--- a/examples/src/shapes/shapes_logo_raylib_anim.c
+++ b/examples/src/shapes/shapes_logo_raylib_anim.c
@@ -2,7 +2,7 @@
*
* raylib [shapes] example - raylib logo animation
*
-* This example has been created using raylib 1.4 (www.raylib.com)
+* This example has been created using raylib 2.3 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
@@ -140,7 +140,7 @@ int main()
DrawRectangle(screenWidth/2 - 112, screenHeight/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
- DrawText(SubText("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
+ DrawText(TextSubtext("raylib", 0, lettersCount), screenWidth/2 - 44, screenHeight/2 + 48, 50, Fade(BLACK, alpha));
}
else if (state == 4)
{
diff --git a/examples/src/shapes/shapes_rectangle_scaling.c b/examples/src/shapes/shapes_rectangle_scaling.c
new file mode 100644
index 0000000..036a1dd
--- /dev/null
+++ b/examples/src/shapes/shapes_rectangle_scaling.c
@@ -0,0 +1,94 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - rectangle scaling by mouse
+*
+* This example has been created using raylib 2.5 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#define MOUSE_SCALE_MARK_SIZE 12
+
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ int screenWidth = 800;
+ int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [shapes] example - rectangle scaling mouse");
+
+ Rectangle rec = { 100, 100, 200, 80 };
+
+ Vector2 mousePosition = { 0 };
+
+ bool mouseScaleReady = false;
+ bool mouseScaleMode = false;
+
+ SetTargetFPS(60);
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ mousePosition = GetMousePosition();
+
+ if (CheckCollisionPointRec(mousePosition, rec) &&
+ CheckCollisionPointRec(mousePosition, (Rectangle){ rec.x + rec.width - MOUSE_SCALE_MARK_SIZE, rec.y + rec.height - MOUSE_SCALE_MARK_SIZE, MOUSE_SCALE_MARK_SIZE, MOUSE_SCALE_MARK_SIZE }))
+ {
+ mouseScaleReady = true;
+ if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) mouseScaleMode = true;
+ }
+ else mouseScaleReady = false;
+
+ if (mouseScaleMode)
+ {
+ mouseScaleReady = true;
+
+ rec.width = (mousePosition.x - rec.x);
+ rec.height = (mousePosition.y - rec.y);
+
+ if (rec.width < MOUSE_SCALE_MARK_SIZE) rec.width = MOUSE_SCALE_MARK_SIZE;
+ if (rec.height < MOUSE_SCALE_MARK_SIZE) rec.height = MOUSE_SCALE_MARK_SIZE;
+
+ if (IsMouseButtonReleased(MOUSE_LEFT_BUTTON)) mouseScaleMode = false;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ DrawText("Scale rectangle dragging from bottom-right corner!", 10, 10, 20, GRAY);
+
+ DrawRectangleRec(rec, Fade(GREEN, 0.5f));
+
+ if (mouseScaleReady)
+ {
+ DrawRectangleLinesEx(rec, 1, RED);
+ DrawTriangle((Vector2){ rec.x + rec.width - MOUSE_SCALE_MARK_SIZE, rec.y + rec.height },
+ (Vector2){ rec.x + rec.width, rec.y + rec.height },
+ (Vector2){ rec.x + rec.width, rec.y + rec.height - MOUSE_SCALE_MARK_SIZE }, RED);
+ }
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file