Skip to content
This repository has been archived by the owner on Feb 19, 2025. It is now read-only.

Commit

Permalink
Fix Zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
aplerdal committed Feb 17, 2024
1 parent 7811616 commit fb644c4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions TrackEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,18 @@ public void ScrollWheel(SDL_Event e)
if (e.wheel.y == 0) return;

var scroll = e.wheel.y / Math.Abs(e.wheel.y);
tilemap.tileSize = Math.Clamp(tilemap.tileSize + scroll, 1, 32);
double oldSize = tilemap.tileSize;
tilemap.tileSize = Math.Clamp(tilemap.tileSize + scroll, 2, 32);

var offsetX = tilemap.rows * tilemap.tileSize / 2;
var offsetY = tilemap.columns * tilemap.tileSize / 2;
double scaleFactor = tilemap.tileSize / oldSize -1;

var offsetX = mousePosition.X * scaleFactor;
var offsetY = mousePosition.Y * scaleFactor;

tilemap.ContentPosition = new Point
(
mousePosition.X - offsetX,
mousePosition.Y - offsetY
(int)(tilemap.ContentPosition.X * (scaleFactor+1) - offsetX),
(int)(tilemap.ContentPosition.Y * (scaleFactor+1) - offsetY)
);


Expand Down

0 comments on commit fb644c4

Please sign in to comment.