Skip to content

Commit

Permalink
Update core_2d_camera_mouse_zoom.c
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Nov 6, 2024
1 parent b47fffb commit a617e1e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions examples/core/core_2d_camera_mouse_zoom.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main ()
else if (IsKeyPressed(KEY_TWO)) zoomMode = 1;

// Translate based on mouse right click
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
{
Vector2 delta = GetMouseDelta();
delta = Vector2Scale(delta, -1.0f/camera.zoom);
Expand Down Expand Up @@ -76,8 +76,8 @@ int main ()
}
else
{
// Zoom based on mouse left click
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
// Zoom based on mouse right click
if (IsMouseButtonPressed(MOUSE_BUTTON_RIGHT))
{
// Get the world point that is under the mouse
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
Expand All @@ -89,7 +89,7 @@ int main ()
// under the cursor to the screen space point under the cursor at any zoom
camera.target = mouseWorldPos;
}
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT))
if (IsMouseButtonDown(MOUSE_BUTTON_RIGHT))
{
// Zoom increment
float deltaX = GetMouseDelta().x;
Expand Down Expand Up @@ -119,10 +119,16 @@ int main ()
DrawCircle(GetScreenWidth()/2, GetScreenHeight()/2, 50, MAROON);

EndMode2D();

// Draw mouse reference
//Vector2 mousePos = GetWorldToScreen2D(GetMousePosition(), camera)
DrawCircleV(GetMousePosition(), 4, DARKGRAY);
DrawTextEx(GetFontDefault(), TextFormat("[%i, %i]", GetMouseX(), GetMouseY()),
Vector2Add(GetMousePosition(), (Vector2){ -44, -24 }), 20, 2, BLACK);

DrawText("[1][2] Select mouse zoom mode (Wheel or Move)", 20, 20, 20, DARKGRAY);
if (zoomMode == 0) DrawText("Mouse right button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
else DrawText("Mouse right button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);
if (zoomMode == 0) DrawText("Mouse left button drag to move, mouse wheel to zoom", 20, 50, 20, DARKGRAY);
else DrawText("Mouse left button drag to move, mouse press and move to zoom", 20, 50, 20, DARKGRAY);

EndDrawing();
//----------------------------------------------------------------------------------
Expand Down

0 comments on commit a617e1e

Please sign in to comment.