diff options
| author | ChrisDill <[email protected]> | 2019-07-28 10:12:13 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2019-07-28 11:12:13 +0200 |
| commit | 879c874330e2946ca0dcce74a5dfbe852b4d1f4a (patch) | |
| tree | e2745d0c01ef19f825b9f5ecde352f8682fd7cb8 /examples/core | |
| parent | 153f078bd135af4d947feaa35367c21f5ecdd854 (diff) | |
| download | raylib-879c874330e2946ca0dcce74a5dfbe852b4d1f4a.tar.gz raylib-879c874330e2946ca0dcce74a5dfbe852b4d1f4a.zip | |
Added scissor test and mouse painting examples proposed in #890 (#919)
- Updated Makefile with new examples
Diffstat (limited to 'examples/core')
| -rw-r--r-- | examples/core/core_scissor_test.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/examples/core/core_scissor_test.c b/examples/core/core_scissor_test.c new file mode 100644 index 00000000..acc84202 --- /dev/null +++ b/examples/core/core_scissor_test.c @@ -0,0 +1,77 @@ +/******************************************************************************************* +* +* raylib [core] example - Scissor test +* +* 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 Chris Dill (@MysteriousSpace) +* +********************************************************************************************/ + +#include "raylib.h" + +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - scissor test"); + + Rectangle scissorArea = { 0, 0, 300, 300}; + bool scissorMode = true; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_S)) + { + scissorMode = !scissorMode; + } + + // Centre the scissor area around the mouse position + scissorArea.x = GetMouseX() - scissorArea.width / 2; + scissorArea.y = GetMouseY() - scissorArea.height / 2; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (scissorMode) + { + BeginScissorMode(scissorArea.x, scissorArea.y, scissorArea.width, scissorArea.height); + } + + DrawRectangle(80, 45, 640, 360, RED); + DrawRectangleLines(80, 45, 640, 360, BLACK); + DrawText("Move the mouse around to reveal this text!", 190, 200, 20, LIGHTGRAY); + + if (scissorMode) + { + EndScissorMode(); + } + + DrawRectangleLinesEx(scissorArea, 2, BLACK); + DrawText("Press s to toggle scissor test", 10, 10, 20, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} |
