diff options
| author | Arne Dußin | 2020-11-02 00:53:18 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-02 00:53:18 +0100 |
| commit | 81b531aaec7ad12b138dbf1bd2c24d2bd4352024 (patch) | |
| tree | afbc9a7671a0b15e295ce9d65dc33b009f3cd174 /src/transform.rs | |
| parent | a3513e6ba22a00899b6c63ea7ce768e2f9fcd462 (diff) | |
| download | graf_karto-81b531aaec7ad12b138dbf1bd2c24d2bd4352024.tar.gz graf_karto-81b531aaec7ad12b138dbf1bd2c24d2bd4352024.zip | |
Tether on zoom
Diffstat (limited to 'src/transform.rs')
| -rw-r--r-- | src/transform.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/transform.rs b/src/transform.rs index ca359f0..b0b0e0a 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -96,11 +96,17 @@ impl Transform { /// Attempts to zoom in a step and return true. /// If the maximum zoom is reached, this function changes nothing and returns false. - pub fn try_zoom_in(&mut self) -> bool { - // TODO: Zoom in on mouse pointer position + pub fn try_zoom_in(&mut self, mouse_pos_px: Vec2<f32>) -> bool { if self.pixels_per_m < MAX_PIXELS_PER_M { + // Save the absolute mouse position for tethering later + let mouse_pos_m = self.point_px_to_m(mouse_pos_px); + self.pixels_per_m *= 1.2; self.normalise_zoom(); + + // Perform tethering (zoom in on mouse position) + self.translation_px += mouse_pos_px - self.point_m_to_px(mouse_pos_m); + true } else { false @@ -109,11 +115,18 @@ impl Transform { /// Attempts to zoom out a step and return true. /// If the minimum zoom is reached, this function changes nothing and returns false. - pub fn try_zoom_out(&mut self) -> bool { + pub fn try_zoom_out(&mut self, mouse_pos_px: Vec2<f32>) -> bool { // TODO: Zoom out at mouse pointer position if self.pixels_per_m > MIN_PIXELS_PER_M { + // Save the absolute mouse position for tethering later + let mouse_pos_m = self.point_px_to_m(mouse_pos_px); + self.pixels_per_m /= 1.2; self.normalise_zoom(); + + // Perform tethering (zoom out at mouse position) + self.translation_px += mouse_pos_px - self.point_m_to_px(mouse_pos_m); + true } else { false |
