Skip to content

Commit

Permalink
update shapes rectangle scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
CrackedPixel committed Aug 7, 2024
1 parent 9c2ba3b commit e82c27c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions examples/shapes/shapes_rectangle_scaling.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(void)

Vector2 mousePosition = { 0 };

bool mouseScaleReady = false;
bool mouseOverRectangle = false;
bool mouseScaleMode = false;

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
Expand All @@ -46,17 +46,19 @@ int main(void)
//----------------------------------------------------------------------------------
mousePosition = GetMousePosition();

if (CheckCollisionPointRec(mousePosition, rec))
{
mouseOverRectangle = true;
}
else mouseOverRectangle = false;

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);

Expand All @@ -82,7 +84,7 @@ int main(void)

DrawRectangleRec(rec, Fade(GREEN, 0.5f));

if (mouseScaleReady)
if (mouseOverRectangle || mouseScaleMode)
{
DrawRectangleLinesEx(rec, 1, RED);
DrawTriangle((Vector2){ rec.x + rec.width - MOUSE_SCALE_MARK_SIZE, rec.y + rec.height },
Expand Down

0 comments on commit e82c27c

Please sign in to comment.