aboutsummaryrefslogtreecommitdiff
path: root/deps/raylib/examples/shapes/shapes_rectangle_scaling.c
diff options
context:
space:
mode:
authorbonmas14 <bonmas14@gmail.com>2025-09-20 22:28:15 +0300
committerbonmas14 <bonmas14@gmail.com>2025-09-20 22:28:15 +0300
commitcdda4c4182c9ee068567529715e4a5c68a8efb58 (patch)
tree38a63f62a64018a2d35fc33354f8589fd33b7514 /deps/raylib/examples/shapes/shapes_rectangle_scaling.c
downloadc_wizard-cdda4c4182c9ee068567529715e4a5c68a8efb58.tar.gz
c_wizard-cdda4c4182c9ee068567529715e4a5c68a8efb58.zip
Init commit v1.0
Diffstat (limited to 'deps/raylib/examples/shapes/shapes_rectangle_scaling.c')
-rw-r--r--deps/raylib/examples/shapes/shapes_rectangle_scaling.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/deps/raylib/examples/shapes/shapes_rectangle_scaling.c b/deps/raylib/examples/shapes/shapes_rectangle_scaling.c
new file mode 100644
index 0000000..dcafab9
--- /dev/null
+++ b/deps/raylib/examples/shapes/shapes_rectangle_scaling.c
@@ -0,0 +1,103 @@
+/*******************************************************************************************
+*
+* raylib [shapes] example - rectangle scaling by mouse
+*
+* Example originally created with raylib 2.5, last time updated with raylib 2.5
+*
+* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
+*
+* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
+* BSD-like license that allows static linking with closed source software
+*
+* Copyright (c) 2018-2024 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+#define MOUSE_SCALE_MARK_SIZE 12
+
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+int main(void)
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const 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); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!WindowShouldClose()) // Detect window close button or ESC key
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ mousePosition = GetMousePosition();
+
+ if (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_BUTTON_LEFT)) mouseScaleMode = true;
+ }
+ else mouseScaleReady = false;
+
+ if (mouseScaleMode)
+ {
+ mouseScaleReady = true;
+
+ rec.width = (mousePosition.x - rec.x);
+ rec.height = (mousePosition.y - rec.y);
+
+ // Check minimum rec size
+ 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;
+
+ // Check maximum rec size
+ if (rec.width > (GetScreenWidth() - rec.x)) rec.width = GetScreenWidth() - rec.x;
+ if (rec.height > (GetScreenHeight() - rec.y)) rec.height = GetScreenHeight() - rec.y;
+
+ if (IsMouseButtonReleased(MOUSE_BUTTON_LEFT)) 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