summaryrefslogtreecommitdiffhomepage
path: root/examples/shapes
diff options
context:
space:
mode:
authorRay <[email protected]>2019-04-11 18:07:20 +0200
committerRay <[email protected]>2019-04-11 18:07:20 +0200
commite54a74f4e7842b0e33f8cf8f7d78e58e297e1cb0 (patch)
tree467e2a544c449cbc9d061ec9fa34a2f91b11b886 /examples/shapes
parent24f07aaf5a58aa1fc1d18a9eae4327f5a3f58014 (diff)
downloadraylib-e54a74f4e7842b0e33f8cf8f7d78e58e297e1cb0.tar.gz
raylib-e54a74f4e7842b0e33f8cf8f7d78e58e297e1cb0.zip
new example: shapes_rectangle_scaling_mouse
Diffstat (limited to 'examples/shapes')
-rw-r--r--examples/shapes/shapes_rectangle_scaling_mouse.c92
-rw-r--r--examples/shapes/shapes_rectangle_scaling_mouse.pngbin0 -> 15191 bytes
2 files changed, 92 insertions, 0 deletions
diff --git a/examples/shapes/shapes_rectangle_scaling_mouse.c b/examples/shapes/shapes_rectangle_scaling_mouse.c
new file mode 100644
index 00000000..d8c521ca
--- /dev/null
+++ b/examples/shapes/shapes_rectangle_scaling_mouse.c
@@ -0,0 +1,92 @@
+/*******************************************************************************************
+*
+* 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)
+*
+* Copyright (c) 2019 Demioz 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
diff --git a/examples/shapes/shapes_rectangle_scaling_mouse.png b/examples/shapes/shapes_rectangle_scaling_mouse.png
new file mode 100644
index 00000000..83d67de9
--- /dev/null
+++ b/examples/shapes/shapes_rectangle_scaling_mouse.png
Binary files differ