diff options
| author | Ray <[email protected]> | 2019-05-14 15:34:23 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-05-14 15:34:23 +0200 |
| commit | 424d3ca8d9c5d612606444b2a2099cfad37f1888 (patch) | |
| tree | 873e8ec9dbd5965d828ed450a8c12feafe714597 /examples/shapes | |
| parent | 2edec8ae288ba70630021b330fe61c9005bc03d9 (diff) | |
| download | raylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.tar.gz raylib-424d3ca8d9c5d612606444b2a2099cfad37f1888.zip | |
examples review
Redesigns, deletes and renames
Also noted authors propertly on contributed examples
Diffstat (limited to 'examples/shapes')
| -rw-r--r-- | examples/shapes/shapes_colors_palette.c | 114 | ||||
| -rw-r--r-- | examples/shapes/shapes_colors_palette.png | bin | 6591 -> 18089 bytes | |||
| -rw-r--r-- | examples/shapes/shapes_draw_circle_sector.c | 4 | ||||
| -rw-r--r-- | examples/shapes/shapes_draw_rectangle_rounded.c | 4 | ||||
| -rw-r--r-- | examples/shapes/shapes_draw_ring.c | 4 | ||||
| -rw-r--r-- | examples/shapes/shapes_rectangle_scaling.c (renamed from examples/shapes/shapes_rectangle_scaling_mouse.c) | 4 | ||||
| -rw-r--r-- | examples/shapes/shapes_rectangle_scaling.png (renamed from examples/shapes/shapes_rectangle_scaling_mouse.png) | bin | 15191 -> 15191 bytes |
7 files changed, 70 insertions, 60 deletions
diff --git a/examples/shapes/shapes_colors_palette.c b/examples/shapes/shapes_colors_palette.c index dcab862e..d6ac30a9 100644 --- a/examples/shapes/shapes_colors_palette.c +++ b/examples/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/shapes/shapes_colors_palette.png b/examples/shapes/shapes_colors_palette.png Binary files differindex 4073b670..b68e497e 100644 --- a/examples/shapes/shapes_colors_palette.png +++ b/examples/shapes/shapes_colors_palette.png diff --git a/examples/shapes/shapes_draw_circle_sector.c b/examples/shapes/shapes_draw_circle_sector.c index a88a59d5..597b85a7 100644 --- a/examples/shapes/shapes_draw_circle_sector.c +++ b/examples/shapes/shapes_draw_circle_sector.c @@ -5,7 +5,9 @@ * 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) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5) +* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/shapes/shapes_draw_rectangle_rounded.c b/examples/shapes/shapes_draw_rectangle_rounded.c index 35fe63fb..e36e2731 100644 --- a/examples/shapes/shapes_draw_rectangle_rounded.c +++ b/examples/shapes/shapes_draw_rectangle_rounded.c @@ -5,7 +5,9 @@ * 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) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5) +* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/shapes/shapes_draw_ring.c b/examples/shapes/shapes_draw_ring.c index d56b9c2e..44a3ec5f 100644 --- a/examples/shapes/shapes_draw_ring.c +++ b/examples/shapes/shapes_draw_ring.c @@ -5,7 +5,9 @@ * 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) 2019 Vlad Adrian (@Demizdor) and Ramon Santamaria (@raysan5) +* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/shapes/shapes_rectangle_scaling_mouse.c b/examples/shapes/shapes_rectangle_scaling.c index d8c521ca..036a1dd4 100644 --- a/examples/shapes/shapes_rectangle_scaling_mouse.c +++ b/examples/shapes/shapes_rectangle_scaling.c @@ -5,7 +5,9 @@ * 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) 2019 Demioz and Ramon Santamaria (@raysan5) +* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) +* +* Copyright (c) 2018 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/shapes/shapes_rectangle_scaling_mouse.png b/examples/shapes/shapes_rectangle_scaling.png Binary files differindex 83d67de9..83d67de9 100644 --- a/examples/shapes/shapes_rectangle_scaling_mouse.png +++ b/examples/shapes/shapes_rectangle_scaling.png |
