Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Examples] update shapes rectangle scaling #4227

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading